Add support for the Trusted Types CSP directives - #394
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 the require-trusted-types-for and trusted-types Content Security Policy directives. They are registered as a dedicated policies-list type (always emitted, never fallbacked by default-src) and advertised for Chromium-based browsers only, which are currently the ones shipping Trusted Types. The 'script' and 'allow-duplicates' keywords are quoted by the CSP parser.
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 Trusted Types CSP
directives
require-trusted-types-forandtrusted-types(Fix #233).Trusted Types help mitigate DOM-based XSS by locking down dangerous DOM sinks.
This lets applications configure the two directives through the bundle's usual
CSP configuration.
What
require-trusted-types-forandtrusted-typesinDirectiveSet::$directiveNamesunder a dedicatedTYPE_TRUSTED_TYPES_LISTtype. Like other non-source-list directives they are always emitted and never
deduplicated against
default-src.PolicyManager::getChromeDirectives()only. Trusted Typesis currently shipped by Chromium-based browsers, so (with
browser_adaptiveenabled) they are emitted for Chrome/Opera and omitted for Firefox/Safari,
consistent with how the bundle already gates browser-specific directives.
scriptandallow-duplicateskeywords inContentSecurityPolicyParsersorequire-trusted-types-for: ['script']renders as
require-trusted-types-for 'script'and the'allow-duplicates'trusted-types keyword is quoted, while custom policy names are left untouched.
DirectiveSet::getNames()).Resources/doc/index.rst.Purely additive, opt-in, no new dependency and no BC break. This revives the
approach from the (now stale) PR #235.
Test verification (RED → GREEN)
New cases in
ContentSecurityPolicyParserTestandDirectiveSetTest::testTrustedTypesDirectives.RED (unmodified branch, only the tests applied):
GREEN (with the fix):
Full suite: 433 tests green (was 428 + 5 new). PHP-CS-Fixer and
composer-normalize clean; PHPStan reports no new errors.