Skip to main content
Vulnerability Database/CVE-2024-53382

CVE-2024-53382: Prismjs Prism DOM Clobbering XSS Vulnerability

CVE-2024-53382 is a DOM Clobbering XSS vulnerability in Prismjs Prism that allows attackers to execute malicious scripts through injected HTML elements. This article covers technical details, affected versions, and mitigation steps.

Published:

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

CVE-2024-53382 Overview

CVE-2024-53382 affects Prism (PrismJS) through version 1.29.0, a widely deployed JavaScript syntax highlighter. The library is vulnerable to DOM Clobbering, which can escalate to Cross-Site Scripting (XSS) when applications render untrusted HTML that does not itself contain JavaScript. The root cause is Prism's reliance on document.currentScript, a property that attacker-injected HTML elements can shadow. Successful exploitation enables script execution in the victim's browser within the context of the hosting application.

Critical Impact

Attackers who can inject sanitized HTML (without <script> tags) into pages that load Prism can trigger XSS by clobbering document.currentScript, bypassing common HTML sanitizer configurations.

Affected Products

  • PrismJS (prismjs:prism) versions up to and including 1.29.0
  • Node.js distributions of the prismjs package
  • Web applications and documentation sites bundling vulnerable Prism builds

Discovery Timeline

  • 2025-03-03 - CVE-2024-53382 published to the National Vulnerability Database
  • 2026-06-17 - Last updated in NVD database

Technical Details for CVE-2024-53382

Vulnerability Analysis

Prism loads language and plugin components dynamically. To determine its own script location, it reads document.currentScript and inspects attributes such as src and data-*. The lookup assumes document.currentScript always returns the currently executing <script> element. DOM Clobbering breaks this assumption. An attacker who injects an HTML element with an id or name of currentScript can shadow the property on the document object. Prism then reads attacker-controlled attributes and uses them to construct URLs or configuration values, which can be redirected to attacker-controlled JavaScript.

The weakness maps to CWE-94 (Improper Control of Generation of Code) and CWE-79 (Improper Neutralization of Input During Web Page Generation).

Root Cause

Prism trusts the value returned by document.currentScript without verifying that the reference points to an actual <script> element. Browsers permit named HTML elements to shadow properties on the document object, so an injected <img name="currentScript" src="..."> or similar element replaces the expected value. The relevant initialization logic is visible in the PrismJS source.

Attack Vector

The attacker must be able to inject HTML into a page that includes a vulnerable Prism build. Many sanitizers permit anchor, image, form, and iframe elements with id or name attributes, which is sufficient to clobber document.currentScript. Prism then dereferences attacker-controlled attributes and may fetch and evaluate remote resources, resulting in XSS in the application origin. A proof of concept is published as a GitHub Gist.

Detection Methods for CVE-2024-53382

Indicators of Compromise

  • Presence of HTML elements with id="currentScript" or name="currentScript" in rendered user-generated content
  • Outbound requests from browsers to unexpected domains originating from pages that load Prism
  • Prism script tags without data-manual attributes in applications that process untrusted HTML

Detection Strategies

  • Perform Software Composition Analysis (SCA) across repositories and container images for prismjs versions at or below 1.29.0
  • Audit server-rendered and client-rendered HTML paths for sanitizer configurations that allow id or name attributes on inline elements
  • Review Content Security Policy (CSP) reports for script-src violations tied to pages using Prism

Monitoring Recommendations

  • Enable browser-side CSP reporting to capture blocked script loads and inline execution attempts
  • Monitor web application firewall (WAF) logs for HTML payloads containing name=currentScript or id=currentScript
  • Track dependency manifests (package.json, package-lock.json, yarn.lock) for pinned vulnerable Prism versions

How to Mitigate CVE-2024-53382

Immediate Actions Required

  • Upgrade prismjs to a patched release above 1.29.0 as soon as it is published by the maintainers
  • Configure HTML sanitizers (DOMPurify, sanitize-html) to strip id and name attributes from user-supplied content
  • Deploy a strict Content Security Policy that blocks inline scripts and restricts script-src to trusted origins

Patch Information

At the time of publication, no fixed version was referenced in the NVD entry. Monitor the PrismJS repository for a release addressing the DOM Clobbering vector, and track the GitHub Gist PoC for additional technical context.

Workarounds

  • Replace Prism with a syntax highlighter that does not rely on document.currentScript for runtime configuration
  • Load Prism with explicit configuration flags such as data-manual and preload required components to avoid runtime script lookups
  • Isolate rendering of untrusted content in a sandboxed iframe with the sandbox attribute to contain any resultant XSS
bash
# Example sanitizer hardening with DOMPurify
DOMPurify.sanitize(userHtml, {
  FORBID_ATTR: ['id', 'name'],
  FORBID_TAGS: ['form', 'iframe']
});

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

Experience the Most Advanced Cybersecurity Platform

See how the world’s most intelligent, autonomous cybersecurity platform can protect your organization today and into the future.