# CVE-2025-59840: Vega Cross-Site Scripting (XSS) via expressions abusing toString calls in environments using the VEGA_DEBUG global variable

> Attackers can execute arbitrary JavaScript in Vega applications if the library and View instances are attached to the global window object.

- **Severity:** High 8.1 (`CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:N`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** A user has to click or open something
- **Fix available:** Yes
- **Published:** 13 Nov 2025
- **Updated:** 14 Nov 2025
- **Also known as:** DEBIAN-CVE-2025-59840, GHSA-7f2v-3qq3-vvjf, UBUNTU-CVE-2025-59840

## What is CVE-2025-59840?

CVE-2025-59840 is a high-severity cross-site scripting vulnerability in vega, published on 13 Nov 2025. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.

### Official description

Vega is a visualization grammar, a declarative format for creating, saving, and sharing interactive visualization designs. In Vega prior to version 6.2.0, applications meeting 2 conditions are at risk of arbitrary JavaScript code execution, even if "safe mode" expressionInterpreter is used. They are vulnerable if they use `vega` in an application that attaches `vega` library and a `vega.View` instance similar to the Vega Editor to the global `window` and if they allow user-defined Vega `JSON` definitions (vs JSON that was is only provided through source code). Patches are available in the following Vega applications. If using the latest Vega line (6.x), upgrade to `vega` `6.2.0` / `vega-expression` `6.1.0` / `vega-interpreter`  `2.2.1` (if using AST evaluator mode). If using Vega in a non-ESM environment, upgrade to `vega-expression` `5.2.1` / `1.2.1` (if using AST evaluator mode). Some workarounds are available. Do not attach `vega` View instances to global variables, and do not attach `vega` to the global window. These practices of attaching the vega library and View instances may be convenient for debugging, but should not be used in production or in any situation where vega/vega-lite definitions could be provided by untrusted parties.

Weakness: CWE-79 (Improper Neutralization of Input During Web Page Generation)

## Which versions are affected by CVE-2025-59840?

10 open source packages ship an affected version, including vega-expression, vega and vega-interpreter.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `vega-expression` | npm | All versions | 5.2.1 |
| `vega-expression` | npm | All versions | 5.2.1 |
| `vega-expression` | npm | From 6.0.0 | 6.1.0 |
| `vega-expression` | npm | From 6.0.0 | 6.1.0 |
| `vega` | npm | All versions | 6.2.0 |
| `vega` | npm | All versions | 6.2.0 |
| `vega-interpreter` | npm | All versions | 1.2.1 |
| `vega-interpreter` | npm | All versions | 1.2.1 |
| `vega-interpreter` | npm | From 2.0.0 | 2.2.1 |
| `vega-interpreter` | npm | From 2.0.0 | 2.2.1 |

## How do I fix CVE-2025-59840?

Upgrade vega-expression to a fixed version for your release line: 5.2.1 or 6.1.0.

## Is CVE-2025-59840 being exploited?

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

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2025-59840 and fix it if it is affected.

What it is: CVE-2025-59840 is a high-severity cross-site scripting vulnerability in vega, published on 13 Nov 2025. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.
Exploitation: It is not confirmed as exploited in the wild, but public exploit code for CVE-2025-59840 exists.

Affected packages and fixed versions:
- vega-expression (npm): affected all versions; fixed in 5.2.1
- vega-expression (npm): affected all versions; fixed in 5.2.1
- vega-expression (npm): affected from 6.0.0; fixed in 6.1.0
- vega-expression (npm): affected from 6.0.0; fixed in 6.1.0
- vega (npm): affected all versions; fixed in 6.2.0
- vega (npm): affected all versions; fixed in 6.2.0
- vega-interpreter (npm): affected all versions; fixed in 1.2.1
- vega-interpreter (npm): affected all versions; fixed in 1.2.1
- vega-interpreter (npm): affected from 2.0.0; fixed in 2.2.1
- vega-interpreter (npm): affected from 2.0.0; fixed in 2.2.1

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-2025-59840/ (Markdown: https://insights.sbomify.com/CVE-2025-59840/index.md)
```

## Sources

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

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