Skip to content

fix(referrer-policy): parse comma-separated fallback list per spec#75

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

fix(referrer-policy): parse comma-separated fallback list per spec#75
dmchaledev wants to merge 1 commit into
mainfrom
claude/nice-mendel-fjy1yy

Conversation

@dmchaledev

Copy link
Copy Markdown
Contributor

Problem

The Referrer-Policy header supports a comma-separated fallback list per the W3C spec. Browsers pick the last recognised value in the list, so this header:

Referrer-Policy: unsafe-url, strict-origin-when-cross-origin

is effectively strict-origin-when-cross-origin in every modern browser — a strong, fully-compliant policy.

Before this fix, checkReferrerPolicy compared the raw string against the set of strong values. That string never matches, so the header above was incorrectly graded as a warning with the finding:

Value 'unsafe-url, strict-origin-when-cross-origin' may leak referrer information

That's a false positive: the site is well-configured, but the tool tells it to fix something that isn't broken. Real-world CDNs (e.g. Cloudflare) and some frameworks emit multi-value Referrer-Policy headers, so this affects users in the wild.

Fix

src/rules.tscheckReferrerPolicy:

  • Split the raw value on commas
  • Filter tokens to the set of all valid policy names (per spec)
  • Score from the last recognised token (the effective policy for modern browsers)
  • Report the effective value in findings, not the full raw string, so remediation guidance is actionable

Tests

Three new cases added to test/analyzer.test.ts:

Case Expected
unsafe-url, strict-origin-when-cross-origin score 10, good
strict-origin-when-cross-origin, unsafe-url score 5, warning
Finding text references effective value only

All 88 tests pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Vbd3LGpLmTBEfbH5gKD3Jx


Generated by Claude Code

The Referrer-Policy header supports a comma-separated list of values;
browsers use the last recognised policy in the list. The previous check
compared the raw header string against a fixed set of strong values,
so a valid header like "unsafe-url, strict-origin-when-cross-origin"
was incorrectly graded as a warning even though browsers enforce the
strict policy.

The fix splits on commas, filters to recognised policy tokens, takes
the last one as the effective value, and scores from that. The finding
message now reports the effective policy rather than the raw string,
which makes remediation guidance actionable.

Adds three test cases covering: strong-last list earns full score,
weak-last list earns warning, and finding text references effective value.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vbd3LGpLmTBEfbH5gKD3Jx
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