admin: view images and PDFs inline in the file browser (#9751)

The viewer embedded images and PDFs through the download URL, which sent
Content-Disposition: attachment, so the browser downloaded them instead of
rendering. Add an inline mode to the download endpoint, limited to images and
PDFs so a hostile upload (HTML, SVG) can't run as same-origin script, set
X-Content-Type-Options: nosniff, and resolve the MIME the same way the viewer
does. The viewer now requests the inline URL.
This commit is contained in:
Chris Lu authored and GitHub committed 2026-05-30 23:46:09 -07:00
1 parent 05c6500453
commit 186747e7e8
3 files changed
+17 -11

No files matched your search

+2 -2
View File
@@ -1788,7 +1788,7 @@ function createFileViewerContent(file, content) {
if (file.mime.startsWith('image/')) {
return `
<div class="text-center">
<img src="${basePath('/api/files/download?path=' + encodeURIComponent(file.full_path))}"
<img src="${basePath('/api/files/download?path=' + encodeURIComponent(file.full_path) + '&inline=true')}"
class="img-fluid" alt="${file.name}" style="max-height: 500px;">
</div>
`;
@@ -1806,7 +1806,7 @@ function createFileViewerContent(file, content) {
} else if (file.mime === 'application/pdf') {
return `
<div class="text-center">
<embed src="${basePath('/api/files/download?path=' + encodeURIComponent(file.full_path))}"
<embed src="${basePath('/api/files/download?path=' + encodeURIComponent(file.full_path) + '&inline=true')}"
type="application/pdf" width="100%" height="500px">
</div>
`;