DEV Community

NTCTech
NTCTech

Posted on Originally published at rack2cloud.com

JWT Claim Validation Has Three Assumptions. Cloudflare Access Just Tested One.

Field Notes — Engineering Notes from the Complexity Gap | Rack2Cloud

JWT claim validation is a contract between a token issuer and every service that checks its tokens, and most services never write that contract down. On November 19, Cloudflare's status page reported that a recent Cloudflare Access release removed the sub claim from service token JWTs, which can cause authentication failures for applications that strictly validate token claims. The change was reverted. The incident tests one assumption that validators make, and there are two more it did not test.

JWT claim validation: three assumptions, with the sub claim missing from a service token

What Cloudflare's Status Page and Docs State

Everything in the table is Cloudflare's own text or the RFC's, read on November 21. NOT STATED marks something those pages do not say; it is not a finding that the answer is no. A token consumer's dependency on its issuer is a cloud architecture strategy question before it is a library setting.

Source What it states
Status incident, November 19, 06:48 to 08:56 UTC A recent Access release removed the sub claim from service token JWTs; applications that strictly validate token claims can see authentication failures. The change was reverted and the fix was rolling out globally at 06:48, implemented and monitored at 08:32, resolved at 08:56.
Application token docs, user token sub is the user's ID, unique to an email address per account.
Application token docs, service token sub contains an empty string. The documented payload also carries type, aud, exp, iss, common_name (the service token's Client ID) and iat.
Validate JWTs docs Check the signature, iss against your team domain, aud against your application's AUD tag, exp and nbf. Cloudflare's Python example requires exp, iss and aud.
RFC 7519 Which claims a JWT must contain to be valid is context dependent and outside the specification. Use of sub is optional and its processing is application specific.
NOT STATED Release time, intent, root cause, number of affected accounts or applications, named third-party breakage, the post-release payload, whether any library or framework failed.

Two details frame the JWT claim validation question. Cloudflare's documentation never lists sub among the claims an origin should require. And for service tokens it documented sub as present and empty, not absent. The status page says the claim was removed; it shows no post-release payload, so this post treats the claim as absent and goes no further.

Three Assumptions Inside JWT Claim Validation

JWT claim validation can rest on three separate assumptions about a claim, and each fails differently. The first is that the claim is present: the key exists in the payload. The second is that it is non-empty: when the key exists, the value means something. The third is that both hold on every authentication path, which depends on how the caller authenticated and on an issuer that can change either answer.

The documentation had already put the second assumption on record. A user token carries a user ID in sub; a service token carries an empty string. A validator requiring a non-empty sub would have rejected every service token before November 19, so the incident did not cause its failures. A validator requiring sub to be present while tolerating an empty value matched the documented behavior until the key went missing. That is the assumption the incident tested. A validator that checks the signature, iss, aud and exp, the set Cloudflare documents, never depended on sub.

That last group is the point. The exposure sat in requirements a consuming team added beyond what the issuer documents. Whether a given service added one deliberately is exactly what a claim contract records, and what JWT claim validation without one leaves unrecorded. This is analysis of the documented behavior; no application's code was examined.

The third assumption sits underneath the other two. Google's run-as check, covered in the run-as service account post, has the same shape in a different product: one control, several identity paths, and behavior that differs by path.

The Claim Contract

The JWT claim validation contract is a worksheet with one row per claim your application reads or requires, answered separately for each authentication path. The user-token and service-token columns record what the documentation shows. The last column is the validation rule, which is proposed method, not Cloudflare guidance.

Claim User token (docs) Service token (docs) Validation rule (proposed)
iss Cloudflare Access domain URL Same Required. Exact match to your team domain.
aud Array containing the application's AUD tag Same Required. Must contain your application's AUD tag.
exp Expiration timestamp Same Required. Reject expired tokens.
nbf In the documented payload Not in the documented payload Enforce where present. Do not require on the service path.
sub User ID, unique to an email address per account Empty string Presence and meaning differ by path. Require it only where your application uses it, and record the empty case separately.
common_name Not in the documented payload Client ID of the service token Verify against your own tokens first. Infer no identity semantics beyond the docs.
email Authenticated user's verified email Not in the documented payload Do not require on the service path.

Two rows deserve a second look. If an application uses sub as the key for audit records, rate limits or ownership, every service token documented with an empty sub shares one key, so sub cannot tell one service token from another. The docs describe common_name as the service token's Client ID, which can. Whether your application keys on either is something its row has to say. The Dependency Architecture stage maps identity as one of five dependency classes, and each claim your validator requires is a hard dependency on the issuer's token shape.

Five sub claim inputs entering one illustrative truthiness check: valid and wrong-type accepted, empty, absent and null rejected

Negative Tests for JWT Claim Validation

Present, empty, absent, null and the wrong type are five different inputs to JWT claim validation. RFC 7519 allows a claim value to be any JSON value and defines sub as a string, so each is a legitimate thing for a validator to meet. A single truthiness check in a common scripting language rejects the empty string, the absent claim and null identically, and accepts a number where a string belongs.

Input Example for sub Question the test answers
Valid value "sub": "a1b2c3" Does the validator accept the documented user-token shape?
Empty string "sub": "" Does the service path accept the documented service-token shape?
Absent no sub key Is presence required, and on which path? This is the state the status page describes.
Null "sub": null Is null treated as absent, as empty or as invalid?
Unexpected type "sub": 12345 Is a non-string rejected, coerced or ignored?

Run the matrix for each claim your application reads and each token path, using synthetic tokens signed by a test key against a staging validator pointed at that key. Record the expected outcome for every cell before running it; a cell with no recorded expectation is an assumption nobody examined. Keep the signature, iss, aud and exp checks on in every test. The aim of JWT claim validation testing is to know which claims you require and why, not to tolerate missing ones. A claim your contract marks required must fail closed when absent, and a claim it marks optional must not break the request. That is the policy fail mode decision applied to a token claim, made per rule instead of inherited from a library. The same discipline runs through testing MCP policy enforcement: ask the control to do what it is meant to refuse, somewhere that is safe. Re-run the matrix when the issuer's status page, changelog or token documentation changes.

What This Post Does Not Establish

It does not establish why the release removed the claim, whether that was intended, when it shipped, or how many accounts or applications were affected; the status page gives none of those. It shows no post-release payload, so it treats the claim as absent and nothing more. It names no application or library that failed and examined no application's code. The documentation pages describe behavior as read on November 21 and can change. Cloudflare's Python example shows what its documentation demonstrates, not what any deployment requires. And nothing here argues that a validator should accept arbitrary missing claims: Cloudflare states that the origin must validate the token, and that checking only that the header exists is not sufficient.

Architect's Verdict

JWT claim validation is a contract, and a contract needs both parties to know its terms. Cloudflare Access removed a claim its documentation listed with an empty value and reverted the change. The incident demonstrates how a validator that requires a documented claim's presence can fail when the issuer changes its payload. The issuer's documented checks never included sub.

The real problem is that the requirement had no owner. Present, non-empty and path-dependent are three separate assumptions, and a validator that mixes them leaves nobody able to say which claim it depends on or why. Writing the contract per claim and per token path turns each assumption into an explicit decision.

Make JWT claim validation explicit: test the five inputs, keep the checks the issuer documents, and treat any claim you require beyond that set as your own dependency. A claim your validator requires and nobody can explain is a dependency you never agreed to.

Additional Resources


Originally published at rack2cloud.com

Top comments (0)