Skip to content

Commit 0d9d342

Browse files
committed
Remove sandbox attribute from PDF to make it work in Safari
1 parent ec4ce64 commit 0d9d342

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

routers/common/repo.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,16 @@ func ServeData(ctx *context.Context, filePath string, size int64, reader io.Read
9898
ctx.Resp.Header().Set("X-Content-Type-Options", "nosniff")
9999

100100
// serve types that can present a security risk with CSP
101-
if st.IsImage() || st.IsPDF() {
101+
if st.IsSvgImage() {
102102
ctx.Resp.Header().Set("Content-Security-Policy", "default-src 'none'; style-src 'unsafe-inline'; sandbox")
103+
} else if st.IsPDF() {
104+
// no sandbox attribute for pdf as it breaks rendering in at least safari. this
105+
// should generally be safe as scripts inside PDF can not escape the PDF document
106+
// see https://bugs.chromium.org/p/chromium/issues/detail?id=413851 for more discussion
107+
ctx.Resp.Header().Set("Content-Security-Policy", "default-src 'none'; style-src 'unsafe-inline'")
103108
}
104109

110+
105111
ctx.Resp.Header().Set("Content-Disposition", `inline; filename*=UTF-8''`+url.PathEscape(fileName))
106112
ctx.Resp.Header().Set("Access-Control-Expose-Headers", "Content-Disposition")
107113

0 commit comments

Comments
 (0)