Repository navigation
Fix all open CodeQL code scanning alerts - #11
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checked all 7 open CodeQL alerts. All are valid — none were false positives. Each is fixed.
The premise behind the four security alerts:
index.mjsis the packagemainentry and exports theSupportclass (publicly typed inindex.d.ts).cli.mjsvalidates 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.
killProcessinterpolatedpidstraight intoexecAsyncshell strings. Now usesexecFilewith 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 runkill -9 -1, signalling every process owned by the user.Regex injection — alerts #3, #4 (
index.mjs:59,index.mjs:81)portwas interpolated intonew RegExp(...). Added anescapeRegExphelper.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
.ps1output is byte-identical (confirming the call did nothing), while the.cmdoutput loses the stray doubled separators produced by the other replace.Missing workflow permissions — alerts #1, #2
Added explicit read-only
GITHUB_TOKENscope to thebuildjob and top-level intest.yml.publish-gprand the npmjs workflow already had explicit blocks.Notes for the reviewer
index.d.tsneeded no update. The only new observable behavior iskillProcessthrowingInvalid process id: <x>for non-positive-integer input.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.create-local-bin.mjsI initially stripped the CRLF endings in the.cmdtemplate and redid the edit byte-exactly. Worth knowing: those CRLFs are inert regardless — JS normalizes CRLF to LF inside template literals, so the generatedkillp.cmdhas always been LF-terminated.getProcessId's patternTCP.*:.*${port}.*(LISTEN)matches loosely, so port80also matches8080. 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