Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
1b759e8
fix(client): refuse unsafe credential and replay inputs
thymikee Nov 30, 2026
22f9adc
test(provider): match daemon restart hint without case sensitivity
thymikee Nov 30, 2026
1ee9fd1
test(remote): prove trace stop ignores daemon paths
thymikee Nov 30, 2026
99552c0
fix: keep Maestro selectors usable with long labels and escaped literals
thymikee Nov 30, 2026
ba1adca
fix: validate Maestro selectors before normalized matching
thymikee Nov 30, 2026
07e3043
chore(gates): keep Maestro regex construction in bounded owner
thymikee Nov 30, 2026
b5402c7
fix: reserve unique client paths for unnamed remote artifacts
thymikee Nov 30, 2026
04c5bd2
chore(gates): format security boundary changes
thymikee Nov 30, 2026
d10bbc3
test(remote): record unique artifact destinations in compatibility ch…
thymikee Nov 30, 2026
015c949
refactor(gates): keep Maestro regex guard traversal focused
thymikee Nov 30, 2026
7b42986
fix: retain overlong artifact extension in bounded client name
thymikee Nov 30, 2026
1413a2d
fix: restrict remote artifact extraction and Windows names
thymikee Nov 30, 2026
fa4f1bb
fix: admit safe Maestro patterns with a bounded matcher
thymikee Nov 30, 2026
3c9ae22
docs: align transport guidance with refusal behavior
thymikee Nov 30, 2026
9cbfada
chore(gates): bundle Maestro regex parser in published runtime
thymikee Nov 30, 2026
415ad5a
chore(gates): declare regex parser as root runtime dependency
thymikee Nov 30, 2026
0725f0d
fix(maestro): explain oversized selector values
thymikee Nov 30, 2026
69f97a9
chore(gates): canonicalize Maestro lockfile importer order
thymikee Nov 30, 2026
bcdc48b
fix(maestro): validate regex-shaped exact selector matches
thymikee Nov 30, 2026
c35fac4
chore(gates): classify client-only artifact handling
thymikee Nov 30, 2026
568ee71
chore(maestro): format bounded regex guard
thymikee Nov 30, 2026
94c120c
chore(gates): prove bundled runtime dependencies in packed artifact
thymikee Nov 30, 2026
1ff1a3b
chore(gates): format packed dependency proof
thymikee Nov 30, 2026
eb3cfeb
fix(remote): persist scoped capture destinations for pathless stops
thymikee Nov 30, 2026
1eeabef
docs(security): trim duplicate capture guidance
thymikee Nov 30, 2026
a729f39
test(remote): avoid closure-narrowed capture request
thymikee Nov 30, 2026
179b490
chore(gates): record capture materialization compatibility
thymikee Nov 30, 2026
c36d1cf
fix(client): address security review findings
thymikee Nov 30, 2026
17af034
fix: keep Maestro regex guard and package declarations within CI cont…
thymikee Nov 30, 2026
ef6651f
chore(gates): format Maestro regex guard
thymikee Nov 30, 2026
a1c00f5
fix: isolate provider hint scenario and simplify regex guard scopes
thymikee Nov 30, 2026
aab1b0a
fix(maestro): preserve exact text for safe regex-shaped selectors
thymikee Nov 30, 2026
a36cd07
fix(maestro): bound selector regex paths and retain full text matches
thymikee Nov 30, 2026
251351f
fix(maestro): refuse indeterminate partial multiline selector matches
thymikee Nov 30, 2026
11aba64
fix(remote): bind capture destinations to live capture identity
thymikee Nov 30, 2026
f78867e
docs: record capture identity refusals and destination rules
thymikee Nov 30, 2026
250db80
fix(remote): bound uncertain capture start state
thymikee Nov 30, 2026
bfa9437
chore(gates): record additive capture identity wire changes
thymikee Nov 30, 2026
d0b0999
fix(maestro): satisfy selector regex type and escape checks
thymikee Nov 30, 2026
61cc572
fix(remote): resolve capture CI type errors
thymikee Nov 30, 2026
6a32e82
refactor(remote): simplify capture start settlement
thymikee Nov 30, 2026
0a4c09f
fix(maestro): allow long exact selector text safely
thymikee Nov 30, 2026
6629a75
fix(remote): settle capture destinations across refusals and close races
thymikee Dec 1, 2026
9515bb3
fix(maestro): bound multiline selector matching and preserve exact ma…
thymikee Dec 1, 2026
624c3f2
refactor(remote): separate capture dispatch paths
thymikee Dec 1, 2026
9a37623
chore(gates): isolate Maestro target ranking decisions
thymikee Dec 1, 2026
ae98615
fix(maestro): preserve bounded whole-value multiline matches
thymikee Dec 1, 2026
46650fa
fix(security): align guidance and focused assertions
thymikee Dec 1, 2026
650b06c
chore(gates): prove bundled workspace dev dependencies
thymikee Dec 1, 2026
fd9dc6d
fix(capture): refuse foreign and invalid destination state
thymikee Dec 1, 2026
1890356
fix(capture): type unreadable record refusals
thymikee Dec 1, 2026
dfd7fc9
chore(gates): align capture guidance with reason source
thymikee Dec 1, 2026
efaf61b
fix(capture): distinguish own and foreign live captures
thymikee Dec 1, 2026
b6696bb
fix: preserve maestro failure reporting for unsafe selectors
thymikee Dec 1, 2026
7f9c92c
fix: reduce capture certainty branch complexity
thymikee Dec 1, 2026
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
2 changes: 1 addition & 1 deletion docs/adr/0041-credential-transport.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Status

