Session Management
Sessions in Frontier allow the system to remember that a user is authenticated without requiring them to authenticate again for every request. Sessions are created automatically after successful authentication and are stored as encrypted cookies in the user’s browser.Session management APIs are used internally by the Frontier SDK and are not typically called directly by client applications. The SDK automatically handles session creation, validation, tracking, and revocation.
What is a Session?
A session represents an authenticated user’s active connection to Frontier. Each session contains:- Session ID - Unique identifier for the session
- User ID - The authenticated user
- Metadata - Device and location information (browser, OS, IP address, location)
- Timestamps - Created at, updated at, authenticated at, and expiration time
- Validity - Whether the session is still active and not expired
Session Data Example
Session Lifecycle
1. Creation
Sessions are created automatically after successful authentication through any strategy (OIDC, email OTP, passkey, etc.). What Happens:- User completes authentication flow
- Frontier creates a new session record
- Session is encrypted and stored as an HTTP-only cookie
- Cookie is automatically sent with all subsequent requests
2. Validation
On each request, Frontier validates the session to ensure it’s still valid. Validation Checks:- Session exists in the database
- Session hasn’t been explicitly revoked (
deleted_atis null) - Session hasn’t expired (current time <
expires_at) - Session cookie signature is valid
3. Activity Tracking
Frontier tracks when sessions are used to provide “Last Active” information. Whenupdated_at is Updated:
- User makes authenticated API requests
- SDK’s
useLastActiveTrackerhook pings the session (every 10 minutes)
4. Expiration
Sessions expire when:- Time-based expiration - Configured validity period elapsed (e.g., 7 days from creation)
- Manual revocation - User or admin explicitly revokes the session
- User logout - User initiates logout
Session Metadata
Frontier automatically extracts and stores metadata about each session for security monitoring and user experience.Metadata Fields
| Field | Description | Example |
|---|---|---|
| browser | Web browser being used | ”Chrome”, “Firefox”, “Safari” |
| operating_system | Device operating system | ”Windows”, “macOS”, “Linux” |
| ip_address | IP address of the client | ”203.0.113.42” |
| city | Geographic city | ”San Francisco” |
| country | Geographic country | ”United States” |
| latitude | Geographic latitude | ”37.7749” |
| longitude | Geographic longitude | ”-122.4194” |
Use Cases for Metadata
Security Monitoring:- Detect suspicious logins from new locations
- Alert users to unexpected access
- Identify compromised accounts
- Show users where they’re logged in
- Display “Current device” in session list
- Help users identify their own sessions
- Track where actions were performed
- Compliance and regulatory requirements
- Forensic analysis
HTTP Headers Used
Frontier extracts session metadata from HTTP headers:| Metadata Field | Default Header | Configurable |
|---|---|---|
| IP Address | x-forwarded-for | Yes |
| Country | x-frontier-country | Yes |
| City | x-frontier-city | Yes |
| Latitude | x-frontier-latitude | Yes |
| Longitude | x-frontier-longitude | Yes |
| Browser & OS | User-Agent | Yes |
x-forwarded-for contains multiple comma-separated values (common with proxies), Frontier uses the first value.
Browser & OS Parsing:
Frontier uses the uap-go library to parse the User-Agent header and extract browser family and OS family.
Configuring Headers
Customize header names in yourconfig.yaml:
- Using CloudFront or CDN with custom headers
- Reverse proxy that sets different header names
- Security requirements for custom header names
If a header is not present in the request, the corresponding metadata field will be empty. Frontier gracefully handles missing headers.
Viewing Active Sessions
The Frontier SDK provides built-in UI components for users to view their active sessions.What Users See
- List of all active sessions
- Device information (browser, OS)
- Location information (IP, city, country)
- Last active timestamp
- Indicator for current session
SDK Implementation (Internal)
The SDK uses theuseSessions hook:
API Endpoint
While the SDK handles this automatically, the underlying API is:Revoking Sessions
Users can revoke any of their active sessions, which immediately invalidates the session and logs out the user from that device.When to Revoke
- User suspects account compromise
- User wants to log out from a specific device
- User wants to clean up old sessions
- User lost a device
SDK Implementation (Internal)
API Endpoint
Revoking Current Session (Logout)
To logout from the current session:Automatic Activity Tracking
The Frontier React SDK automatically tracks user activity to maintain accurate “Last Active” timestamps.How It Works
The SDK’s internaluseLastActiveTracker hook:
- Pings every 10 minutes - Automatically calls the session ping endpoint
- Updates metadata - Refreshes browser, OS, IP, and location data
- Works in background - Continues even when browser tab is inactive
- Automatic activation - Enabled when user is logged in
Ping Flow
Accessing Session Metadata
You can access the current session’s metadata in your application:Important: Activity tracking only updates the
updated_at timestamp. It does NOT extend session validity. Sessions always expire based on the configured validity period from creation time.Session Configuration
Configure session behavior in yourconfig.yaml:
Configuration Options
| Option | Description | Default |
|---|---|---|
hash_secret_key | Secret for session integrity (32 chars) | Required |
block_secret_key | Secret for session encryption (32 chars) | Required |
validity | Session lifetime from creation | 168h (7 days) |
domain | Cookie domain | Request domain |
secure | Require HTTPS | true |
same_site | SameSite cookie policy | lax |
Generating Secret Keys
Generate secure random keys:gRPC APIs
Frontier provides gRPC APIs for session management.User APIs
Available to authenticated users for managing their own sessions: 1. ListSessions - Get all active sessions for current userAdmin APIs
Require admin privileges for managing any user’s sessions: 1. ListUserSessions - Get sessions for any userSecurity Best Practices
Use Secure Cookies in Production
Use Secure Cookies in Production
Rotate Secret Keys Regularly
Rotate Secret Keys Regularly
Rotate session encryption keys periodically:
- Generate new keys
- Update configuration with both old and new keys
- Deploy changes
- After all sessions expire, remove old keys
Monitor Session Activity
Monitor Session Activity
Set up monitoring for:
- Unusual login locations
- Multiple concurrent sessions
- Failed session validations
- Rapid session creation
Implement Session Limits
Implement Session Limits
Consider limiting concurrent sessions per user:
- Helps detect account sharing
- Reduces attack surface
- Improves security posture
Enable HTTPS Only
Enable HTTPS Only
Never transmit session cookies over HTTP:
Troubleshooting
Session Validation Failed
Symptoms: User repeatedly logged out Possible Causes:- Session expired
- Session revoked
- Cookie not being sent (CORS issues)
- Secret keys changed
- Check session expiration time
- Verify CORS configuration
- Ensure cookies are enabled in browser
- Check secret key configuration
Metadata Not Being Captured
Symptoms: Session metadata fields empty Possible Causes:- Headers not being forwarded by proxy
- Incorrect header configuration
- Reverse proxy configuration issue
- Verify proxy forwards required headers
- Check header name configuration
- Test with direct connection (bypass proxy)
Sessions Not Expiring
Symptoms: Old sessions remain active Possible Causes:- Cron job not running
- Database cleanup failed
- Incorrect validity configuration
- Check cron job logs
- Verify database connectivity
- Review session validity configuration
Related Documentation
User Authentication
Learn about user authentication strategies
Security
Understand Frontier’s security features