feat(jwe): decrypt JWE-encrypted access tokens#864
Open
jd3vi1 wants to merge 3 commits into
Open
Conversation
Decrypt JWE-encrypted access tokens before writing them to the session, at both the callback and on token refresh, so req.oidc.accessToken and afterCallback always receive a plaintext JWT. Enabled by setting accessTokenDecryptionKey. The key-management algorithm is read from the JWE header and validated against a strong-algorithm allowlist; accessTokenDecryptionAlg can pin it. Decryption failures surface a clear error.
…g pin Address review feedback on JWE: - decryptAccessToken now returns non-JWE tokens (not five compact parts) unchanged instead of throwing. Toggling Token Encryption off, a mid-rollout mismatch, or an opaque-token audience no longer turns every login and refresh into a hard 500. - Constrain accessTokenDecryptionAlg to the strong-algorithm allowlist at the config layer (defense in depth), mirroring the runtime allowlist. - Add tests: an off-allowlist alg (A128KW) is rejected, non-JWE and opaque tokens pass through, and the clear-error path now uses a genuine JWE with a wrong key.
Contributor
Author
|
Addressed both majors in 95908d1:
Minor: Full suite and tsd green. |
Drop unused exportSPKI, privateJWK, privateKeyPem, fs, path bindings in the decryptAccessToken test block and an unused jar binding in the callback test.
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.
Summary
Adds decryption of JWE-encrypted access tokens. When an API is configured to encrypt access tokens, the token returned at the callback is a JWE. With
accessTokenDecryptionKeyset, the SDK decrypts it before writing it to the session, soreq.oidc.accessTokenandafterCallbackalways receive a plaintext JWT with no change to consuming code.What's included
accessTokenDecryptionKey— private key for decryption. Accepts PEM string, Buffer, KeyObject, JWK, or CryptoKey. Requires a code flow (implicit flow returns no access token from the token endpoint).accessTokenDecryptionAlg— optional pin for the key-management algorithm.offline_access.afterCallbackfires, so hooks receive a usable token.accessTokenDecryptionAlg, when set, narrows the allowlist to that one value.Usage
Tests
decryptAccessToken(header auto-detect for RSA-OAEP-256/512, pin match/mismatch, non-JWE input), config validation (code-flow requirement), and end-to-end callback + refresh decryption with a clear-error case.index.test-d.ts.EXAMPLES.mdand an example atexamples/jwe.js.