Skip to content

fix(csp): flag scheme-only sources (https:, data:) as permissive in sensitive CSP directives#58

Open
dmchaledev wants to merge 1 commit into
mainfrom
claude/nice-mendel-9emdN
Open

fix(csp): flag scheme-only sources (https:, data:) as permissive in sensitive CSP directives#58
dmchaledev wants to merge 1 commit into
mainfrom
claude/nice-mendel-9emdN

Conversation

@dmchaledev
Copy link
Copy Markdown
Contributor

$(cat <<'EOF'

Problem

The CSP wildcard check only caught the literal * token but silently passed scheme-only sources like https: or data: in sensitive fetch directives.

A policy such as:

Content-Security-Policy: default-src https:; form-action 'self'

allows loading scripts, stylesheets, workers, etc. from any HTTPS host — nearly as permissive as default-src * — yet the tool previously awarded it full marks with no finding.

Root Cause

rules.ts filtered directives using sources.includes('*'), missing any token matched by the existing isPermissiveSource() helper (bare * or any scheme-only source like https: / data: / blob:).

Fix

Replace sources.includes('*') with sources.some(isPermissiveSource) in the sensitive-directive filter. The isPermissiveSource helper was already defined in the file for the frame-ancestors check — this change reuses it consistently.

The finding message is updated to name both forms so users understand why their policy was flagged:

Overly permissive source in default-src (e.g. '*' or 'https:') allows any origin

Tests

Three new test cases (85 total, all passing):

Case Expected
default-src https: flagged as permissive
script-src data: flagged as permissive
img-src https: not flagged (low-risk directive, intentional carve-out)
Tests  85 passed (85)

Checklist

  • npm run typecheck passes
  • npm test passes (85/85)
  • No new dependencies

https://claude.ai/code/session_019zKAbhaab16mcuuP2McH2K
EOF
)


Generated by Claude Code

…sitive directives

The CSP wildcard check only caught literal `*` but missed scheme-only
sources like `https:` or `data:` in sensitive fetch directives.
A policy such as `default-src https:` allows loading from any HTTPS
host and is nearly as permissive as `*`, yet previously scored as safe.

Reuse the existing `isPermissiveSource` helper (which already handles
both `*` and scheme-only patterns) in the directive filter, and update
the finding message to name both forms. Three new tests cover
`https:` in default-src, `data:` in script-src, and the correct
non-flagging of `https:` in the low-risk img-src.

https://claude.ai/code/session_019zKAbhaab16mcuuP2McH2K
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.

2 participants