fix(shared): harden ripgrep-cli, zip-extractor, binary-downloader subprocess paths

Same Web-Response-on-Node hazard existed in ripgrep auto-download flow,
zip extraction helpers, and binary downloader streams. Switch to the new
Node-safe reader and ensure no spawn path escapes as unhandledRejection.

Related to #3919.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-05-22 20:40:24 +09:00
parent d17b2127f2
commit aded57ff1f
8 changed files with 42 additions and 20 deletions
+6 -3
View File
@@ -4,6 +4,7 @@ import { spawn } from "./bun-spawn-shim";
import { bunWrite } from "./bun-file-shim";
import { validateArchiveEntries, type ArchiveEntry } from "./archive-entry-validator";
import { extractZip } from "./zip-extractor";
import { readProcessStream } from "./process-stream-reader";
function isTarTraversalErrorOutput(output: string): boolean {
return /path contains '\.\.'|member name contains '\.\.'|removing leading [`'\"]?\.\.\//i.test(output)
@@ -47,7 +48,8 @@ export async function extractTarGz(
const exitCode = await proc.exited;
if (exitCode !== 0) {
const stderr = await new Response(proc.stderr).text();
// #3919: Avoid Response(stream).text() in Windows Desktop utility processes.
const stderr = await readProcessStream(proc.stderr);
if (isTarTraversalErrorOutput(stderr)) {
throw new Error(`Unsafe archive entry: path contains path traversal (${archivePath})`)
@@ -107,8 +109,9 @@ async function listTarEntries(archivePath: string, cwd?: string): Promise<Archiv
const [exitCode, stdout, stderr] = await Promise.all([
proc.exited,
new Response(proc.stdout).text(),
new Response(proc.stderr).text(),
// #3919: Use Buffer-concat stream reads for Node utility-process compatibility.
readProcessStream(proc.stdout),
readProcessStream(proc.stderr),
])
if (isTarTraversalErrorOutput(stderr)) {
+11 -4
View File
@@ -20,12 +20,19 @@ let autoInstallAttempted = false
function findExecutable(name: string): string | null {
const isWindows = process.platform === "win32"
const cmd = isWindows ? "where" : "which"
const cmd = isWindows ? "where.exe" : "which"
try {
const result = spawnSync(cmd, [name], { encoding: "utf-8", timeout: 5000 })
if (result.status === 0 && result.stdout.trim()) {
return result.stdout.trim().split("\n")[0]
// #3919: Keep Windows executable probes hidden and shell-free in Desktop utility processes.
const result = spawnSync(cmd, [name], {
encoding: "utf-8",
timeout: 5000,
windowsHide: isWindows,
shell: false,
})
const stdout = result.stdout
if (result.status === 0 && stdout.trim()) {
return stdout.trim().split("\n")[0]
}
} catch {
return null
@@ -1,6 +1,7 @@
import { spawn } from "../bun-spawn-shim"
import type { ArchiveEntry } from "../archive-entry-validator"
import { readProcessStream } from "../process-stream-reader"
export type PowerShellZipExtractor = "pwsh" | "powershell"
@@ -82,8 +83,9 @@ export async function listZipEntriesWithPowerShell(
const [exitCode, stdout, stderr] = await Promise.all([
proc.exited,
new Response(proc.stdout).text(),
new Response(proc.stderr).text(),
// #3919: Use Buffer-concat stream reads for Node utility-process compatibility.
readProcessStream(proc.stdout),
readProcessStream(proc.stderr),
])
if (exitCode !== 0) {
@@ -1,6 +1,7 @@
import { spawn, spawnSync } from "../bun-spawn-shim"
import type { ArchiveEntry } from "../archive-entry-validator"
import { readProcessStream } from "../process-stream-reader"
export function isPythonZipListingAvailable(): boolean {
const proc = spawnSync(["python3", "--version"], {
@@ -43,8 +44,9 @@ export async function listZipEntriesWithPython(
const [exitCode, stdout, stderr] = await Promise.all([
proc.exited,
new Response(proc.stdout).text(),
new Response(proc.stderr).text(),
// #3919: Use Buffer-concat stream reads for Node utility-process compatibility.
readProcessStream(proc.stdout),
readProcessStream(proc.stderr),
])
if (exitCode !== 0) {
@@ -1,4 +1,5 @@
import { spawn } from "../bun-spawn-shim"
import { readProcessStream } from "../process-stream-reader"
export async function readZipSymlinkTarget(
archivePath: string,
@@ -11,8 +12,9 @@ export async function readZipSymlinkTarget(
const [exitCode, stdout, stderr] = await Promise.all([
proc.exited,
new Response(proc.stdout).text(),
new Response(proc.stderr).text(),
// #3919: Use Buffer-concat stream reads for Node utility-process compatibility.
readProcessStream(proc.stdout),
readProcessStream(proc.stderr),
])
if (exitCode !== 0) {
@@ -2,6 +2,7 @@ import { spawn } from "../bun-spawn-shim"
import type { ArchiveEntry } from "../archive-entry-validator"
import { log } from "../logger"
import { readProcessStream } from "../process-stream-reader"
@@ -81,8 +82,9 @@ export async function listZipEntriesWithTar(
const [exitCode, stdout, stderr] = await Promise.all([
proc.exited,
new Response(proc.stdout).text(),
new Response(proc.stderr).text(),
// #3919: Use Buffer-concat stream reads for Node utility-process compatibility.
readProcessStream(proc.stdout),
readProcessStream(proc.stderr),
])
if (exitCode !== 0) {
@@ -1,6 +1,7 @@
import { spawn, spawnSync } from "../bun-spawn-shim"
import type { ArchiveEntry } from "../archive-entry-validator"
import { readProcessStream } from "../process-stream-reader"
import { readZipSymlinkTarget } from "./read-zip-symlink-target"
export function parseZipInfoListedEntry(line: string): ArchiveEntry | null {
@@ -45,8 +46,9 @@ export async function listZipEntriesWithZipInfo(
const [exitCode, stdout, stderr] = await Promise.all([
proc.exited,
new Response(proc.stdout).text(),
new Response(proc.stderr).text(),
// #3919: Use Buffer-concat stream reads for Node utility-process compatibility.
readProcessStream(proc.stdout),
readProcessStream(proc.stderr),
])
if (exitCode !== 0) {
+5 -3
View File
@@ -1,7 +1,8 @@
import { spawn, spawnSync } from "./bun-spawn-shim"
import { spawn, spawnSync, type SpawnedProcess } from "./bun-spawn-shim"
import { release } from "os"
import { validateArchiveEntries } from "./archive-entry-validator"
import { readProcessStream } from "./process-stream-reader"
import {
isPythonZipListingAvailable,
isZipInfoZipListingAvailable,
@@ -53,7 +54,7 @@ export async function extractZip(archivePath: string, destDir: string): Promise<
const entries = await listZipEntries(archivePath)
validateArchiveEntries(entries, destDir)
let proc
let proc: SpawnedProcess
if (process.platform === "win32") {
const extractor = getWindowsZipExtractor()
@@ -89,7 +90,8 @@ export async function extractZip(archivePath: string, destDir: string): Promise<
const exitCode = await proc.exited
if (exitCode !== 0) {
const stderr = await new Response(proc.stderr).text()
// #3919: Avoid Response(stream).text() in Windows Desktop utility processes.
const stderr = await readProcessStream(proc.stderr)
throw new Error(`zip extraction failed (exit ${exitCode}): ${stderr}`)
}
}