refactor: replace execSync shell-string curl with spawnSync argv-array#415
Open
shaun0927 wants to merge 1 commit intoEvoMap:mainfrom
Open
refactor: replace execSync shell-string curl with spawnSync argv-array#415shaun0927 wants to merge 1 commit intoEvoMap:mainfrom
shaun0927 wants to merge 1 commit intoEvoMap:mainfrom
Conversation
EvoMap#410) Two places built curl command lines as shell strings and ran them through child_process.execSync, interpolating Bearer tokens into the command: src/gep/signals.js:260-274 curl with nodeSecret src/adapters/scripts/evolver-session-end.js:104-109 curl with apiKey Today the interpolated values are internally sourced, so exploit difficulty is high; the pattern is still an anti-pattern because any future contributor piping user-influenced data into nodeSecret or apiKey would turn a shell metacharacter into code execution. Both call sites move to child_process.spawnSync with an argv array and shell: false. Behaviour is preserved: - Still synchronous (addresses the comment in signals.js noting that the spin-wait loop cannot await async fetch). - Still uses curl, so no new dependency. - Same timeout, stdio, and windowsHide options. signals.js additionally reads spawnSync return status (res.status, res.error) to match the existing catch-all return [] behaviour; the prior code relied on execSync's throw-on-nonzero, so the explicit check is equivalent. evolver-session-end.js imports spawnSync alongside the existing execSync (the other two execSync call sites in this file use git shell pipelines with 2>/dev/null fallbacks, which are not credential call sites and stay as-is). Testing: node test/signals.test.js # fail 0 node -c src/adapters/scripts/evolver-session-end.js # syntax OK Closes EvoMap#410
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.
Problem
Two places build
curlcommand lines as shell strings and run themthrough
child_process.execSync, interpolating bearer tokens intothe command:
Today the interpolated values are internally sourced, so the
exploit surface is bounded. The pattern is still worth addressing:
any future change that pipes user-influenced data into
nodeSecretor
apiKeyturns a shell metacharacter into code execution. See#410 for the full rationale.
Fix
Both call sites move to
child_process.spawnSyncwith an argv arrayand
shell: false. Behaviour is preserved:signals.jsis retained,because the spin-wait loop still cannot await async
fetch.curl, so no new dependency.timeout,stdio, andwindowsHideoptions.signals.jsadditionally reads thespawnSyncreturn status(
res.status,res.error) to match the existing catch-allreturn []on failure. The prior code relied onexecSync'sthrow-on-nonzero; the explicit check is equivalent.
evolver-session-end.jsimportsspawnSyncalongside the existingexecSync. The other twoexecSynccall sites in that file usegit shell pipelines with
2>/dev/nullfallbacks and do notinterpolate credentials, so they stay as-is.
Testing
Unit tests covering signals pass; the credential-carrying code
paths cannot be exercised in CI without a live hub, but the
behaviour change is purely at the child-process invocation layer
(shell-string → argv array). curl still does the wire work with the
same flags, so the HTTP request emitted on the wire is identical.
Scope
Two files, +27/−18 lines. Argv-array conversion only. No new
dependency. No logic change outside the subprocess call form.
Not in this PR
curl's argv, so it is visible topson Unix. Moving it to stdin via--header-file @-wouldconflict with
-d -for the body; a fix requires choosingbetween the two, which is a behaviour tradeoff I did not want to
bundle with the pure argv-ification. Happy to follow up.
Closes #410.