#103640CSP: default-src: 'none' is inherited to other directives
Description
Using this configuration:
inheritDefault: false
mutations:
- mode: set
directive: 'default-src'
sources:
- "'none'"
- mode: extend
directive: "child-src"
sources:
- "'self'"
results in this output:
default-src 'none'; child-src 'none' 'self'
The ‘none’ in “child-src” is obviously wrong.
Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.
Fix this issue
Start the commit message of your patch with this. Add what the patch does, and the versions it goes to in "Releases:". How to create a patch
- Commit message
-
[BUGFIX] CSP: default-src: 'none' is inherited to other directives Resolves: #103640 Releases: main
Okay, another scenario: “child-src” is not configured, so the “default-src” with “none” kicks in:
inheritDefault: false mutations: - mode: set directive: 'default-src' sources: - "'none'" # child-src is not configuredNow I have an event listener which listens to the PolicyMutatedEvent and adjusts the policy depending on some conditions. In the listener I thought I may be clever and remove the “none” keyword for “child-src” and then add some URL for child-src. Obviously, the “none” keyword is not available (as it is inherited by “default-src”):
$event->getCurrentPolicy() ->reduce( // $event->getCurrentPolicy()->get(Directive::ChildSrc) is null, so this does not work Directive::ChildSrc, SourceKeyword::none, ) ->extend( Directive::ChildSrc, new UriValue('example.com'), )But in the compiled policy output by the browser, I see now “child-src: ‘none’ example.com”.
This might not an issue for browsers, as they ignore ‘none’ when used with other values (like Chrome outputs in console):
“The Content-Security-Policy directive ‘child-src’ contains the keyword ‘none’ alongside with other source expressions. The keyword ‘none’ must be the only source expression in the directive value, otherwise it is ignored.”