- Functionality: Implements the Content Security Policy standard (Level 3 W3C Rec), a mechanism to declare security policies for a web page, primarily mitigating XSS and data injection attacks.
- Key Logic: Parsing CSP headers/meta tags (
ContentSecurityPolicy::AddPolicies
), evaluating directives (script-src
,style-src
,img-src
,connect-src
,frame-src
,frame-ancestors
,form-action
,report-uri
,report-to
,sandbox
,require-trusted-types
, etc.) against resource loads, inline scripts/styles (nonce/hash checking), dynamic code execution (unsafe-eval
), and navigation requests. Handling'strict-dynamic'
,'unsafe-inline'
,'self'
, source expressions (schemes, hosts, wildcards). Integration with other features (Service Workers, extensions, special URL schemes). - Core Files:
third_party/blink/renderer/core/frame/csp/content_security_policy.cc
/.h
: Core CSP object attached toDocument
. Key methods:AllowScriptFromSource
,AllowStyleFromSource
,AllowImageFromSource
,AllowConnectToSource
,AllowFrameFromSource
,AllowInline
,AllowEval
,ReportViolation
.third_party/blink/renderer/core/frame/csp/csp_directive_list.cc
/.h
: Parses and stores CSP directives from a policy string.third_party/blink/renderer/core/frame/csp/csp_source.cc
/.h
: Handles parsing and matching of source expressions (hosts, schemes, wildcards, nonces, hashes). IncludesHostMatches
,SchemeMatches
.third_party/blink/renderer/core/frame/csp/csp_context.cc
/.h
: Provides context for CSP checks.content/browser/renderer_host/navigation_request.cc
: Enforces frame-src/fenced-frame-src during navigation (CheckCSPDirectives
).//extensions/common/manifest_handlers/csp_info.cc
: Handles CSP specified in extension manifests.
-
Directive Bypass via Scheme/Navigation: Exploiting how CSP is applied (or not applied) during navigations to specific schemes or in specific contexts.
- VRP Pattern (
about:blank
): Navigating a frame toabout:blank
incorrectly losing inherited CSP restrictions (VRP:996741
, VRP2.txt#1924). - VRP Pattern (
blob:
): Navigating toblob:
URLs potentially bypassing the original context's CSP (VRP:1115628
, VRP2.txt#7831). Using blob URLs opened by cross-origin frames (VRP2.txt#11985). - VRP Pattern (
filesystem:
): Navigating tofilesystem:
URLs bypassing CSP (VRP:1116446
, VRP2.txt#5009). - VRP Pattern (
javascript:
): Incorrect handling ofjavascript:
URIs, especially insrcdoc
attributes (VRP:1006188
) or specific platforms (iOS VRP2.txt#8077), leading to execution despite CSP. Bypassing CSP via javascript: URL + doubly-nested iframe (VRP2.txt#11985). - VRP Pattern (
about:srcdoc
): Navigating toabout:srcdoc
potentially bypassing CSP (VRP2.txt#11413). Usingsrcdoc
assignment with specific HTML parsing differences (tree_builder_simulator
) leading to mutation XSS bypassing sanitizers that rely on standard parsing (VRP2.txt#4643, #1185).
- VRP Pattern (
-
Directive Bypass via Feature Interaction: Exploiting interactions with other browser features.
- VRP Pattern (Service Workers): Service workers intercepting requests and potentially modifying responses in ways that bypass CSP checks (VRP:
598077
). See service_workers.md.
- VRP Pattern (Service Workers): Service workers intercepting requests and potentially modifying responses in ways that bypass CSP checks (VRP:
-
Policy Parsing and Enforcement Flaws: Errors in parsing directives or enforcing the policy correctly.
- VRP Pattern (Directive Validation): Insufficient validation or incorrect handling of newer directives like
script-src-elem
/script-src-attr
allowing bypasses, especially in extensions (VRP:1288035
, VRP2.txt#589). - VRP Pattern (
strict-dynamic
Interaction): Incorrectly allowing'unsafe-inline'
when'strict-dynamic'
is present indefault-src
(VRP2.txt#11841). Spec requires'unsafe-inline'
to be ignored in this case. - VRP Pattern (Nonce/Hash Bypass): Potential flaws in nonce generation, verification (
AllowInline
), or hash verification allowing injection. Dangling markup injection into nonced elements.
- VRP Pattern (Directive Validation): Insufficient validation or incorrect handling of newer directives like
-
Source Matching Issues: Problems in matching source expressions (hosts, schemes, wildcards) against target URLs.
- VRP Pattern (Unicode/IDN): Improper handling of Unicode homographs or inconsistent Punycode/Unicode handling in host source matching (
HostMatches
incsp_source.cc
).
- VRP Pattern (Unicode/IDN): Improper handling of Unicode homographs or inconsistent Punycode/Unicode handling in host source matching (
-
Reporting Leaks: CSP reporting mechanisms (
report-uri
,report-to
) leaking sensitive information.- VRP Pattern (Fragment Leak): Reports incorrectly including the URL fragment (VRP2.txt#15887).
- VRP Pattern (Redirect URL Leak): CSP reports and error stack traces leaking post-redirect URLs for blocked scripts (VRP2.txt#5947).
(Original list items like "Policy Parsing and Enforcement", "Nonce and Hash Verification", "Request Handling", "Bypass Techniques", "Unsafe Directives", "Dangling Markup Injection", "Unicode and IDN Hostname Vulnerabilities" are now integrated into the VRP Patterns above for better context).
- Parser (
csp_directive_list.cc
): Thoroughly audit the parsing logic for all directives. How are complex values, edge cases, and newer directives (script-src-elem
/attr
) handled? Is the parsing fully spec-compliant regarding interaction rules (e.g.,'strict-dynamic'
ignoring'unsafe-inline'
VRP2.txt#11841)? - Enforcement (
content_security_policy.cc
): Review the enforcement logic (Allow*
methods). Are checks performed at the correct stages of resource loading/execution? How does it interact withNavigationRequest
checks, especially for schemes likeabout:blank
,blob:
,filesystem:
where bypasses occurred (VRP:996741
,1115628
,1116446
)? 'strict-dynamic'
Logic: Analyze the implementation. Does it correctly ignore host/scheme sources,'self'
, and'unsafe-inline'
? How does it interact with nonces/hashes and script propagation?- Nonce/Hash Implementation: Review nonce generation (is it sufficiently random?), storage, and comparison logic (
AllowInline
). How are hashes calculated and checked (AllowHash
)? Is dangling markup injection preventable? - Source Matching (
csp_source.cc
): Re-verifyHostMatches
andSchemeMatches
against spec requirements, especially for wildcards, ports, redirects, and Unicode/IDN variations. Ensure consistent Punycode handling. - Reporting Security: Ensure reporting endpoints (
report-uri
,report-to
) don't leak sensitive cross-origin information beyond what's allowed by the spec (e.g., fragments VRP2.txt#15887, detailed redirect URLs VRP2.txt#5947). - Interaction with other features: Analyze interactions with Service Workers (VRP:
598077
), Extensions (Manifest V3 CSP, VRP:1288035
), Sandboxed Iframes, Portals, Fenced Frames, WebUI, Pre-rendering, Back/Forward Cache. How is CSP state propagated and enforced in these complex contexts?
ContentSecurityPolicy::AllowScriptFromSource
,AllowStyleFromSource
, etc.: Core enforcement points. Check conditions and how source lists are evaluated. How do these interact with schemes likeblob:
orfilesystem:
?ContentSecurityPolicy::AllowInline
: Handles'unsafe-inline'
, nonces, and hashes. Check verification logic, especially against dangling markup.ContentSecurityPolicy::AllowEval
: Handles'unsafe-eval'
.CSPDirectiveList::Parse
: Entry point for parsing a policy string. Review handling of newer directives (script-src-elem
,script-src-attr
) and interaction rules ('strict-dynamic'
).CSPSource::HostMatches
,SchemeMatches
: Core source expression matching logic. Needs review for Unicode/IDN/wildcard edge cases.ContentSecurityPolicy::ReportViolation
: Builds and sends violation reports. Check for fragment/redirect URL leaks (VRP2.txt#15887, #5947).NavigationRequest::CheckCSPDirectives
: Enforcement during navigation. How does it handle CSP onabout:blank
/about:srcdoc
?HTMLScriptElement::IsAllowedByCsp
: Checks script execution permission.CSPSourceList::Allow*
: Check functions likeAllowSpecificSource
and how they handle different schemes.CSPParser
: Underlying parsing logic.
- Spec Compliance: Thoroughly compare implementation against the latest CSP Level 3 specification, especially regarding
'strict-dynamic'
ignoring'unsafe-inline'
/'self'
/hosts (VRP2.txt#11841), reporting details, and handling of newer directives. - Navigation Interaction: Analyze all navigation scenarios (including redirects, special schemes like
blob:
,filesystem:
,about:srcdoc
) to ensure CSP inheritance and enforcement are correct at all stages. Re-testabout:blank
andblob:
bypasses (VRP:996741
,1115628
). - Service Worker Interactions: How does CSP apply to scripts executed within service workers and requests intercepted by
FetchEvent
? (VRP:598077
). - Extension Manifest V3 CSP: Security review of the CSP specified in Manifest V3 and its enforcement, especially regarding
script-src-elem
/attr
(VRP:1288035
). - Trusted Types Interaction: How does
require-trusted-types
directive interact with other directives and enforcement points? - Unicode/IDN Robustness: Add extensive test cases for various Unicode/IDN hostname scenarios in
csp_source_test.cc
. - Reporting Leaks: Verify fixes for fragment (VRP2.txt#15887) and redirect URL (VRP2.txt#5947) leaks in reporting.
- Scheme/Navigation Bypass: VRP:
996741
(about:blank
),1115628
(blob:
),1116446
(filesystem:
),1006188
(javascript:
insrcdoc
); VRP2.txt#1924, #7831, #5009, #11413, #8077 (iOSjavascript:
), #1185 (about:srcdoc
/mXSS), #4643 (mXSS viasrcdoc
), #11985 (blob:
popup). - Feature Interaction: VRP:
598077
(Service Worker intercept). - Directive Validation/Parsing: VRP:
1288035
(script-src-elem
/attr
bypass); VRP2.txt#589 (same), VRP2.txt#11841 ('strict-dynamic'
+'unsafe-inline'
issue). - Reporting Leaks: VRP2.txt#15887 (fragment leak), VRP2.txt#5947 (redirect URL leak).
third_party/blink/renderer/core/frame/csp/content_security_policy.cc
third_party/blink/renderer/core/frame/csp/csp_directive_list.cc
third_party/blink/renderer/core/frame/csp/csp_source.cc