/

CVE-2026-115895

Severity:

HIGH RISK

(8.8)

Code Injection (CWE-94) in Happy DOM ESM Module Compiler

CVE-2026-115895

Awaiting Analysis

Vulnerability type

Category:

Code Injection

CWE:

CWE-94

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

Happy DOM contains a code injection flaw in its ECMAScript module compiler that can place an unvalidated import alias into generated JavaScript. When JavaScript evaluation is enabled and attacker-controlled HTML or module source is processed, this may cause code to execute in the Node.js host process.

Happy DOM contains a code injection flaw in its ECMAScript module compiler that can place an unvalidated import alias into generated JavaScript. When JavaScript evaluation is enabled and attacker-controlled HTML or module source is processed, this may cause code to execute in the Node.js host process.

Affected context

The vulnerability affects Happy DOM deployments within the impacted 17.0.0 through 21.0.4 release range when JavaScript evaluation is enabled. It arises in the ESM compilation path when attacker-controlled module or HTML content can supply a named import alias that is inserted into a generated destructuring binding without being checked as a valid JavaScript binding identifier. A reachable scenario involves JSON module import attributes and generated circular-import handling.

The vulnerability affects Happy DOM deployments within the impacted 17.0.0 through 21.0.4 release range when JavaScript evaluation is enabled. It arises in the ESM compilation path when attacker-controlled module or HTML content can supply a named import alias that is inserted into a generated destructuring binding without being checked as a valid JavaScript binding identifier. A reachable scenario involves JSON module import attributes and generated circular-import handling.

Exploit preconditions

  • Attack surface: Happy DOM's ECMAScript module compilation and evaluation functionality
  • Required access: The ability to provide or influence HTML or module source processed by the application
  • Trigger point: Compilation and evaluation of an ESM import with a named alias
  • Required configuration: JavaScript evaluation must be enabled
  • Why exploitation is possible: The alias is incorporated into generated JavaScript without validation, allowing compiler output to acquire unintended executable semantics while remaining syntactically valid in the relevant import-flow scenario
  • Attack surface: Happy DOM's ECMAScript module compilation and evaluation functionality
  • Required access: The ability to provide or influence HTML or module source processed by the application
  • Trigger point: Compilation and evaluation of an ESM import with a named alias
  • Required configuration: JavaScript evaluation must be enabled
  • Why exploitation is possible: The alias is incorporated into generated JavaScript without validation, allowing compiler output to acquire unintended executable semantics while remaining syntactically valid in the relevant import-flow scenario

Why this happens

The underlying bug is insufficient validation of a user-controlled identifier during source-code generation. The compiler accepts a named ESM import alias without confirming that it conforms to JavaScript binding-identifier rules, then inserts it into a generated destructuring binding. This maps to CWE-94: Improper Control of Generation of Code ('Code Injection'), because input data can influence executable JavaScript produced for evaluation. The issue represents a residual validation gap in a related remediation: one import-name path was checked, while the named-import alias path remained trusted.

The underlying bug is insufficient validation of a user-controlled identifier during source-code generation. The compiler accepts a named ESM import alias without confirming that it conforms to JavaScript binding-identifier rules, then inserts it into a generated destructuring binding. This maps to CWE-94: Improper Control of Generation of Code ('Code Injection'), because input data can influence executable JavaScript produced for evaluation. The issue represents a residual validation gap in a related remediation: one import-name path was checked, while the named-import alias path remained trusted.

Potential impact

  • An attacker could execute JavaScript in the Node.js host process
  • The application may suffer confidentiality, integrity, or availability loss
  • Host environment secrets or accessible files could be exposed
  • The process could be used for unauthorized network activity or lateral movement
  • Test, rendering, or server-side automation workloads could be compromised
  • An attacker could execute JavaScript in the Node.js host process
  • The application may suffer confidentiality, integrity, or availability loss
  • Host environment secrets or accessible files could be exposed
  • The process could be used for unauthorized network activity or lateral movement
  • Test, rendering, or server-side automation workloads could be compromised

General mitigation guidance

Mitigation generally focuses on treating all source-level names as untrusted before they reach code-generation logic.

