Skip to content

Commit a75b2f2

Browse files
authored
Allow BASIC authentication access to /:owner/:repo/releases/download/* (#16916)
Duplicate #15987 to allow access to releases download through BASIC authentication. Fix #16914 Signed-off-by: Andrew Thornton <art27@cantab.net>
1 parent 268b2d0 commit a75b2f2

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

services/auth/auth.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ func isAttachmentDownload(req *http.Request) bool {
9090
return strings.HasPrefix(req.URL.Path, "/attachments/") && req.Method == "GET"
9191
}
9292

93-
var gitRawPathRe = regexp.MustCompile(`^/[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+/(?:(?:git-(?:(?:upload)|(?:receive))-pack$)|(?:info/refs$)|(?:HEAD$)|(?:objects/)|raw/)`)
93+
var gitRawReleasePathRe = regexp.MustCompile(`^/[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+/(?:(?:git-(?:(?:upload)|(?:receive))-pack$)|(?:info/refs$)|(?:HEAD$)|(?:objects/)|(?:raw/)|(?:releases/download/))`)
9494
var lfsPathRe = regexp.MustCompile(`^/[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+/info/lfs/`)
9595

96-
func isGitRawOrLFSPath(req *http.Request) bool {
97-
if gitRawPathRe.MatchString(req.URL.Path) {
96+
func isGitRawReleaseOrLFSPath(req *http.Request) bool {
97+
if gitRawReleasePathRe.MatchString(req.URL.Path) {
9898
return true
9999
}
100100
if setting.LFS.StartServer {

services/auth/auth_test.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ func Test_isGitRawOrLFSPath(t *testing.T) {
8383
"/owner/repo/commit/123456789012345678921234567893124567894",
8484
false,
8585
},
86+
{
87+
"/owner/repo/releases/download/tag/repo.tar.gz",
88+
true,
89+
},
8690
}
8791
lfsTests := []string{
8892
"/owner/repo/info/lfs/",
@@ -102,11 +106,11 @@ func Test_isGitRawOrLFSPath(t *testing.T) {
102106
t.Run(tt.path, func(t *testing.T) {
103107
req, _ := http.NewRequest("POST", "http://localhost"+tt.path, nil)
104108
setting.LFS.StartServer = false
105-
if got := isGitRawOrLFSPath(req); got != tt.want {
109+
if got := isGitRawReleaseOrLFSPath(req); got != tt.want {
106110
t.Errorf("isGitOrLFSPath() = %v, want %v", got, tt.want)
107111
}
108112
setting.LFS.StartServer = true
109-
if got := isGitRawOrLFSPath(req); got != tt.want {
113+
if got := isGitRawReleaseOrLFSPath(req); got != tt.want {
110114
t.Errorf("isGitOrLFSPath() = %v, want %v", got, tt.want)
111115
}
112116
})
@@ -115,11 +119,11 @@ func Test_isGitRawOrLFSPath(t *testing.T) {
115119
t.Run(tt, func(t *testing.T) {
116120
req, _ := http.NewRequest("POST", tt, nil)
117121
setting.LFS.StartServer = false
118-
if got := isGitRawOrLFSPath(req); got != setting.LFS.StartServer {
119-
t.Errorf("isGitOrLFSPath(%q) = %v, want %v, %v", tt, got, setting.LFS.StartServer, gitRawPathRe.MatchString(tt))
122+
if got := isGitRawReleaseOrLFSPath(req); got != setting.LFS.StartServer {
123+
t.Errorf("isGitOrLFSPath(%q) = %v, want %v, %v", tt, got, setting.LFS.StartServer, gitRawReleasePathRe.MatchString(tt))
120124
}
121125
setting.LFS.StartServer = true
122-
if got := isGitRawOrLFSPath(req); got != setting.LFS.StartServer {
126+
if got := isGitRawReleaseOrLFSPath(req); got != setting.LFS.StartServer {
123127
t.Errorf("isGitOrLFSPath(%q) = %v, want %v", tt, got, setting.LFS.StartServer)
124128
}
125129
})

services/auth/basic.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (b *Basic) Name() string {
4040
// Returns nil if header is empty or validation fails.
4141
func (b *Basic) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User {
4242
// Basic authentication should only fire on API, Download or on Git or LFSPaths
43-
if !middleware.IsAPIPath(req) && !isAttachmentDownload(req) && !isGitRawOrLFSPath(req) {
43+
if !middleware.IsAPIPath(req) && !isAttachmentDownload(req) && !isGitRawReleaseOrLFSPath(req) {
4444
return nil
4545
}
4646

services/auth/reverseproxy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (r *ReverseProxy) Verify(req *http.Request, w http.ResponseWriter, store Da
7070
}
7171

7272
// Make sure requests to API paths, attachment downloads, git and LFS do not create a new session
73-
if !middleware.IsAPIPath(req) && !isAttachmentDownload(req) && !isGitRawOrLFSPath(req) {
73+
if !middleware.IsAPIPath(req) && !isAttachmentDownload(req) && !isGitRawReleaseOrLFSPath(req) {
7474
if sess != nil && (sess.Get("uid") == nil || sess.Get("uid").(int64) != user.ID) {
7575
handleSignIn(w, req, sess, user)
7676
}

0 commit comments

Comments
 (0)