Skip to content

Add support for CSP reports with extended effective-directive #1973

Closed

Description

@oioki

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-directive CSP field to effective-directive-full (or something similar), make it unsearchable;
  • save the first keyword of effective-directive CSP field to effective-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

  1. changed the title [-]Add support for CSP reports with extended `violated-directive`[/-] [+]Add support for CSP reports with extended `effective-directive`[/+] on Mar 28, 2023
  2. iker-barriocanal commented on Mar 29, 2023

    @iker-barriocanal
    Contributor

    Related error: POP-RELAY-2GC.

  3. self-assigned this
    on Apr 19, 2023
  4. TBS1996 commented on Apr 21, 2023

    @TBS1996
    Contributor

    @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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions