JSON Web Token Validation: Application Token, Edge Policy, and Origin Verification
How Cloudflare Access application tokens and API Shield JWT validation work, when to verify at the origin, and how to enforce tokens at the edge.
This page summarizes Cloudflare documentation on two related flows: Cloudflare Access issues an application token (JWT) on authenticated requests to protected HTTP applications, while API Shield validates client JWTs at the edge before traffic reaches your API origin. Both use JSON Web Tokens, but they answer different questions—whether a user passed Access policies versus whether an API client presented an untampered, unexpired token from your identity provider.
Application token: what reaches your origin after Access
Section titled “Application token: what reaches your origin after Access”Cloudflare Access includes an application token with authenticated requests to your origin. The token is a typical JWT with header, payload, and signature segments.
Cloudflare Access includes the application token with all authenticated requests to your origin.
— Cloudflare, Application token
Unless the application is connected to Access through Cloudflare Tunnel, your application must validate the token to protect the origin. Checking the header alone is not enough—the JWT and signature must be confirmed to avoid identity spoofing.
Unless your application is connected to Access through Cloudflare Tunnel, your application must validate the token to ensure the security of the origin. Validation of the header alone is not sufficient — the JWT and signature must be confirmed to avoid identity spoofing.
— Cloudflare, Application token
When Cloudflare forwards traffic, the token appears as the Cf-Access-Jwt-Assertion request header. Browser sessions also store it in the CF_Authorization cookie. Prefer validating the header: the cookie is not guaranteed to be passed.
We recommend validating the Cf-Access-Jwt-Assertion header instead of the CF_Authorization cookie, since the cookie is not guaranteed to be passed.
— Cloudflare, Validate JWTs
Access signs tokens with RS256 (SHA-256 with RSA). The header’s kid selects the verification key from your team’s certificate endpoint.
Application token payload: users, service tokens, and size limits
Section titled “Application token payload: users, service tokens, and size limits”Identity-based authentication: which claims appear in the JWT
Section titled “Identity-based authentication: which claims appear in the JWT”For users who sign in through an identity provider, the payload commonly includes aud (application audience tag), email, time claims (exp, iat, nbf), iss (your https://<team>.cloudflareaccess.com domain), type (app for application token), sub, country, and identity_nonce. The aud claim must match your application’s Application Audience (AUD) tag from the Access application settings.
Cloudflare Access assigns a unique AUD tag to each application. The aud claim in the token payload specifies which application the JWT is valid for.
— Cloudflare, Validate JWTs
sub is unique per email per account but can change if the user is removed and re-added or signs into a different organization.
Service token authentication: how machine access differs
Section titled “Service token authentication: how machine access differs”Service token JWTs use type app, include aud and iss, set common_name to the service token Client ID, and set sub to an empty string. User email and group claims are absent.
Custom SAML attributes and OIDC claims: when groups disappear from the cookie
Section titled “Custom SAML attributes and OIDC claims: when groups disappear from the cookie”IdP groups are not added automatically. You must map groups as custom SAML attributes or OIDC claims. Custom values sit in a custom claim on a best-effort basis; if the serialized custom claim exceeds roughly 1 KB, Access trims from the end of the list—users in many groups may lose the groups claim while others keep it.
Do not rely on custom claims in the JWT for authorization decisions when they may grow large. To retrieve the user’s full identity, including all groups, call the /cdn-cgi/access/get-identity endpoint described below.
— Cloudflare, Application token
Validate Access JWTs at the origin: keys, audience, and programmatic checks
Section titled “Validate Access JWTs at the origin: keys, audience, and programmatic checks”Access signing keys: rotation and kid matching
Section titled “Access signing keys: rotation and kid matching”Public keys live at https://<your-team-name>.cloudflareaccess.com/cdn-cgi/access/certs. Access rotates signing keys about every six weeks; previous keys stay valid for seven days after rotation.
Validate tokens using the external endpoint rather than saving the public key as a hard-coded value. Do not fetch the current key from public_cert, since your origin may inadvertently read an expired value from an outdated cache. Instead, match the kid value in the JWT to the corresponding certificate in public_certs.
— Cloudflare, Validate JWTs
Verification must check signature, iss, aud, and time claims (exp, nbf as applicable).
Consume the Cloudflare JWT instead of double SSO login
Section titled “Consume the Cloudflare JWT instead of double SSO login”Apps that already integrate SSO directly behind Access can force users to authenticate twice—once to Access and again at the app. Cloudflare recommends using the Access-issued JWT so Access remains responsible for IdP validation and users see a single sign-on.
Instead of managing a direct SSO integration in your application, we recommend using the JSON Web Token (JWT) issued by Cloudflare Access to authenticate requests.
— Cloudflare, Authenticate without integrated SSO
Origins should still verify that requests were authenticated by Cloudflare; the inserted JWT is the cryptographic proof.
It is important to note that the origin should, too, verify that the incoming requests are authenticated by Cloudflare in order to avoid any illegitimate access.
— Cloudflare, Extend ZTNA with external authorization and serverless computing
Full user identity: get-identity when the JWT is not enough
Section titled “Full user identity: get-identity when the JWT is not enough”The application token carries only a subset of identity. For full IdP data, groups, device posture, and related fields, send the CF_Authorization cookie to:
https://<your-team-name>.cloudflareaccess.com/cdn-cgi/access/get-identity
The Cloudflare Access Pages Plugin exposes data.cloudflareAccess.JWT.getIdentity() after the plugin validates the request. On Workers invoked directly through Access, ctx.access.getIdentity() returns identity without manual JWT parsing when Access authenticated the request.
When Cloudflare Access authenticates a request that directly invokes your Worker, the Worker can read the signed-in user’s identity — including email, groups, device posture, and more identity fields — through ctx.access. No extra configuration or JWT parsing is required.
— Cloudflare, Read authenticated user identity with ctx.access
ctx.access is undefined if Access did not authenticate the request. For manual validation on Workers, set POLICY_AUD and TEAM_DOMAIN and verify cf-access-jwt-assertion with a JWKS client (see Validate JWTs).
API Shield JWT validation: verify tokens before the API origin
Section titled “API Shield JWT validation: verify tokens before the API origin”What API Shield JWT validation does on each request
Section titled “What API Shield JWT validation does on each request”API Shield cryptographically verifies incoming JWTs before they reach your API. It detects expired, tampered, or not-yet-valid tokens; you then attach a rule to log, block, or combine results with other signals.
API Shield’s JWT validation cryptographically verifies incoming JWTs before they reach your API origin.
— Cloudflare, JSON Web Tokens validation
Validation has two parts: a token configuration (where to find the JWT and which keys verify it) and a rule (what to do with the result). After configuration exists, Cloudflare checks every zone request at the configured locations, validates any JWT found, and exposes verified claims in http.request.jwt.claims. You do not need a rule for validation itself—rules define enforcement.
Token configuration: sources, keys, and zone limits
Section titled “Token configuration: sources, keys, and zone limits”Each zone supports up to 32 token configurations by default, with up to 16 keys per configuration. A configuration needs a title, token_sources (Ruleset Engine expressions, up to four, OR logic), token_type (jwt), and credentials (JWK set).
Supported algorithms include RSA (RS256–RS512, PS256–PS512), EC (ES256, ES384), and HMAC (HS256, HS384, HS512). Cloudflare recommends asymmetric keys for new deployments; HMAC secrets must meet minimum byte lengths and are never returned in API responses after storage.
Token sources may be unprefixed JWTs or Bearer (capital B, one space) in headers or cookies—for example http.request.headers["authorization"][0].
Configurations do not auto-fetch JWKS URLs. Paste keys in the dashboard or use a Worker cron job to sync from your IdP (see Configure the Worker). Cloudflare Access certificates for API validation can be fetched from https://<your-team-name>.cloudflareaccess.com/cdn-cgi/access/certs.
During validation, Cloudflare matches header kid and alg to configured keys; missing keys invalidate the token. exp and nbf allow up to 60 seconds of clock skew.
WAF custom rules vs API JWT validation rules: when to use which
Section titled “WAF custom rules vs API JWT validation rules: when to use which”For new policies, Cloudflare recommends WAF custom rules acting on cf.api_gateway.tokens.valid, cf.api_gateway.tokens.presented, and http.request.jwt.claims—for example not any(cf.api_gateway.tokens.valid[*] == "<TOKEN_CONFIGURATION_ID>") to block requests without a valid token.
Token validation rules use is_jwt_valid() and is_jwt_present() with a configuration ID; the rule fires when the expression evaluates false (opposite of typical Ruleset behavior). These functions are only available in API JWT validation rules, not WAF custom rules (see Rules language functions).
| Goal | Typical approach |
|---|---|
| Zone-wide or claim-based policy with attack score | WAF custom rule + lookup_json_string(http.request.jwt.claims[...], "claim") |
| Endpoint-scoped log/block via API Shield operations | Token validation rule + selector |
| Forward claim to origin | Request Header Transform Rule |
| Per-user rate limits | Advanced Rate Limiting on JWT claims (valid tokens only) |
For browser APIs, add or http.request.method eq "OPTIONS" so CORS preflight without credentials is not blocked (JSON Web Tokens validation).
Configure token configurations via the API (POST to /zones/{zone_id}/token_validation/config, rules at .../token_validation/rules/bulk).
Workers and headers: pass identity without re-parsing SSO
Section titled “Workers and headers: pass identity without re-parsing SSO”When apps lack integrated SSO or JIT provisioning, a Worker can insert headers from the Access JWT—email, device posture, or custom SAML/OIDC claims—before the request hits the origin (Send authorization headers with Workers, Create custom headers). Cloudflare may also add headers such as Cf-Access-Authenticated-User-Email; your Worker can map them to application-specific names.
Service-to-service and cross-origin patterns can use Workers with Access service tokens on routes, as described in CORS for Access-protected APIs.
External APIs integrated with Cloudflare One should validate the Access application token so traffic that bypasses Access is rejected (Custom device posture integration).
Common mistakes
Section titled “Common mistakes”- Trusting cookies only for Access when proxies strip cookies; validate
Cf-Access-Jwt-Assertionwhen possible. - Hard-coding one public key instead of resolving
kidagainst the live certs endpoint during rotation. - Authorizing from trimmed JWT groups instead of calling
/cdn-cgi/access/get-identity. - Skipping origin validation for non-Tunnel Access layouts, allowing forged requests if Access is bypassed.
- Expecting API Shield to pull JWKS automatically; rotation requires dashboard updates or the JWKS sync Worker.
- Using
is_jwt_validin WAF custom rules—usecf.api_gateway.tokens.*fields instead. - Blocking OPTIONS on browser-facing APIs without an explicit exception.
How to check this on your site
Section titled “How to check this on your site”- Sign in through your Access-protected URL and confirm
Cf-Access-Jwt-AssertionorCF_Authorizationis present; decode claims at jwt.io per Validate JWTs and verify signature againsthttps://<team>.cloudflareaccess.com/cdn-cgi/access/certs. - Confirm
audmatches the AUD tag from Zero Trust → Access controls → Applications → Configure → Additional settings (Validate JWTs). - Call
https://<team>.cloudflareaccess.com/cdn-cgi/access/get-identitywith the user cookie and compare groups to the JWT (Application token). - For API Shield, send a request with a valid and an invalid JWT; in Security Analytics, review Token validation violations and WAF events (Perform JWT validation).
- You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact wording you are asking about, and we will correct or clarify it.