feat(csp): flag missing base-uri directive#51
Open
dmchaledev wants to merge 1 commit into
Open
Conversation
base-uri does not inherit from default-src, so its absence leaves <base> injection unrestricted — an attacker who can inject a <base> element can redirect relative nonce sources to a controlled host. This is the same class of gap as the existing form-action check. Deducts 2 points and emits a recommendation; full score (20/30) now requires default-src, form-action, and base-uri to all be present. Tests updated and three new base-uri-specific cases added. https://claude.ai/code/session_01JH6HiZVtPYVDWeankB34ng
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.
Summary
base-uridoes not inherit fromdefault-src(same gap asform-action, which is already checked), so its absence silently leaves<base>injection unrestricted<base href="…">element can redirect relative nonce sources to a controlled host, bypassing nonce-based CSPbase-uri, matching the style of the existingform-actioncheckdefault-src,form-action, andbase-urito be explicitly setWhat changed
src/rules.ts— after theform-actioncheck incheckCSP, added:test/analyzer.test.ts— updated score assertions for existing tests affected by the new deduction, and added three dedicatedbase-uritest cases.Test plan
npx vitest run— all 82 tests pass (3 new tests added)base-uri 'none'andbase-uri 'self'both satisfy the check (no finding, score 20)base-uriemits the finding and loses 2 pointsdefault-src,form-action,base-uri)https://claude.ai/code/session_01JH6HiZVtPYVDWeankB34ng
Generated by Claude Code