JWT Sign/Verify throws `TypeError: Right-hand side of 'instanceof' is not an object` in browser build (crypto-browserify doesn't export `KeyObject`)
CyberChef version: v11.4.0 (confirmed still present in v11.5.0 / latest master — jsonwebtoken still pinned at 9.0.3, webpack.config.js still maps crypto → crypto-browserify)
Steps to reproduce:
- Open the JWT Sign operation
- Enter any input, e.g.
{"sub":"user123","role":"admin"} - Set Private/Secret Key to
secret, algorithmHS256 - Bake
Expected: a valid signed JWT
Actual:
Error: Have you entered the key correctly? The key should be either the secret for HMAC algorithms or the PEM-encoded private key for RSA and ECDSA.
TypeError: Right-hand side of 'instanceof' is not an objectThis happens for any input/secret — not a usage error.
Root cause: [email protected]'s sign.js/verify.js do:
const { KeyObject, createSecretKey, createPrivateKey } = require('crypto')
...
if (secretOrPrivateKey != null && !(secretOrPrivateKey instanceof KeyObject)) { ... }In the browser bundle, webpack.config.js aliases crypto → crypto-browserify, which has never implemented KeyObject, createSecretKey, createPrivateKey, or createPublicKey. So KeyObject is undefined, and instanceof undefined throws. This affects both JWT Sign and JWT Verify for every algorithm.
Suggested fix: add a minimal polyfill for KeyObject/createSecretKey (sufficient for HS256/384/512, the common case) to the webpack crypto alias/shim — happy to submit a PR with the patch we've verified working (validated the signed output against native Node HMAC-SHA256, byte-for-byte match) if that's useful.
Source: gchq/CyberChef