fix(session): add httpOnly, Secure, and SameSite=strict cookie flags#576
fix(session): add httpOnly, Secure, and SameSite=strict cookie flags#576anshul23102 wants to merge 1 commit into
Conversation
Fixes GitMetricsLab#554 The session cookie was issued with browser defaults because no cookie options were set. This exposed three attack vectors: - No httpOnly: any JavaScript on the page could read the session cookie via document.cookie and exfiltrate it to an attacker server. - No Secure: the cookie was sent over plain HTTP, allowing passive observers on the same network to capture it. - No SameSite: every cross-origin request the browser made to this origin included the cookie, enabling CSRF attacks. Added httpOnly:true, sameSite:'strict', and secure conditioned on NODE_ENV=production so local HTTP development still works. Also set maxAge to 24 hours as an explicit session TTL.
✅ Deploy Preview for github-spy ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Warning Review limit reached
More reviews will be available in 20 minutes and 38 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Hey @GitMetricsLab, pinging this as part of NSoC'26. Let me know if there is anything to address. Thanks! |
Summary
Fixes #554
The
express-sessionmiddleware was configured with nocookieoptions, so the session cookie was issued with browser defaults.Attack vectors closed
httpOnlydocument.cookieand exfiltrates the session tokenhttpOnly: trueSecuresecure: isProduction(on in prod, off for local HTTP dev)SameSitesameSite: 'strict'Also added
maxAge: 24has an explicit session TTL.Change
backend/server.jsTest Plan
HttpOnlyandSameSite=Strictchecked.Secureflag is present.document.cookiereturns an empty string (HttpOnly prevents JS access).Important
GSSoC'26 contribution - Please add labels (
gssoc26,type:security,level:intermediate) to help with point tracking. Thank you!