Cookies and Security
The SDK uses HTTP-only, secure cookies for session management with built-in protections against common attacks.Cookie Security Flags
All cookies are automatically configured with security flags:Always enabled. Prevents client-side JavaScript from accessing the cookie, reducing the attack surface for XSS (Cross-Site Scripting) attacks.This flag cannot be disabled.
Set to
Lax by default to help mitigate CSRF (Cross-Site Request Forgery) attacks.Lax: Cookies sent with top-level navigation and same-site requestsStrict: Cookies only sent with same-site requestsNone: Cookies sent with all requests (requiresSecureflag)
Automatically set to
true when APP_BASE_URL uses https://.Ensures cookies are only transmitted over HTTPS connections, preventing interception over insecure networks.Important: When using dynamic base URLs in production, the SDK enforces secure: true. Explicitly setting secure: false will throw InvalidConfigurationError.Cookie Configuration
Customize cookie settings via configuration or environment variables:Session Security
Session Encryption
All session data is encrypted using AES-256-GCM before being stored in cookies. Generate a strong secret:Rolling Sessions
The SDK uses rolling sessions by default, which automatically extends the session expiry on each request. Benefits:- Active users stay logged in
- Idle sessions expire
- Reduces re-authentication friction
Set-Cookie header on every request that touches the session. This means:
Session Duration
Configure session timeouts to balance security and user experience:- Rolling duration: How long the session lasts without activity
- Absolute duration: Maximum session lifetime regardless of activity
Stateful Sessions
For enhanced security or large sessions, store session data server-side:- No 4KB cookie size limit
- Server-side session revocation
- Reduced client-side data exposure
Token Security
Access Token Storage
Access tokens are stored encrypted in the session cookie (or session store).Refresh Token Security
Refresh tokens are long-lived credentials that can obtain new access tokens. Best practices:Request offline_access scope
Request offline_access scope
Only request refresh tokens when needed:
Enable Refresh Token Rotation
Enable Refresh Token Rotation
Configure in Auth0 Dashboard:
- Go to Applications > Your App > Advanced Settings
- Enable Refresh Token Rotation
- Enable Refresh Token Reuse Detection
Set appropriate lifetimes
Set appropriate lifetimes
Configure in Auth0 Dashboard:
- Go to Applications > Your App > Advanced Settings
- Set Refresh Token Expiration based on security requirements
- Enable Inactivity Expiration to expire tokens after periods of inactivity
Token Refresh Buffer
Refresh tokens proactively to avoid expiration mid-request:XSS Protection
Error Message Handling
Content Security Policy
Implement CSP headers to mitigate XSS:CSRF Protection
The SDK provides built-in CSRF protection through:- SameSite cookies: Default
Laxsetting prevents CSRF attacks - State parameter: Validated on OAuth callback
- Transaction cookies: Bind authentication state to the session
Custom CSRF Protection
For additional protection on custom routes:Input Validation
Safe Redirect Handling
beforeSessionSaved Hook Validation
DPoP (Demonstrating Proof-of-Possession)
DPoP binds access tokens to cryptographic key pairs, preventing token theft and replay attacks.Enable DPoP
- Prevents token theft (stolen tokens are useless without private key)
- Prevents replay attacks (proof is bound to request)
- Enhanced security for high-value transactions
Caching Security
Many hosting providers (Vercel, Netlify) cache responses at the edge. Caching authenticated responses can:- Expose session cookies via cached
Set-Cookieheaders - Leak user data to other users
- Bypass authentication checks
What NOT to Cache
Never cache responses from:auth0.getSession()auth0.getAccessToken()useUser()hook- Any route that checks authentication
- Rolling session responses (contain
Set-Cookie)
Safe Caching
Only cache:- Public, unauthenticated content
- Static assets
- API responses that don’t require authentication
Dynamic Base URLs
For preview environments (Vercel, Netlify), the SDK can infer the base URL from the request host.- Secure cookies enforced: When using dynamic base URLs in production,
secure: falsethrowsInvalidConfigurationError - Callback URL validation: Auth0 validates the callback URL against your registered URLs
- Protocol inference: HTTPS is assumed for security
APP_BASE_URL in production:
Logout Security
OIDC Logout
The SDK supports OIDC logout with optionalid_token_hint:
includeIdTokenHintInOIDCLogoutUrl | Security Benefit | Privacy Impact |
|---|---|---|
true (default) | Better DoS protection | ID token in logout URL (PII in logs) |
false | No PII in logout URLs | Reduced DoS protection |
Backchannel Logout
Implement backchannel logout for server-initiated session termination:- Configure backchannel logout URI in Auth0 Dashboard:
https://yourdomain.com/auth/backchannel-logout
- The SDK automatically handles logout token validation
- Sessions are terminated immediately
Vulnerability Reporting
Please report security issues through Auth0’s Responsible Disclosure Program.Security Checklist
Configuration Security
Configuration Security
- Use strong
AUTH0_SECRET(32+ bytes, hex-encoded) - Rotate secrets periodically
- Never commit secrets to source control
- Use different secrets per environment
- Enable Refresh Token Rotation in Auth0 Dashboard
Cookie Security
Cookie Security
Token Security
Token Security
- Store tokens server-side only
- Request minimum required scopes
- Use token refresh buffer
- Implement token refresh error handling
- Consider DPoP for high-security apps
Input Validation
Input Validation
- Validate all redirect URLs
- Escape OAuth error messages
- Sanitize user inputs in hooks
- Implement CSRF tokens for custom forms
- Use allowlists for redirects
Caching
Caching
- Never cache authenticated responses
- Check hosting provider caching rules
- Set appropriate
Cache-Controlheaders - Verify
Set-Cookienot cached
Auth0 Configuration
Auth0 Configuration
- Register all callback URLs in Auth0 Dashboard
- Enable Refresh Token Rotation
- Configure appropriate token lifetimes
- Enable MFA for sensitive operations
- Review Auth0 logs regularly