Defensive patterns include:

  • Validate every generated binding, including named import aliases, against the language's binding-identifier grammar
  • Prefer structured parsers, AST transformations, or safe module APIs over string-based source generation
  • Reject malformed or unexpected module identifiers before compilation and before evaluation
  • Keep JavaScript evaluation disabled unless the application requires it
  • Isolate evaluated content in a least-privileged process or sandbox with restricted filesystem, network, and credential access
  • Apply consistent validation across initial imports, re-exports, and circular-import bookkeeping paths
  • Treat HTML, module source, and import metadata as untrusted input regardless of their apparent origin

Mitigation generally focuses on treating all source-level names as untrusted before they reach code-generation logic.

Defensive patterns include:

  • Validate every generated binding, including named import aliases, against the language's binding-identifier grammar
  • Prefer structured parsers, AST transformations, or safe module APIs over string-based source generation
  • Reject malformed or unexpected module identifiers before compilation and before evaluation
  • Keep JavaScript evaluation disabled unless the application requires it
  • Isolate evaluated content in a least-privileged process or sandbox with restricted filesystem, network, and credential access
  • Apply consistent validation across initial imports, re-exports, and circular-import bookkeeping paths
  • Treat HTML, module source, and import metadata as untrusted input regardless of their apparent origin

How teams detect issues like this

Detection can combine static analysis, review controls, and runtime policy enforcement:

  • Search for generated JavaScript that interpolates import names or aliases without identifier validation
  • Use static-analysis rules to flag string concatenation or template generation involving module-source tokens
  • Review compiler paths for inconsistent validation between local names, aliases, re-exports, and circular-import assignments
  • Add negative tests for invalid binding identifiers across ordinary, JSON-module, and circular-import flows
  • Enforce policies that restrict JavaScript evaluation in server-side DOM environments
  • Monitor evaluated Node.js processes for unexpected child-process creation, filesystem access, or outbound connections
  • Automated code-review and dependency-analysis tools may help identify unsafe code-generation patterns and affected dependency usage

Detection can combine static analysis, review controls, and runtime policy enforcement:

  • Search for generated JavaScript that interpolates import names or aliases without identifier validation
  • Use static-analysis rules to flag string concatenation or template generation involving module-source tokens
  • Review compiler paths for inconsistent validation between local names, aliases, re-exports, and circular-import assignments
  • Add negative tests for invalid binding identifiers across ordinary, JSON-module, and circular-import flows
  • Enforce policies that restrict JavaScript evaluation in server-side DOM environments
  • Monitor evaluated Node.js processes for unexpected child-process creation, filesystem access, or outbound connections
  • Automated code-review and dependency-analysis tools may help identify unsafe code-generation patterns and affected dependency usage

Sources

SourceLink
github.comgithub.com/capricorn86/happy-dom/commit/fd163520b74d9fa146be91f7b4e4f46d6cccbe13
github.comgithub.com/capricorn86/happy-dom/pull/2537
github.comgithub.com/capricorn86/happy-dom/releases/tag/v21.0.4
github.comgithub.com/capricorn86/happy-dom/security/advisories/GHSA-834v-8h66-3h79

Frequently asked

questions

It can be exploitable through an application that processes attacker-controlled HTML or module source with Happy DOM's JavaScript evaluation enabled. The practical scope depends on how that input reaches the vulnerable compiler.

An attacker generally needs a way to influence source content or import metadata that the application passes to Happy DOM. Direct operating-system access is not necessarily required when the application exposes a suitable processing endpoint.

Validate every identifier before it enters generated code, avoid string-based code generation where structured APIs are available, and disable JavaScript evaluation when it is not essential.

Treat module names and aliases as untrusted data, test all compiler branches including circular-import paths, apply least privilege and process isolation, and use static-analysis policies for generated-code sinks.

It can be exploitable through an application that processes attacker-controlled HTML or module source with Happy DOM's JavaScript evaluation enabled. The practical scope depends on how that input reaches the vulnerable compiler.

An attacker generally needs a way to influence source content or import metadata that the application passes to Happy DOM. Direct operating-system access is not necessarily required when the application exposes a suitable processing endpoint.

Validate every identifier before it enters generated code, avoid string-based code generation where structured APIs are available, and disable JavaScript evaluation when it is not essential.

Treat module names and aliases as untrusted data, test all compiler branches including circular-import paths, apply least privilege and process isolation, and use static-analysis policies for generated-code sinks.

Find out what's already
exploitable in your codebase.