Skip to content

Commit 8c3f157

Browse files
committed
fix(approvals): normalize exec policy enums and escape host at creation
security/ask are closed enums — arbitrary strings now null out via the canonical normalizers instead of reaching reviewer meta rows; host gets the display escape (identity for valid values). nodeId/agentId/sessionKey stay raw by design: they are matched against the node registry and session routing, noted inline.
1 parent 61b84e9 commit 8c3f157

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

‎src/gateway/server-methods/exec-approval.agent-runtime.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,17 @@ describe("exec approval signed agent runtime", () => {
121121
// Bidi override in cwd/resolvedPath can spoof what path reviewers see.
122122
(opts.params as Record<string, unknown>).cwd = "/tmp/safe‮evil";
123123
(opts.params as Record<string, unknown>).resolvedPath = "/usr/bin/echo​x";
124+
// Free-form policy strings must not reach reviewer meta rows: security/ask
125+
// are closed enums (arbitrary values null out), host is escape-hardened.
126+
(opts.params as Record<string, unknown>).security = "full‮looks-deny";
127+
(opts.params as Record<string, unknown>).ask = "always​ish";
124128
const pending = handler(opts);
125129
await vi.waitFor(() => expect(manager.listPendingRecords()).toHaveLength(1));
126130
const record = manager.listPendingRecords()[0]!;
127131
expect(record.request.cwd).toBe("/tmp/safe\\u{202E}evil");
128132
expect(record.request.resolvedPath).toBe("/usr/bin/echo\\u{200B}x");
133+
expect(record.request.security).toBeNull();
134+
expect(record.request.ask).toBeNull();
129135
manager.resolve(record.id, "deny");
130136
await pending;
131137
});

‎src/gateway/server-methods/exec-approval.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
sanitizeExecApprovalWarningText,
1818
} from "../../infra/exec-approval-command-display.js";
1919
import type { ExecApprovalForwarder } from "../../infra/exec-approval-forwarder.js";
20+
import { normalizeExecAsk, normalizeExecSecurity } from "../../infra/exec-approvals-core.js";
2021
import {
2122
DEFAULT_EXEC_APPROVAL_TIMEOUT_MS,
2223
normalizeExecApprovalUnavailableDecisions,
@@ -328,10 +329,17 @@ export function createExecApprovalHandlers(
328329
// binds effectiveCwd via systemRunBinding above); sanitize like the
329330
// command so bidi/invisible chars cannot spoof reviewer surfaces.
330331
cwd: effectiveCwd ? sanitizeExecApprovalDisplayText(effectiveCwd) : null,
332+
// nodeId/agentId/sessionKey stay raw: they are matched against the
333+
// node registry and session routing, so escaping would break real
334+
// lookups without display gain (hostile values match nothing).
331335
nodeId: host === "node" ? nodeId : null,
332-
host: host || null,
333-
security: p.security ?? null,
334-
ask: p.ask ?? null,
336+
// host is enum-gated ("node" checks); escape is identity for valid
337+
// values and defuses invisible-char spoofing in reviewer meta rows.
338+
host: host ? sanitizeExecApprovalDisplayText(host) : null,
339+
// Closed enums: arbitrary strings become null instead of reaching
340+
// reviewer surfaces; decision resolution already treats them as null.
341+
security: normalizeExecSecurity(p.security) ?? null,
342+
ask: normalizeExecAsk(p.ask) ?? null,
335343
warningText: warningText ? sanitizeExecApprovalWarningText(warningText) : null,
336344
commandAnalysis,
337345
commandSpans,

0 commit comments

Comments
 (0)