VOOZH about

URL: https://deepwiki.com/auth0/wordpress/3.7-security-model

⇱ Security Model | auth0/wordpress | DeepWiki


Loading...
Menu

Security Model

This document describes the security mechanisms implemented by the Auth0 WordPress plugin to protect user authentication and authorization. The security model encompasses cryptographic secret generation, session pairing between WordPress and Auth0, token lifecycle management, back-channel logout coordination, and secure cookie configuration.

For information about the authentication flow itself, see Authentication Flow. For configuration options related to security settings, see Configuration Options.


Overview of Security Layers

The plugin implements multiple layers of security to protect user sessions and prevent unauthorized access:

Security LayerPurposeConfiguration Section
Cryptographic SecretsGenerate secure random keys for cookie encryption and authenticationauth0_cookies, auth0_backchannel_logout, auth0_authentication
Session PairingEnsure WordPress and Auth0 sessions remain synchronizedauth0_authentication[pair_sessions]
Token ManagementValidate and refresh authentication tokensauth0_sessions[refresh_tokens]
Back-Channel LogoutCoordinate session termination across devicesauth0_backchannel_logout
Fallback AuthenticationProvide emergency access mechanismauth0_authentication[allow_fallback]
Cookie SecurityProtect session cookies from interceptionauth0_cookies

Sources: wpAuth0.php40-67 src/Actions/Authentication.php353-431 src/Actions/Configuration.php328-431


Cryptographic Secret Generation

During plugin activation, three cryptographic secrets are automatically generated using PHP's random_bytes() function with 64 bytes of entropy (128 hexadecimal characters):


Secret Generation During Plugin Activation

Secret Types and Usage

SecretOption KeyPurpose
Cookie Secretauth0_cookies[secret]Encrypts session data stored in cookies or PHP sessions
Back-Channel Logout Secretauth0_backchannel_logout[secret]Authenticates back-channel logout requests from Auth0
Fallback Secretauth0_authentication[fallback_secret]Provides emergency WordPress login access via secret URL parameter

The cookie secret is required for the plugin to function and is passed to the Auth0-PHP SDK's SdkConfiguration during initialization. Changing the cookie secret logs out all users.

Sources: wpAuth0.php40-67 src/Plugin.php312 src/Actions/Configuration.php332-336


Session Security

Session Pairing

Session pairing ensures that WordPress and Auth0 sessions remain synchronized. When enabled, users must maintain valid sessions in both systems or they will be logged out.


Session Pairing Validation Flow

The Authentication::onInit() method performs session pairing validation on every request. The pairing behavior is controlled by the auth0_authentication[pair_sessions] setting:

  • 0 (Non-Administrators): Enforces pairing for all users except administrators
  • 1 (All Users - Recommended): Enforces pairing for all users including administrators
  • 2 (Disabled): Allows independent WordPress and Auth0 sessions

When pairing is enforced, the system:

  1. Verifies both WordPress and Auth0 sessions exist
  2. Validates the Auth0 sub claim matches the WordPress user's linked connection
  3. Checks if the access token has expired
  4. Attempts token refresh if refresh tokens are enabled
  5. Clears both sessions if any validation fails

Sources: src/Actions/Authentication.php353-431

Session Storage Methods

The plugin supports two methods for storing session data:

MethodConfiguration ValueSecurity Considerations
Encrypted CookiescookiesData stored client-side, encrypted with cookie secret; works across load-balanced servers
PHP Native Sessionssessions (Recommended)Data stored server-side; requires proper PHP session configuration for security

The storage method is configured via auth0_sessions[method]. PHP sessions are recommended but require external configuration to work securely and reliably across server environments.

Sources: src/Actions/Configuration.php277-286 src/Plugin.php300-320

Rolling Sessions

When rolling sessions are enabled (auth0_sessions[rolling_sessions] = true), session expiration times are updated on each request, extending the user's authenticated session. This is implemented in the Authentication::onShutdown() method:


Rolling Session Update Flow

Rolling sessions prevent users from being logged out due to inactivity while actively using the site.

Sources: src/Actions/Authentication.php573-589 src/Actions/Configuration.php306-315


Token Management

Token Validation and Lifecycle

The plugin manages JSON Web Token (JWT) validation and lifecycle through the Auth0-PHP SDK:


Token Lifecycle Management

Token Refresh Mechanism

When access tokens expire and refresh tokens are enabled, the plugin attempts to obtain new access tokens without requiring user reauthentication:

  1. The Authentication::onInit() method detects expired access tokens via $session->accessTokenExpired
  2. If auth0_sessions[refresh_tokens] = true, the plugin calls $this->getSdk()->renew()
  3. The SDK uses the refresh token to request a new access token from Auth0
  4. If renewal fails (e.g., refresh token expired or revoked), both sessions are cleared and the user is logged out

Refresh tokens must be enabled in the Auth0 Application settings ("Allow Offline Access") for this feature to work.

Sources: src/Actions/Authentication.php413-428 src/Actions/Configuration.php316-326

JWKS Caching

The plugin caches JSON Web Key Sets (JWKS) used to validate JWT signatures. Caching is controlled by auth0_tokens[caching]:

  • wp_object_cache (Recommended): Uses WordPress's object caching system
  • disable: Disables caching (negatively impacts performance)

