Repository navigation
Description
Consider this CSP violation report:
{"csp-report":{"document-uri":"REDACTED","referrer":"REDACTED","violated-directive":"script-src 'report-sample' 'strict-dynamic' 'unsafe-eval' 'nonce-random'","original-policy":"base-uri 'self'; object-src 'none'; script-src 'report-sample' 'strict-dynamic' 'unsafe-eval' 'nonce-random'","blocked-uri":"REDACTED","effective-directive":"script-src 'report-sample' 'strict-dynamic' 'unsafe-eval' 'nonce-random'"}}
Currently, Relay drops those with such error:
failed to extract security report: invalid security report
caused by: invalid value: string "script-src 'report-sample' 'strict-dynamic' 'unsafe-eval' 'nonce-random'", expected a csp directive at line 1 column 729
Apparently, this has something to do with older browsers before CSPv3 where effective-directive and violated-directive contained a longer substring of CSP. Check this excerpt from csplite.com:
According to recomendations for CSP 1 and CSP 2, in the violated-directive (unlike effective-directive), not only the name of the directive is sent, but also a set of its rules, for example:
"violated-directive":"script-src 'unsafe-inline' 'unsafe-eval' 'self' https://site.com ..."
In CSP 3 this behavior has been changed - now always violated-directive = effective-directive, and it is more does not contain violated policy rules:Note CSP 3. Both effectiveDirective and violatedDirective have the same value (meaning the name of the directive). This is intentional to maintain backwards compatibility.
My proposal is to add support for such cases. Seems like effective-directive is a searchable field (i.e. we can have a filter on the issues page like effective-directive:img-src), so I guess it should be of low cardinality. To keep cardinality low, we can do the following:
- save the original value of
effective-directiveCSP field toeffective-directive-full(or something similar), make it unsearchable; - save the first keyword of
effective-directiveCSP field toeffective-directive.
That is, for the CSP violation above, the results would look like:
effective-directive: script-src
effective-directive-full: script-src 'report-sample' 'strict-dynamic' 'unsafe-eval' 'nonce-random'
Activity
[-]Add support for CSP reports with extended `violated-directive`[/-][+]Add support for CSP reports with extended `effective-directive`[/+]iker-barriocanal commentedon Mar 29, 2023
Related error: POP-RELAY-2GC.
TBS1996 commentedon Apr 21, 2023
@oioki
does 'effective-directive' ever contain the long form like "script-src 'unsafe-inline' 'unsafe-eval' 'self' https://site.com ...""
or just violated-directive does (in version 1 and 2)
the quote you used from csplite seems to suggest its only violated-directive, but your solutions seem to imply that it's effective-directive
feat(protocol): Support old effective-directory format (#2048)