Skip to content

Commit

Permalink
restore setting.UI.SVG.Enabled behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
silverwind committed Jul 27, 2022
1 parent b40db99 commit 4dceedd
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions routers/common/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ func ServeData(ctx *context.Context, filePath string, size int64, reader io.Read
}
ctx.Resp.Header().Set("X-Content-Type-Options", "nosniff")

isSVG := sniffedType.IsSvgImage()

// serve types that can present a security risk with CSP
if sniffedType.IsSvgImage() {
if isSVG {
ctx.Resp.Header().Set("Content-Security-Policy", "default-src 'none'; style-src 'unsafe-inline'; sandbox")
} else if sniffedType.IsPDF() {
// no sandbox attribute for pdf as it breaks rendering in at least safari. this
Expand All @@ -107,8 +109,15 @@ func ServeData(ctx *context.Context, filePath string, size int64, reader io.Read
ctx.Resp.Header().Set("Content-Security-Policy", "default-src 'none'; style-src 'unsafe-inline'")
}

disposition := "inline"
if isSVG && !setting.UI.SVG.Enabled {
disposition = "attachment"
}

// encode filename per https://datatracker.ietf.org/doc/html/rfc5987
ctx.Resp.Header().Set("Content-Disposition", `inline; filename*=UTF-8''`+url.PathEscape(fileName))
encodedFileName := `filename*=UTF-8''` + url.PathEscape(fileName)

ctx.Resp.Header().Set("Content-Disposition", disposition+"; "+encodedFileName)
ctx.Resp.Header().Set("Access-Control-Expose-Headers", "Content-Disposition")

_, err = ctx.Resp.Write(buf)
Expand Down

0 comments on commit 4dceedd

Please sign in to comment.