Skip to content

Commit 65e0688

Browse files
authored
Fix raw endpoint PDF file headers (#19825)
1 parent 410df1f commit 65e0688

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

modules/typesniffer/typesniffer.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ import (
1717
// Use at most this many bytes to determine Content Type.
1818
const sniffLen = 1024
1919

20-
// SvgMimeType MIME type of SVG images.
21-
const SvgMimeType = "image/svg+xml"
20+
const (
21+
// SvgMimeType MIME type of SVG images.
22+
SvgMimeType = "image/svg+xml"
23+
// ApplicationOctetStream MIME type of binary files.
24+
ApplicationOctetStream = "application/octet-stream"
25+
)
2226

2327
var (
2428
svgTagRegex = regexp.MustCompile(`(?si)\A\s*(?:(<!--.*?-->|<!DOCTYPE\s+svg([\s:]+.*?>|>))\s*)*<svg[\s>\/]`)

routers/common/repo.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,14 @@ func ServeData(ctx *context.Context, name string, size int64, reader io.Reader)
8888
}
8989
if (st.IsImage() || st.IsPDF()) && (setting.UI.SVG.Enabled || !st.IsSvgImage()) {
9090
ctx.Resp.Header().Set("Content-Disposition", fmt.Sprintf(`inline; filename="%s"`, name))
91-
if st.IsSvgImage() {
91+
if st.IsSvgImage() || st.IsPDF() {
9292
ctx.Resp.Header().Set("Content-Security-Policy", "default-src 'none'; style-src 'unsafe-inline'; sandbox")
9393
ctx.Resp.Header().Set("X-Content-Type-Options", "nosniff")
94-
ctx.Resp.Header().Set("Content-Type", typesniffer.SvgMimeType)
94+
if st.IsSvgImage() {
95+
ctx.Resp.Header().Set("Content-Type", typesniffer.SvgMimeType)
96+
} else {
97+
ctx.Resp.Header().Set("Content-Type", typesniffer.ApplicationOctetStream)
98+
}
9599
}
96100
} else {
97101
ctx.Resp.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, name))

0 commit comments

Comments
 (0)