fix(auth): harden session cookie (HttpOnly/Secure/SameSite)#258
Open
ttonyxx wants to merge 1 commit into
Open
Conversation
This was referenced May 29, 2026
## Why this change is needed The session is stored in a signed cookie via the gorilla cookie store, but no cookie options were configured. The gorilla defaults leave every security flag off, which means the `session` cookie was: - readable by page JavaScript (no `HttpOnly`) — any XSS, or a malicious third-party script, could exfiltrate the session and impersonate the user; - sent over plain HTTP (no `Secure`) — the session could leak over an unencrypted connection / be stripped by an active network attacker; - emitted with no explicit `SameSite` — weaker CSRF posture than necessary. ## What this does Configures the cookie store options: - `HttpOnly: true` always — keep the session out of reach of JavaScript. - `Secure: utils.IsRelease()` — require HTTPS in production while still allowing `http://localhost` during local development. - `SameSite=Lax` — mitigate CSRF while still permitting top-level navigations. - Explicit `Path` and 30-day `MaxAge`. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
d2919b6 to
e3c36eb
Compare
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.
Severity: 🟠 High — session theft via XSS / insecure transport
The problem
The session is a signed cookie (
cookie.NewStore), but no options were ever set on the store. The underlying gorilla defaults leave all security flags off, so thesessioncookie was:HttpOnly→ readable by page JavaScript; any XSS or malicious script can steal the session and impersonate the user.Secure→ sent over plain HTTP; vulnerable to interception / SSL-strip.SameSite→ weaker CSRF posture than necessary.The fix
Secureis gated onutils.IsRelease()so local development overhttp://localhost:8080keeps working, while production (same-origin HTTPS) gets the hardened cookie.SameSite=Laxis safe for the same-origin production setup and the same-site localhost dev setup.🤖 Generated with Claude Code