When caching is enabled, the WpObjectCachePool class provides PSR-6 compatible caching to the Auth0-PHP SDK.

Sources: src/Plugin.php322-326 src/Actions/Configuration.php261-271


Back-Channel Logout

Back-Channel Logout enables Auth0 to notify the WordPress plugin when a user's session is terminated elsewhere (e.g., from another device or the Auth0 dashboard).


Back-Channel Logout Request Handling

Back-Channel Logout Configuration

To enable back-channel logout:

  1. Set auth0_backchannel_logout[enabled] = true in the plugin

  2. Configure the back-channel logout URL in the Auth0 Application settings:

    https://yoursite.com/wp-login.php?auth0_bcl={secret}
    

    Where {secret} is the value from auth0_backchannel_logout[secret]

  3. Optionally configure auth0_backchannel_logout[ttl] to control how long unclaimed logout tokens remain valid (default: 1 month)

The back-channel logout secret authenticates requests from Auth0, preventing unauthorized session termination attempts.

Sources: src/Actions/Authentication.php454-469 src/Actions/Configuration.php391-431 src/Plugin.php325


Fallback Authentication

The fallback authentication mechanism provides emergency access to the standard WordPress login form when Auth0 authentication is unavailable or misconfigured.

Fallback Access Method

When auth0_authentication[allow_fallback] = true, administrators can access the WordPress login form by appending a secret parameter:

https://yoursite.com/wp-login.php?auth0_fb={fallback_secret}

The Authentication::onLogin() method validates the fallback secret before allowing access:


Fallback Authentication Validation

The fallback secret is automatically generated during plugin activation and can be regenerated from the Advanced Options page. Administrators should store this URL securely for emergency access.

Sources: src/Actions/Authentication.php443-452 src/Actions/Configuration.php212-228 wpAuth0.php59-65


Cookie Security Configuration

The plugin provides granular control over cookie security attributes to protect session data from interception and unauthorized access.

Cookie Security Settings

SettingOption KeyPurposeRecommended Value
Secretauth0_cookies[secret]Encrypts cookie contentsAuto-generated 128-char hex
Domainauth0_cookies[domain]Restricts cookie to specific domainSite's domain
Pathauth0_cookies[path]Restricts cookie to URL path/ (default)
Secureauth0_cookies[secure]Requires HTTPS for cookie transmissiontrue for HTTPS sites
SameSiteauth0_cookies[samesite]Prevents CSRF attackslax (suggested)
Expiresauth0_cookies[ttl]Cookie lifetime in secondsBased on security policy

Cookie Configuration Flow


Cookie Configuration Architecture

SameSite Attribute

The SameSite cookie attribute protects against Cross-Site Request Forgery (CSRF) attacks:

  • lax (Suggested): Cookies sent with top-level navigations and same-site requests
  • strict: Cookies only sent with same-site requests (most secure, but may break some flows)
  • none: Cookies sent with all requests (requires secure flag)

Sources: src/Actions/Configuration.php328-390 src/Plugin.php282-320


Input Sanitization

All user input from configuration forms is sanitized to prevent injection attacks and ensure data integrity. The Sanitize utility class provides specialized sanitization methods:

MethodPurposeUsage
Sanitize::string()Basic text sanitizationClient IDs, secrets, general text
Sanitize::domain()Domain validationAuth0 domain, custom domain
Sanitize::alphanumeric()Alphanumeric filteringAPI audiences, organization IDs
Sanitize::integer()Integer validation with boundsTTL values, numeric settings
Sanitize::boolean()Boolean normalizationToggle settings
Sanitize::textarea()Multi-line text sanitizationOrganization lists, API audience lists

Sanitization in Configuration Updates

The Configuration action class applies sanitization in onUpdate*() methods before storing settings:


Configuration Update Sanitization Flow

For example, the onUpdateClient() method sanitizes client credentials:

  • Client ID: Sanitize::string() removes non-printable characters
  • Client Secret: Sanitize::string() removes non-printable characters
  • Domain: Sanitize::domain() validates domain format and extracts hostname

API audiences and organization IDs receive additional validation to ensure proper format (e.g., organization IDs must start with org_).

Sources: src/Utilities/Sanitize.php src/Actions/Configuration.php688-828


Security Best Practices

When deploying the plugin in production environments, follow these security best practices:

  1. Enable HTTPS: Set auth0_cookies[secure] = true only on sites served exclusively over HTTPS
  2. Enable Session Pairing: Use auth0_authentication[pair_sessions] = 1 (All Users) for maximum security
  3. Configure Back-Channel Logout: Enable and configure back-channel logout to coordinate session termination
  4. Use Refresh Tokens: Enable auth0_sessions[refresh_tokens] = true to maintain sessions without reauthentication
  5. Secure Fallback URL: Store the fallback authentication URL securely and only share with trusted administrators
  6. Enable JWKS Caching: Use auth0_tokens[caching] = wp_object_cache for performance and reduced API load
  7. Configure PHP Sessions Properly: If using PHP sessions, follow OWASP recommendations for secure session configuration

Sources: src/Actions/Configuration.php src/Actions/Authentication.php