Skip to content

fix(csp): detect scheme-only sources (e.g. https:) as permissive in sensitive directives#64

Open
dmchaledev wants to merge 1 commit into
mainfrom
claude/nice-mendel-3tdbm3
Open

fix(csp): detect scheme-only sources (e.g. https:) as permissive in sensitive directives#64
dmchaledev wants to merge 1 commit into
mainfrom
claude/nice-mendel-3tdbm3

Conversation

@dmchaledev

Copy link
Copy Markdown
Contributor

$(cat <<'EOF'

Problem

The CSP wildcard check in checkCSP only tested for a literal * token:

return sources !== undefined && sources.includes('*');

But script-src https: is equally permissive — it allows loading scripts from any HTTPS origin, exactly like script-src *. A site with this policy would receive no penalty today, even though it provides no meaningful XSS restriction.

The helper isPermissiveSource (already defined in rules.ts) correctly identifies both bare wildcards and scheme-only sources, but it was never wired into the CSP check.

Fix

Replace sources.includes('*') with sources.some(isPermissiveSource) so that scheme-only sources (https:, http:, data:, blob:, etc.) in sensitive directives are penalised the same way bare wildcards are.

Affected directives: default-src, script-src, connect-src, form-action, frame-src, worker-src. Low-risk directives (img-src, style-src, etc.) remain unaffected — permissive sources there are intentionally allowed.

The finding message is updated to "Wildcard or scheme-only source…" so existing tests that match on Wildcard continue to pass.

Tests

Five new test cases added (85 total, all passing):

  • https: in script-src is flagged and scores −5
  • data: in connect-src is flagged
  • https: in img-src is not flagged (low-risk allow-list unchanged)
  • Existing * wildcard tests unchanged

Test plan

  • npm test → 85/85 pass
  • Existing score assertions all unaffected
  • New cases match expected scores

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


Generated by Claude Code

…nsitive directives

`script-src https:` is just as open as `script-src *` — both allow loading
scripts from any matching origin — but the wildcard check only tested for
the literal `*` token.  Wire the existing `isPermissiveSource` helper into
the check so that scheme-only sources in script-src, connect-src,
form-action, frame-src, worker-src, and default-src are penalised the same
way bare wildcards are.  Also add three new test cases: https: in
script-src, data: in connect-src, and a negative check confirming that
scheme-only sources in low-risk img-src are still not flagged.

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