Skip to content

Commit c82b72e

Browse files
committed
fix(web): confine executable proofs to managed installs
1 parent 3ae0bf6 commit c82b72e

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

‎packages/platform-web/src/agent-browser-lifecycle.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,34 @@ function observeProcesses(processes: ProcessFixture[]) {
519519
);
520520
}
521521

522+
test('a managed binary symlink cannot confer ownership on an executable outside its install', async () => {
523+
const stateDir = mkdtempForTestSync('agent-device-web-install-boundary-');
524+
try {
525+
installFakeManagedAgentBrowser(stateDir);
526+
const status = getManagedAgentBrowserStatus({
527+
stateDir,
528+
host: { env: process.env, cwd: process.cwd() },
529+
});
530+
const binary = nativeBinary(status.installDir);
531+
const linkedBinary = nativeBinary(managedInstallPaths(stateDir, '0.27.1').installDir);
532+
const linkedBin = path.dirname(linkedBinary);
533+
const outsideBin = path.join(stateDir, 'unrelated-bin');
534+
fs.renameSync(linkedBin, outsideBin);
535+
fs.symlinkSync(outsideBin, linkedBin, process.platform === 'win32' ? 'junction' : 'dir');
536+
const unrelated = fs.realpathSync.native(path.join(outsideBin, path.basename(linkedBinary)));
537+
observeProcesses([
538+
{ pid: 101, command: `${binary} daemon`, executable: binary },
539+
{ pid: 102, command: unrelated, executable: unrelated },
540+
]);
541+
const store = { replace: vi.fn(), clear: vi.fn(), read: vi.fn(() => []) };
542+
543+
expect((await recordManagedAgentBrowserProcesses(status, store)).pids).toEqual([101]);
544+
expect(store.replace.mock.calls[0]?.[1].map(({ pid }: { pid: number }) => pid)).toEqual([101]);
545+
} finally {
546+
fs.rmSync(stateDir, { recursive: true, force: true });
547+
}
548+
});
549+
522550
test('records verified current and retained native roots and stable descendants', async () => {
523551
const stateDir = mkdtempForTestSync('agent-device web life-');
524552
try {

‎packages/platform-web/src/agent-browser-process-record.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,12 @@ function managedFleetOwnership(status: AgentBrowserToolStatus): ManagedFleetOwne
270270
launchMarkers: installs.map(agentBrowserChromeLaunchMarker),
271271
browserHomeRoots: uniqueStrings(installs.flatMap(managedBrowserHomeMarkers)),
272272
daemonEntries: installs.flatMap((install) => {
273+
let installRoot: string;
274+
try {
275+
installRoot = normalizePathSeparators(realHostPathSync(install.installDir));
276+
} catch {
277+
return [];
278+
}
273279
const bin = path.join(install.installDir, 'package', 'node_modules', 'agent-browser', 'bin');
274280
return [
275281
'agent-browser-darwin-arm64',
@@ -278,10 +284,12 @@ function managedFleetOwnership(status: AgentBrowserToolStatus): ManagedFleetOwne
278284
'agent-browser-linux-x64',
279285
'agent-browser-linux-musl-arm64',
280286
'agent-browser-linux-musl-x64',
287+
'agent-browser-win32-arm64.exe',
281288
'agent-browser-win32-x64.exe',
282289
].flatMap((name) => {
283290
try {
284-
return [normalizePathSeparators(realHostPathSync(path.join(bin, name)))];
291+
const executable = normalizePathSeparators(realHostPathSync(path.join(bin, name)));
292+
return executable.startsWith(`${installRoot}/`) ? [executable] : [];
285293
} catch {
286294
return [];
287295
}

0 commit comments

Comments
 (0)