Happy DOM ECMAScriptModuleCompiler Remote Code Execution
A code injection vulnerability exists in Happy DOM's ECMAScriptModuleCompiler, allowing remote code execution (RCE) by injecting arbitrary JavaScript expressions into `export { }` declarations, enabling command execution if JavaScript evaluation is enabled.
CVE search metadata
CVE search record: CVE-2024-51757. EPSS: 0.77%. KEV: no. Product: Happy Dom. Brief: Happy DOM ECMAScriptModuleCompiler Remote Code Execution. Brief link: https://feed.craftedsignal.io/briefs/2024-07-happy-dom-rce/
CVE search record: CVE-2025-61927. EPSS: 0.64%. KEV: no. Product: Happy Dom. Brief: Happy DOM ECMAScriptModuleCompiler Remote Code Execution. Brief link: https://feed.craftedsignal.io/briefs/2024-07-happy-dom-rce/
CVE search record: CVE-2026-33943. Severity: high. CVSS: 8.8. EPSS: 0.97%. KEV: no. Product: Happy Dom. Brief: Happy DOM ECMAScriptModuleCompiler Remote Code Execution. Brief link: https://feed.craftedsignal.io/briefs/2024-07-happy-dom-rce/
CVE search record: CVE-2026-115895. Severity: high. CVSS: 8.8. KEV: no. Product: Happy Dom. Brief: Happy DOM ECMAScriptModuleCompiler Remote Code Execution. Brief link: https://feed.craftedsignal.io/briefs/2024-07-happy-dom-rce/
Triage facts
Revision 1- Evidence
- Unknown
- Severity
- Critical
- Sources
- 2 public sources
- Freshness
- Revision 1Jul 3, 14:00 UTC
- Detection
- 2 rules
- Vulnerabilities
- 4 CVEs
What's new
- 1. poc_available; added CVE-2024-51757 +3 Oct 24, 03:46 via ghsa
Happy DOM, a browser automation library, is susceptible to a code injection vulnerability within its ECMAScriptModuleCompiler. This flaw allows attackers to inject arbitrary JavaScript expressions into export { } declarations in ES module scripts. Specifically, the compiler directly interpolates unsanitized content into generated code as an executable expression. The inadequate sanitization, which fails to strip backticks, enables the use of template literals to bypass security measures. This vulnerability is present in versions 15.10.0 through 20.8.7 and can be exploited when JavaScript evaluation is explicitly enabled. This issue differs from CVE-2024-51757 and CVE-2025-61927, which were patched in earlier versions. Defenders should be aware of the risk, particularly in environments where happy-dom processes untrusted HTML content.
Attack Chain
- The attacker injects malicious JavaScript code within an HTML
<script type="module">tag intended for processing by happy-dom. The payload is crafted within anexport { ... }declaration. For example:export { require(child_process).execSync(id) }. - Happy DOM's
ECMAScriptModuleCompiler.tsprocesses the HTML, extracting the content within theexport { ... }declaration using a regular expression that is overly permissive. - The extracted content,
require(\child_process`).execSync(`id`)`, is passed through a flawed sanitization function that removes single and double quotes but fails to remove backticks. - The unsanitized content is then directly interpolated into the generated JavaScript code as an executable expression:
$happy_dom.exports['${exportName}'] = ${importName}. - The generated JavaScript code, now containing the injected malicious command, is evaluated by happy-dom's scripting engine.
- The
child_process.execSyncfunction executes the injected command (idin this example) on the host system. - The output of the command is captured and potentially used for further exploitation or data exfiltration.
- The attacker achieves Remote Code Execution (RCE) on the host system, gaining the ability to execute arbitrary commands.
Impact
Successful exploitation of this vulnerability allows an attacker to achieve remote code execution (RCE) on systems using happy-dom to process HTML with JavaScript evaluation enabled. This can lead to complete system compromise, data theft, or denial of service. The vulnerability affects applications using happy-dom for server-side rendering (SSR) of user-supplied HTML, web scraping of untrusted content, and testing pipelines that load untrusted HTML fixtures. Given the wide use of JavaScript-based tools and frameworks, the impact can be significant for vulnerable systems where JavaScript evaluation is enabled.
Recommendation
- Upgrade to a patched version of happy-dom that addresses CVE-2026-33943 once available.
- Disable JavaScript evaluation in happy-dom if it is not required for your application to mitigate CVE-2026-33943.
- Implement strict input validation and sanitization of any HTML content processed by happy-dom, ensuring that
export { ... }declarations do not contain potentially malicious JavaScript code. - Deploy the Sigma rule
Detect Happy DOM RCE via export injectionto detect exploitation attempts based on process creation with thechild_processmodule. - Monitor web server logs for suspicious requests containing JavaScript code within
<script type="module">tags that could be used to inject malicious payloads (seeDetect Happy DOM RCE via web requestSigma rule). - Enable Sysmon process creation logging to enhance visibility into spawned processes and detect potential command execution resulting from this vulnerability.
Detection coverage 2
Detect Happy DOM RCE via export injection
criticalDetects potential RCE attempts in Happy DOM by monitoring for process creation events where 'child_process' is involved, indicating command execution via the vulnerability.
Detect Happy DOM RCE via web request
highDetects potential RCE attempts in Happy DOM by monitoring for suspicious web requests containing <script type='module'> tags with javascript code within the export statement.
Detection queries are available on the platform. Get full rules →