Repository navigation
fix!: refuse a JWT claims set that repeats a claim, and document how the RS classifies subjects - #995
Merged
Merged
Conversation
…tokens SubjectKind and EndUser tell a client credentials token from an end user's by the "grant_type" claim a FAPIgo authorization server sets on it. A token from any other authorization server carries no such claim: RFC 9068 §2.2 makes a client credentials token's sub the client's own client_id, and §5 leaves keeping client_ids and user identifiers apart to the authorization server. Such a token reads as SubjectEndUser, and EndUser reports its sub, the client_id, as a user, so a client whose client_id equals a user's identifier gets that user's InternalSubject. The same holds for a custom AccessTokenIssuer that drops the claim, or a custom AccessTokenResolver that doesn't return it. Verify doesn't infer the kind from sub equaling client_id: a user's own token can have that too (a user whose identifier is some client's client_id, using that client), and reading it as the client's would refuse that user. The SubjectKind and EndUser docs, GETTING_STARTED and the production checklist now say the distinction holds only for FAPIgo-issued tokens, and what to do behind another authorization server; AccessTokenParams.Claims says an issuer must keep grant_type. A new test pins the behaviour with hand-signed RFC 9068 tokens: a client credentials token (sub == client_id), one whose client_id collides with a user's sub and that user's own token all read as SubjectEndUser with the same InternalSubject, and one carrying grant_type reads as SubjectClient. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RFC 7519 §4 requires a JWT's claim names to be unique, and lets a
recipient either reject a repeat or keep the lexically last copy. The
access token parser kept the last: encoding/json decoded the claims
set into a map, so {"sub":"alice",...,"sub":"admin"} verified as
admin's token. A gateway or other verifier in front of the resource
server that keeps the first copy of a repeated member reads the same
signed token as alice's, so the two would authorize different
subjects, scopes or bindings from one token.
The parser now runs strictjson.CheckDuplicateMembers on the claims set
first, as the JOSE header parsers already do, and refuses one that
repeats a member name at any depth, or holds two names that differ
only in case, with ErrMalformedClaims. Verify answers such a token
with invalid_token. A conformant token is unaffected.
Tests cover a repeated sub, scope and cnf, and a repeated jkt inside
cnf, at the parser, and a hand-signed RFC 9068 token naming its sub
twice through Verify.
BREAKING CHANGE: a JWT access token whose claims set repeats a member
name, or holds two names that differ only in case, is now refused with
invalid_token, where its last copy of the claim was used before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ats a claim RFC 7519 §4 requires a JWT's claim names to be unique, and lets a recipient either reject a repeat or keep the lexically last copy. The client kept the last: the ID token and JARM parsers, and the UserInfo decoder (for a plain JSON body and a signed response's payload alike), decoded into a map with encoding/json. An ID token or UserInfo response naming sub twice, or a JARM response naming iss or code twice, was read by its last copy, where another reader of the same message that keeps the first copy (a gateway, a log processor, a second verifier) reads the other, so the two would disagree on who signed in or which code to redeem. Each now runs strictjson.CheckDuplicateMembers first, as the JOSE header parsers already do, refusing a claims set or UserInfo body that repeats a member name at any depth, or holds two names that differ only in case. The client answers such a response with invalid_response, as for any malformed one. A conformant response is unaffected. BREAKING CHANGE: an ID token, JARM response or UserInfo response that repeats a member name, or holds two names that differ only in case, is now refused with invalid_response, where its last copy was used before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s a claim RFC 7519 §4 requires a JWT's claim names to be unique, and lets a recipient either reject a repeat or keep the lexically last copy. The server's parsers for request objects (and signed CIBA requests), client assertions, DPoP proofs and attestation PoPs kept the last copy, which is what encoding/json does. A first-wins reader of the same JWT reads the first, so a request object naming scope twice, an assertion naming aud twice or a proof naming htm or htu twice meant one thing to the server and another to a gateway or audit log in front of it. The DPoP parser is shared with the resource server. Each now refuses a claims set that repeats a member name at any depth, or holds two names that differ only in case (strictjson.CheckDuplicateMembers), as a client attestation's claims and the JOSE headers already were. The PoP parser reuses the attestation's unmarshalUniqueMembers, and the DPoP parser strictjson.UnmarshalNoRepeats. The server answers such a request object with invalid_request_object, a signed CIBA request with invalid_request, a client assertion or attestation PoP with invalid_client, and a DPoP proof with invalid_dpop_proof; a resource server answers the proof with invalid_dpop_proof. A conformant JWT is unaffected. BREAKING CHANGE: a request object, signed CIBA request, client assertion, DPoP proof or attestation PoP that repeats a member name, or holds two names that differ only in case, is now refused, where its last copy was used before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eats a claim Entity Statements already refused a repeated member name, but the other federation JWTs did not: Trust Marks, Trust Mark Delegations, Trust Mark Status responses, Resolve responses and Historical Keys responses decoded their claims sets into a map with encoding/json, which keeps the last copy of a repeated member. A Trust Mark Status response naming status twice, or a Resolve response naming sub twice, was read by its last copy, where another resolver reading the same signed response may keep the first. RFC 7519 §4 requires unique claim names. Each parser now decodes its claims set through decodeClaimsObject, which runs refuseDuplicateMembers first, as Entity Statements do, and refuses a repeat at any depth, or two names that differ only in case, with ErrMalformedClaims. A Historical Keys entry's repeated "revoked" is now refused rather than read from its last copy. Resolve response trust_marks parsing moves into its own function, unchanged, to keep the parser's complexity down. A conformant JWT is unaffected. BREAKING CHANGE: a Trust Mark, Trust Mark Delegation or Status response, Resolve response or Historical Keys response that repeats a member name, or holds two names that differ only in case, is now refused, where its last copy was used before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ed claim RFC 7515 §10.12 warns that two JSON parsers can take different values from an object that repeats a member. A new strictjson test models a first-wins reader beside encoding/json, which keeps the last copy, on a repeated sub, aud and kid, shows they disagree, and checks that CheckDuplicateMembers refuses each, so no FAPIgo parser that runs it acts on either reading. strictjson's package doc said only the JOSE headers, attestation claims, metadata and Entity Statements ran CheckDuplicateMembers, and that the other claims sets kept encoding/json's last copy. It now lists every JWT claims parser, the UserInfo decoder and the token, PAR and CIBA response decoders, all of which refuse a repeat. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A v0.87.0 section says which peers are affected by the claims parsers now refusing a repeated or case-variant member name, why, the error each path gives, and that a peer must write each claim once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
One mutant per claims parser that now refuses a repeated member (ID and JWT access tokens, JARM, request objects, client assertions, DPoP proofs, attestation PoPs, federation JWTs and UserInfo responses), each disabling its check, and one making every token read as SubjectEndUser whatever its grant_type claim. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
osanderson
force-pushed
the
test/audit-e1-e10
branch
from
November 26, 2026 08:42
84fbf05 to
c0b8695
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
The JWT claims parsers this branch made strict refused any repeated
member name. An authorization server that writes iss in a JARM
response both as the JWT claim and as the RFC 9207 iss response
parameter sends iss twice with one value, and such a response was
refused. A repeat whose copies are identical leaves no differential:
a reader keeping the first copy and encoding/json, keeping the last,
take the same value.
strictjson.CheckConflictingMembers (and UnmarshalNoConflicts) is
CheckDuplicateMembers, except that an exact repeat whose value is the
same JSON text as the first copy's, after json.Compact, is accepted.
Copies that differ, including ones spelled differently but equal to
some readers ("a" and "a", 1 and 1.0), and two names that differ
only in case are still refused, at any depth and within the existing
nesting bound; each copy's own members are checked too. A document
that repeats nothing still takes the byte scanner's fast path.
ID tokens, JWT access tokens, JARM responses, request objects, client
assertions, DPoP proofs, attestation PoPs, the federation JWTs other
than Entity Statements, and UserInfo responses now use it. The parsers
that were strict before (JOSE and JWE headers, client attestations,
Entity Statements, metadata, and token, PAR and CIBA responses) still
refuse any repeat: clientattestation's shared helper now serves only
the attestation, and the federation JWTs no longer go through
refuseDuplicateMembers.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The UPGRADING section on repeated JWT claims now says a repeat is refused when its copies differ, that identical copies (as in a JARM response carrying iss as both claim and RFC 9207 parameter) are accepted, that case-variant names are always refused, and that copies are compared as text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds mutants for CheckConflictingMembers' branches (identical copies accepted, differing copies refused, case variants refused, nested objects checked, copies compared after compacting) and for the JARM parser accepting an iss repeated with one value. Re-anchors the duplicate-claim mutants on the call sites' new check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Breaking. This covers two of the audit's unverified hypotheses (section E). E-10 is confirmed and fixed: every inbound JWT claims set now refuses a repeated claim. E-1 is a limitation, now documented.
E-10: repeated claims (
fix(resource)!,fix(client)!,fix(server)!,fix(federation)!)JOSE headers, client attestations, Entity Statements and AS metadata already refused a repeated member name (v0.81.0). Every other JWT claims set was decoded with encoding/json, which keeps the last copy. So
{"sub":"alice",...,"sub":"admin"}verified at the resource server as admin's token. A gateway, log processor or second verifier that keeps the first copy would read the same signed token as alice's.invalid_tokeninvalid_responseEach path runs a new
strictjson.CheckConflictingMembersfirst.json.Compact, so equal values spelled differently ("a"and"\u0061",1and1.0) count as differing.This is what keeps JARM working against Keycloak, whose JARM response writes
isstwice with the same value; the interop leg found it. The paths that were already strict since v0.81.0 (headers, attestations, Entity Statements, metadata and token responses) keep refusing every repeat, through the unchangedCheckDuplicateMembers. A peer that sent differing repeated claims, or case-variant names, is now refused, which is why the four commits are marked breaking.internal/strictjson/first_wins_differential_test.gomodels a first-wins reader. It shows that reader and encoding/json disagree on a repeatedsub,audandkid, and that the check refuses each one.UPGRADING.md has a section under v0.87.0. Conformance is running, since this changes decoding on every inbound JWT path.
E-1: how the resource server classifies a token's subject (
docs(resource))SubjectKindisSubjectClientonly when FAPIgo's owngrant_typeclaim is present.The limitation: a third-party issuer's client-credentials token, following RFC 9068 with
sub == client_idand nogrant_type, is classified as an end-user token, andEndUser()returns ok. When aclient_idcollides with a user'ssub, the resource server can't tell the two tokens apart.Why no heuristic: RFC 9068 defines no other marker. Treating
sub == client_idas a client would misclassify a genuine user whose identifier equals a client'sclient_id, and clients can choose theirclient_id, for example through federation automatic registration. So the behaviour is unchanged.What's documented:
SubjectKindandEndUserdoc comments,server.AccessTokenParams.Claims(a customAccessTokenIssuermust keepgrant_type), GETTING_STARTED.md and the production checklist now say this;Tests
resource.Verifyand the UserInfo decoder.FuzzCheckConflictingMembersOneReadingtarget checks that anything accepted reads the same to a first-wins reader and to encoding/json. It's added to the nightly matrix.🤖 Generated with Claude Code