Skip to Content

Security

Entro Auth security features.

This page contains information about security features of Entro Auth.

Password Hashing

Entro Auth uses the scrypt algorithm to hash passwords by default. This algorithm is designed to be memory-hard and CPU-intensive, making it resistant to brute-force attacks. You can customize the password hashing function by setting the password option in the configuration. This option should include a hash function to hash passwords and a verify function to verify them.

Secret Rotation

Entro Auth supports non-destructive rotation of ENTRO_AUTH_SECRET within the same encryption format and purpose. When you configure versioned secrets via the secrets option or the ENTRO_AUTH_SECRETS environment variable, all new encrypted data includes a key version identifier. Decryption performs a direct key lookup by version, with no trial decryption.

Within the same encryption purpose, legacy data encrypted before rotation (bare-hex format) remains decryptable using the original ENTRO_AUTH_SECRET as a fallback. Ordinary key rotation requires no database migration or downtime. Data is lazily re-encrypted with the current key when it is next written.

Upgrading from shared encryption keys to purpose-specific keys changes the format used for pending OAuth and SAML state cookies and OAuth Proxy payloads. Keeping the original secret does not preserve these pending flows. Upgrade participating servers together and restart sign-in and account-linking flows that began before the cutover. See the state-cookie upgrade guidance and OAuth Proxy upgrade instructions.

See the secrets option for configuration details.

Session Management

Session Expiration

Entro Auth uses secure session management to protect user data. Sessions are stored in the database or a secondary storage, if configured, to prevent unauthorized access. By default, sessions expire after 7 days, but you can customize this value in the configuration. Additionally, each time a session is used, if it reaches the updateAge threshold, the expiration date is extended, which by default is set to 1 day.

Session Revocation

Entro Auth allows you to revoke sessions to enhance security. When a session is revoked, the user is logged out and can no longer access the application. A logged in user can also revoke their own sessions to log out from different devices or browsers.

See the session management for more details.

CSRF Protection

Entro Auth includes multiple safeguards to prevent Cross-Site Request Forgery (CSRF) attacks:

  1. Avoid simple requests See Avoiding simple requests for more details. By default, Entro Auth prefers non-simple requests for state-changing operations, typically by requiring a non-simple header or a Content-Type header of application/json.

    Some routes intentionally accept application/x-www-form-urlencoded requests for progressive enhancement or protocol interoperability, including sign-in/sign-up email flows and some callback/token-style endpoints. Those routes rely on additional protections such as origin validation, Fetch Metadata checks where applicable, and protocol-specific state or nonce validation.

  2. Origin Validation Each request’s Origin header is verified to confirm it comes from your application or another explicitly trusted source. Requests from untrusted origins are rejected. By default, Entro Auth trusts the base URL of your app, but you can specify additional trusted origins via the trustedOrigins configuration option.

    A same-origin form submission from a page using Referrer-Policy: no-referrer can carry Origin: null. When Sec-Fetch-Site confirms the request is same-origin, Entro Auth validates the request URL's origin against trustedOrigins instead. Requests without that Fetch Metadata evidence and requests targeting an untrusted origin remain rejected.

  3. Secure Cookie Settings Session cookies use the SameSite=Lax attribute by default, preventing browsers from sending cookies with most cross-site requests. You can override this behavior using the defaultCookieAttributes option.

  4. Fetch Metadata Protection for First-Login CSRF Entro Auth also uses Fetch Metadata headers (Sec-Fetch-Site, Sec-Fetch-Mode, Sec-Fetch-Dest) to provide additional CSRF protection specifically for first-login scenarios, where the client does not yet have any cookies.

    This protection applies to routes a browser can call as a simple request: the sign-in and sign-up email routes, which accept form submissions to support progressive enhancement patterns, and routes that take no request body, such as anonymous sign-in.

    When such a request is received without any cookies:

    • If the browser indicates a cross-site navigation (for example: Sec-Fetch-Site: cross-site and Sec-Fetch-Mode: navigate), Entro Auth blocks the request as a potential login CSRF attack.

    • Otherwise, if the request carries an Origin or Referer header, Entro Auth validates it against your trustedOrigins configuration and rejects untrusted origins. This applies whether or not the client sends Fetch Metadata headers.

    • Only when the request carries neither Fetch Metadata headers nor an Origin/Referer header (typical of non-browser clients) does Entro Auth fall back to permissive behavior, so server-to-server and native clients are not rejected.

    This mechanism allows modern browsers to receive stronger protection against first-login CSRF attacks without requiring CSRF tokens or client-side JavaScript, and works seamlessly with progressive enhancement patterns.

    Non-browser HTTP clients (mobile apps, server-to-server) that send an Origin or Referer header must use a value listed in trustedOrigins, since Entro Auth validates it whenever it is present. Clients that send no origin header and no Fetch Metadata (typical of non-browser tooling) are not affected.

  5. No Mutations on GET Requests (with additional safeguards) GET requests are assumed to be read-only and should not alter the application's state. In cases where a GET request must perform a mutation—such as during OAuth callbacks - Entro Auth applies extra security measures, including validating nonce and state parameters to ensure the request's authenticity.

  6. Your own routes that call auth.api These checks run only for requests that reach auth.handler. A direct auth.api call skips them, even when you pass the browser's headers. It also skips the trustedOrigins check on callbackURL, errorCallbackURL, newUserCallbackURL, and redirectTo, so validate any of those your route takes from the request. If your own route changes state for a cookie-authenticated browser request, reject it unless its Origin is trusted:

    const origin = request.headers.get("origin");
    const context = await auth.$context;
    if (!origin || !context.isTrustedOrigin(origin)) {
      return new Response(null, { status: 403 });
    }

    isTrustedOrigin checks the origins resolved at startup. If your trustedOrigins function adds origins based on the request, include those in the check, or forward the request to auth.handler when the endpoint has an HTTP route.

