Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(server): revert CSP for HTML while making shareRaw dangerous
Elian Doranb2d501604eb4
diff --git a/apps/server/src/share/routes.ts b/apps/server/src/share/routes.tsindex e1027e6f2a..d40745e9b9 100644--- a/apps/server/src/share/routes.ts+++ b/apps/server/src/share/routes.ts@@ -143,9 +143,13 @@ function register(router: Router) {addNoIndexHeader(note, res);if (note.isLabelTruthy("shareRaw") || typeof req.query.raw !== "undefined") {- // For HTML and SVG content, add restrictive Content-Security-Policy- // to prevent stored XSS via script execution (CWE-79).- if (note.mime === "text/html" || note.mime === "image/svg+xml") {+ // For SVG content, add a restrictive Content-Security-Policy to prevent+ // stored XSS via script execution (CWE-79). HTML is intentionally served+ // unrestricted here: serving raw HTML requires the `#shareRaw` attribute (or an+ // explicit `?raw`), and `#shareRaw` is flagged dangerous (see builtin_attributes.ts),+ // so the instance owner is deliberately opting in to serve their own scriptable+ // content. Restricting it would break legitimate self-contained HTML pages.+ if (note.mime === "image/svg+xml") {res.setHeader("Content-Security-Policy", "default-src 'none'; style-src 'unsafe-inline'; img-src * data:; font-src * data:");res.setHeader("X-Content-Type-Options", "nosniff");}diff --git a/packages/commons/src/lib/builtin_attributes.ts b/packages/commons/src/lib/builtin_attributes.tsindex 54dae5aa65..4038752845 100644--- a/packages/commons/src/lib/builtin_attributes.ts+++ b/packages/commons/src/lib/builtin_attributes.ts@@ -63,7 +63,7 @@ export default [{ type: "label", name: "shareOmitDefaultCss" },{ type: "label", name: "shareRoot" },{ type: "label", name: "shareDescription" },- { type: "label", name: "shareRaw" },+ { type: "label", name: "shareRaw", isDangerous: true },{ type: "label", name: "shareDisallowRobotIndexing" },{ type: "label", name: "shareCredentials" },{ type: "label", name: "shareIndex" },