Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/utils/__tests__/simulator-steps-pid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,24 @@ describe.sequential('launchSimulatorAppWithLogging PID resolution', () => {
expect(result.processId).toBe(42567);
});

it('rejects bundle identifiers that would escape the OSLog predicate', async () => {
const spawner = vi.fn(createMockSpawner());
const executor = vi.fn(createMockExecutor(42567));

const result = await launchSimulatorAppWithLogging(
'test-sim-uuid',
'com.evil" OR subsystem != "x',
executor,
undefined,
{ spawner },
);

expect(result.success).toBe(false);
expect(result.error).toMatch(/invalid.*bundle/i);
expect(spawner).not.toHaveBeenCalled();
expect(executor).not.toHaveBeenCalled();
});

it('writes logs under the current workspace log directory when no test override is set', async () => {
setSimulatorLogDirOverrideForTests(null);
const spawner = createMockSpawner();
Expand Down
14 changes: 14 additions & 0 deletions src/utils/simulator-steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
stopSimulatorLaunchOsLogSessionsForApp,
} from './log-capture/simulator-launch-oslog-sessions.ts';

const VALID_LOG_SUBSYSTEM_PATTERN = /^[a-zA-Z0-9._-]+$/;

let logDirOverrideForTests: string | null = null;

interface ResolvedSimulatorLogDir {
Expand Down Expand Up @@ -152,6 +154,13 @@ export interface LaunchWithLoggingResult {
error?: string;
}

function validateLogSubsystem(value: string): string | undefined {
if (VALID_LOG_SUBSYSTEM_PATTERN.test(value)) {
return undefined;
}
return `Invalid bundle identifier: '${value}'. Bundle IDs must contain only alphanumeric characters, dots, hyphens, and underscores.`;
}

/**
* Launch an app on a simulator with implicit runtime logging.
*
Expand All @@ -176,6 +185,11 @@ export async function launchSimulatorAppWithLogging(
spawner?: ProcessSpawner;
},
): Promise<LaunchWithLoggingResult> {
const validationError = validateLogSubsystem(bundleId);
if (validationError) {
return { success: false, error: validationError };
}

const spawner = deps?.spawner ?? spawn;

const logsDir = resolveSimulatorLogDir();
Expand Down
Loading