Skip to content

fix: parse Referrer-Policy as comma-separated list per W3C spec#86

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

fix: parse Referrer-Policy as comma-separated list per W3C spec#86
dmchaledev wants to merge 1 commit into
mainfrom
claude/nice-mendel-l8pvez

Conversation

@dmchaledev

Copy link
Copy Markdown
Contributor

Summary

The checkReferrerPolicy function was comparing the raw header string directly against the strong-value allowlist, which broke for comma-separated multi-value headers.

Root cause: The W3C Referrer Policy spec allows the Referrer-Policy header to contain a comma-separated list of policy tokens. Browsers parse the list left-to-right and use the last recognised token (unrecognised tokens are skipped as a forwards-compatibility mechanism). The old code treated the full raw string as a single value, so a perfectly valid header like:

Referrer-Policy: no-referrer-when-downgrade, strict-origin-when-cross-origin

was scored 5/10 (warning) instead of the correct 10/10 (good), producing false positives in security audits.

Fix: Split on commas, reverse the token list, and find the first recognised policy token — exactly the same last-recognised-wins logic browsers use. Single-value headers behave identically to before.

Changes

  • src/rules.ts — updated checkReferrerPolicy to apply last-recognised-token semantics for comma-separated header values
  • test/analyzer.test.ts — added 3 new test cases:
    • weak leading token + strong trailing token → good (10/10)
    • strong leading token + weak trailing token → warning (5/10)
    • unrecognised trailing token falls back to last recognised strong token → good (10/10)

All 88 tests pass.


Generated by Claude Code

The W3C Referrer Policy spec allows the header value to be a
comma-separated list of tokens; browsers use the last recognised value
and skip any unrecognised tokens. The previous implementation compared
the raw header string directly against the strong-value allowlist, so
a valid multi-value header like:

  Referrer-Policy: no-referrer-when-downgrade, strict-origin-when-cross-origin

was incorrectly scored as 5/10 (warning) instead of 10/10 (good),
producing false positives in security audits.

Fix: split on commas, reverse, and find the last recognised policy token
(matching browser behaviour). Adds three new tests covering the
multi-value cases.

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