Disabling Security Checks

Entro Auth provides two separate options to disable security checks. These options control different aspects of security:

disableCSRFCheck

Disables all CSRF protection, including:

  • Origin header validation when cookies are present
  • Fetch Metadata checks (Sec-Fetch-Site, Sec-Fetch-Mode, Sec-Fetch-Dest)
  • Cross-site navigation blocking for first-login scenarios
{
  advanced: {
    disableCSRFCheck: true
  }
}

Disabling CSRF checks allows requests from any origin to use cookies and perform actions on behalf of users. This opens your application to CSRF attacks.

disableOriginCheck

Disables URL validation against trustedOrigins, including:

  • callbackURL validation
  • redirectTo validation
  • errorCallbackURL validation
  • newUserCallbackURL validation
{
  advanced: {
    disableOriginCheck: true
  }
}

Disabling origin checks allows any URL to be used in redirects and callbacks. This opens your application to open redirect vulnerabilities.

When disableOriginCheck is not set, it defaults to true while NODE_ENV is test. A test of your own trustedOrigins therefore passes whatever the configuration says. Set disableOriginCheck: false in the configuration your tests build to have them exercise the check.

For backward compatibility, disableOriginCheck: true also disables CSRF protection. If you only want to disable URL validation without affecting CSRF protection, this is not currently possible - both checks are disabled together when using this option.

Summary

OptionWhat it disables
disableCSRFCheckCSRF protection only (origin header validation, Fetch Metadata checks)
disableOriginCheckURL validation AND CSRF protection (for backward compatibility)

OAuth State and PKCE

To secure OAuth flows, Entro Auth stores the OAuth state and PKCE (Proof Key for Code Exchange) using the configured state storage strategy. By default, the state payload is stored in verification storage and the state value is also persisted in a signed cookie for validation. When storeStateStrategy is set to cookie, the full state payload is encrypted into a short-lived cookie instead of creating a verification record.

The state helps prevent CSRF attacks, while PKCE protects against code injection threats. After the OAuth callback is processed, Entro Auth expires the relevant cookie and, when verification storage is used, deletes the stored verification record.

Cookies

