The minimalistic document archiving platform.
fix(documents): enhance file fetching security by setting appropriate headers (#499)
Corentin Thomasset40cb1d71d5e5
diff --git a/.changeset/seven-drinks-wait.md b/.changeset/seven-drinks-wait.mdnew file mode 100644index 00000000..270389f2--- /dev/null+++ b/.changeset/seven-drinks-wait.md@@ -0,0 +1,5 @@+---+"@papra/app-server": patch+---++Enhanced security by serving files as attachement and with an octet-stream content typediff --git a/apps/papra-server/src/modules/documents/documents.routes.ts b/apps/papra-server/src/modules/documents/documents.routes.tsindex d283ff5d..701113bd 100644--- a/apps/papra-server/src/modules/documents/documents.routes.ts+++ b/apps/papra-server/src/modules/documents/documents.routes.ts@@ -288,9 +288,13 @@ function setupGetDocumentFileRoute({ app, db, documentsStorageService }: RouteDeReadable.toWeb(fileStream),200,{- 'Content-Type': document.mimeType,- 'Content-Disposition': `inline; filename*=UTF-8''${encodeURIComponent(document.name)}`,+ // Prevent XSS by serving the file as an octet-stream+ 'Content-Type': 'application/octet-stream',+ // Always use attachment for defense in depth - client uses blob API anyway+ 'Content-Disposition': `attachment; filename*=UTF-8''${encodeURIComponent(document.name)}`,'Content-Length': String(document.originalSize),+ 'X-Content-Type-Options': 'nosniff',+ 'X-Frame-Options': 'DENY',},);},