opyeb jwkslab

jwkslab · Key exposure

When a private key ends up in a JWKS

A private key in a public JWKS lets anyone forge signatures with it. Rotation is mandatory the moment it is found; deleting the document is not enough.

Why it matters

A JWKS is a public document. If it carries the private fields d, p, q, dp, dq, qi or the symmetric k, anyone who reads it can sign or decrypt with that key. An RS256 verifier checks the signature against the public key in the JWKS, so a forged token made with the private key passes normally.

The trouble is that a JWK represents public and private keys in the same shape. A library that serialises a private key object emits d, and placing that object in the JWKS response publishes it. It is the kind of incident that is easy to miss in review.

What to do immediately

  1. Mark the exposed key for retirement and generate a new key pair.
  2. Publish the new key in the JWKS first, then switch signing to it. Keep the old public key until old tokens expire.
  3. After one token lifetime, remove the old public key and stop using the exposed private key anywhere.
  4. Find the path of exposure: a public repository, a log, a cache or a misconfigured endpoint.
  5. Invalidate tokens and sessions issued with that key, and check audit logs for unexpected use.

Deleting a key cannot recall a copy of the private half. Rotation is the substance; deletion only prevents further distribution.

What this tool shows

If a JWK contains any of d, p, q, dp, dq, qi or k, it is reported as a private key field and rated critical. An oct key is critical in any case because k is the secret itself. The report keeps the field names and never the values.

Preventing a repeat

When building a JWKS response, keep a function that copies only the public fields. Never hand a private key object to the serialiser; copy kty, kid, alg, use and n, e or crv, x, y explicitly. A CI test that asserts the JWKS output contains no d, p, q or k stops the same accident.

When checking a key by hand, use a synthetic test key rather than a production private key. This tool transmits nothing, but habits are what cause incidents.

Questions

Is deleting the private key enough?

No. The published document remains in caches, logs and archives. Rotate to a new key and retire the exposed one.

Is an oct key also a private key?

Yes. k is the symmetric secret. Publishing it in a JWKS lets anyone create HS256 signatures, so it is equivalent to publishing a private key.

Must a leaked test key be rotated too?

If it was never used in production, the impact is limited. But if test and production share keys as a habit, first establish which environment used it.

Paste a key set that contains private material and the exposed fields are listed.

Open the tool

This article follows RFC 7517 (JWK), RFC 7518 (JWA), RFC 7638 (JWK thumbprint), RFC 5280 (X.509), RFC 5958 (PKCS#8), RFC 5915 (SEC1) and RFC 8037 (OKP). Every example key is synthetic and was made for this site.