Entro Auth gives cookies the Secure attribute and the __Secure- prefix when advanced.useSecureCookies is true, or, when that option is unset, when the base URL (from the baseURL option or an environment variable such as ENTRO_AUTH_URL) uses https. Without a base URL to check (none set, or a dynamic baseURL with protocol: "auto"), cookies are secure when NODE_ENV is production. See Secure Cookies for the full order. Secure cookies are only sent over HTTPS connections. They are also set with the sameSite attribute to lax by default to prevent cross-site request forgery attacks. And the httpOnly attribute is enabled to prevent client-side JavaScript from accessing the cookie.

For Cross-Subdomain Cookies, you can set the crossSubDomainCookies option in the configuration. This option allows cookies to be shared across subdomains, enabling seamless authentication across multiple subdomains.

Customizing Cookies

You can customize cookie names to minimize the risk of fingerprinting attacks and set specific cookie options as needed for additional control. For more information, refer to the cookie options.

Plugins can also set custom cookie options to align with specific security needs. If you're using Entro Auth in non-browser environments, plugins offer ways to manage cookies securely in those contexts as well.

Rate Limiting

Entro Auth includes built-in rate limiting to safeguard against brute-force attacks. Rate limits are applied across all routes by default, with specific routes subject to stricter limits based on potential risk.

IP Address Headers

Entro Auth uses client IP addresses for rate limiting and security monitoring. By default, it reads the address from the X-Forwarded-For header. Clients can set this header themselves. Per-client limits only work in one of these setups:

  • Your proxy or server code sets the address in a header on every request and replaces any value the client sent.
  • Your proxies append to X-Forwarded-For, and you list them in trustedProxies.

Connecting IP Address explains how to configure each setup.

Trusted Proxy Headers

If your application runs behind a reverse proxy or load balancer, Entro Auth can derive the base URL from the inbound request's X-Forwarded-Host and X-Forwarded-Proto headers. This is useful when your app is accessible from multiple domains (e.g. example.com and app.example.dev) and you don't want to hardcode a single baseURL in the configuration.

When trustedProxyHeaders is enabled and no baseURL is set in the configuration (or via environment variables), Entro Auth uses the forwarded headers to construct the base URL on each request. This means OAuth callbacks, email verification links, and redirects will automatically use whichever domain the user loaded the app on.

{
  advanced: {
    trustedProxyHeaders: true
  }
}

Only enable this option if you trust the proxy headers reaching your application. Your reverse proxy or load balancer must be configured to set X-Forwarded-Host and X-Forwarded-Proto correctly, and end users must not be able to set these headers directly. If untrusted clients can forge these headers, they could manipulate redirects and callback URLs.

When enabled, the base URL resolution follows this priority:

  1. Static baseURL from the configuration (if set, proxy headers are ignored)
  2. Environment variables (ENTRO_AUTH_URL, NEXT_PUBLIC_ENTRO_AUTH_URL, etc.)
  3. X-Forwarded-Host + X-Forwarded-Proto headers (when trustedProxyHeaders is true)
  4. The request URL origin as a final fallback

If you're serving your app from multiple approved domains, you'll typically want to:

  • Omit baseURL from the configuration so it's derived per-request from the proxy headers
  • Set trustedOrigins to an allowlist of your approved domains (see below)
  • Leave crossSubDomainCookies disabled — cookies are host-only by default, which means each domain gets its own independent session

Trusted Origins

Trusted origins prevent CSRF attacks and block open redirects. You can set a list of trusted origins in the trustedOrigins configuration option. Requests from origins not on this list are automatically blocked.

