#2860·CyberChef

JWT Sign/Verify throws `TypeError: Right-hand side of 'instanceof' is not an object` in browser build (crypto-browserify doesn't export `KeyObject`)

Author: d4rkbbCreated Sep 30, 2026Updated Sep 30, 2026

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:

  1. Open the JWT Sign operation
  2. Enter any input, e.g. {"sub":"user123","role":"admin"}
  3. Set Private/Secret Key to secret, algorithm HS256
  4. 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 object

This happens for any input/secret — not a usage error.

Root cause: [email protected]'s sign.js/verify.js do:

javascript
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.