Skip to content

Fix all open CodeQL code scanning alerts - #11

Merged
rfoerthe merged 1 commit into
masterfrom
claude/code-scanning-issues-61627b
Aug 29, 2026
Merged

rfoerthe merged 1 commit into
masterfrom
claude/code-scanning-issues-61627b

Conversation

@rfoerthe

Copy link
Copy Markdown
Owner

Checked all 7 open CodeQL alerts. All are valid — none were false positives. Each is fixed.

The premise behind the four security alerts: index.mjs is the package main entry and exports the Support class (publicly typed in index.d.ts). cli.mjs validates the port, but that validation is bypassed entirely by any library consumer — which is exactly what CodeQL's "from library input" rules flag.

Shell command injection — alerts #5, #6 (index.mjs:120)

Most serious. killProcess interpolated pid straight into execAsync shell strings. Now uses execFile with an argument array so no shell interprets them, plus a positive-integer check.

Verified: killProcess("1; touch /tmp/canary", ...) no longer executes anything (canary never created), and real processes are still terminated correctly.

The pid check also closes a hazard nobody filed: killProcess(-1, _, true) would have run kill -9 -1, signalling every process owned by the user.

Regex injection — alerts #3, #4 (index.mjs:59, index.mjs:81)

port was interpolated into new RegExp(...). Added an escapeRegExp helper.

Not only theoretical ReDoS: against a live listener I confirmed that passing .* previously matched an arbitrary listening process, so the wrong process could be selected and killed. Now inert; legitimate lookups still resolve to the correct PID.

Identity replacement — alert #7 (scripts/create-local-bin.mjs:27)

replace(/\\/g, '\\') replaced a backslash with itself — dead code, no security impact. Neither batch nor PowerShell treats \ as an escape, so the escaping is dropped in both templates.

Proved against real Windows path values that the .ps1 output is byte-identical (confirming the call did nothing), while the .cmd output loses the stray doubled separators produced by the other replace.

Missing workflow permissions — alerts #1, #2

Added explicit read-only GITHUB_TOKEN scope to the build job and top-level in test.yml. publish-gpr and the npmjs workflow already had explicit blocks.

Notes for the reviewer

  • No API changes. Signatures are unchanged; index.d.ts needed no update. The only new observable behavior is killProcess throwing Invalid process id: <x> for non-positive-integer input.
  • Existing tests pass unchanged (5/5). They stub killProcess, so they don't exercise the new path — I verified injection blocking, real process termination, and regex behavior manually against live processes and a real listener.
  • While editing create-local-bin.mjs I initially stripped the CRLF endings in the .cmd template and redid the edit byte-exactly. Worth knowing: those CRLFs are inert regardless — JS normalizes CRLF to LF inside template literals, so the generated killp.cmd has always been LF-terminated.
  • Pre-existing bug, deliberately not touched: getProcessId's pattern TCP.*:.*${port}.*(LISTEN) matches loosely, so port 80 also matches 8080. The Windows path carries a comment showing this was fixed there but not on the Unix side. Fixing it changes matching semantics beyond the scope of these alerts — happy to do it separately.

🤖 Generated with Claude Code

index.mjs is the package main entry and exports the Support class (also
declared in index.d.ts), so cli.mjs's argument validation is bypassed
entirely by any library consumer. That is what made the four security
alerts real rather than theoretical.

Shell command injection (alerts #5, #6, index.mjs:120)
killProcess interpolated the pid directly into a shell command string.
Pass arguments as an array via execFile so no shell interprets them, and
reject anything that is not a positive integer. The pid check also closes
an unreported hazard: killProcess(-1, _, true) would have run
`kill -9 -1`, signalling every process owned by the user.

Regular expression injection (alerts #3, #4, index.mjs:59, index.mjs:81)
The port was interpolated into new RegExp(). Escape it first. This was
not only a ReDoS concern: passing `.*` previously matched an arbitrary
listening process, so the wrong process could be selected and killed.

Identity replacement (alert #7, scripts/create-local-bin.mjs:27)
replace(/\\/g, '\\') replaced a backslash with itself and did nothing.
Neither batch nor PowerShell treats a backslash as an escape character,
so drop the escaping in both templates. On Windows path values the .ps1
output is byte-identical, confirming the call was dead code, while the
.cmd output loses the stray doubled separators produced by the other
replace.

Missing workflow permissions (alerts #1, #2)
Add an explicit read-only GITHUB_TOKEN scope to the build job and to
test.yml. The publish-gpr and npmjs workflows already had one.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@rfoerthe
rfoerthe merged commit e8b7f91 into master Aug 29, 2026
12 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