mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-23 21:59:14 +09:00
executeUpdate and rollbackUpdate built `npm install ${pkg}@${version}
--save-exact` as a shell string and ran it via execSync. Both inputs
came from untrusted sources:
update.package + update.latestVersion — parsed from `npm view <pkg>`
output (a network response).
lastUpdate.package + lastUpdate.fromVersion — read from
~/.claude-flow/update-history.json (writable by anyone with FS
access to the user's home).
A tampered package name like 'evil; touch /tmp/x' would have been
interpreted by /bin/sh.
Two-layer fix:
isSafePackageSpec(pkg, version) — pre-flight regex gate.
SAFE_PKG_RE allows scoped/unscoped npm names but forbids the
unscoped first char from being '-' (defangs CLI-flag confusion in
the eventual `npm install <spec>`).
SAFE_VERSION_RE allows semver/dist-tag/range chars only —
no shell metas. Length capped 64.
Spec rejects empties.
execFileSync('npm', argv, { shell: false }) replaces the shell-string
execSync. Even if the gate were widened later, argv elements aren't
interpreted by /bin/sh — backticks, $(...), ; stay literal.
Tests:
__tests__/update-executor-injection.test.ts — 28 cases
happy path: 9 real-world specs (claude-flow@3.6.10, @claude-flow/cli,
latest, ^1.0.0, ~2.3.4, 1.x, prerelease tags, build metadata)
package-name injection: 8 payloads (;, `, $, |, &, >, \n, \\)
version injection: 5 payloads
edge cases: empty pkg/version, leading-dash/dot pkg, oversized,
malformed scoped names
Verified: tsc --noEmit clean; full audit-fix surface 74/74 passing.