fix: parse Referrer-Policy as comma-separated list per W3C spec#86
Open
dmchaledev wants to merge 1 commit into
Open
fix: parse Referrer-Policy as comma-separated list per W3C spec#86dmchaledev wants to merge 1 commit into
dmchaledev wants to merge 1 commit into
Conversation
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
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
The
checkReferrerPolicyfunction 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-Policyheader 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: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— updatedcheckReferrerPolicyto apply last-recognised-token semantics for comma-separated header valuestest/analyzer.test.ts— added 3 new test cases:good(10/10)warning(5/10)good(10/10)All 88 tests pass.
Generated by Claude Code