Repository navigation
Conversation
crypto-browserify does not implement KeyObject or the create*Key helpers, so jsonwebtoken throws "Right-hand side of 'instanceof' is not an object" for every JWT Sign/Verify call in the browser bundle. Add a minimal shim for symmetric keys and unwrap KeyObject instances before passing them to crypto-browserify's createHmac.
|
Thank you for your contribution - unfortunately this repository only accepts pull requests from organisation members or approved outside collaborators. Due to that, this pull request has been closed automatically. |
|
Hi @GCHQDeveloper581, following up on #2860, where a PR for this was welcomed. This PR was closed automatically because the repository now only accepts PRs from organization members or approved outside collaborators. Could you let me know the process for becoming an approved outside collaborator, or review the branch directly?
Happy to adjust the change or provide more context. |
|
@Henglie - we are currently working out the process on this. When we've completed this exercise, relevant affected PRs will be reopened/looked at for processing. In the meantime I suggest not making any changes to older PRs as this is likely to result in the bot closing them, and older ones are more likely to be missed when reopening. |
Problem
JWT Sign and JWT Verify fail in the browser build for every algorithm with:
TypeError: Right-hand side of 'instanceof' is not an object
jsonwebtoken@9.0.3callsKeyObject,createSecretKey, and the othercreate*Keyhelpers fromcrypto. The webpack build resolvescryptotocrypto-browserify, which does not implement any of them, sosecretOrPrivateKey instanceof KeyObjectthrows before signing starts.Fix
Add a small crypto shim used only by the webpack browser build:
KeyObject,createSecretKey,createPrivateKey, andcreatePublicKeycrypto-browserifyKeyObjectinstances before passing them tocreateHmacSymmetric (HS256/384/512) JWT signing and verification now work in the browser bundle. Asymmetric keys are still rejected in the browser build, matching the previous behaviour.
Validation
npx eslint src/core/lib/CryptoShim.js tests/node/tests/lib/CryptoShim.mjs tests/node/index.mjspasses.283 passed(includes new unit tests for the shim and HMAC output parity with native crypto).npm run buildstill fails locally on unrelated existing PNG loader errors and a$ is not a functionCSS error; no crypto-related build errors were reported.