Skip to content

feat(nginx): add a Content-Security-Policy to the editor documents - #16

Merged
chrip merged 2 commits into
mainfrom
feat/editor-document-csp
Oct 22, 2026
Merged

chrip merged 2 commits into
mainfrom
feat/editor-document-csp

Conversation

@chrip

@chrip chrip commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

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

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 <christoph.schaefer@nextcloud.com>
@chrip
chrip marked this pull request as ready for review October 9, 2026 09:52
@juliusknorr
juliusknorr self-requested a review October 21, 2026 09:37
Comment on lines +39 to +50
# 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker, but I find this rather extensive for a config that admins may browse. Could be more compact and the full one may go into the commit message?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I summarized the comment to two lines.

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 <christoph.schaefer@nextcloud.com>
@chrip
chrip force-pushed the feat/editor-document-csp branch from 466cf32 to 32396d0 Compare October 22, 2026 07:41
@chrip
chrip merged commit 0ad83f6 into main Oct 22, 2026
2 checks passed
@juliusknorr juliusknorr added this to the 9.3.8 milestone Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants