refactor: replace execSync shell-string curl with spawnSync argv-array#415
refactor: replace execSync shell-string curl with spawnSync argv-array#415shaun0927 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
|
Thank you for the contribution, @shaun0927. As noted in SECURITY.md and our previous triage on related PRs, This specific change has been recorded and will be hand-ported into the internal maintainer branch ahead of the next release, with credit to you. Closing this PR accordingly; the underlying issue will be closed or referenced when the port lands. If you have more suggestions we welcome them as issues (not PRs) so we can triage without creating merge-path confusion. |
|
Hi @shaun0927 — this has shipped in v1.69.10 (release, npm). Ported:
Same attribution note as the other PRs: the public mirror is built from an internal maintainer branch. Credit is noted in the v1.69.10 release notes. Thanks again for the security-focused contribution. |
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.