mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-24 06:06:02 +09:00
fix(plugins): make npm install/uninstall/upgrade work on Windows (#2366)
`PluginManager` spawned `npm` via `execFile` without a shell. On Windows
that hits two separate Node failure modes:
1. `npm` is a bash shim (no `.exe`), so `spawn('npm', ...)` resolves to
a file Node cannot launch and fails with `spawn npm ENOENT`.
2. Falling back to `npm.cmd` runs into CVE-2024-27980 (Node
18.20.2 / 20.12.2): the runtime refuses to spawn `.cmd`/`.bat`
files directly and throws `spawn EINVAL`.
Route all three call sites (install / uninstall / upgrade) through a
single `runNpm` helper that invokes `cmd.exe /d /s /c npm <args>` on
Windows. `cmd.exe` is a real `.exe`, so neither failure mode applies,
and Node's safe array-form argument escaping is preserved.
Verified locally on Windows 11 / Node 20:
ruflo plugins install -n @claude-flow/security
-> Installed @claude-flow/security@3.0.0-alpha.10
Co-authored-by: RuFlo <ruv@ruv.net>
This commit is contained in:
1 parent
7c6362633e
commit
a21f6808fb
1 file changed
+18
-12
@@ -11,6 +11,21 @@ import { promisify } from 'util';
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
|
||||
// On Windows, `npm` is a shell script (no `.exe`) and `npm.cmd` is a batch
|
||||
// wrapper. Since Node 18.20.2 / 20.12.2 (CVE-2024-27980) the runtime refuses
|
||||
// to spawn `.cmd`/`.bat` files directly and throws `spawn EINVAL` — the only
|
||||
// supported invocation is via a real `.exe` shell. We wrap every npm call
|
||||
// through `cmd.exe /d /s /c npm <args>`, which keeps Node's safe array-form
|
||||
// argument escaping intact and avoids both ENOENT and EINVAL.
|
||||
const isWindows = process.platform === 'win32';
|
||||
|
||||
function runNpm(args: string[], timeoutMs: number): Promise<{ stdout: string; stderr: string }> {
|
||||
if (isWindows) {
|
||||
return execFileAsync('cmd.exe', ['/d', '/s', '/c', 'npm', ...args], { timeout: timeoutMs });
|
||||
}
|
||||
return execFileAsync('npm', args, { timeout: timeoutMs });
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate npm package name to prevent shell injection (S-3)
|
||||
*/
|
||||
@@ -160,10 +175,7 @@ export class PluginManager {
|
||||
// Use npm to install (array form prevents shell injection)
|
||||
console.log(`[PluginManager] Installing ${versionSpec}...`);
|
||||
|
||||
await execFileAsync(
|
||||
'npm', ['install', '--prefix', this.config.pluginsDir, versionSpec],
|
||||
{ timeout: 120000 }
|
||||
);
|
||||
await runNpm(['install', '--prefix', this.config.pluginsDir, versionSpec], 120000);
|
||||
|
||||
// Get installed version
|
||||
const packageJsonPath = path.join(installDir, packageName, 'package.json');
|
||||
@@ -291,10 +303,7 @@ export class PluginManager {
|
||||
// For npm-installed plugins, remove from node_modules
|
||||
if (plugin.source === 'npm') {
|
||||
validatePackageName(packageName);
|
||||
await execFileAsync(
|
||||
'npm', ['uninstall', '--prefix', this.config.pluginsDir, packageName],
|
||||
{ timeout: 60000 }
|
||||
);
|
||||
await runNpm(['uninstall', '--prefix', this.config.pluginsDir, packageName], 60000);
|
||||
}
|
||||
|
||||
// Remove from manifest
|
||||
@@ -451,10 +460,7 @@ export class PluginManager {
|
||||
validatePackageName(versionSpec);
|
||||
|
||||
// Reinstall with new version (array form prevents shell injection)
|
||||
await execFileAsync(
|
||||
'npm', ['install', '--prefix', this.config.pluginsDir, versionSpec],
|
||||
{ timeout: 120000 }
|
||||
);
|
||||
await runNpm(['install', '--prefix', this.config.pluginsDir, versionSpec], 120000);
|
||||
|
||||
// Update manifest
|
||||
const installDir = path.join(this.config.pluginsDir, 'node_modules');
|
||||
|
||||
Reference in new issue
Block a user