# GHSA-8j8c-7jfh-h6hx: Code Injection in js-yaml

> Attackers can execute arbitrary code via malicious YAML files processed by the vulnerable load function in the js-yaml library.

- **Severity:** Not scored
- **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:** 4 Jun 2019

## What is GHSA-8j8c-7jfh-h6hx?

GHSA-8j8c-7jfh-h6hx is a code injection vulnerability in js-yaml, published on 4 Jun 2019. 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

Versions of `js-yaml` prior to 3.13.1 are vulnerable to Code Injection. The `load()` function may execute arbitrary code injected through a malicious YAML file. Objects that have `toString` as key, JavaScript code as value and are used as explicit mapping keys allow attackers to execute the supplied code through the `load()` function. The `safeLoad()` function is unaffected.

An example payload is 
`{ toString: !<tag:yaml.org,2002:js/function> 'function (){return Date.now()}' } : 1` 
which returns the object 
{
  "1553107949161": 1
}

## Recommendation

Upgrade to version 3.13.1.

## Which versions are affected by GHSA-8j8c-7jfh-h6hx?

2 open source packages ship an affected version, including js-yaml.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `js-yaml` | npm | All versions | 3.13.1 |
| `js-yaml` | npm | All versions | 3.13.1 |

## How do I fix GHSA-8j8c-7jfh-h6hx?

Upgrade js-yaml to 3.13.1 or later.

## Is GHSA-8j8c-7jfh-h6hx being exploited?

There is no known exploitation of GHSA-8j8c-7jfh-h6hx in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-8j8c-7jfh-h6hx and fix it if it is affected.

What it is: GHSA-8j8c-7jfh-h6hx is a code injection vulnerability in js-yaml, published on 4 Jun 2019. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.
Exploitation: There is no known exploitation of GHSA-8j8c-7jfh-h6hx in the wild and no public exploit code.

Affected packages and fixed versions:
- js-yaml (npm): affected all versions; fixed in 3.13.1
- js-yaml (npm): affected all versions; fixed in 3.13.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/GHSA-8j8c-7jfh-h6hx/ (Markdown: https://insights.sbomify.com/GHSA-8j8c-7jfh-h6hx/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-8j8c-7jfh-h6hx

---
From sbomify Insights: https://insights.sbomify.com/GHSA-8j8c-7jfh-h6hx/
Summaries are generated and may contain mistakes; the official description above is the record.
