fix(websearch): avoid shell for legacy CLI fallbacks (#1267)

* fix(websearch): avoid shell for legacy CLI fallbacks

* style: apply prettier formatting
This commit is contained in:
Kai (Tam Nhu) Tran
2026-05-16 13:58:52 -04:00
committed by GitHub
parent 14cbe8fb67
commit 2115742caf
2 changed files with 21 additions and 3 deletions
+12 -3
View File
@@ -874,7 +874,10 @@ function runGeminiCommand(args, timeoutMs) {
timeout: timeoutMs,
maxBuffer: 1024 * 1024 * 2,
stdio: ['pipe', 'pipe', 'pipe'],
shell: isWindows,
// Never route query-derived prompts through a shell. Node concatenates
// arguments for shell-backed Windows spawns, which lets shell metacharacters
// in WebSearch queries escape the intended CLI invocation.
shell: false,
});
if (result.error) {
@@ -929,7 +932,10 @@ function tryOpenCodeSearch(query, timeoutSec = DEFAULT_TIMEOUT_SEC) {
timeout: timeoutSec * 1000,
maxBuffer: 1024 * 1024 * 2,
stdio: ['pipe', 'pipe', 'pipe'],
shell: isWindows,
// Never route query-derived prompts through a shell. Node concatenates
// arguments for shell-backed Windows spawns, which lets shell metacharacters
// in WebSearch queries escape the intended CLI invocation.
shell: false,
}
);
@@ -965,7 +971,10 @@ function tryGrokSearch(query, timeoutSec = DEFAULT_TIMEOUT_SEC) {
timeout: timeoutSec * 1000,
maxBuffer: 1024 * 1024 * 2,
stdio: ['pipe', 'pipe', 'pipe'],
shell: isWindows,
// Never route query-derived prompts through a shell. Node concatenates
// arguments for shell-backed Windows spawns, which lets shell metacharacters
// in WebSearch queries escape the intended CLI invocation.
shell: false,
});
if (result.error) {
@@ -131,6 +131,15 @@ function runHookWithMockedFetch(mode: 'success' | 'empty' | 'non-result' | 'fail
}
}
describe('websearch-transformer legacy CLI safety', () => {
it('does not enable shell execution for query-derived legacy CLI prompts', () => {
const source = readFileSync(hookPath, 'utf8');
expect(source).not.toContain('shell: isWindows');
expect(source.match(/shell: false/g) || []).toHaveLength(3);
});
});
describe('websearch-transformer hook helpers', () => {
it('parses Retry-After seconds and HTTP dates', () => {
expect(hook.parseRetryAfterSeconds('2')).toBe(2);