Skip to content

fix: saveCookieJar wrote every non-secure cookie twice - #5

Merged
tannevaled merged 1 commit into
mainfrom
fix-cookie-duplicate-save
Nov 10, 2026
Merged

tannevaled merged 1 commit into
mainfrom
fix-cookie-duplicate-save

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Summary

Caught by a live smoke test after PR #4 merged: building the real webtest binary and running it against a real local test server (not just the in-process unit suite) showed the saved cookies.json held the same session cookie twice.

Root cause: cookiejar.Jar stores by domain, not by scheme — scheme only gates a Secure-flagged cookie (hidden from an http:// query), it never partitions storage. saveCookieJar queried both "https" and "http" for the same host, so the same non-secure cookie came back from both queries. "https" alone already returns every cookie (secure or not) a real request to that host would carry.

New regression test (TestSaveCookieJarNoDuplicateEntries) reads the raw saved JSON array length directly — the existing roundtrip test didn't catch this because reloading via SetCookies collapses duplicate (name, domain, path) entries back down to one, hiding the bug in the on-disk file itself.

Test plan

  • TestSaveCookieJarNoDuplicateEntries (new) — fails on the old code, passes now
  • Live smoke test: built the real binary, ran a login scenario with --submit against a real local server, confirmed the saved cookie file now has exactly one entry, and a second separate run invocation still correctly reuses the session
  • go build/go vet/gofmt -l/govulncheck ./... clean
  • go test ./... green (44 tests), go test ./... -race clean

🤖 Generated with Claude Code

A live smoke test (building the real binary, running it against a real
local test server, not just the unit test suite) caught this: the
saved cookies.json held the same session cookie twice.

cookiejar.Jar stores by domain, not by scheme — scheme only gates a
Secure-flagged cookie (hidden from an http:// query), it never
partitions storage. Querying BOTH "https" and "http" for the same host
therefore returned the same non-secure cookie from both queries.
"https" alone already returns every cookie (secure or not) a real
request to that host would carry.

New regression test (TestSaveCookieJarNoDuplicateEntries) reads the
raw saved JSON array length directly — the existing roundtrip test
didn't catch this because reloading via SetCookies collapses duplicate
(name, domain, path) entries back down to one, hiding the bug in the
on-disk file.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit e5b0f39 into main Nov 10, 2026
1 check passed
@tannevaled
tannevaled deleted the fix-cookie-duplicate-save branch November 10, 2026 20:25
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