/

CVE-2026-33979

Severity:

HIGH RISK

(8.2)

XSS in Express XSS Sanitizer Middleware

CVE-2026-33979

Analyzed

Vulnerability type

Category:

Cross-Site Scripting (XSS)

CWE:

CWE-79, CWE-183

Impact:

Bypass of XSS Sanitization Leading to Cross-Site Scripting

Severity:

HIGH RISK

(8.2)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

Express XSS Sanitizer middleware for Express 4.x and 5.x contains a flaw where restrictive sanitization configurations are silently ignored in versions prior to 2.0.2. This means that developer-specified policies, such as empty allowedTags or allowedAttributes, are not enforced as intended, weakening XSS defenses.

In affected versions, applications that rely on strict sanitization rules may inadvertently allow unsafe HTML or script content to pass through, increasing the risk of cross-site scripting attacks when this data is rendered in a browser.

Affected context

This vulnerability affects Node.js applications using Express XSS Sanitizer as middleware for Express 4.x and 5.x, specifically in deployments that rely on custom or restrictive sanitization options. When developers configure the middleware with explicit allowedTags or allowedAttributes values—especially empty arrays or highly restrictive sets—the library may ignore these inputs and fall back to default behavior in versions prior to 2.0.2.

The issue manifests in any path where user-controlled data in req.body, req.query, req.headers, or req.params is sanitized with the assumption that strict rules are applied, and later rendered in HTML, templates, or front-end views.

Exploit preconditions

  • Attack surface: Any HTTP endpoint using Express XSS Sanitizer to clean user input that is subsequently reflected or stored and rendered in a browser.
  • Required access: Ability for an attacker to send crafted input via request bodies, query parameters, headers, or route parameters.
  • Trigger point: The middleware processes user input under a configuration where restrictive allowedTags or allowedAttributes are provided but silently ignored.
  • Why exploitation is possible: Due to mis-handling of explicit configuration, the sanitizer applies less restrictive defaults than intended. This can preserve HTML or attributes that developers expected to be stripped or blocked, enabling injection of script-capable content when the data is later embedded in web pages.

Why this happens

The root cause lies in how the middleware interprets and validates its configuration, particularly allowedTags and allowedAttributes. In versions prior to 2.0.2, the logic does not properly distinguish between intentionally empty configurations and absent configurations, leading to restrictive settings being overridden by defaults.

This behavior maps to CWE-183: Permissive List of Allowed Inputs and CWE-79: Improper Neutralization of Input During Web Page Generation (XSS). The sanitizer effectively uses a more permissive allowlist than the developer specified, enabling dangerous content to slip through. Conceptually, the bug is an incorrect policy application: explicitly supplied restrictive policies are discarded or ignored instead of being honored, reducing the trustworthiness of the sanitization boundary.

Potential impact

  • User-supplied HTML or attributes that developers intended to block may be retained after sanitization.
  • Stored or reflected cross-site scripting (XSS) attacks could become possible where they were believed to be mitigated.
  • Attackers can potentially execute arbitrary JavaScript in victims' browsers when crafted payloads are rendered.
  • Session hijacking, credential theft, or sensitive data exposure could occur through successful XSS exploits.
  • Integrity of client-side content could be compromised, including UI defacement or injection of malicious links.

General mitigation guidance

To mitigate this class of issue, focus on hardening input handling and defense-in-depth around HTML rendering rather than depending on a single middleware configuration:

  • Treat sanitization configuration as security-sensitive: ensure that explicit allowlists (including empty ones) are honored and tested with unit and integration tests.
  • Favor conservative defaults that remove all HTML where possible, only enabling narrowly scoped tags/attributes when absolutely necessary.
  • Apply output encoding based on context (HTML, attribute, JavaScript, URL) even when input sanitization is present.
  • Reduce the need to accept raw HTML from users; prefer structured, non-HTML inputs or safe markup subsets if feasible.
  • Segregate untrusted content in isolated contexts (e.g., sandboxed iframes, strict CSP) to limit the impact of any sanitization failure.
  • Implement least-privilege principles in the front end by using Content Security Policy (CSP) and disabling inline scripts where practical.

How teams detect issues like this

Organizations can detect and monitor this vulnerability pattern by:

  • Reviewing middleware configuration for Express XSS Sanitizer and verifying that restrictive allowedTags and allowedAttributes are exercised in automated tests.
  • Using static analysis or linters to flag locations where untrusted input is assumed safe purely because a sanitizer was applied, especially when HTML is rendered.
  • Implementing security-focused code review checklists that require explicit verification of sanitization logic, including handling of empty or edge-case configurations.
  • Adding regression tests with malicious HTML/XSS payloads to validate that configured policies are actually enforced, not silently overridden.
  • Employing dynamic application security testing (DAST) tools or scanners that probe endpoints for XSS, particularly those relying on configurable sanitization libraries.

Sources

SourceLink
github.comgithub.com/AhmedAdelFahim/express-xss-sanitizer/commit/5623009ef11dcf095c163a38dea07b9cc22ad19f
github.comgithub.com/AhmedAdelFahim/express-xss-sanitizer/releases/tag/v2.0.2
github.comgithub.com/AhmedAdelFahim/express-xss-sanitizer/security/advisories/GHSA-3843-rr4g-m8jq

Frequently asked

questions

Exploitability depends on whether the application relies on restrictive Express XSS Sanitizer configurations and then renders that data into web pages. If the application expects strict stripping of HTML or attributes, but the middleware silently falls back to permissive defaults, XSS attacks can become feasible where they were believed to be mitigated.

An attacker only needs the ability to submit crafted data to endpoints that pass user input through the vulnerable middleware and later render it in a browser. No special privileges are required beyond normal user input capabilities (e.g., submitting forms, query parameters, or headers).

The safest pattern is to ensure that your sanitization library faithfully enforces your configuration while also applying robust output encoding on all untrusted data when generating HTML. Additionally, adopt a default-deny approach: strip all HTML unless there is a strong, validated business need for specific tags and attributes, and verify behavior through automated tests.

Prevent recurrence by treating security-related configurations as code: track them in version control, test them with targeted unit and integration tests, and subject them to security-focused code review. Combine multiple layers of defense—sanitization, context-aware output encoding, CSP, and minimized acceptance of raw HTML—to ensure that a single configuration bug does not re-enable XSS.

Find out what's already
exploitable in your codebase.