Skip to content

Commit

Permalink
Prevent Authorization header for presigned LFS urls (go-gitea#21531)
Browse files Browse the repository at this point in the history
Fixes go-gitea#21525

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
  • Loading branch information
KN4CK3R and lunny committed Oct 23, 2022
1 parent 8043fbc commit 48c492e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions services/lfs/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,14 +438,21 @@ func buildObjectResponse(rc *requestContext, pointer lfs_module.Pointer, downloa
}

if download {
rep.Actions["download"] = &lfs_module.Link{Href: rc.DownloadLink(pointer), Header: header}
var link *lfs_module.Link
if setting.LFS.ServeDirect {
// If we have a signed url (S3, object storage), redirect to this directly.
u, err := storage.LFS.URL(pointer.RelativePath(), pointer.Oid)
if u != nil && err == nil {
rep.Actions["download"] = &lfs_module.Link{Href: u.String(), Header: header}
// Presigned url does not need the Authorization header
// https://github.com/go-gitea/gitea/issues/21525
delete(header, "Authorization")
link = &lfs_module.Link{Href: u.String(), Header: header}
}
}
if link == nil {
link = &lfs_module.Link{Href: rc.DownloadLink(pointer), Header: header}
}
rep.Actions["download"] = link
}
if upload {
rep.Actions["upload"] = &lfs_module.Link{Href: rc.UploadLink(pointer), Header: header}
Expand Down

0 comments on commit 48c492e

Please sign in to comment.