aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZettat123 <zettat123@gmail.com>2024-02-24 01:49:46 +0800
committerGitHub <noreply@github.com>2024-02-23 17:49:46 +0000
commitb762a1f1b1f7941a7db2207552d7b441d868cbe9 (patch)
treee1dc1f1f58dae269e67c5b667fb40ebe08a23f75
parent2a278b996fd6608973c3ab2a2cfb584e67d5bd8b (diff)
downloadgitea-b762a1f1b1f7941a7db2207552d7b441d868cbe9.tar.gz
gitea-b762a1f1b1f7941a7db2207552d7b441d868cbe9.zip
Fix tarball/zipball download bug (#29342)
Fix #29249 ~~Use the `/repos/{owner}/{repo}/archive/{archive}` API to download.~~ Apply #26430 to archive download URLs.
-rw-r--r--services/auth/auth.go5
-rw-r--r--services/auth/oauth2.go2
2 files changed, 6 insertions, 1 deletions
diff --git a/services/auth/auth.go b/services/auth/auth.go
index 6746dc2a54..7c07dc438e 100644
--- a/services/auth/auth.go
+++ b/services/auth/auth.go
@@ -40,6 +40,7 @@ func isContainerPath(req *http.Request) bool {
var (
gitRawOrAttachPathRe = regexp.MustCompile(`^/[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+/(?:(?:git-(?:(?:upload)|(?:receive))-pack$)|(?:info/refs$)|(?:HEAD$)|(?:objects/)|(?:raw/)|(?:releases/download/)|(?:attachments/))`)
lfsPathRe = regexp.MustCompile(`^/[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+/info/lfs/`)
+ archivePathRe = regexp.MustCompile(`^/[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+/archive/`)
)
func isGitRawOrAttachPath(req *http.Request) bool {
@@ -56,6 +57,10 @@ func isGitRawOrAttachOrLFSPath(req *http.Request) bool {
return false
}
+func isArchivePath(req *http.Request) bool {
+ return archivePathRe.MatchString(req.URL.Path)
+}
+
// handleSignIn clears existing session variables and stores new ones for the specified user object
func handleSignIn(resp http.ResponseWriter, req *http.Request, sess SessionStore, user *user_model.User) {
// We need to regenerate the session...
diff --git a/services/auth/oauth2.go b/services/auth/oauth2.go
index f2f7858a85..46d8510143 100644
--- a/services/auth/oauth2.go
+++ b/services/auth/oauth2.go
@@ -133,7 +133,7 @@ func (o *OAuth2) userIDFromToken(ctx context.Context, tokenSHA string, store Dat
func (o *OAuth2) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) (*user_model.User, error) {
// These paths are not API paths, but we still want to check for tokens because they maybe in the API returned URLs
if !middleware.IsAPIPath(req) && !isAttachmentDownload(req) && !isAuthenticatedTokenRequest(req) &&
- !isGitRawOrAttachPath(req) {
+ !isGitRawOrAttachPath(req) && !isArchivePath(req) {
return nil, nil
}