Skip to content

Hardening: use execFileSync argv form in scanner + add CI - #1

Merged
davidcjw merged 1 commit into
mainfrom
security/audit-hardening
Jul 2, 2026
Merged

davidcjw merged 1 commit into
mainfrom
security/audit-hardening

Conversation

@davidcjw

@davidcjw davidcjw commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Vulnerability (LOW — defense-in-depth)

scan.mjs used string-mode execSync with shell interpolation for several system-inspection commands, most notably:

execSync(`lsof -a -d cwd -p ${pids} 2>/dev/null`, ...)

pids is built from Number()-parsed listening PIDs, so it's digits-only and not currently exploitable. But string-mode execSync on a machine scanner is a smell: it invokes a shell and would be injection-prone if any interpolated input ever became attacker-influenced.

Fix

  • Switched to execFileSync(cmd, [args...]) argv form (no shell), importing execFileSync from node:child_process.
  • The lsof ... -p ${pids} call now passes pids as a discrete argv argument (['-a','-d','cwd','-p', pids]).
  • Converted the other constant string calls (git remote get-url origin, launchctl list, ps -axww -o pid=,command=, lsof -nP -iTCP -sTCP:LISTEN) to argv form too for consistency.
  • Shell 2>/dev/null redirection is replaced by stdio: ['ignore','pipe','ignore'] to suppress stderr identically. Output parsing is unchanged.

CI

Added .github/workflows/ci.yml (the repo had no CI): Node build + test, plus npm audit (high) and a gitleaks secret scan.

Verification

  • node --check scan.mjs passes.
  • npm run build passes.
  • npm test — 18/18 pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_01BAMbBXXNhnUcztWtqTHzmu

Convert the string-mode execSync calls in scan.mjs to execFileSync argv
form to eliminate shell interpolation on a machine scanner (defense in
depth). The `lsof ... -p ${pids}` call previously interpolated a
comma-joined pid list into a shell string; pids is now passed as a
discrete argv argument. The constant git/launchctl/ps/lsof calls are
converted for consistency. Shell `2>/dev/null` redirection is replaced
by stdio: ['ignore','pipe','ignore'] to suppress stderr identically.
Output parsing is unchanged.

Also add a Node CI workflow (build + test + npm audit + gitleaks).

Claude-Session: https://claude.ai/code/session_01BAMbBXXNhnUcztWtqTHzmu
@davidcjw
davidcjw merged commit 7758da4 into main Jul 2, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant