CVE-2025-61927: Happy DOM Remote Code Execution Vulnerability

CRITICAL
Advisory Identifier: GHSA-37j7-fg3j-429f
CWE-94
Published
Advisory Summary

CVE-2025-61927 is a CRITICAL remote code execution vulnerability (CWE-94: Improper Control of Generation of Code ('Code Injection')) affecting Happy DOM libraries in the npm ecosystem. The issue involves vm context escape can lead to remote code execution. Remediation is available by upgrading affected packages to version 20.0.0.

CVE-2025-61927 at a Glance

CVE Identifier CVE-2025-61927
GHSA Identifier GHSA-37j7-fg3j-429f
Severity CRITICAL
CVSS v3.1 Base Score N/A
CWE Classification CWE-94: Improper Control of Generation of Code ('Code Injection')
Affected Product Happy DOM
Package Ecosystem npm
Published Date
Last Updated

How to Fix CVE-2025-61927

To remediate this vulnerability, upgrade all affected Happy DOM dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

happy-dom fixed: 20.0.0
npm install happy-dom@20.0.0
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

npm ls happy-dom

How to Check if You Are Affected

To determine whether your Node.js application is affected by CVE-2025-61927, inspect your project dependencies using npm:

npm ls happy-dom

Analyze the terminal output to locate any version of Happy DOM in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 20.0.0), your application is affected.

Note: The npm ls happy-dom command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-94: Improper Control of Generation of Code ('Code Injection'), where the product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment. In Happy DOM, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

# Escape of VM Context gives access to process level functionality ## Summary Happy DOM v19 and lower contains a security vulnerability that puts the owner system at the risk of RCE (Remote Code Execution) attacks. A Node.js VM Context is not an isolated environment, and if the user runs untrusted JavaScript code within the Happy DOM VM Context, it may escape the VM and get access to process level functionality. It seems like what the attacker can get control over depends on if the process is using ESM or CommonJS. With CommonJS the attacker can get hold of the `require()` function to import modules. Happy DOM has JavaScript evaluation enabled by default. This may not be obvious to the consumer of Happy DOM and can potentially put the user at risk if untrusted code is executed within the environment. ## Reproduce ### CommonJS (Possible to get hold of require) ```javascript const { Window } = require('happy-dom'); const window = new Window({ console }); window.document.write(` <script> const process = this.constructor.constructor('return process')(); const require = process.mainModule.require; console.log('Files:', require('fs').readdirSync('.').slice(0,3)); </script> `); ``` ### ESM (Not possible to get hold of import or require) ```javascript const { Window } = require('happy-dom'); const window = new Window({ console }); window.document.write(` <script> const process = this.constructor.constructor('return process')(); console.log('PID:', process.pid); </script> `); ``` ## Potential Impact #### Server-Side Rendering (SSR) ```javascript const { Window } = require('happy-dom'); const window = new Window(); window.document.innerHTML = userControlledHTML; ``` #### Testing Frameworks Any test suite using Happy-DOM with untrusted content may be at risk ## Attack Scenarios 1. **Data Exfiltration**: Access to environment variables, configuration files, secrets 2. **Lateral Movement**: Network access for connecting to internal systems. Happy DOM already gives access to the network by fetch, but has protections in place (such as CORS and header validation etc.). 3. **Code Execution**: Child process access for running arbitrary commands 4. **Persistence**: File system access ## Recommended Immediate Actions 1. Update Happy DOM to v20 or above - This version has JavaScript evaluation disabled by default - This version will output a warning if JavaScript is enabled in an insecure environment 2. Run Node.js with the "--disallow-code-generation-from-strings" if you need JavaScript evaluation enabled - This makes sure that evaluation can't be used at process level to escape the VM - `eval()` and `Function()` can still be used within the Happy DOM VM without any known security risk - Happy DOM v20 and above will output a warning if this flag is not in use 4. If you can't update Happy DOM right now, it's recommended to disable JavaScript evaluation, unless you completely trust the content within the environment ## Technical Root Cause All classes and functions inherit from [Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function). By walking the constructor chain it's possible to get hold of [Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) at process level. As [Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) can evaluate code from strings, it's possible to execute code at process level. Running Node with the "--disallow-code-generation-from-strings" flag protects against this.

CVE-2025-61927 Affected Happy DOM Versions

1 component(s)
Fixed Versions:
20.0.0
Product / Package Ecosystem Affected Versions Fixed Version
happy-dom
npm
< 20.0.0
20.0.0

References

Frequently Asked Questions

