Skip to content

Commit ce45a8c

Browse files
davidsvantessonsapk
authored andcommitted
Allow token as authorization for accessing attachments (#7909)
* Allow token as authorization for accessing attachments Signed-off-by: David Svantesson <[email protected]> * Only allow token authentication for attachments if it is a download (GET)
1 parent 70d2244 commit ce45a8c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

modules/auth/auth.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,19 @@ func IsAPIPath(url string) bool {
2929
return strings.HasPrefix(url, "/api/")
3030
}
3131

32+
// IsAttachmentDownload check if request is a file download (GET) with URL to an attachment
33+
func IsAttachmentDownload(ctx *macaron.Context) bool {
34+
return strings.HasPrefix(ctx.Req.URL.Path, "/attachments/") && ctx.Req.Method == "GET"
35+
}
36+
3237
// SignedInID returns the id of signed in user.
3338
func SignedInID(ctx *macaron.Context, sess session.Store) int64 {
3439
if !models.HasEngine {
3540
return 0
3641
}
3742

3843
// Check access token.
39-
if IsAPIPath(ctx.Req.URL.Path) {
44+
if IsAPIPath(ctx.Req.URL.Path) || IsAttachmentDownload(ctx) {
4045
tokenSHA := ctx.Query("token")
4146
if len(tokenSHA) == 0 {
4247
tokenSHA = ctx.Query("access_token")

0 commit comments

Comments
 (0)