mirror of
https://github.com/davidkaya/aryx.git
synced 2026-08-06 19:58:43 +02:00
fix: sanitize sidecar launch environment
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
const blockedEnvironmentKeys = new Set(['ELECTRON_RUN_AS_NODE', 'NODE_OPTIONS']);
|
||||||
|
|
||||||
|
export function createSidecarEnvironment(baseEnvironment: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
|
||||||
|
const sanitizedEnvironment: NodeJS.ProcessEnv = {};
|
||||||
|
|
||||||
|
for (const [name, value] of Object.entries(baseEnvironment)) {
|
||||||
|
const normalizedName = name.toUpperCase();
|
||||||
|
|
||||||
|
if (normalizedName.startsWith('COPILOT_') || blockedEnvironmentKeys.has(normalizedName)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
sanitizedEnvironment[name] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sanitizedEnvironment;
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ import type {
|
|||||||
RunTurnCommand,
|
RunTurnCommand,
|
||||||
} from '@shared/contracts/sidecar';
|
} from '@shared/contracts/sidecar';
|
||||||
import type { ChatMessageRecord } from '@shared/domain/session';
|
import type { ChatMessageRecord } from '@shared/domain/session';
|
||||||
|
import { createSidecarEnvironment } from '@main/sidecar/sidecarEnvironment';
|
||||||
import { resolveSidecarProcess } from '@main/sidecar/sidecarRuntime';
|
import { resolveSidecarProcess } from '@main/sidecar/sidecarRuntime';
|
||||||
|
|
||||||
type PendingCommand =
|
type PendingCommand =
|
||||||
@@ -78,6 +79,7 @@ export class SidecarClient {
|
|||||||
});
|
});
|
||||||
this.process = spawn(sidecar.command, sidecar.args, {
|
this.process = spawn(sidecar.command, sidecar.args, {
|
||||||
cwd: sidecar.cwd,
|
cwd: sidecar.cwd,
|
||||||
|
env: createSidecarEnvironment(process.env),
|
||||||
stdio: 'pipe',
|
stdio: 'pipe',
|
||||||
windowsHide: true,
|
windowsHide: true,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import { describe, expect, test } from 'bun:test';
|
||||||
|
|
||||||
|
import { createSidecarEnvironment } from '@main/sidecar/sidecarEnvironment';
|
||||||
|
|
||||||
|
describe('createSidecarEnvironment', () => {
|
||||||
|
test('removes inherited Copilot loader variables before spawning the sidecar', () => {
|
||||||
|
expect(
|
||||||
|
createSidecarEnvironment({
|
||||||
|
PATH: 'C:\\tools',
|
||||||
|
COPILOT_CLI: '1',
|
||||||
|
COPILOT_LOADER_PID: '1234',
|
||||||
|
copilot_run_app: '1',
|
||||||
|
NODE_OPTIONS: '--no-warnings',
|
||||||
|
electron_run_as_node: '1',
|
||||||
|
}),
|
||||||
|
).toEqual({
|
||||||
|
PATH: 'C:\\tools',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('preserves unrelated environment variables', () => {
|
||||||
|
expect(
|
||||||
|
createSidecarEnvironment({
|
||||||
|
PATH: 'C:\\tools',
|
||||||
|
HOME: 'C:\\Users\\mail',
|
||||||
|
FORCE_COLOR: '1',
|
||||||
|
}),
|
||||||
|
).toEqual({
|
||||||
|
PATH: 'C:\\tools',
|
||||||
|
HOME: 'C:\\Users\\mail',
|
||||||
|
FORCE_COLOR: '1',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user