diff options
author | Giteabot <teabot@gitea.io> | 2023-10-11 10:39:12 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-11 04:39:12 +0200 |
commit | 9da92835d18f20261e4e97c0e97a7dd74a78f01c (patch) | |
tree | 2a3606b931203327efcb9e9e3ea2aa2403b0a2d2 /services/auth/auth.go | |
parent | 478e7042f5c4b4da9f72b11ee55a171e326a1603 (diff) | |
download | gitea-9da92835d18f20261e4e97c0e97a7dd74a78f01c.tar.gz gitea-9da92835d18f20261e4e97c0e97a7dd74a78f01c.zip |
Fix attachment download bug (#27486) (#27571)
Backport #27486 by @lunny
Fix #27204
This PR allows `/<username>/<reponame>/attachments/<uuid>` access with
personal access token and also changed attachments API download url to
it so it can be download correctly.
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'services/auth/auth.go')
-rw-r--r-- | services/auth/auth.go | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/services/auth/auth.go b/services/auth/auth.go index 0c8acac61f..713463a3d4 100644 --- a/services/auth/auth.go +++ b/services/auth/auth.go @@ -36,12 +36,16 @@ func isContainerPath(req *http.Request) bool { } var ( - gitRawReleasePathRe = regexp.MustCompile(`^/[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+/(?:(?:git-(?:(?:upload)|(?:receive))-pack$)|(?:info/refs$)|(?:HEAD$)|(?:objects/)|(?:raw/)|(?:releases/download/))`) - lfsPathRe = regexp.MustCompile(`^/[a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+/info/lfs/`) + 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/`) ) -func isGitRawReleaseOrLFSPath(req *http.Request) bool { - if gitRawReleasePathRe.MatchString(req.URL.Path) { +func isGitRawOrAttachPath(req *http.Request) bool { + return gitRawOrAttachPathRe.MatchString(req.URL.Path) +} + +func isGitRawOrAttachOrLFSPath(req *http.Request) bool { + if isGitRawOrAttachPath(req) { return true } if setting.LFS.StartServer { |