Skip to content

fix(admin): secure session cookies by default, clear semgrep findings - #48

Merged
shreyanshjain7174 merged 1 commit into
mainfrom
fix/semgrep-findings
Oct 18, 2026
Merged

shreyanshjain7174 merged 1 commit into
mainfrom
fix/semgrep-findings

Conversation

@shreyanshjain7174

Copy link
Copy Markdown
Contributor

Plan

Clear the 4 Semgrep findings that already existed on main (noted in #47), so semgrep --config auto --error ./internal ./cmd can gate CI cleanly.

Findings

  1. cmd/agentgate-mcp/main.go, modified-variable use: false positive. parseRequest returns a value with a safe, echoable ID on error, never a nil pointer. Added a scoped nosemgrep with the reason.
  2. internal/admin/session.go, missing Secure on the session cookie: real gap. Secure was set only when AGENTGATE_PUBLIC_URL started with https://.
  3. Same file, the logout cookie: same gap.
  4. internal/receipt/export_handler.go, direct write to the response: false positive. The output is JSON-encoded NDJSON with nosniff already set. Added regression tests and a scoped nosemgrep.

Behavior change (findings 2 and 3)

  • Admin cookies are now Secure by default. Only an explicit http://localhost or http://127.0.0.1 public URL turns it off, for local dev. A direct TLS request always gets Secure, and forwarded headers cannot downgrade it.
  • SameSite moved from Lax to Strict. OAuth callbacks validate encrypted state without an admin session, so they do not need Lax.
  • If you run the admin UI on a plain-HTTP, non-loopback URL (for example 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 ./...: passed
  • go vet ./...: passed
  • go test -race ./...: passed
  • semgrep --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.

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>
@shreyanshjain7174
shreyanshjain7174 merged commit f42a5a8 into main Oct 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant