/

CVE-2026-33943

Severity:

HIGH RISK

(8.8)

Code Injection in Happy DOM ECMAScriptModuleCompiler

CVE-2026-33943

Modified

Vulnerability type

Category:

Code Injection

CWE:

CWE-94, CWE-917

Impact:

Remote Code Execution

Severity:

HIGH RISK

(8.8)

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

A code injection vulnerability in Happy DOM's ECMAScriptModuleCompiler allows arbitrary JavaScript execution when specially crafted export { } declarations are processed in ES module scripts.

If an attacker can influence module source code consumed by happy-dom, they may achieve remote code execution in the host environment where Happy DOM is running.

Affected context

This vulnerability appears in projects that embed or depend on Happy DOM versions 15.10.0 through 20.8.7, particularly in test runners, server-side rendering tools, or automation frameworks that execute untrusted or semi-trusted ES modules through Happy DOM.

It is most relevant where:

  • ES module scripts are dynamically loaded or transformed via ECMAScriptModuleCompiler
  • User-controlled or third‑party content can influence export { ... } declarations
  • Executed module code runs with meaningful access to the file system, network, or sensitive process capabilities

Exploit preconditions

  • Attack surface: ES module scripts processed by Happy DOM's ECMAScriptModuleCompiler.
  • Required access: Ability to provide or modify module source code (e.g., plugin ecosystem, test fixtures, user‑generated scripts, or compromised package).
  • Trigger point: Parsing and compilation of an ES module that contains an export { } declaration with injected expressions.
  • Why exploitation is possible:
  • The compiler interpolates export specifiers directly into generated JavaScript as executable expressions.
  • Sanitization is incomplete: while some quoting is filtered, backticks are not stripped, enabling template literal expressions to be injected.
  • Generated code executes in the same context as the host application using Happy DOM, giving the payload access to that environment's APIs and resources.

Why this happens

The root cause is unsafe code generation where untrusted fragments from export { } declarations are treated as benign identifiers but are directly embedded into dynamically constructed JavaScript.

This matches CWE-94: Improper Control of Generation of Code ('Code Injection'), in which input that should be handled as data is instead used to construct executable code.

The quote filter only partially escapes characters and fails to neutralize backticks, so an attacker can wrap arbitrary JavaScript in template literals or expressions that are then evaluated when the generated module code runs.

Potential impact

  • Execution of arbitrary JavaScript code within the process hosting Happy DOM
  • Access to and modification of in‑memory data, including test secrets and configuration
  • File system read/write operations if the environment exposes such APIs
  • Outbound or internal network requests (e.g., data exfiltration, SSRF) via available network libraries
  • Lateral movement within CI/CD or build pipelines that rely on Happy DOM for testing or rendering
  • Compromise of downstream build artifacts or test outputs used in supply-chain processes

General mitigation guidance

Mitigation focuses on eliminating unsafe code generation paths and treating module components as data, not executable fragments.

Recommended patterns include:

  • Avoid direct string interpolation of parsed identifiers or specifiers into generated code; use structured AST transformations or safe code emitters.
  • Apply strict validation and canonicalization of export specifiers, ensuring they conform to identifier syntax rather than arbitrary expressions.
  • Fully neutralize or reject characters that can introduce new execution contexts (such as backticks, semicolons, or template literal delimiters) when dynamic code generation is unavoidable.
  • Prefer static module resolution and compilation pipelines where possible, instead of on‑the‑fly code generation based on runtime input.
  • Run Happy DOM workloads with least privilege (restricted file system and network access, limited environment variables) to reduce impact if code execution occurs.
  • Limit or sandbox user‑supplied or plugin‑supplied scripts, for example via dedicated processes or restricted JavaScript runtimes, instead of executing them directly in the host process.

How teams detect issues like this

Detection is typically achieved by focusing on unsafe dynamic code generation and module compilation logic:

  • Static analysis:
  • Rules that flag dynamic construction of JavaScript source using string concatenation or template literals, especially in compilers or loaders.
  • Patterns that look for insertion of user-controlled values into export/import statements or other syntactic constructs.
  • Checks for incomplete sanitization routines that ignore backticks or other execution-enabling characters.
  • Code review:
  • Manual review of module compilation, bundling, or transformation utilities, with attention to how identifiers and specifiers are handled.
  • Examination of any quote-filtering or escaping functions to confirm they neutralize all code execution vectors, not just quotes.
  • Runtime and policy enforcement:
  • Logging and monitoring of dynamically compiled code paths, including source snippets and callers.
  • CI policies that forbid or heavily scrutinize new usages of eval, Function, or equivalent dynamic compilation flows in libraries like Happy DOM.
  • Automated tools:
  • Use of SAST tools and linters configured with rules for dynamic code evaluation and unsafe string interpolation in JavaScript/TypeScript codebases.

Sources

SourceLink
github.comgithub.com/capricorn86/happy-dom/commit/5437fdf8f13adb9590f9f52616d9f69c3ee8db3c
github.comgithub.com/capricorn86/happy-dom/releases/tag/v20.8.8
github.comgithub.com/capricorn86/happy-dom/security/advisories/GHSA-6q6h-j7hj-3r64
access.redhat.comaccess.redhat.com/security/cve/CVE-2026-33943
bugzilla.redhat.combugzilla.redhat.com/show_bug.cgi?id=2452522
security.access.redhat.comsecurity.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-33943.json

Frequently asked

questions

It can be, depending on how Happy DOM is integrated. If remote users or external systems can influence the ES module source code processed by Happy DOM—such as through user-generated scripts, plugins, or remote content—then the vulnerability can be exploited remotely. In closed, locally controlled test setups, the practical risk is lower but still relevant for supply-chain scenarios.

The attacker must be able to supply or modify ES module scripts that Happy DOM compiles with ECMAScriptModuleCompiler, particularly the export { } sections. This might occur via compromised dependencies, malicious test fixtures, CI configuration, or any feature that executes modules derived from user or third‑party input.

The safest pattern is to remove direct string interpolation of untrusted specifiers into generated JavaScript and instead operate on a structured AST representation. Export specifiers should be strictly validated as identifiers and rendered using robust code-generation utilities that cannot be tricked into emitting arbitrary expressions. Comprehensive neutralization of all execution-enabling characters, including backticks, is critical where dynamic generation remains.

Future prevention relies on minimizing dynamic code generation, enforcing strict separation between data and executable code, and adopting secure-by-default compilation pipelines. This includes: using AST-based transforms rather than hand-built strings, applying strong input validation on all syntactic elements, running security-focused static analysis on compiler code, and performing targeted reviews of any logic that constructs or evaluates code at runtime.

Find out what's already
exploitable in your codebase.