You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(auth): stateless OAuth2 state via securecookie
Drops the in-memory state map, the RWMutex protecting it and the
cleanup goroutine. The OAuth2 `state` parameter is now a self-contained
signed blob — `securecookie.Encode` packs (returnURL, expiry) into the
string we hand to the IdP, `Decode` verifies the signature and pulls
them back out on callback. No server-side bookkeeping.
Removed:
- states map[string]*StateData + statesMu sync.RWMutex
- cleanupStates goroutine + stateCleanupEvery constant
- StateData struct (replaced by tiny private stateBlob)
- crypto/rand + encoding/base64 + sync imports
Added:
- github.com/gorilla/securecookie (battle-tested; the lib handles all
the HMAC + AES details and the MaxAge bookkeeping)
Trade-offs vs the in-memory map:
- Pod restart: same behaviour. Both the in-memory map AND the
process-random securecookie keys are lost on restart, so in-flight
logins fail closed either way. Stable keys (env or k8s secret) is a
one-line follow-up that would also let multiple replicas share state.
- Replay within TTL: theoretically possible with the new code (no
nonce store to detect reuse), where the old code deleted on first
use. Mitigated by the IdP's own one-time-code semantics and the
10-min TTL. Acceptable for the threat model; can add a nonce later
if needed.
Stats:
- oidc.go: 252 -> 234 lines (-18)
- Combined with phases A+B: 655 -> 319 (-336, -51% of pre-refactor
auth code)
0 commit comments