JWKS and `kid` Explained: How to Find the Key That Signed Your Token (and Spot a Leaked Private Key)
A practical guide to reading a jwks.json file, matching the right key, and checking it is safe to publish. Your API receives a token signed by an identity provider. To verify it, you need the provider's public key. But which one? Providers rotate keys, and a single endpoint can publish several at once. The answer is a small JSON document called a JWKS, and a header field called kid. JWK and JWKS…
A JSON Web Key (JWK) is a standard way to represent a single cryptographic key using JSON, as defined in RFC 7517. A JSON Web Key Set (JWKS) is a JSON object containing an array of JWKs, which can be published by identity providers at a public URL, often at /.well-known/jwks.json or in the jwks_uri field of their OpenID Connect discovery document.
When an API receives a token signed by a provider, it needs the provider's public key to verify the signature. The token's header contains a kid (key ID) field, and the verification process involves decoding the token, reading the kid, finding the matching JWK in the JWKS, and building a public key to verify the signature. Providers may rotate keys, and a single endpoint can publish multiple keys, so it's crucial to use the kid field to select the correct key.
JWKS files contain various key types, such as RSA and EC, and include fields like kty (key type), kid (key ID), use (intended use), alg (algorithm), and n and e (RSA public modulus and exponent). When inspecting a JWKS, look out for private key material (like d, p, q, dp, dq, or qi for RSA keys), symmetric keys (kty: "oct"), missing kid fields, duplicate kid values, and weak RSA keys (modulus under 2048 bits).
To check for security issues, you can use the JWKS Viewer tool or write a few lines of code to scan the JSON for private fields, symmetric keys, missing or duplicate kid values, and weak RSA keys.
Rewritten by urgent.news; may contain errors — check the original.