# CVE-2024-51757: Fixes security vulnerability that allowed for server side code to be executed by a <script> tag

> An attacker can execute arbitrary server-side code by injecting a script tag into the happy-dom JavaScript library environment.

- **Severity:** Critical 9.3 (`CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 6 Nov 2024
- **Updated:** 6 Nov 2024
- **Also known as:** CLSA-2026-1790102017, CLSA-2026-1792254628, CLSA-2026-1792866963, GHSA-96g7-g7g9-jxw8

## What is CVE-2024-51757?

CVE-2024-51757 is a critical code injection vulnerability in capricorn86 happy-dom, published on 6 Nov 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

happy-dom is a JavaScript implementation of a web browser without its graphical user interface. Versions of happy-dom prior to 15.10.2 may execute code on the host via a script tag. This would execute code in the user context of happy-dom. Users are advised to upgrade to version 15.10.2. There are no known workarounds for this vulnerability.

Weakness: CWE-94 (Improper Control of Generation of Code), CWE-79 (Improper Neutralization of Input During Web Page Generation)

## Which versions are affected by CVE-2024-51757?

2 open source packages ship an affected version, including happy-dom.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `happy-dom` | npm | All versions | 15.10.2 |
| `happy-dom` | npm | All versions | 15.10.2 |

## How do I fix CVE-2024-51757?

Upgrade happy-dom to 15.10.2 or later.

## Is CVE-2024-51757 being exploited?

It is not confirmed as exploited in the wild, but public exploit code for CVE-2024-51757 exists.

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2024-51757 and fix it if it is affected.

What it is: CVE-2024-51757 is a critical code injection vulnerability in capricorn86 happy-dom, published on 6 Nov 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: It is not confirmed as exploited in the wild, but public exploit code for CVE-2024-51757 exists.

Affected packages and fixed versions:
- happy-dom (npm): affected all versions; fixed in 15.10.2
- happy-dom (npm): affected all versions; fixed in 15.10.2

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2024-51757/ (Markdown: https://insights.sbomify.com/CVE-2024-51757/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2024-51757
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2024-51757
- OSV: https://osv.dev/vulnerability/CVE-2024-51757

---
From sbomify Insights: https://insights.sbomify.com/CVE-2024-51757/
Summaries are generated and may contain mistakes; the official description above is the record.
