fix: prevent command injection in setup verify PID check
Validate PID as positive integer and use process.kill() instead of shell interpolation via execSync, eliminating injection vector. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -68,9 +68,10 @@ export async function run(_args: string[]): Promise<void> {
|
|||||||
const pidFile = path.join(projectRoot, 'nanoclaw.pid');
|
const pidFile = path.join(projectRoot, 'nanoclaw.pid');
|
||||||
if (fs.existsSync(pidFile)) {
|
if (fs.existsSync(pidFile)) {
|
||||||
try {
|
try {
|
||||||
const pid = fs.readFileSync(pidFile, 'utf-8').trim();
|
const raw = fs.readFileSync(pidFile, 'utf-8').trim();
|
||||||
if (pid) {
|
const pid = Number(raw);
|
||||||
execSync(`kill -0 ${pid}`, { stdio: 'ignore' });
|
if (raw && Number.isInteger(pid) && pid > 0) {
|
||||||
|
process.kill(pid, 0);
|
||||||
service = 'running';
|
service = 'running';
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
Reference in New Issue
Block a user