at_hash and c_hash validation depends on one token-hash algorithm decision
at_hash and c_hash validation depends on one token-hash algorithm decision OpenID Connect hybrid flows can return an ID Token from the authorization endpoint alongside an access token, an authorization code, or both. T
at_hash and c_hash validation depends on one token-hash algorithm decision
OpenID Connect hybrid flows can return an ID Token from the authorization endpoint alongside an access token, an authorization code, or both. The ID Token then includes at_hash or c_hash claims so the client can bind those values to the authentication response. The check looks simple: hash the token, take the left-most half, base64url encode it, and compare. The difficult part is choosing the hash function consistently with the ID Token signing algorithm.
OpenID Connect Core defines at_hash as the base64url encoding of the left-most half of the hash of the ASCII representation of the access token. The hash uses the hash algorithm associated with the alg header parameter of the ID Token's JOSE header. For an RS256 ID Token, the access token is hashed with SHA-256 and the left-most 128 bits are encoded. c_hash follows the same construction for the authorization code.
A September 2026 implementer's guide addresses algorithms whose JOSE identifier does not fully determine the digest function. That matters for implementations that support newer signature families. The guide treats at_hash, c_hash, s_hash, and profile-defined hash claims as one construction: select the digest and output length from the algorithm profile, hash the ASCII value, encode the required prefix, and compare the claim. The application should not choose SHA-256 merely because it is common when the ID Token uses a different hashing rule.
Check the response that carried the token
The claims are most useful at the authorization endpoint. A client should verify c_hash when the endpoint returns an authorization code, and at_hash when it returns an access token. The precise requirement depends on the response type and the flow. A client that ignores the claim can accept an attacker-modified token response even though the ID Token signature is valid.
ID Tokens returned from the token endpoint have a different context. The TLS channel protects the token exchange, and Core allows the hash claims to be omitted there even if they were present in an authorization-endpoint ID Token. Validation code should therefore know which endpoint produced the response instead of applying one generic rule to every ID Token.
Make the algorithm map explicit
Store the supported ID Token signing algorithms and their digest mappings in one configuration table. Reject an algorithm that is not in the table before validating the hash claim. Record the selected algorithm, digest, expected left-most length, and the result of a constant-time comparison in diagnostic logs, but never record the raw access token or authorization code.
Test unusual encodings as well as the normal case. The input is the ASCII representation of the token value, not the decoded JWT payload. Base64url encoding must use the unpadded form required by JOSE. A validator that compares decoded bytes without checking length can accept a truncated or extended value, while a validator that compares strings without the algorithm map can accept a value from the wrong hash family.
Keep nonce, issuer, audience, and signature checks
The hash claim binds the ID Token to another response value. It does not authenticate the provider, establish the client, or prevent replay by itself. Continue to verify the signature, issuer, audience, authorized party, nonce, issue time, and expiration. In a hybrid response, bind the nonce to the client's transaction and make the callback state single-use.
The safest implementation exposes one validation routine that knows the flow, endpoint, response type, and ID Token algorithm. It should fail closed when the token is present but the expected hash claim is missing, malformed, or computed with an unsupported algorithm. Interoperability problems should be fixed in the algorithm map, not by skipping a claim that guards the response the user is about to use.
References
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes โ full credit and traffic to the original publisher.