Skip to content

Commit

Permalink
Allow token as authorization for accessing attachments (#7909)
Browse files Browse the repository at this point in the history
* Allow token as authorization for accessing attachments

Signed-off-by: David Svantesson <davidsvantesson@gmail.com>

* Only allow token authentication for attachments if it is a download (GET)
  • Loading branch information
davidsvantesson authored and sapk committed Aug 24, 2019
1 parent 70d2244 commit ce45a8c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion modules/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,19 @@ func IsAPIPath(url string) bool {
return strings.HasPrefix(url, "/api/")
}

// IsAttachmentDownload check if request is a file download (GET) with URL to an attachment
func IsAttachmentDownload(ctx *macaron.Context) bool {
return strings.HasPrefix(ctx.Req.URL.Path, "/attachments/") && ctx.Req.Method == "GET"
}

// SignedInID returns the id of signed in user.
func SignedInID(ctx *macaron.Context, sess session.Store) int64 {
if !models.HasEngine {
return 0
}

// Check access token.
if IsAPIPath(ctx.Req.URL.Path) {
if IsAPIPath(ctx.Req.URL.Path) || IsAttachmentDownload(ctx) {
tokenSHA := ctx.Query("token")
if len(tokenSHA) == 0 {
tokenSHA = ctx.Query("access_token")
Expand Down

0 comments on commit ce45a8c

Please sign in to comment.