Skip to content

Commit c4439c8

Browse files
committed
fix: remove remote host path install opt-in
1 parent 733fd31 commit c4439c8

6 files changed

Lines changed: 62 additions & 283 deletions

File tree

‎src/cli-schema/cli-help-topics.test.ts‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,6 @@ test('root help routes detailed reference material to progressive topics', async
143143
assert.match(commandsHelp, /Default config files: ~\/\.agent-device\/config\.json/);
144144
assert.match(commandsHelp, /^Environment:/m);
145145
assert.match(commandsHelp, /AGENT_DEVICE_SESSION\s+Explicit session name/);
146-
assert.match(
147-
commandsHelp,
148-
/AGENT_DEVICE_HTTP_ALLOW_HOST_PATH_INSTALL\s+Explicit remote host-path install opt-in/,
149-
);
150-
assert.match(
151-
commandsHelp,
152-
/AGENT_DEVICE_HTTP_HOST_PATH_INSTALL_ROOT\s+Realpath root for remote host-path installs/,
153-
);
154146
assert.match(commandsHelp, /^Examples:/m);
155147
assert.match(commandsHelp, /agent-device open Settings --platform ios/);
156148

@@ -473,9 +465,8 @@ test('usageForCommand resolves remote help topic', async () => {
473465
assert.match(help, /disconnect releases local connection state/);
474466
assert.match(help, /A busy direct-proxy device error means another agent owns the device/);
475467
assert.match(help, /AGENT_DEVICE_HTTP_AUTH_HOOK configured treats HTTP requests as remote/);
476-
assert.match(help, /AGENT_DEVICE_HTTP_ALLOW_HOST_PATH_INSTALL=true/);
477-
assert.match(help, /AGENT_DEVICE_HTTP_HOST_PATH_INSTALL_ROOT/);
478-
assert.match(help, /rejects traversal or symlink escapes/);
468+
assert.match(help, /host-path install sources are rejected/);
469+
assert.match(help, /uploaded artifacts remain supported/);
479470
assert.match(help, /Limrun, BrowserStack, and AWS Device Farm through local provider profiles/);
480471
assert.match(help, /Limrun uses LIMRUN_API_KEY/);
481472
assert.match(help, /BrowserStack uses BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY/);

‎src/cli-schema/cli-help.ts‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,6 @@ const ENVIRONMENT_LINES = [
3737
label: 'AGENT_DEVICE_DAEMON_AUTH_TOKEN',
3838
description: 'Remote daemon service/API token',
3939
},
40-
{
41-
label: 'AGENT_DEVICE_HTTP_ALLOW_HOST_PATH_INSTALL',
42-
description: 'Explicit remote host-path install opt-in',
43-
},
44-
{
45-
label: 'AGENT_DEVICE_HTTP_HOST_PATH_INSTALL_ROOT',
46-
description: 'Realpath root for remote host-path installs',
47-
},
4840
{
4941
label: 'AGENT_DEVICE_CLOUD_BASE_URL',
5042
description: 'Bridge/control-plane API origin for cloud auth and /api-keys',
@@ -830,7 +822,7 @@ Rules:
830822
disconnect releases local connection state; close releases the active session and device lease.
831823
A busy direct-proxy device error means another agent owns the device until it closes or its inactivity lease expires.
832824
Keep the proxy token secret. Anyone with the token can control the proxied daemon.
833-
A daemon with AGENT_DEVICE_HTTP_AUTH_HOOK configured treats HTTP requests as remote: host-path install sources are rejected by default, and Maestro runScript HTTP helpers allow only public network destinations. To opt into path installs, set AGENT_DEVICE_HTTP_ALLOW_HOST_PATH_INSTALL=true and AGENT_DEVICE_HTTP_HOST_PATH_INSTALL_ROOT to an existing directory; the daemon resolves the requested path and rejects traversal or symlink escapes. No-hook local HTTP and socket flows retain their local behavior.
825+
A daemon with AGENT_DEVICE_HTTP_AUTH_HOOK configured treats HTTP requests as remote: host-path install sources are rejected, uploaded artifacts remain supported, and Maestro runScript HTTP helpers allow only public network destinations. No-hook local HTTP and socket flows retain their local behavior.
834826
If local/proxy iOS reports that the runner is already owned by another agent-device daemon after lease admission, retry after the owning session closes or after lease expiry. If the conflict repeats, clean stale daemon state on the machine with simulator access.
835827
Do not use --config as a remote profile flag. --config loads CLI defaults; --remote-config selects remote daemon/profile settings.
836828
For self-contained scripts, pass the same --remote-config to every operational command, including disconnect; a preceding connect is optional but not required.

‎src/daemon/__tests__/http-server-rpc-validation.test.ts‎

Lines changed: 10 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -178,26 +178,6 @@ async function withInstallFromSourceRpcServer(
178178
}
179179
}
180180

181-
test('install_from_source rejects a host path source on an authenticated HTTP surface', async (t) => {
182-
const root = mkdtempForTestSync('agent-device-http-path-boundary-');
183-
try {
184-
await withInstallFromSourceRpcServer(
185-
async (post) => {
186-
const { status, body, dispatched } = await post({ kind: 'path', path: '/etc/passwd' });
187-
188-
assert.equal(status, 400);
189-
assert.equal(body.error?.code, -32602);
190-
assert.equal(body.error?.data?.code, 'INVALID_ARGS');
191-
assert.equal(dispatched.length, 0, 'a host path source must never reach the handler');
192-
},
193-
t,
194-
remoteHttpEnvironment(writeAllowingAuthHook(root)),
195-
);
196-
} finally {
197-
fs.rmSync(root, { recursive: true, force: true });
198-
}
199-
});
200-
201181
test('install_from_source still admits url sources', async (t) => {
202182
await withInstallFromSourceRpcServer(async (post) => {
203183
const { status, dispatched } = await post({ kind: 'url', url: 'https://example.com/app.apk' });
@@ -225,14 +205,19 @@ test('install_from_source still admits github-actions-artifact sources', async (
225205
assert.equal(dispatched[0]?.meta?.installSource?.kind, 'github-actions-artifact');
226206
}, t);
227207
});
228-
test('remote HTTP rejects host path install sources by default', async (t) => {
208+
test('remote HTTP rejects host path install sources', async (t) => {
229209
if (await skipWhenLoopbackUnavailable(t)) return;
230210

231211
const root = mkdtempForTestSync('agent-device-http-path-default-');
232212
const hookPath = writeAllowingAuthHook(root);
213+
const artifactPath = path.join(root, 'app.apk');
214+
fs.writeFileSync(artifactPath, 'untrusted host file');
215+
const env = remoteHttpEnvironment(hookPath);
216+
env.AGENT_DEVICE_HTTP_ALLOW_HOST_PATH_INSTALL = 'true';
217+
env.AGENT_DEVICE_HTTP_HOST_PATH_INSTALL_ROOT = root;
233218
let handlerCalls = 0;
234219
const server = await createDaemonHttpServer({
235-
env: remoteHttpEnvironment(hookPath),
220+
env,
236221
handleRequest: async (): Promise<DaemonResponse> => {
237222
handlerCalls += 1;
238223
return { ok: true, data: {} };
@@ -243,7 +228,7 @@ test('remote HTTP rejects host path install sources by default', async (t) => {
243228
const port = await listenOnLoopback(server);
244229
const response = await postInstallFromSource(port, {
245230
kind: 'path',
246-
path: path.join(root, 'app.apk'),
231+
path: artifactPath,
247232
});
248233
assert.equal(response.status, 400);
249234
assert.equal(response.body.error?.code, -32602);
@@ -335,17 +320,6 @@ test('remote HTTP accepts an uploaded path artifact without resolving the client
335320
}
336321
});
337322

338-
test('remote HTTP confines opted-in path installs to the realpath-approved root', async (t) => {
339-
if (await skipWhenLoopbackUnavailable(t)) return;
340-
341-
await withPathConfinementServer(async ({ port, received, inside, traversal, outsideLink }) => {
342-
await assertAllowedPathInstall(port, received, inside);
343-
await assertRejectedPathInstall(port, traversal);
344-
await assertRejectedPathInstall(port, outsideLink);
345-
assert.equal(received.length, 1);
346-
});
347-
});
348-
349323
test('local HTTP keeps path install sources available without an auth hook', async (t) => {
350324
if (await skipWhenLoopbackUnavailable(t)) return;
351325

@@ -384,95 +358,16 @@ function writeAllowingAuthHook(root: string): string {
384358
return hookPath;
385359
}
386360

387-
async function withPathConfinementServer(
388-
run: (context: {
389-
port: number;
390-
received: DaemonRequest[];
391-
inside: string;
392-
traversal: string;
393-
outsideLink: string;
394-
}) => Promise<void>,
395-
): Promise<void> {
396-
const parent = mkdtempForTestSync('agent-device-http-path-confinement-');
397-
const root = path.join(parent, 'approved');
398-
const outside = path.join(parent, 'outside.apk');
399-
const inside = path.join(root, 'inside.apk');
400-
const insideLink = path.join(root, 'inside-link.apk');
401-
const outsideLink = path.join(root, 'outside-link.apk');
402-
fs.mkdirSync(root);
403-
fs.writeFileSync(outside, 'outside');
404-
fs.writeFileSync(inside, 'inside');
405-
fs.symlinkSync(inside, insideLink);
406-
fs.symlinkSync(outside, outsideLink);
407-
const hookPath = writeAllowingAuthHook(parent);
408-
const received: DaemonRequest[] = [];
409-
const server = await createDaemonHttpServer({
410-
env: remoteHttpEnvironment(hookPath, {
411-
AGENT_DEVICE_HTTP_ALLOW_HOST_PATH_INSTALL: 'true',
412-
AGENT_DEVICE_HTTP_HOST_PATH_INSTALL_ROOT: root,
413-
}),
414-
handleRequest: async (request): Promise<DaemonResponse> => {
415-
received.push(request);
416-
return { ok: true, data: {} };
417-
},
418-
});
419-
420-
try {
421-
await run({
422-
port: await listenOnLoopback(server),
423-
received,
424-
inside,
425-
traversal: path.join(root, '..', path.basename(outside)),
426-
outsideLink,
427-
});
428-
} finally {
429-
await closeLoopbackServer(server);
430-
fs.rmSync(parent, { recursive: true, force: true });
431-
}
432-
}
433-
434-
async function assertAllowedPathInstall(
435-
port: number,
436-
received: DaemonRequest[],
437-
inside: string,
438-
): Promise<void> {
439-
const allowed = await postInstallFromSource(port, {
440-
kind: 'path',
441-
path: path.join(path.dirname(inside), 'inside-link.apk'),
442-
});
443-
assert.equal(allowed.status, 200);
444-
assert.equal(received[0]?.meta?.installSource?.kind, 'path');
445-
assert.equal(
446-
received[0]?.meta?.installSource?.kind === 'path'
447-
? received[0].meta.installSource.path
448-
: undefined,
449-
fs.realpathSync(inside),
450-
);
451-
assert.equal(received[0]?.internal?.networkAccess, 'public-only');
452-
}
453-
454-
async function assertRejectedPathInstall(port: number, rejectedPath: string): Promise<void> {
455-
const rejected = await postInstallFromSource(port, { kind: 'path', path: rejectedPath });
456-
assert.equal(rejected.status, 400, rejectedPath);
457-
assert.equal(rejected.body.error?.data?.code, 'INVALID_ARGS');
458-
assert.match(rejected.body.error?.message ?? '', /outside the approved root/);
459-
}
460-
461-
function remoteHttpEnvironment(
462-
hookPath: string,
463-
overrides: NodeJS.ProcessEnv = {},
464-
): NodeJS.ProcessEnv {
361+
function remoteHttpEnvironment(hookPath: string): NodeJS.ProcessEnv {
465362
const env = localHttpEnvironment();
466363
env.AGENT_DEVICE_HTTP_AUTH_HOOK = hookPath;
467-
return { ...env, ...overrides };
364+
return env;
468365
}
469366

470367
function localHttpEnvironment(): NodeJS.ProcessEnv {
471368
const env = { ...process.env };
472369
delete env.AGENT_DEVICE_HTTP_AUTH_HOOK;
473370
delete env.AGENT_DEVICE_HTTP_AUTH_EXPORT;
474-
delete env.AGENT_DEVICE_HTTP_ALLOW_HOST_PATH_INSTALL;
475-
delete env.AGENT_DEVICE_HTTP_HOST_PATH_INSTALL_ROOT;
476371
return env;
477372
}
478373

‎src/daemon/server/http-server.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -533,10 +533,7 @@ export async function createDaemonHttpServer(options: {
533533
}): Promise<http.Server> {
534534
const environment = options.env ?? process.env;
535535
const authHook = await loadHttpAuthHook(environment);
536-
const trustPolicy = await resolveHttpTrustPolicy({
537-
authHookConfigured: authHook !== null,
538-
env: environment,
539-
});
536+
const trustPolicy = resolveHttpTrustPolicy({ authHookConfigured: authHook !== null });
540537
const { handleRequest, token, retainArtifacts = false, resolveRequestDiagnosticsPath } = options;
541538
return http.createServer((req, res) => {
542539
if (req.method === 'GET' && req.url === '/health') {
@@ -695,7 +692,7 @@ export async function createDaemonHttpServer(options: {
695692
'tenant',
696693
};
697694
}
698-
daemonRequest = await applyHttpTrustPolicy(daemonRequest, trustPolicy);
695+
daemonRequest = applyHttpTrustPolicy(daemonRequest, trustPolicy);
699696

700697
let canceledInFlight = false;
701698
// Request-scoped cancellation: mark this request canceled whenever its client
Lines changed: 39 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,49 @@
11
import assert from 'node:assert/strict';
2-
import fs from 'node:fs';
3-
import path from 'node:path';
42
import { test } from 'vitest';
5-
import {
6-
HTTP_ALLOW_HOST_PATH_INSTALL_ENV,
7-
HTTP_HOST_PATH_INSTALL_ROOT_ENV,
8-
confineHttpInstallSourcePath,
9-
resolveHttpTrustPolicy,
10-
} from './http-trust-policy.ts';
11-
import { mkdtempForTestSync } from '../../__tests__/test-utils/tmp-dir.ts';
3+
import type { DaemonRequest } from '../types.ts';
4+
import { applyHttpTrustPolicy, resolveHttpTrustPolicy } from './http-trust-policy.ts';
125

13-
test('remote host-path opt-in fails closed without an approved root', async () => {
14-
await assert.rejects(
15-
resolveHttpTrustPolicy({
16-
authHookConfigured: true,
17-
env: { [HTTP_ALLOW_HOST_PATH_INSTALL_ENV]: 'true' },
18-
}),
19-
new RegExp(
20-
`${HTTP_ALLOW_HOST_PATH_INSTALL_ENV} requires ${HTTP_HOST_PATH_INSTALL_ROOT_ENV}`,
21-
'i',
22-
),
23-
);
6+
test('an auth-hook HTTP server uses the public-only trust policy', () => {
7+
assert.deepEqual(resolveHttpTrustPolicy({ authHookConfigured: true }), {
8+
networkAccess: 'public-only',
9+
});
2410
});
2511

26-
test('remote host-path opt-in resolves a symlinked approved root', async () => {
27-
const parent = mkdtempForTestSync('agent-device-http-trust-root-');
28-
const root = path.join(parent, 'root');
29-
const rootLink = path.join(parent, 'root-link');
30-
fs.mkdirSync(root);
31-
fs.symlinkSync(root, rootLink);
12+
test('an HTTP server without an auth hook keeps local unrestricted behavior', () => {
13+
assert.deepEqual(resolveHttpTrustPolicy({ authHookConfigured: false }), {
14+
networkAccess: 'unrestricted',
15+
});
16+
});
3217

33-
try {
34-
const policy = await resolveHttpTrustPolicy({
35-
authHookConfigured: true,
36-
env: {
37-
[HTTP_ALLOW_HOST_PATH_INSTALL_ENV]: 'yes',
38-
[HTTP_HOST_PATH_INSTALL_ROOT_ENV]: rootLink,
39-
},
40-
});
41-
assert.equal(policy.networkAccess, 'public-only');
42-
assert.equal(policy.hostPathInstallRoot, fs.realpathSync(root));
43-
} finally {
44-
fs.rmSync(parent, { recursive: true, force: true });
45-
}
18+
test('the public-only policy rejects every unbacked host path source', () => {
19+
assert.throws(
20+
() =>
21+
applyHttpTrustPolicy(
22+
requestWithMeta({ installSource: { kind: 'path', path: '/etc/passwd' } }),
23+
{ networkAccess: 'public-only' },
24+
),
25+
/path install sources are disabled on the remote HTTP surface/,
26+
);
4627
});
4728

48-
test('path confinement returns the canonical target and rejects a symlink escape', async () => {
49-
const parent = mkdtempForTestSync('agent-device-http-trust-path-');
50-
const root = path.join(parent, 'root');
51-
const inside = path.join(root, 'inside.apk');
52-
const outside = path.join(parent, 'outside.apk');
53-
const link = path.join(root, 'outside-link.apk');
54-
fs.mkdirSync(root);
55-
fs.writeFileSync(inside, 'inside');
56-
fs.writeFileSync(outside, 'outside');
57-
fs.symlinkSync(outside, link);
29+
test('the public-only policy preserves daemon-owned uploaded path sources', () => {
30+
const request = requestWithMeta({
31+
installSource: { kind: 'path', path: '/client/path.apk' },
32+
uploadedArtifactId: 'artifact-1',
33+
});
5834

59-
try {
60-
const approvedRoot = fs.realpathSync(root);
61-
assert.equal(await confineHttpInstallSourcePath(inside, approvedRoot), fs.realpathSync(inside));
62-
await assert.rejects(
63-
confineHttpInstallSourcePath(link, approvedRoot),
64-
(error: unknown) =>
65-
error instanceof Error && error.message.includes('resolves outside the approved root'),
66-
);
67-
} finally {
68-
fs.rmSync(parent, { recursive: true, force: true });
69-
}
35+
assert.deepEqual(applyHttpTrustPolicy(request, { networkAccess: 'public-only' }), {
36+
...request,
37+
internal: { networkAccess: 'public-only' },
38+
});
7039
});
40+
41+
function requestWithMeta(meta: DaemonRequest['meta']): DaemonRequest {
42+
return {
43+
command: 'install_source',
44+
positionals: [],
45+
token: 'test-token',
46+
session: 'test-session',
47+
meta,
48+
};
49+
}

0 commit comments

Comments
 (0)