Repository navigation
fix(admin): secure session cookies by default, clear semgrep findings - #48
Merged
Merged
Conversation
Default admin cookies to Secure except for explicit local HTTP. Direct TLS always enables Secure. OAuth state permits Strict cookies. Scope suppressions to safe parser IDs and JSON-encoded NDJSON. Test cookie modes, export headers, and receipt text encoding. Signed-off-by: Shreyansh Sancheti <43677304+shreyanshjain7174@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Plan
Clear the 4 Semgrep findings that already existed on
main(noted in #47), sosemgrep --config auto --error ./internal ./cmdcan gate CI cleanly.Findings
cmd/agentgate-mcp/main.go, modified-variable use: false positive.parseRequestreturns a value with a safe, echoable ID on error, never a nil pointer. Added a scopednosemgrepwith the reason.internal/admin/session.go, missingSecureon the session cookie: real gap.Securewas set only whenAGENTGATE_PUBLIC_URLstarted withhttps://.internal/receipt/export_handler.go, direct write to the response: false positive. The output is JSON-encoded NDJSON withnosniffalready set. Added regression tests and a scopednosemgrep.Behavior change (findings 2 and 3)
Secureby default. Only an explicithttp://localhostorhttp://127.0.0.1public URL turns it off, for local dev. A direct TLS request always getsSecure, and forwarded headers cannot downgrade it.SameSitemoved fromLaxtoStrict. OAuth callbacks validate encrypted state without an admin session, so they do not needLax.http://agentgate.internal), the browser will not send the cookie. Put TLS in front, as the README already recommends.The docker-compose default (
http://localhost:8080) keeps working.Validation
go build ./...: passedgo vet ./...: passedgo test -race ./...: passedsemgrep --config auto --error --quiet ./internal ./cmd: passed (exit 0)New tests cover each cookie mode: https, loopback http, non-loopback http, direct TLS override, and logout. They also cover NDJSON headers.