Skip to content

Migration Notes: v8 to v9

julienwoll edited this page Dec 21, 2022 · 2 revisions

Version 9 introduces several security fixes to follow best practices. These changes may impact you if you were relying on previous insecure behaviour.

  • Removed support for Node versions 11 and below.

  • The verify() function no longer accepts unsigned tokens by default.

  • RSA key size must be 2048 bits or greater.

  • Asymmetric keys cannot be used to sign & verify HMAC tokens.

  • Key types must be valid for the signing / verification algorithm

Minimum Node 12 Support

Verifying unsigned tokens now requires explicitly providing none in options.algorithms.

const decoded = jwt.verify(unsigned, undefined, { algorithms: ['none'] });

RSA key size must be 2048 bits or greater

sign now enforces a minimum key size for RSA keys. To preserver the old behaviour and allow keys of less than 2048 bits, set allowInsecureKeySizes to true.

jwt.sign({ foo: 'bar' }, privateKey, { algorithm: 'RS256', allowInsecureKeySizes: true })

Asymmetric keys cannot be used to sign & verify HMAC tokens.

sign and verify will fail if an asymmetric key is provided when using HS algorithms.

secretOrPublicKey & secretOrPrivateKey must contain a valid key material, which is compatible with the Node's Crypto createSecretKey, createPrivateKey/createPublicKey method.

Remove unrestricted key types - Key types must be valid for the signing / verification algorithm

sign and verify will now fail if you’re using keys with algorithms that don’t confirm to the JWS standard. You will need to use the following key types with the following algorithms:

Asymmetric Key Type Algorithms
ec ES256, ES384, ES512
rsa RS256, PS256, RS384, PS384, RS512, PS512
rsa-pss PS256, PS384, PS512

If you need to preserve the old behaviour, set allowInvalidAsymmetricKeyTypes.