CVE-2023-48238: Json web token Json-web-token Library Is Vulnerable To Vulnerability
HIGHCVE-2023-48238 is a HIGH (CVSS 7.5) json-web-token library is vulnerable to vulnerability (CWE-20: Improper Input Validation) affecting Json web token libraries in the npm ecosystem. The issue involves json-web-token library is vulnerable to a jwt algorithm confusion attack. Remediation is available by upgrading affected packages to version 4.0.0.
CVE-2023-48238 at a Glance
Security Impact
CVSS: 7.5
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N).
How to Fix CVE-2023-48238
To remediate this vulnerability, upgrade all affected Json web token dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
npm install json-web-token@4.0.0
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
npm ls json-web-token
How to Check if You Are Affected
To determine whether your Node.js application is affected by CVE-2023-48238, inspect your project dependencies using npm:
npm ls json-web-token
Analyze the terminal output to locate any version of Json web token in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 4.0.0), your application is affected.
Note: The npm ls json-web-token command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-20: Improper Input Validation, where the product receives input or data, but it does not validate or incorrectly validates that the input has the properties that are required to process the data safely and correctly. In Json web token, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
CVE-2023-48238 Affected Json web token Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
json-web-token
|
npm |
< 4.0.0
|
4.0.0
|
References
Frequently Asked Questions
What is CVE-2023-48238?
Which Json web token versions are affected?
What version fixes CVE-2023-48238?
Is json-web-token affected?
What is the CVSS score of CVE-2023-48238?
What CWE is associated with CVE-2023-48238?
How can I check npm dependencies for CVE-2023-48238?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-4xw9-cx39-r355",
"modified" : "2026-06-08T23:38:28Z",
"published" : "2023-11-17T22:48:15Z",
"aliases" : [ "CVE-2023-48238" ],
"summary" : "json-web-token library is vulnerable to a JWT algorithm confusion attack",
"details" : "### Summary\nThe json-web-token library is vulnerable to a JWT algorithm confusion attack.\n\n### Details\nOn line 86 of the 'index.js' file, the algorithm to use for verifying the signature of the JWT token is taken from the JWT token, which at that point is still unverified and thus shouldn't be trusted. To exploit this vulnerability, an attacker needs to craft a malicious JWT token containing the HS256 algorithm, signed with the public RSA key of the victim application. This attack will only work against this library is the RS256 algorithm is in use, however it is a best practice to use that algorithm.\n\n### PoC\nTake a server running the following code:\n```javascript\nconst express = require('express');\nconst jwt = require('json-web-token');\nconst fs = require('fs');\nconst path = require('path');\n\nconst app = express();\nconst port = 3000;\n\n// Load the keys from the file\nconst publicKeyPath = path.join(__dirname, 'public-key.pem');\nconst publicKey = fs.readFileSync(publicKeyPath, 'utf8');\nconst privateKeyPath = path.join(__dirname, 'private-key.pem');\nconst privateKey = fs.readFileSync(privateKeyPath, 'utf8');\n\napp.use(express.json());\n\n// Endpoint to generate a JWT token with admin: False\napp.get('/generateToken', async (req, res) => {\n const payload = { admin: false, name: req.query.name };\n const token = await jwt.encode(privateKey, payload, 'RS256', function (err, token) {\n res.json({ token });\n });\n});\n\n// Middleware to verify the JWT token\nfunction verifyToken(req, res, next) {\n const token = req.query.token;\n\n jwt.decode(publicKey, token, (err, decoded) => {\n if (err) {\n console.log(err)\n return res.status(401).json({ message: 'Token authentication failed' });\n }\n\n req.decoded = decoded;\n next();\n });\n}\n\n// Endpoint to check if you are the admin or not\napp.get('/checkAdmin', verifyToken, (req, res) => {\n res.json(req.decoded);\n});\n\napp.listen(port, () => {\n console.log(`Server is running on port ${port}`);\n});\n```\n\n**Public key recovery**\nFirst, an attacker needs to recover the public key from the server in any way possible. It is possible to extract this from just two JWT tokens as shown below.\nGrab two different JWT tokens and utilize the following tool: `https://github.com/silentsignal/rsa_sign2n/blob/release/standalone/jwt_forgery.py`\n```\npython3 jwt_forgery.py token1 token2\n```\nThe tool will generate 4 different public keys, all in different formats. Try the following for all 4 formats.\n\n**Algorithm confusion**\nChange the JWT to the HS256 algorithm and modify any of the contents to your liking at `https://jwt.io/`.\nCopy the resulting JWT token and use with the following tool: `https://github.com/ticarpi/jwt_tool`.\n```\npython /opt/jwt_tool/jwt_tool.py --exploit k -pk public_key token\n```\nYou will now get a resulting JWT token that is validly signed.\n\n### Impact\nApplications using the RS256 algorithm, are vulnerable to this algorithm confusion attack which allows attackers to sign arbitrary payloads that the verifier will accept.\n\n### Solution\nEither one of the following solutions will work.\n1. Change the signature of the `decode` function to ensure that the algorithm is set in that call\n2. Check whether or not the secret could be a public key in the decode function and in that case, set the key to be a public key.\n\n\n> Fixed in 4.0.0. Both encode and decode now reject combinations where the key type (PEM vs plain secret) doesn't match the algorithm family. Upgrade with npm install json-web-token@^4.",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "npm",
"name" : "json-web-token"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "4.0.0"
} ]
} ],
"database_specific" : {
"last_known_affected_version_range" : "<= 3.1.1"
}
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/joaquimserafim/json-web-token/security/advisories/GHSA-4xw9-cx39-r355"
}, {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2023-48238"
}, {
"type" : "WEB",
"url" : "https://github.com/joaquimserafim/json-web-token/commit/b6e56b1346f48432d29133c76b65222ad93956b7"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/joaquimserafim/json-web-token"
}, {
"type" : "WEB",
"url" : "https://github.com/joaquimserafim/json-web-token/blob/acf6a462471e1b14187eb77414e9161b8b7bff7e/index.js#L86"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-20", "CWE-345" ],
"severity" : "HIGH",
"github_reviewed" : true,
"github_reviewed_at" : "2023-11-17T22:48:15Z",
"nvd_published_at" : "2023-11-17T22:15:07Z"
}
}