From 89a4984964052f458b610f9fc59f8645e4e3f07a Mon Sep 17 00:00:00 2001 From: Christoph Schaefer Date: Tue, 6 Oct 2026 14:12:59 +0200 Subject: [PATCH 1/2] feat(nginx): add a Content-Security-Policy to the editor documents Harden the editor index.html responses with a script-focused CSP. The editor needs 'unsafe-eval' (eval/Function, WebAssembly) and blob: (Blob-URL Workers), so those stay; restricting script-src to 'self' is defense in depth so the editor context cannot load or dynamically import a script from another origin. A Blob-URL Worker inherits its document's policy, so Workers started from these pages are covered too. Scoped to every editor entry point under web-apps/apps: the main, mobile, embed and forms apps, and the index / index_loader / index_internal / index.reporter variants that getAppPath() can load. The redirector (common/index.html) and the api/documents helper pages are left out, as are all subresource responses. Minimal script/worker policy, not a full editor CSP: img-src, style-src, font-src, connect-src, frame-ancestors and the rest are intentionally left unset. nginx add_header does not merge across levels, so the Cache-Control from the block below is repeated here on purpose. Assisted-by: ClaudeCode:claude-opus-4-8 Signed-off-by: Christoph Schaefer --- .../nginx/includes/ds-docservice.conf.m4 | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/common/documentserver/nginx/includes/ds-docservice.conf.m4 b/common/documentserver/nginx/includes/ds-docservice.conf.m4 index 3c2659d..2f9d350 100644 --- a/common/documentserver/nginx/includes/ds-docservice.conf.m4 +++ b/common/documentserver/nginx/includes/ds-docservice.conf.m4 @@ -36,6 +36,25 @@ location ~ ^(\/[\d]+\.[\d]+\.[\d]+[\.|-][\w]+)?\/(sdkjs-plugins)(\/.*\.json)$ { alias M4_DS_ROOT/$2$3; } +# Harden the editor documents with a script-focused Content-Security-Policy. +# The editor compiles code at runtime (eval/Function, WebAssembly) and starts +# Blob-URL Workers, so 'unsafe-eval' and blob: have to stay. Pinning script-src +# to 'self' means the editor context can neither load nor dynamically import a +# script from another origin, and a Blob-URL Worker inherits this document's +# policy, so that restriction reaches those Workers too. This is a deliberately +# minimal script/worker policy; the other directives (img-src, style-src, +# font-src, connect-src, frame-ancestors, ...) are intentionally left unset. +# Covers every editor entry point: main, mobile, embed and forms, and the +# index/index_loader/index_internal/index.reporter variants getAppPath() loads. +# nginx add_header does not merge across levels, so the Cache-Control from the +# block below is repeated here on purpose. +location ~ ^(\/[\d]+\.[\d]+\.[\d]+[\.|-][\w]+)?\/(web-apps\/apps\/[^/]+\/(main|mobile|embed|forms)\/index[\w.]*\.html)$ { + add_header Cache-Control "public, max-age=31536000, immutable" always; + add_header Content-Security-Policy "script-src 'self' 'unsafe-inline' 'unsafe-eval' blob:; worker-src 'self' blob:; object-src 'none'; base-uri 'self'" always; + # gzip_static on; + alias M4_DS_ROOT/$2; +} + location ~ ^(\/[\d]+\.[\d]+\.[\d]+[\.|-][\w]+)?\/(web-apps|sdkjs|sdkjs-plugins|fonts|dictionaries)(\/.*)$ { add_header Cache-Control "public, max-age=31536000, immutable" always; # gzip_static on; From 32396d0adea0a3a8cbc6a38519d5d98175eeee44 Mon Sep 17 00:00:00 2001 From: Christoph Schaefer Date: Thu, 22 Oct 2026 09:35:15 +0200 Subject: [PATCH 2/2] docs(nginx): shorten the editor CSP comment Keep only what an admin reading the config needs: why 'unsafe-eval' and blob: are in the policy and why Cache-Control is repeated. The full rationale stays in the commit that added the block. Signed-off-by: Christoph Schaefer --- .../nginx/includes/ds-docservice.conf.m4 | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/common/documentserver/nginx/includes/ds-docservice.conf.m4 b/common/documentserver/nginx/includes/ds-docservice.conf.m4 index 2f9d350..9c28822 100644 --- a/common/documentserver/nginx/includes/ds-docservice.conf.m4 +++ b/common/documentserver/nginx/includes/ds-docservice.conf.m4 @@ -36,18 +36,8 @@ location ~ ^(\/[\d]+\.[\d]+\.[\d]+[\.|-][\w]+)?\/(sdkjs-plugins)(\/.*\.json)$ { alias M4_DS_ROOT/$2$3; } -# Harden the editor documents with a script-focused Content-Security-Policy. -# The editor compiles code at runtime (eval/Function, WebAssembly) and starts -# Blob-URL Workers, so 'unsafe-eval' and blob: have to stay. Pinning script-src -# to 'self' means the editor context can neither load nor dynamically import a -# script from another origin, and a Blob-URL Worker inherits this document's -# policy, so that restriction reaches those Workers too. This is a deliberately -# minimal script/worker policy; the other directives (img-src, style-src, -# font-src, connect-src, frame-ancestors, ...) are intentionally left unset. -# Covers every editor entry point: main, mobile, embed and forms, and the -# index/index_loader/index_internal/index.reporter variants getAppPath() loads. -# nginx add_header does not merge across levels, so the Cache-Control from the -# block below is repeated here on purpose. +# Script-focused CSP for the editor pages; the editor needs 'unsafe-eval' and blob:. +# Cache-Control is repeated here because add_header does not inherit across levels. location ~ ^(\/[\d]+\.[\d]+\.[\d]+[\.|-][\w]+)?\/(web-apps\/apps\/[^/]+\/(main|mobile|embed|forms)\/index[\w.]*\.html)$ { add_header Cache-Control "public, max-age=31536000, immutable" always; add_header Content-Security-Policy "script-src 'self' 'unsafe-inline' 'unsafe-eval' blob:; worker-src 'self' blob:; object-src 'none'; base-uri 'self'" always;