Skip to content

Update js-yaml to 4.3.1 - #15

Merged
tidy-dev merged 2 commits into
mainfrom
copilot/fix-js-yaml-vulnerability
Aug 10, 2026
Merged

Update js-yaml to 4.3.1#15
tidy-dev merged 2 commits into
mainfrom
copilot/fix-js-yaml-vulnerability

Conversation

Copilot AI commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

js-yaml@4.3.0 is affected by GHSA-5p4m-2wfm-xmqj, where !!omap resolution can consume quadratic CPU during YAML parsing. The patched version is 4.3.1.

  • Dependency update
    • Updated the npm override for js-yaml from 4.3.0 to 4.3.1.
    • Regenerated package-lock.json so the resolved package version is no longer vulnerable.
"overrides": {
  "js-yaml": "4.3.1"
}
  • Reachability Assessment
    • Affected path: js-yaml default-schema parsing via YAML load APIs such as yaml.load() when handling !!omap.
    • Repository search found no source imports of js-yaml and no calls to yaml.load, loadAll, safeLoad, DEFAULT_SCHEMA, or !!omap.
    • The vulnerable code path does not appear reachable from this action’s runtime code; this update primarily removes the vulnerable version from the dependency graph for scanner compliance.
    • Confidence: high.
Original prompt

This section details the Dependabot vulnerability alert you should resolve

<alert_title>JS-YAML: Quadratic CPU consumption in !!omap resolution (3.x and 4.x) — CVE-2026-59870 fix not backported</alert_title>
<alert_description># Quadratic CPU consumption in !!omap resolution (js-yaml 3.x and 4.x)

Summary

resolveYamlOmap() enforces key uniqueness for !!omap sequences with a linear
scan (objectKeys.indexOf(...)) inside the per-element loop, making resolution
O(n²) in the number of entries. A modestly sized YAML document therefore
consumes disproportionate CPU inside yaml.load(), giving a denial of service
against any consumer that parses untrusted YAML.

!!omap is registered in the default schema
(lib/schema/default.jsrequire('../type/omap')), so a plain
yaml.load(untrustedInput) with no options is affected — no custom schema or
non-default configuration is required.

This is the same weakness as CVE-2026-59870 / GHSA-724g-mxrg-4qvm, which was
fixed in the 5.x line in 5.2.1. That fix was never backported: both currently
maintained legacy lines still carry the original implementation.

Affected versions

Line Latest tested Status
3.x 3.15.0 Affected — objectKeys.indexOf(pairKey) at lib/type/omap.js:29
4.x 4.3.0 Affected — objectKeys.indexOf(pairKey) at lib/type/omap.js:30
5.x 5.2.2 Not affected — fixed in 5.2.1 (uses a Set)

Both figures are the newest release of each line at the time of writing, so
this is not a "you are on an old version" issue.

Details

lib/type/omap.js (js-yaml 4.3.0):

if (objectKeys.indexOf(pairKey) === -1) objectKeys.push(pairKey)
else return false

objectKeys grows by one element per entry, and Array.prototype.indexOf is a
linear scan, so resolving an n-entry !!omap performs roughly
1 + 2 + … + n comparisons — quadratic in n. The work happens synchronously
inside yaml.load(), blocking the event loop for its whole duration.

The 5.x line already solves exactly this by tracking seen keys in a Set
(src/tag/sequence/omap.ts):

if (carrier.seen.has(key)) return 'duplicate key in ordered map'
carrier.seen.add(key)

Proof of concept

// poc.js  —  node poc.js
const yaml = require('js-yaml');
const doc = n => '!!omap\n' + Array.from({length: n}, (_, i) => `- k${i}: ${i}`).join('\n') + '\n';

for (const n of [10000, 20000, 40000, 80000]) {
  const d = doc(n), t = Date.now();
  yaml.load(d);                      // default schema, no options
  console.log(`n=${n} bytes=${d.length} load=${Date.now() - t}ms`);
}

Measured (node v20.20.2, default heap, no flags)

js-yaml 4.3.0

n=10000  bytes=137787   load=54ms
n=20000  bytes=297787   load=169ms
n=40000  bytes=617787   load=646ms
n=80000  bytes=1257787  load=2607ms

js-yaml 3.15.0

n=10000  bytes=137787   load=53ms
n=20000  bytes=297787   load=166ms
n=40000  bytes=617787   load=641ms
n=80000  bytes=1257787  load=2567ms

Runtime grows by a factor of ~4 for each doubling of n, which is the
signature of O(n²) (linear growth would be ~2×).

Scaling further: a 2.48 MB document with 150,000 entries blocked
yaml.load() for 10.8 seconds.

Impact

Any service that parses attacker-influenced YAML with js-yaml 3.x or 4.x can be
stalled with a small input. Because the loop is synchronous, a single request
blocks the Node.js event loop and stalls every other request in the process —
so the amplification is per-process, not just per-request.

Suggested severity: consistent with CVE-2026-59870 (the same weakness in
5.x), i.e. Availability-only impact, network attack vector, no privileges or
user interaction required.

Suggested fix

Mirror the 5.x fix — replace the linear scan with a Set:

// lib/type/omap.js
const seen = new Set()
// ...
if (seen.has(pairKey)) return false
seen.add(pairKey)

This preserves the existing duplicate-key rejection semantics exactly while
making resolution O(n). A maxOmapLength-style cap would also work, but the
Set matches what 5.x already ships and requires no new option.

References

  • CVE-2026-59870 / GHSA-724g-mxrg-4qvm — same weakness in 5.0.0–5.2.0, fixed in 5.2.1
  • lib/type/omap.js (3.x, 4.x) — the affected resolver
  • lib/schema/default.js — registers !!omap in the default schema

Discovery

Found by an automated static-analysis and executed-proof-of-concept scanner run
against js-yaml 4.2.0, then manually verified against 3.15.0 and 4.3.0 by
executing the proof of concept above. All timings in this report were measured
on the current releases of each line, not on the version originally scanned.</alert_description>

high
GHSA-5p4m-2wfm-xmqj
js-yaml
npm
<vulnerable_versions>4.3.0</vulnerable_versions>
<patched_version>4.3.1</patched_version>
<manifest_path>package-lock.json</manifest...

  • Resolves github/copilot-release-notes alert #34

Co-authored-by: tidy-dev <75402236+tidy-dev@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix quadratic CPU consumption in js-yaml Update js-yaml to 4.3.1 Aug 10, 2026
Copilot AI requested a review from tidy-dev August 10, 2026 14:13
@tidy-dev
tidy-dev marked this pull request as ready for review August 10, 2026 14:24
@tidy-dev
tidy-dev requested a review from a team as a code owner August 10, 2026 14:24
Copilot AI balanced review requested due to automatic review settings August 10, 2026 14:24
@tidy-dev
tidy-dev enabled auto-merge August 10, 2026 14:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates js-yaml to the patched release addressing GHSA-5p4m-2wfm-xmqj.

Changes:

  • Pins the override to js-yaml 4.3.1.
  • Regenerates lockfile metadata for the patched package.
Show a summary per file
File Description
package.json Updates the dependency override.
package-lock.json Locks the patched version and integrity hash.

Review details

Tip

Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 1/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

@tidy-dev
tidy-dev merged commit eb17e6b into main Aug 10, 2026
6 checks passed
@tidy-dev
tidy-dev deleted the copilot/fix-js-yaml-vulnerability branch August 10, 2026 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants