CodexBar icon indicating copy to clipboard operation
CodexBar copied to clipboard

Renew Claude web cookies

Open ProspectOre opened this issue 5 months ago • 4 comments

Summary

  • renew Claude Web session keys from successful Set-Cookie: sessionKey=... responses
  • reuse a rotated session key for later requests in the same Web fetch
  • track renewal for manual cookie fetches too, while keeping manual cookies read-only so they do not rewrite cached browser-derived state

Root cause

Claude Web usage requests reused a cached sessionKey but ignored Set-Cookie renewal headers from claude.ai. Once the cached key aged out, later refreshes could keep sending stale credentials. The first patch fixed browser/cache-backed fetches, but the manual-cookie path still skipped the renewal tracker because persistence provenance was also controlling in-memory renewal tracking.

Fix

  • create the renewal tracker for every Claude Web fetch
  • use the tracker's current session key for /usage, extra usage, and account calls
  • keep CookieHeaderCache.store gated on cacheSourceLabel, so only browser/cache-backed cookies are persisted
  • extend the manual-cookie regression test to assert that /usage receives the renewed key while the cached browser cookie remains unchanged

Proof

swift test --filter ClaudeWebCookieRenewalTests:

Suite ClaudeWebCookieRenewalTests passed after 0.025 seconds.
Test run with 2 tests in 1 suite passed after 0.025 seconds.

make check:

SwiftFormat completed in 0.2s.
0/1100 files require formatting.
Done linting! Found 0 violations, 0 serious in 1099 files.

Redacted live Claude Web fetch on 2026-06-14 17:06 Pacific:

[claude-web] Found sessionKey in Safari
[claude-web] Found session key (24 cookies)
[claude-web] Organizations API status: 200
[claude-web] Organization resolved
[claude-web] Usage API status: 200
[claude-web] Account API status: 200
Cookie cache stored provider=claude source=Safari

Redacted live header probe on 2026-06-14 17:06 Pacific:

cache-source: Safari
initial-sessionKey-sha256-12: e42266eaa620
organizations-status: 200
organizations-set-cookie-count: 1
organizations-sessionKey-set-cookie: no
usage-request-sessionKey-sha256-12: e42266eaa620
usage-used-renewed-sessionKey: not-applicable-no-renewal
usage-status: 200
usage-set-cookie-count: 1
usage-sessionKey-set-cookie: no

Redacted renewal watcher proof on 2026-06-15 05:43 Pacific:

renewal_observed source=Safari initial=e42266eaa620 observed_from=usage renewed=e42266eaa620 changed=no usage_status=200 used_renewed=no followup_status=200 followup_used_observed=yes

This shows claude.ai emitted a live Set-Cookie: sessionKey=... response from the usage endpoint, and a follow-up request using that observed sessionKey succeeded with HTTP 200. The emitted value matched the existing key, so this is same-value sessionKey renewal proof rather than rotation proof.

Proof limitation

Live proof now shows claude.ai emitting Set-Cookie: sessionKey=... and accepting a follow-up request with the observed key. The observed value matched the initial key, so the live artifact proves same-value renewal and follow-up reuse, while rotated-value behavior remains covered by request-header regression tests.

Refs #1287

ProspectOre avatar Jun 14 '26 23:06 ProspectOre

ok

Sm0k367 avatar May 02 '26 21:05 Sm0k367