Skip to content

Commit

Permalink
Fix tarball/zipball download bug (go-gitea#29342) (go-gitea#29352)
Browse files Browse the repository at this point in the history
Backport go-gitea#29342 by @Zettat123

Fix go-gitea#29249

~~Use the `/repos/{owner}/{repo}/archive/{archive}` API to download.~~

Apply go-gitea#26430 to archive download URLs.

Co-authored-by: Zettat123 <zettat123@gmail.com>
  • Loading branch information
GiteaBot and Zettat123 authored Feb 23, 2024
1 parent 874cdcc commit 829b807
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions services/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,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 {
Expand All @@ -54,6 +55,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...
Expand Down
2 changes: 1 addition & 1 deletion services/auth/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 829b807

Please sign in to comment.