Repository navigation
Add granular script-src/style-src CSP directives - #393
Open
ousamabenyounes wants to merge 1 commit into
Open
ousamabenyounes wants to merge 1 commit into
ousamabenyounes wants to merge 1 commit into
Conversation
Add support for the CSP level 3 script-src-attr, script-src-elem, style-src-attr and style-src-elem directives. They are registered as no-default-fallback source lists (they fall back to script-src/style-src, not default-src) and advertised as available for CSP level 3 browsers.
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.
Adds support for the CSP level 3 granular source directives:
script-src-attr,script-src-elem,style-src-attr,style-src-elem.Why
These directives let applications control inline event handlers and
<script>/<style>elements separately from the genericscript-src/style-srcdirectives (see the CSP3 spec).They have been requested for a while (Fix #200).
What
DirectiveSet::$directiveNamesasTYPE_SRC_LIST_NOFB. They fall back toscript-src/style-src(notdefault-src), so they must always be emitted as configured rather thanbeing deduplicated against
default-src.PolicyManager(
getLevel3()), so they are emitted for Chrome/Firefox and omitted forSafari (CSP level 1), consistent with the other level 3 directives.
Configuration.php) and DI are automatic: the config tree isbuilt from
DirectiveSet::getNames().Resources/doc/index.rst.No new dependency, no BC break — the directives are purely additive and opt-in.
Test verification (RED → GREEN)
New data-driven cases in
DirectiveSetTest::testGranularSrcDirectives.RED (on the unmodified branch, only the test applied):
GREEN (with the fix):
Full suite: 431 tests green (was 428 + 3 new). PHP-CS-Fixer and
composer-normalize clean; PHPStan reports no new errors.