Understanding client session IDs as time-sensitive salts for secure session dropoff URLs.
The Client Session ID is a time-sensitive salt tied to the end-user's device and IP address. It is only needed if you are using Session Dropoff URLs to redirect users from your headless frontend to WordPress.
Enable Client Session IDs only if your application redirects users to WordPress-rendered pages:
You do NOT need Client Session IDs if your application:
Generate dropoff URLs client-side using the TokenManager and generateDropoffURL() function. This approach:
WooGraphQL can expose session dropoff URL fields on the Customer type that you can query directly. However:
Warning: Querying dropoff URLs from the GraphQL API is highly insecure. It's strongly recommended to leave the session dropoff URL fields unregistered in the GraphQL API in production environments. Always use client-side generation instead.
Session Dropoff URLs contain a nonce that WordPress uses to validate the handoff request. The Client Session ID serves as part of the salt for generating these nonces, making them:
When SessionBehavior.withClientSession is enabled, the TokenManager generates a Client Session ID:
┌─────────────────────────────────────────────────────────────┐
│ createClientSessionId() │
├─────────────────────────────────────────────────────────────┤
│ 1. Load or create client credentials: │
│ - User-Agent (from browser) │
│ - IP address (fetched from api.ipify.org) │
│ - Issued timestamp │
│ - Expiration timestamp (1 hour from now) │
│ │
│ 2. Generate nonce hash from credentials │
│ (WordPress-compatible nonce algorithm) │
│ │
│ 3. Save to storage: │
│ - Client Session ID │
│ - Expiration timestamp │
│ │
│ 4. Return { clientSessionId, timeout } │
└─────────────────────────────────────────────────────────────┘
After generation, the Client Session ID is sent to WordPress via the updateSession callback:
updateSession(tokens, { sessionData: [ { key: 'client_session_id', value: clientSessionId }, { key: 'client_session_id_expiration', value: timeout }, ], });
This stores the Client Session ID in the WooCommerce session meta. When a dropoff URL is accessed, WordPress uses the stored Client Session ID to verify the nonce.
When generating a dropoff URL, the Client Session ID is used as salt:
// The nonce is generated using: // - User ID (from session token) // - Client Session ID (device/time-bound) // - Action type (cart, checkout, account, etc.) const nonce = createNonce(action, userId, clientSessionId); const url = `${wpUrl}/transfer-session?session_id=${userId}&${param}=${nonce}`;
Include SessionBehavior.withClientSession in your TokenManager configuration:
import { TokenManager, SessionBehavior } from '@woographql/session-utils'; const tokenManager = new TokenManager({ ID: 'my-store', behavior: [ SessionBehavior.withAuth, SessionBehavior.withClientSession, // Enable ONLY if using dropoff URLs ], startSession: async (tokens) => { // Fetch session token }, updateSession: async (tokens, input) => { // Required for client session IDs - sends ID to WordPress const result = await graphqlClient.request(UpdateSessionDocument, { input: input.sessionData, }); return result.updateSession.sessionToken; }, // ... });
The Client Session ID is automatically renewed every 45 minutes to ensure it stays valid while the user is active. This renewal:
updateSessionThe Client Session ID is derived from "client credentials" - a combination of device identifiers:
| Property | Source | Purpose |
|---|---|---|
userAgent | navigator.userAgent | Identifies the browser/device |
ip | External API (api.ipify.org) | Identifies the network |
issued | Current timestamp | Tracks credential creation |
expired | issued + 1 hour | Limits validity window |
These credentials are stored separately and refreshed every 14 days. The Client Session ID itself is regenerated every hour.
// Get the current client session ID const clientSessionId = tokenManager.getClientSessionId(); if (clientSessionId) { // Use for session dropoff URL generation const checkoutUrl = generateDropoffURL( clientSessionId, userId, URLTypes.CheckoutPage ); }
The Client Session ID and its derived nonces have a 1-hour lifespan. This short window is intentional:
If a user needs a new dropoff URL after the Client Session ID expires, the TokenManager automatically generates a new one during the next renewTokens() call.