Skip to content

okta: stop storing raw tokens in the session cookie - #17

Merged
fumblehool merged 1 commit into
mainfrom
fix/okta-session-cookie-too-long
Oct 5, 2026
Merged

fumblehool merged 1 commit into
mainfrom
fix/okta-session-cookie-too-long

Conversation

@fumblehool

Copy link
Copy Markdown
Collaborator

Details:

Issue:

User was getting 500 – securecookie: the value is too long: 4128 after signing in through Okta.

Root cause:

Logging in via Okta could fail on the callback with 500 - securecookie: the value is too long: 4128. The callback saved both the raw ID token and the raw access token in the gorilla/sessions cookie store. Okta ID tokens grow with the user's claims (notably a large groups claim), and once encrypted and base64 encoded the two tokens exceeded securecookie's default 4096 byte limit, so Save failed.

Neither token is read after login: the ID token is verified once in the callback, and Ensure only checks that the session value is non-empty. Store a "verified" marker under the existing id_token key instead and drop the access token, which keeps the cookie small regardless of token size. Also delete the one-time nonce once it has been consumed.

Existing sessions still authenticate (the key is unchanged and non-empty). Users who already hold an oversized cookie should clear cookies for the site once.

Logging in via Okta could fail on the callback with
"500 - securecookie: the value is too long: 4128". The callback saved
both the raw ID token and the raw access token in the gorilla/sessions
cookie store. Okta ID tokens grow with the user's claims (notably a
large groups claim), and once encrypted and base64 encoded the two
tokens exceeded securecookie's default 4096 byte limit, so Save failed.

Neither token is read after login: the ID token is verified once in the
callback, and Ensure only checks that the session value is non-empty.
Store a "verified" marker under the existing id_token key instead and
drop the access token, which keeps the cookie small regardless of token
size. Also delete the one-time nonce once it has been consumed.

Existing sessions still authenticate (the key is unchanged and non-empty).
Users who already hold an oversized cookie should clear cookies for the
site once.
@fumblehool
fumblehool merged commit f53a577 into main Oct 5, 2026
3 checks passed
@fumblehool
fumblehool deleted the fix/okta-session-cookie-too-long branch October 5, 2026 15:18
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