Skip to content

fix(csp): flag 'unsafe-inline' in *-src-elem/*-src-attr - #678

Draft
caugner wants to merge 1 commit into
mainfrom
338-csp-attr-elem-unsafe-inline
Draft

caugner wants to merge 1 commit into
mainfrom
338-csp-attr-elem-unsafe-inline

Conversation

@caugner

@caugner caugner commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Description

Update the CSP analyzer to also check script-src-elem, script-src-attr, style-src-elem and style-src-attr:

  • Flag 'unsafe-inline' in all four, unless a nonce or hash is in the same source list.
  • Also flag data: and overly broad sources in the -elem variants, and apply the existing 'strict-dynamic' handling to script-src-elem.
  • Mention the new directives in the affected result and policy descriptions.

Motivation

Ensure that policies allowing inline code through these directives are no longer graded as free of 'unsafe-inline', since the directives override script-src and style-src for their respective checks.

Additional details

When a directive is absent, it falls back to its base directive, so policies without these directives keep their grade. Policies that use them can only stay the same or drop, e.g. the policy from the issue now gets csp-implemented-with-unsafe-inline-in-style-src-only (0 instead of +5).

Related issues and pull requests

Fixes #338.

The analyzer only checked `script-src` and `style-src`, so policies
that allow inline code via `script-src-attr`, `script-src-elem`,
`style-src-attr` or `style-src-elem` were graded as safe.

These directives override the base directive for their checks, so
apply the same rules to them: `'unsafe-inline'` counts unless a nonce
or hash is in the same list (CSP3 6.7.3.2), and the `-elem` variants
also reject `data:` and overly broad sources.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CSP with 'unsafe-inline' reported as without

1 participant