CVE-2024-43796: XSS Vulnerability in Express
Summary
CVE-2024-43796: express vulnerable to XSS via response.redirect(). Affects express across 2 version ranges.
< 4.20.0
>= 5.0.0-alpha.1, < 5.0.0
Fixed in 4.20.0 or 5.0.0, depending on the release line you run. How to fix ↓
Also tracked for
- node-express · Debian:11
The same CVE-2024-43796 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.
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.
No signup required · Results in about 60 seconds
Background
Express is a popular web application framework for Node.js that simplifies the process of building web applications and APIs. It provides a robust set of features and middleware to handle various aspects of web development. However, versions of Express prior to 4.20.0 are vulnerable to a cross-site scripting (XSS) attack when untrusted user input is passed to the response.redirect() function.
Vulnerability Detail
The vulnerability arises when untrusted user input, even after being sanitized, is used as an argument for response.redirect(). This can lead to the execution of untrusted code. Successful exploitation of this vulnerability requires several conditions to be met: 1) The attacker must control the input to response.redirect(), 2) Express must not redirect before the template appears, and 3) The browser must not complete redirection before the user clicks on the link in the template. The impact of this vulnerability can range from unauthorized code execution to the theft of sensitive user information.
How To Fix
Latest published version: 5.3.0 as of 22 Oct 2026
npm install express@5.3.0
Upgrading to it may include breaking changes; the versions below are the minimum fixed release for this vulnerability.
If you can't move to the latest
The minimum fixed version depends on the release line you run.
-
< 4.20.04.20.0npm install express@4.20.0 -
>= 5.0.0-alpha.1, < 5.0.05.0.0npm install express@5.0.0
Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →
Workaround
To mitigate the vulnerability without upgrading, it is important to validate any user input against an allowlist. This can be done by implementing proper input validation and sanitization techniques. Here is an example of how to validate user input using the express-validator library:
const { body, validationResult } = require('express-validator');
app.post('/login', [
body('username').isAlphanumeric(),
body('password').isLength({ min: 8 })
], (req, res) => {
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() });
}
// Proceed with login logic
});
Conclusion
The XSS vulnerability in Express versions prior to 4.20.0 can allow for the execution of untrusted code when untrusted user input is passed to response.redirect(). It is crucial to upgrade to the patched version or implement proper input validation and sanitization techniques to mitigate the risk of exploitation.
See every vulnerability recorded for express →
FAQ
The vulnerability allows for the execution of untrusted code, which can lead to various consequences such as unauthorized code execution or the theft of sensitive user information.
Versions of Express prior to 4.20.0 are affected by this vulnerability.
The vulnerability can be fixed by upgrading to Express version 4.20.0 or higher. Alternatively, you can validate untrusted inputs against an explicit allowlist to ensure their safety.
Yes, if upgrading is not possible, you can implement proper input validation and sanitization techniques to mitigate the vulnerability. Validating user input against an allowlist is recommended.
You can find more information about this vulnerability in the GitHub Advisory Database: https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2024/09/GHSA-qw6h-vgh9-j6wx/GHSA-qw6h-vgh9-j6wx.json
References
Related vulnerabilities
Recent vulnerabilities recorded for express.