Relative callback and redirect URLs support standard path, query, and fragment syntax, but must begin with a single /. Entro Auth rejects protocol-relative URLs (//...), backslashes, control characters, and encoded path separators in the path.

Basic Usage

The most basic usage is to specify exact origins, below is an example of a trusted origins configuration:

{
  trustedOrigins: [
    "https://example.com",
    "https://app.example.com",
    "http://localhost:3000"
  ]
}

Do not leave the localhost origin in a trusted origins list of a production auth instance.

Wildcard Origins

Entro Auth supports wildcard patterns in trusted origins, which allows you to trust multiple subdomains with a single entry:

{
  trustedOrigins: [
    "*.example.com",             // Trust all subdomains of example.com (any protocol)
    "https://*.example.com",     // Trust only HTTPS subdomains of example.com
    "http://*.dev.example.com"   // Trust all HTTP subdomains of dev.example.com
  ]
}

Protocol-specific wildcards

When using a wildcard pattern with a protocol prefix (like https://):

  • The protocol must match exactly
  • The domain can have any subdomain in place of the *
  • Requests using a different protocol will be rejected, even if the domain matches

Protocol-agnostic wildcards

When using a wildcard pattern without a protocol prefix (like *.example.com):

  • Any protocol (http, https, etc.) will be accepted
  • The domain must match the wildcard pattern

Custom Schemes

Trusted origins also support custom schemes for mobile apps and browser extensions:

{
  trustedOrigins: [
    "myapp://",                               // Mobile app scheme
    "chrome-extension://YOUR_EXTENSION_ID",   // Browser extension
    "exp://**",                               // Trust all Expo development URLs
    "exp://10.0.0.*:*/**",                    // Trust 10.0.0.x IP range with any port
  ]
}

Dynamic origin list

You can also dynamically set the list of trusted origins by providing a function that returns it:

{
  trustedOrigins: async (request) => {
    const trustedOrigins = await queryTrustedDomains();
    return trustedOrigins;
  }
}

Important: This function will be invoked per incoming request, so be careful if you decide to dynamically fetch your list of trusted domains.

Outbound OAuth Requests

During sign-in, Entro Auth makes server-side requests to OAuth and OIDC provider endpoints: the token exchange, token refresh, token introspection, and key-set (JWKS) requests. These requests do not follow HTTP redirects. A conformant provider answers these endpoints with a direct response and never redirects, so standard integrations are unaffected. Refusing redirects keeps a provider endpoint from steering a server-side request to an unintended internal address.

Email Enumeration Protection

Entro Auth prevents email enumeration on the sign-up and change-email endpoints. When requireEmailVerification is enabled or autoSignIn is set to false, the sign-up endpoint returns the same 200 response whether the email is already registered or not, following OWASP authentication best practices. Timing attacks are mitigated by simulating password hashing on duplicate sign-up attempts.

See Email and Password — Email Enumeration Protection for configuration details.

Post-Quantum Cryptography

How Entro Auth's cryptography stands against a future quantum computer able to break today's public-key algorithms:

  • Symmetric cryptography. Encrypted data, encrypted session and state tokens, cookie signatures and password hashes use XChaCha20-Poly1305, AES-256-CBC with HMAC-SHA-512, HMAC-SHA-256 and scrypt, with 256-bit keys. Known quantum algorithms do not break these. Their strength rests on your secret: use 32 random bytes, for example openssl rand -base64 32.
  • Signatures. The JWT plugin, and with it the OAuth provider's tokens, signs with EdDSA, ECDSA or RSA by default. These are quantum-vulnerable. It can also sign with ML-DSA (RFC 9964), a post-quantum signature, on a runtime that supports it: see ML-DSA. The OAuth provider accepts ML-DSA client keys for private_key_jwt.
  • Passkeys. The passkey plugin offers ML-DSA-44 as its preferred algorithm when the server runtime can verify it (Node.js 24.7.0 and later, Deno 2.8.2 and later), and the classical algorithms otherwise. The authenticator decides which one a passkey uses. A server runtime without ML-DSA support cannot verify an ML-DSA passkey; registration.algorithms pins the classical algorithms if sign-in may run on one. See Post-quantum passkeys.
  • SAML encrypted assertions use RSA key transport, as chosen by the identity provider.
  • Transport. Data in transit is protected by TLS, which your host or proxy terminates. Choose one that offers hybrid post-quantum key exchange (X25519MLKEM768): it protects traffic recorded today from being decrypted later.

Reporting Vulnerabilities

If you discover a security vulnerability in Entro Auth, please report it via GitHub Security Advisories. We address all reports promptly, and credits will be given for validated discoveries.

On this page