What is CVE-2025-61927?
CVE-2025-61927 is a security vulnerability in Happy DOM involving VM Context Escape can lead to Remote Code Execution under CWE-94: Improper Control of Generation of Code ('Code Injection').
Which Happy DOM versions are affected?
Affected versions include releases prior to 20.0.0 across affected packages: happy-dom.
What version fixes CVE-2025-61927?
Upgrading to 20.0.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is happy-dom affected?
Yes, happy-dom is affected in releases prior to 20.0.0. Upgrade your dependency to 20.0.0 or later.
What CWE is associated with CVE-2025-61927?
CVE-2025-61927 is classified under CWE-94: Improper Control of Generation of Code ('Code Injection') (The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.).
How can I check npm dependencies for CVE-2025-61927?
Run the dependency tree command: 'npm ls happy-dom'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-37j7-fg3j-429f",
  "modified" : "2025-10-13T15:48:53Z",
  "published" : "2025-10-10T23:46:42Z",
  "aliases" : [ "CVE-2025-61927" ],
  "summary" : "Happy DOM: VM Context Escape can lead to Remote Code Execution",
  "details" : "# Escape of VM Context gives access to process level functionality\n\n## Summary\nHappy DOM v19 and lower contains a security vulnerability that puts the owner system at the risk of RCE (Remote Code Execution) attacks.\n\nA Node.js VM Context is not an isolated environment, and if the user runs untrusted JavaScript code within the Happy DOM VM Context, it may escape the VM and get access to process level functionality.\n\nIt seems like what the attacker can get control over depends on if the process is using ESM or CommonJS. With CommonJS the attacker can get hold of the `require()` function to import modules.\n\nHappy DOM has JavaScript evaluation enabled by default. This may not be obvious to the consumer of Happy DOM and can potentially put the user at risk if untrusted code is executed within the environment.\n\n## Reproduce\n\n### CommonJS (Possible to get hold of require)\n\n```javascript\nconst { Window } = require('happy-dom');\nconst window = new Window({ console });\n\nwindow.document.write(`\n  <script>\n     const process = this.constructor.constructor('return process')();\n     const require = process.mainModule.require;\n  \n     console.log('Files:', require('fs').readdirSync('.').slice(0,3));\n  </script>\n`);\n```\n### ESM (Not possible to get hold of import or require)\n\n```javascript\nconst { Window } = require('happy-dom');\nconst window = new Window({ console });\n\nwindow.document.write(`\n  <script>\n     const process = this.constructor.constructor('return process')();\n  \n     console.log('PID:', process.pid);\n  </script>\n`);\n```\n\n## Potential Impact\n\n#### Server-Side Rendering (SSR)\n```javascript\nconst { Window } = require('happy-dom');\nconst window = new Window();\nwindow.document.innerHTML = userControlledHTML;\n```\n\n#### Testing Frameworks\nAny test suite using Happy-DOM with untrusted content may be at risk\n\n## Attack Scenarios\n\n1. **Data Exfiltration**: Access to environment variables, configuration files, secrets\n2. **Lateral Movement**: Network access for connecting to internal systems. Happy DOM already gives access to the network by fetch, but has protections in place (such as CORS and header validation etc.).\n3. **Code Execution**: Child process access for running arbitrary commands\n4. **Persistence**: File system access\n\n## Recommended Immediate Actions\n\n1. Update Happy DOM to v20 or above\n    - This version has JavaScript evaluation disabled by default\n    - This version will output a warning if JavaScript is enabled in an insecure environment\n2. Run Node.js with the \"--disallow-code-generation-from-strings\" if you need JavaScript evaluation enabled\n    - This makes sure that evaluation can't be used at process level to escape the VM\n    - `eval()` and `Function()` can still be used within the Happy DOM VM without any known security risk\n    - Happy DOM v20 and above will output a warning if this flag is not in use\n4. If you can't update Happy DOM right now, it's recommended to disable JavaScript evaluation, unless you completely trust the content within the environment\n\n## Technical Root Cause\n\nAll classes and functions inherit from [Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function). By walking the constructor chain it's possible to get hold of [Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) at process level. As [Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) can evaluate code from strings, it's possible to execute code at process level.\n\nRunning Node with the \"--disallow-code-generation-from-strings\" flag protects against this.",
  "severity" : [ {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H/E:P"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "happy-dom"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "20.0.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/capricorn86/happy-dom/security/advisories/GHSA-37j7-fg3j-429f"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2025-61927"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/capricorn86/happy-dom/commit/819d15ba289495439eda8be360d92a614ce22405"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/capricorn86/happy-dom/commit/de438ad72921c69793584aa657b48d3655dfac97"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/capricorn86/happy-dom"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/capricorn86/happy-dom/releases/tag/v20.0.0"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-94" ],
    "severity" : "CRITICAL",
    "github_reviewed" : true,
    "github_reviewed_at" : "2025-10-10T23:46:42Z",
    "nvd_published_at" : "2025-10-10T20:15:38Z"
  }
}