fix(csp): detect scheme-only sources (e.g. https:) as permissive in sensitive directives#64
Open
dmchaledev wants to merge 1 commit into
Open
fix(csp): detect scheme-only sources (e.g. https:) as permissive in sensitive directives#64dmchaledev wants to merge 1 commit into
dmchaledev wants to merge 1 commit into
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
$(cat <<'EOF'
Problem
The CSP wildcard check in
checkCSPonly tested for a literal*token:But
script-src https:is equally permissive — it allows loading scripts from any HTTPS origin, exactly likescript-src *. A site with this policy would receive no penalty today, even though it provides no meaningful XSS restriction.The helper
isPermissiveSource(already defined inrules.ts) correctly identifies both bare wildcards and scheme-only sources, but it was never wired into the CSP check.Fix
Replace
sources.includes('*')withsources.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
Wildcardcontinue to pass.Tests
Five new test cases added (85 total, all passing):
https:inscript-srcis flagged and scores −5data:inconnect-srcis flaggedhttps:inimg-srcis not flagged (low-risk allow-list unchanged)*wildcard tests unchangedTest plan
npm test→ 85/85 passhttps://claude.ai/code/session_0175hVv1zu7D7wBhtyoWi5LF
EOF
)
Generated by Claude Code