CVE-2022-23541: Insecure Implementation of Key Retrieval Function in jsonwebtoken

jsonwebtoken Updated 02 Oct 2025

Summary

22/12/2022
Yes i
Moderate
5.0

CVE-2022-23541: Overview Versions. Affects jsonwebtoken versions < 9.0.0. Fixed in 9.0.0. How to fix ↓

Free scan

Check if this vulnerability affects your application

Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored Devnack Penetration testing for web, API and mobile Manual testing by engineers who build software, not an auditor's checklist. Trusted by teams at Swift and Google Talk to Devnack

Background

The jsonwebtoken library is an npm package used for generating and verifying JSON Web Tokens (JWTs) in Node.js applications. It provides a set of functions for signing and verifying tokens using various algorithms and key types. However, versions <=8.5.1 of jsonwebtoken suffer from a misconfiguration that can lead to incorrect verification of tokens. This vulnerability allows for the possibility of using a different algorithm and key combination in verification than the one used to sign the tokens. As a result, tokens signed with an asymmetric public key can be successfully verified with a symmetric HS256 algorithm, leading to the validation of forged tokens.

Vulnerability Detail

The vulnerability arises from a misconfiguration in the key retrieval function (secretOrPublicKey argument) of the jsonwebtoken library. If an application supports the usage of both symmetric and asymmetric keys in the jwt.verify() implementation with the same key retrieval function, an attacker can exploit this misconfiguration to forge tokens. By signing a token with an asymmetric public key and then verifying it with a symmetric HS256 algorithm, the attacker can bypass the intended security measures and successfully validate the forged token. This can potentially lead to unauthorized access, privilege escalation, and other security breaches.

How To Fix

Latest published version: 9.0.3 as of 23 Oct 2026

npm install jsonwebtoken@9.0.3

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

9.0.0

This is the first release that contains the fix.

npm install jsonwebtoken@9.0.0

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Workaround

There is no known workaround for this vulnerability. It is essential to update the jsonwebtoken library to the fixed version (9.0.0 or later) to mitigate the risk of token forgery.

Conclusion

The jsonwebtoken library versions up to and including 8.5.1 suffer from a misconfiguration that allows for the validation of forged tokens. By updating to version 9.0.0 or later, the vulnerability can be fixed, ensuring that tokens are verified using the correct algorithm and key combination. It is crucial to promptly update the library to mitigate the risk of unauthorized access and other security breaches. For further support on vulnerability remediation, you can contact DevNack.com.

See every vulnerability recorded for jsonwebtoken →

Share this vulnerability

FAQ

You can use the Vulert Playground at Vulert Scanner to check if your application is affected by this vulnerability. The playground analyzes your package-lock.json file and provides real-time monitoring and alerts for open-source vulnerabilities, including this one.

The vulnerability allows for the validation of forged tokens, which can lead to unauthorized access, privilege escalation, and other security breaches. An attacker could impersonate legitimate users, gain unauthorized privileges, or tamper with sensitive data.

No, only versions up to and including 8.5.1 of the jsonwebtoken library are affected by this vulnerability. Updating to version 9.0.0 or later will fix the issue.

There is no impact on end users directly. However, if the vulnerability is exploited, it can lead to unauthorized access and compromise the security of the application and its users.

Manually verifying tokens can be error-prone and may not provide the necessary security measures. It is recommended to update the jsonwebtoken library to the fixed version (9.0.0 or later) to ensure proper token verification.

Related vulnerabilities

Recent vulnerabilities recorded for jsonwebtoken.

How To Fix

Latest published version: 9.0.3 as of 23 Oct 2026

npm install jsonwebtoken@9.0.3

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

9.0.0

This is the first release that contains the fix.

npm install jsonwebtoken@9.0.0

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback