Skip to content

Commit ceae89c

Browse files
authored
Allow BASIC authentication access to /:owner/:repo/releases/download/* (#16916) (#16923)
Backport #16916 Duplicate #15987 to allow access to releases download through BASIC authentication. Fix #16914 Signed-off-by: Andrew Thornton <[email protected]>
1 parent 8f30078 commit ceae89c

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
@@ -80,11 +80,11 @@ func isAttachmentDownload(req *http.Request) bool {
8080
return strings.HasPrefix(req.URL.Path, "/attachments/") && req.Method == "GET"
8181
}
8282

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

86-
func isGitRawOrLFSPath(req *http.Request) bool {
87-
if gitRawPathRe.MatchString(req.URL.Path) {
86+
func isGitRawReleaseOrLFSPath(req *http.Request) bool {
87+
if gitRawReleasePathRe.MatchString(req.URL.Path) {
8888
return true
8989
}
9090
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
@@ -49,7 +49,7 @@ func (b *Basic) Free() error {
4949
// Returns nil if header is empty or validation fails.
5050
func (b *Basic) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User {
5151
// Basic authentication should only fire on API, Download or on Git or LFSPaths
52-
if !middleware.IsAPIPath(req) && !isAttachmentDownload(req) && !isGitRawOrLFSPath(req) {
52+
if !middleware.IsAPIPath(req) && !isAttachmentDownload(req) && !isGitRawReleaseOrLFSPath(req) {
5353
return nil
5454
}
5555

services/auth/reverseproxy.go

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

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

0 commit comments

Comments
 (0)