Skip to content

Commit 4dceedd

Browse files
committed
restore setting.UI.SVG.Enabled behaviour
1 parent b40db99 commit 4dceedd

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

routers/common/repo.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,10 @@ func ServeData(ctx *context.Context, filePath string, size int64, reader io.Read
9797
}
9898
ctx.Resp.Header().Set("X-Content-Type-Options", "nosniff")
9999

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

112+
disposition := "inline"
113+
if isSVG && !setting.UI.SVG.Enabled {
114+
disposition = "attachment"
115+
}
116+
110117
// encode filename per https://datatracker.ietf.org/doc/html/rfc5987
111-
ctx.Resp.Header().Set("Content-Disposition", `inline; filename*=UTF-8''`+url.PathEscape(fileName))
118+
encodedFileName := `filename*=UTF-8''` + url.PathEscape(fileName)
119+
120+
ctx.Resp.Header().Set("Content-Disposition", disposition+"; "+encodedFileName)
112121
ctx.Resp.Header().Set("Access-Control-Expose-Headers", "Content-Disposition")
113122

114123
_, err = ctx.Resp.Write(buf)

0 commit comments

Comments
 (0)