fix(csp): require explicit allowlist for external-pad framing (#102) - #116
Merged
Conversation
CSPListener handles every AddContentSecurityPolicyEvent, so when external pads were enabled with an empty allowlist it emitted a blanket `https:` frame-src/child-src on *all* Nextcloud pages, not just pad pages. External pads are rendered as locally fetched read-only snapshots (no live iframe to the external host), so the blanket relaxation bought nothing and only widened the framing surface site-wide. Drop it: an empty allowlist now contributes no frame domains, and only concrete allowlisted hosts (plus the configured local Etherpad host) are ever added to frame-src/child-src. The server-side snapshot fetch keeps its existing 'empty allowlist = allow all public HTTPS hosts' behaviour (ExternalPadExportFetcher, guarded by the public-IP / DNS-rebinding checks); only the browser-facing CSP is tightened. Closes #102.
There was a problem hiding this comment.
Pull request overview
Tightens CSP so that enabling external pads with an empty allowlist no longer emits a blanket https: into frame-src/child-src globally. Only concrete allowlisted hosts (plus the configured local Etherpad host) contribute frame domains; the server-side snapshot fetch behavior is unchanged.
Changes:
- Remove the
$domains['https:'] = true;fallback inCSPListener::getAllowedFrameDomains()when the external pad allowlist is empty. - Update existing test to assert no blanket
https:is emitted, and add a new test verifying no policy is added when both local host and allowlist are empty.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| lib/Listeners/CSPListener.php | Stop adding blanket https: frame source for empty external pad allowlist. |
| tests/phpunit/unit/CSPListenerTest.php | Renamed/updated regression test and added empty-config no-policy test. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
CSPListenerhandles everyAddContentSecurityPolicyEvent. When external pads were enabled (allow_external_pads=yes) with an emptyexternal_pad_allowlist, it emitted a blankethttps:intoframe-src/child-src— loosening framing on all Nextcloud pages, not just pad pages.Fix
External pads are rendered as locally fetched read-only snapshots (no live iframe to the external host), so the blanket relaxation bought nothing and only widened the site-wide framing surface. An empty allowlist now contributes no frame domains; only concrete allowlisted hosts (plus the configured local Etherpad host) are ever added to
frame-src/child-src.The server-side snapshot fetch keeps its existing "empty allowlist = allow all public HTTPS hosts" behaviour (
ExternalPadExportFetcher, still guarded by the public-IP / DNS-rebinding checks). Only the browser-facing CSP is tightened — so this fixes all existing installs immediately, with no admin re-save required.Acceptance
frame-src https:globallyVerification
phpunit: 399 tests green (CSP suite covers empty-allowlist + no-local-host cases asserting nohttps:blanket).allow_external_pads=yes, empty allowlist): the served login-page CSP is nowhttps:.Closes #102.