feat(set-cookie): analyze Set-Cookie attributes (Secure/HttpOnly/SameSite)#115
Merged
Conversation
…Site) A site could score A+ while shipping a session cookie with none of Secure, HttpOnly, or SameSite set. Add a Set-Cookie check (10 points, N/A when no cookies are set) and fix fetchHeadersWithMeta, which was silently collapsing multiple Set-Cookie response headers down to just the last one. Closes #95 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NX141JRVNPPMDaeDdYvf8V
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
rules.tschecked 7 header categories but never inspectedSet-Cookie— a site could score A+ while shipping a session cookie with none ofSecure,HttpOnly, orSameSiteset (readable by any injected script, replayable over plain HTTP, and CSRF-exposed). Every comparable tool (securityheaders.com, Mozilla HTTP Observatory) checks this. See #95 for the full writeup.checkSetCookie(src/rules.ts, 10 points): flags cookies missingSecure/HttpOnly/a restrictiveSameSite, and flagsSameSite=NonewithoutSecureas an invalid/broken combination the browser will reject. NoSet-Cookieheader at all is treated as N/A (status: 'good', full credit) rather than penalized — not every response sets cookies.analyzeHeaders(src/analyzer.ts); grading stays percentage-based so no rebalancing of existing weights was needed.fetchHeadersWithMeta(src/fetch.ts):res.headers.forEachemits oneset-cookieentry per cookie (confirmed via a quick Node repro), and the code was assigning each into a flatRecord<string, string>, silently keeping only the last cookie. Now collects all values viagetSetCookie()and joins them with\n(safe against commas insideExpires=...), so multi-cookie responses are each evaluated.maxScore100 → 110, the "empty headers" test, newcheckSetCookieunit tests, and afetchHeaderstest for multi-cookie preservation).Closes #95.
Test plan
npm run typechecknpm run buildnpm test— 150 passing (7 new: 6checkSetCookiecases + 1 multi-cookie fetch case)Generated by Claude Code