Accepted (2026-11-28). Enforcement has not shipped yet; it is tracked in #5182.
Accepted (2026-11-28). `admitCredentialDestination` and upload tickets' `credentialTransportRefusal` use the shared rule.
ADR 0006 continues to govern checked RPC.

## Rules at a glance
Expand Down
29 changes: 17 additions & 12 deletions docs/agents/security.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
# Security boundaries

The CLI client trusts its caller to choose local destinations.
The client trusts a remote daemon for data and validated identifiers.
Scripts and remote record stop reject daemon paths (#4518). Trace and perf take them.
The daemon admits its state directory. Nobody trusts the network or other local users.
Reject daemon-chosen paths in scripts and remote record stops (#4518).
Use caller paths for trace/perf. Give unnamed captures unique cwd names.
Key paths by endpoint, tenant, run, lease, session, and kind.
On start, mark ID pending.
If start rejects the same ID, keep the saved path.
If settled state names a foreign ID, refuse pathless stop.
On pathless stop, send the client ID.
If stop confirms the ID, use the saved path.
If stop rejects the ID, retire the saved path and retry with a unique cwd name.
If an explicit stop succeeds, clear unchanged foreign state.
If the outcome is unclear, use a unique cwd name.
After close or stop, retire the saved path.
The daemon admits state; trust neither network nor other local users.
Out of scope: same uid, hostile root, ACLs, mounts, untrusted filesystems.
ADR 0041 owns credential transport.

## Applied today

ADR 0016 judges caller-named script destinations on POSIX against the writing process's uid.
Both script publishers commit in the judged directory.
Remote script delivery caps in-memory bytes and error answers.
ADR 0016 owns script destination writes and delivery limits.

## Proposed in #4669

#4669 proposes private writes for credentials, client state, and daemon state (#4649): create each under a verified state root, and never write through a link at the final name.
Do not apply these before #4669 is approved.
Do not apply the ADR 0016 walk to other outputs. Screenshot `--out`, contact sheets, JUnit, traces, recordings keep a plain write to the path the caller names.
Until #4669 is approved, do not apply its private-write proposal.
It creates credentials and client/daemon state under a verified root without following a final-name link.
Do not apply ADR 0016's path walk to screenshot `--out`, contact sheets, JUnit, traces, or recordings.
3 changes: 1 addition & 2 deletions packages/contracts/src/credential-transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { isLoopbackHostname } from './loopback-host.ts';
const CREDENTIAL_TRANSPORT_REASONS = {
// A first-party credential would go to a configured URL that is neither https nor plain http to a
// loopback host, and the CLI or SDK environment does not set
// AGENT_DEVICE_ALLOW_INSECURE_TRANSPORT=1 (@agent-device/proxy has no override). agent-device
// 0.21.x warns on stderr instead of failing with it; 0.22 refuses with it before sending anything.
// AGENT_DEVICE_ALLOW_INSECURE_TRANSPORT=1 (@agent-device/proxy has no override).
insecureTransport: { reason: 'insecure_credential_transport' },
} as const satisfies ReasonTable<'remote connection'>;

Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/src/recording.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ export type TraceCommandResult =
| {
trace: 'started';
outPath: string;
clientCaptureId?: string;
}
| {
trace: 'stopped';
outPath: string;
artifacts: DaemonArtifact[];
clientCaptureId?: string;
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import assert from 'node:assert/strict';
import http from 'node:http';
import { EventEmitter } from 'node:events';
import { afterEach, test, vi } from 'vitest';
import { afterEach, beforeEach, test, vi } from 'vitest';
import { isRequestCanceledError } from '@agent-device/kernel/errors';
import { sendToDaemon } from '../index.ts';

Expand Down Expand Up @@ -135,6 +135,10 @@ function driveFakeTime(): () => Promise<void> {

const BASE_URL = 'http://remote-mac.example.test:7777/agent-device';

beforeEach(() => {
vi.stubEnv('AGENT_DEVICE_ALLOW_INSECURE_TRANSPORT', '1');
});

let tokenSeq = 0;
/** A token of its own per test: the process health cache is keyed by it. */
function freshToken(): string {
Expand All @@ -152,6 +156,7 @@ function sessionList(daemonRpc?: 'checked') {
}

afterEach(() => {
vi.unstubAllEnvs();
vi.useRealTimers();
vi.restoreAllMocks();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,37 @@
// A remote daemon token over plain http off loopback is warned about from the settings the client
// reads, before the first request leaves.

import assert from 'node:assert/strict';
import http from 'node:http';
import { afterEach, test, vi } from 'vitest';
import { beginStderrCapture, createTestHostEnvironment } from '@agent-device/test-kit';
import { createTestHostEnvironment } from '@agent-device/test-kit';
import { assertRemoteServesCheckedRpc } from '../index.ts';

function isTransportRefusal(error: unknown): boolean {
const value = error as { code?: string; details?: { reason?: string } };
return (
value?.code === 'INVALID_ARGS' && value.details?.reason === 'insecure_credential_transport'
);
}

afterEach(() => {
vi.restoreAllMocks();
});

/** The stderr written by the time the first request to `daemonBaseUrl` opens; nothing is sent. */
async function stderrAtFirstSend(
daemonBaseUrl: string,
env: Record<string, string> = {},
): Promise<string> {
const stderr = beginStderrCapture();
let atSend: string | undefined;
vi.spyOn(http, 'request').mockImplementation(() => {
atSend ??= stderr.read();
throw new Error('stop at the socket');
test('a plain http daemon off loopback is refused before the token leaves', async () => {
const request = vi.spyOn(http, 'request').mockImplementation(() => {
throw new Error('insecure request reached the transport');
});
try {
await assert.rejects(
assertRemoteServesCheckedRpc(
{ daemonBaseUrl, daemonAuthToken: 'remote-secret' },
createTestHostEnvironment({ env }),
),
);
} finally {
stderr.restore();
}
assert.ok(atSend !== undefined, 'the client never reached the socket');
return atSend;
}

test('a plain http daemon off loopback is warned about before the token leaves', async () => {
const warning = await stderrAtFirstSend('http://warned.example.test:7777/agent-device');
await assert.rejects(
assertRemoteServesCheckedRpc(
{
daemonBaseUrl: 'http://fleet.example.test:7777/agent-device',
daemonAuthToken: 'remote-secret',
},
createTestHostEnvironment({ env: {} }),
),
isTransportRefusal,
);

assert.match(warning, /http:\/\/warned\.example\.test:7777 are sent in cleartext/);
assert.doesNotMatch(warning, /remote-secret|agent-device\/health/);
assert.equal(request.mock.calls.length, 0);
});

test.each([
Expand All @@ -50,6 +41,16 @@ test.each([
'http://overridden.example.test:7777',
{ AGENT_DEVICE_ALLOW_INSECURE_TRANSPORT: '1' },
],
] as const)('%s is not warned about', async (_label, daemonBaseUrl, env) => {
assert.equal(await stderrAtFirstSend(daemonBaseUrl, env), '');
] as const)('%s reaches the transport', async (_label, daemonBaseUrl, env) => {
const request = vi.spyOn(http, 'request').mockImplementation(() => {
throw new Error('stop at the socket');
});

await assert.rejects(
assertRemoteServesCheckedRpc(
{ daemonBaseUrl, daemonAuthToken: 'remote-secret' },
createTestHostEnvironment({ env }),
),
);
assert.ok(request.mock.calls.length > 0);
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import assert from 'node:assert/strict';
import http from 'node:http';
import { EventEmitter } from 'node:events';
import { afterEach, test, vi } from 'vitest';
import { afterEach, beforeEach, test, vi } from 'vitest';
import { AppError, isRequestCanceledError } from '@agent-device/kernel/errors';
import { sendToDaemon } from '../index.ts';

Expand Down Expand Up @@ -71,7 +71,12 @@ function remoteSessionList() {
};
}

beforeEach(() => {
vi.stubEnv('AGENT_DEVICE_ALLOW_INSECURE_TRANSPORT', '1');
});

afterEach(() => {
vi.unstubAllEnvs();
vi.useRealTimers();
vi.restoreAllMocks();
});
Expand Down
4 changes: 4 additions & 0 deletions packages/daemon-client/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ test('sendToDaemon reuses reachable local HTTP daemon metadata with token params
});

test('sendToDaemon uses explicit remote daemon base URL and auth token', async () => {
vi.stubEnv('AGENT_DEVICE_ALLOW_INSECURE_TRANSPORT', '1');
let authHeader = '';
let tokenHeader = '';
let rpcRequest: Record<string, unknown> | null = null;
Expand Down Expand Up @@ -606,6 +607,7 @@ test('sendToDaemon uses explicit remote daemon base URL and auth token', async (
assert.equal((rpcRequest as any)?.params?.token, 'remote-secret');
assert.equal((rpcRequest as any)?.params?.flags?.daemonAuthToken, undefined);
} finally {
vi.unstubAllEnvs();
(http as unknown as { request: typeof http.request }).request = originalHttpRequest;
if (previousBaseUrl === undefined) delete process.env.AGENT_DEVICE_DAEMON_BASE_URL;
else process.env.AGENT_DEVICE_DAEMON_BASE_URL = previousBaseUrl;
Expand Down Expand Up @@ -708,6 +710,7 @@ test.each([
);

test('sendToDaemon sends lease helpers as top-level JSON-RPC methods over HTTP', async () => {
vi.stubEnv('AGENT_DEVICE_ALLOW_INSECURE_TRANSPORT', '1');
const rpcRequests: Record<string, unknown>[] = [];
const originalHttpRequest = http.request;
(http as unknown as { request: typeof http.request }).request = ((
Expand Down Expand Up @@ -844,6 +847,7 @@ test('sendToDaemon sends lease helpers as top-level JSON-RPC methods over HTTP',
leaseId: 'lease-new',
});
} finally {
vi.unstubAllEnvs();
(http as unknown as { request: typeof http.request }).request = originalHttpRequest;
if (previousBaseUrl === undefined) delete process.env.AGENT_DEVICE_DAEMON_BASE_URL;
else process.env.AGENT_DEVICE_DAEMON_BASE_URL = previousBaseUrl;
Expand Down
8 changes: 5 additions & 3 deletions packages/daemon-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { resolveCommandTimeoutPolicy } from '@agent-device/command-registry/regi
import { resolveCommandRequestTimeoutMs } from '@agent-device/command-registry/timeout-policy';
import {
prepareRemoteRequestArtifacts,
sendRemoteCapture,
sendRemoteScriptOpen,
type PreparedRemoteRequest,
} from '@agent-device/remote/daemon-artifacts';
Expand Down Expand Up @@ -183,9 +184,10 @@ async function sendToDaemonOnHost(
...(options.leaseCheckedByAdmission ? { leaseCheckedByAdmission: true } : {}),
},
);
if (!info.baseUrl || !request.meta?.clientArtifactPaths?.savedScript)
return await send(request);
return await sendRemoteScriptOpen(info, request, settings.paths.baseDir, send);
if (!info.baseUrl) return await send(request);
if (request.meta?.clientArtifactPaths?.savedScript)
return await sendRemoteScriptOpen(info, request, settings.paths.baseDir, send);
return await sendRemoteCapture(info.baseUrl, request, settings.paths.baseDir, send);
},
{ requestId, command: req.command },
);
Expand Down
30 changes: 30 additions & 0 deletions packages/daemon/src/core/capture-identity-refusal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { errorResponse, type DaemonResponse } from '@agent-device/kernel/contracts';
import { CAPTURE_IDENTITY_REASONS } from '@agent-device/kernel/errors';

type CaptureKind = 'trace' | 'native perf';
type CaptureRefusal = 'already-active' | 'mismatch';

const messages = {
trace: {
'already-active': 'trace already in progress',
mismatch: 'trace capture identity changed',
},
'native perf': {
'already-active': 'native perf capture already in progress',
mismatch: 'native perf capture identity changed',
},
} as const;

export function captureIdentityRefusal(
kind: CaptureKind,
refusal: CaptureRefusal,
clientCaptureId?: string,
): DaemonResponse {
return errorResponse('INVALID_ARGS', messages[kind][refusal], {
reason:
refusal === 'already-active'
? CAPTURE_IDENTITY_REASONS.alreadyActive.reason
: CAPTURE_IDENTITY_REASONS.mismatch.reason,
...(refusal === 'already-active' ? { clientCaptureId } : {}),
});
}
3 changes: 2 additions & 1 deletion packages/daemon/src/core/session-capture-binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ export function bindSessionPerfCapture(
sessionStore: SessionStore,
ref: SessionRef,
clientOutPath?: string,
clientCaptureId?: string,
) {
return bindSessionCapture(sessionStore, ref, {
read: (session) => session.perfCapture,
write: (perfCapture) => {
sessionStore.update(ref, {
perfCapture: perfCapture ? { ...perfCapture, clientOutPath } : undefined,
perfCapture: perfCapture ? { ...perfCapture, clientOutPath, clientCaptureId } : undefined,
});
},
});
Expand Down
2 changes: 2 additions & 0 deletions packages/daemon/src/core/session-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,15 @@ export type SessionState = {
snapshotDiagnostics?: SnapshotDiagnosticsState;
trace?: {
outPath: string;
clientCaptureId?: string;
clientOutPath?: string;
remoteCaptureOutputPath?: string;
remoteCaptureTenantId?: string;
startedAt: number;
};
/** Native profiling mechanics stay behind one exact-owner durable handle. */
perfCapture?: {
clientCaptureId?: string;
clientOutPath?: string;
handle: PerfNativeCaptureLiveHandle;
envelope: DurableResourceEnvelope<'perf-capture'>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,21 @@ function fixture() {
return { root, session, sessionStore };
}

function request(positionals: string[], clientOutPath?: string): DaemonRequest {
function request(positionals: string[], clientOutPath?: string, captureId?: string): DaemonRequest {
return {
token: 'token',
session: 'trace-session',
command: 'trace',
positionals,
flags: {},
...(clientOutPath ? { meta: { clientArtifactPaths: { outPath: clientOutPath } } } : {}),
...(clientOutPath || captureId
? {
meta: {
...(clientOutPath ? { clientArtifactPaths: { outPath: clientOutPath } } : {}),
...(captureId ? { captureId } : {}),
},
}
: {}),
};
}

Expand All @@ -69,6 +76,36 @@ test('starts and stops one trace through the session-owned trace slot', () => {
expect(session.trace).toBeUndefined();
});

test('a stale client capture identity cannot stop a reopened trace', () => {
const { session, sessionStore } = fixture();
const host = createTestHostEnvironment();
const started = handleTraceCommand({
host,
req: request(['start'], undefined, 'capture-b'),
sessionName: session.name,
sessionStore,
});
expect(started).toMatchObject({ ok: true, data: { clientCaptureId: 'capture-b' } });
const stale = handleTraceCommand({
host,
req: request(['stop'], undefined, 'capture-a'),
sessionName: session.name,
sessionStore,
});
expect(stale).toMatchObject({
ok: false,
error: { details: { reason: 'capture-identity-mismatch' } },
});
expect(session.trace).toBeDefined();
const stopped = handleTraceCommand({
host,
req: request(['stop'], undefined, 'capture-b'),
sessionName: session.name,
sessionStore,
});
expect(stopped).toMatchObject({ ok: true, data: { clientCaptureId: 'capture-b' } });
});

test('relocates trace output and projects the client artifact path', () => {
const { root, session, sessionStore } = fixture();
const original = path.join(root, 'original.trace');
Expand Down
Loading
Loading