@@ -97,8 +97,10 @@ func ServeData(ctx *context.Context, filePath string, size int64, reader io.Read
97
97
}
98
98
ctx .Resp .Header ().Set ("X-Content-Type-Options" , "nosniff" )
99
99
100
+ isSVG := sniffedType .IsSvgImage ()
101
+
100
102
// serve types that can present a security risk with CSP
101
- if sniffedType . IsSvgImage () {
103
+ if isSVG {
102
104
ctx .Resp .Header ().Set ("Content-Security-Policy" , "default-src 'none'; style-src 'unsafe-inline'; sandbox" )
103
105
} else if sniffedType .IsPDF () {
104
106
// 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
107
109
ctx .Resp .Header ().Set ("Content-Security-Policy" , "default-src 'none'; style-src 'unsafe-inline'" )
108
110
}
109
111
112
+ disposition := "inline"
113
+ if isSVG && ! setting .UI .SVG .Enabled {
114
+ disposition = "attachment"
115
+ }
116
+
110
117
// 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 )
112
121
ctx .Resp .Header ().Set ("Access-Control-Expose-Headers" , "Content-Disposition" )
113
122
114
123
_ , err = ctx .Resp .Write (buf )
0 commit comments