Cookie architecture
AuthKit uses two types of cookies:Session cookie (persistent)
The main session cookie stores encrypted session data including access and refresh tokens.- Name:
wos-session(default, configurable viaWORKOS_COOKIE_NAME) - Duration: 400 days (default, configurable via
WORKOS_COOKIE_MAX_AGE) - Security: HttpOnly, Secure (on HTTPS), encrypted with
WORKOS_COOKIE_PASSWORD - Size: ~2-4 KB depending on user data
Access token cookie (ephemeral)
When using eager auth, a temporary cookie provides synchronous token access.- Name:
workos-access-token - Duration: 30 seconds
- Purpose: Enable immediate client-side token access on page load
- Auto-consumed: Deleted after first read
Cookie security attributes
HttpOnly
Status: Always enabled Prevents JavaScript access to the cookie, protecting against XSS attacks.Secure
Status: Automatically set based on protocol Ensures cookies are only sent over HTTPS connections.In local development with
http://localhost, the Secure flag is automatically disabled to allow cookie storage.SameSite
Controls when cookies are sent with cross-site requests.- lax (default)
- strict
- none
Recommended for most applicationsCookies are sent with:
- Same-site requests
- Top-level navigation (e.g., clicking a link)
- Cross-site POST requests
- Embedded iframes
Cookie lifespan
Maximum age
Configure how long the cookie remains valid:The cookie expiry is separate from token expiry. The access token typically expires after 15 minutes, but the cookie persists to enable automatic token refresh.
Token refresh cycle
The long cookie duration enables seamless token refresh without requiring users to re-authenticate.Domain configuration
Single domain (default)
Cookies are scoped to the current domain only:Shared domains
Share sessions across multiple subdomains:example.comapp.example.comdashboard.example.com- Any other subdomain
Multi-application sessions
Example setup for shared authentication across multiple apps:Configure redirect URIs
Each app needs its own callback URL in WorkOS dashboard:
https://app.example.com/callbackhttps://dashboard.example.com/callback
Custom cookie names
Customize the cookie name to avoid conflicts:- Running multiple AuthKit instances on the same domain
- Migrating from another authentication system
- Testing different configurations simultaneously
Cookie size optimization
Session cookies contain:- Access token (~1.5 KB)
- Refresh token (~200 bytes)
- User object (~1-2 KB depending on fields)
- Impersonator data (if present)
Security best practices
Use HTTPS in production
Use HTTPS in production
Always deploy with HTTPS to ensure cookies have the Secure flag and cannot be intercepted.
Set appropriate SameSite
Set appropriate SameSite
Use
lax or strict unless you specifically need cross-origin cookie access.Limit cookie domain scope
Limit cookie domain scope
Rotate cookie passwords
Rotate cookie passwords
Monitor cookie size
Monitor cookie size
Troubleshooting
Cookies not being set
Cookies not being set
Sessions not shared across subdomains
Sessions not shared across subdomains
SameSite=None cookies blocked
SameSite=None cookies blocked
Related resources
Environment variables
Complete configuration reference
CDN deployments
Cache control and CDN considerations