Skip to content

feat(csp): flag missing base-uri directive#51

Merged
dmchaledev merged 1 commit into
mainfrom
claude/nice-mendel-St40j
May 31, 2026
Merged

feat(csp): flag missing base-uri directive#51
dmchaledev merged 1 commit into
mainfrom
claude/nice-mendel-St40j

Conversation

@dmchaledev
Copy link
Copy Markdown
Contributor

Summary

  • base-uri does not inherit from default-src (same gap as form-action, which is already checked), so its absence silently leaves <base> injection unrestricted
  • An attacker who can inject a <base href="…"> element can redirect relative nonce sources to a controlled host, bypassing nonce-based CSP
  • Added a −2 point deduction + finding/recommendation for missing base-uri, matching the style of the existing form-action check
  • Full CSP score (20/30) now requires default-src, form-action, and base-uri to be explicitly set

What changed

src/rules.ts — after the form-action check in checkCSP, added:

if (extractCspDirective(raw, 'base-uri') === undefined) {
  score -= 2;
  findings.push("No base-uri directive — <base> injection can redirect relative nonce sources (base-uri does not inherit from default-src)");
  recommendations.push("Add base-uri 'self' or base-uri 'none' to prevent <base> injection");
}

test/analyzer.test.ts — updated score assertions for existing tests affected by the new deduction, and added three dedicated base-uri test cases.

Test plan

  • npx vitest run — all 82 tests pass (3 new tests added)
  • Verify base-uri 'none' and base-uri 'self' both satisfy the check (no finding, score 20)
  • Verify a CSP without base-uri emits the finding and loses 2 points
  • Verify grade A+ still achievable with a fully-specified CSP (default-src, form-action, base-uri)

https://claude.ai/code/session_01JH6HiZVtPYVDWeankB34ng


Generated by Claude Code

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
@dmchaledev dmchaledev merged commit 9d6ba1d into main May 31, 2026
1 check passed
@dmchaledev dmchaledev deleted the claude/nice-mendel-St40j branch May 31, 2026 20:11
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