@jbkjr/relay 0.0.0-stage → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/LICENSES/Apache-2.0.txt +201 -0
- package/LICENSES/README.md +19 -0
- package/LICENSES/codex-NOTICE.txt +6 -0
- package/README.md +393 -2
- package/SECURITY.md +145 -0
- package/adapters/briefs/claude.md +43 -0
- package/adapters/briefs/codex.md +56 -0
- package/adapters/briefs/models.json +33 -0
- package/adapters/build.mjs +8 -0
- package/adapters/claude/.claude-plugin/marketplace.json +13 -0
- package/adapters/claude/relay/.claude-plugin/plugin.json +5 -0
- package/adapters/claude/relay/agents/codex.md +21 -0
- package/adapters/claude/relay/agents/operator.md +21 -0
- package/adapters/claude/relay/skills/ask/SKILL.md +20 -0
- package/adapters/claude/relay/skills/chat/SKILL.md +13 -0
- package/adapters/claude/relay/skills/delegate/SKILL.md +21 -0
- package/adapters/claude/relay/skills/discuss/SKILL.md +19 -0
- package/adapters/claude/relay/skills/review/SKILL.md +21 -0
- package/adapters/claude/relay/skills/tree/SKILL.md +10 -0
- package/adapters/claude/relay/skills/write-for-codex/SKILL.md +78 -0
- package/adapters/codex/.agents/plugins/marketplace.json +20 -0
- package/adapters/codex/AGENTS.snippet.md +5 -0
- package/adapters/codex/relay/.codex-plugin/plugin.json +6 -0
- package/adapters/codex/relay/skills/relay-ask/SKILL.md +20 -0
- package/adapters/codex/relay/skills/relay-chat/SKILL.md +13 -0
- package/adapters/codex/relay/skills/relay-delegate/SKILL.md +21 -0
- package/adapters/codex/relay/skills/relay-discuss/SKILL.md +19 -0
- package/adapters/codex/relay/skills/relay-review/SKILL.md +21 -0
- package/adapters/codex/relay/skills/relay-tree/SKILL.md +10 -0
- package/adapters/codex/relay/skills/relay-write-for-claude/SKILL.md +66 -0
- package/adapters/generate.mjs +124 -0
- package/bin/relay +59 -0
- package/codex-pin.json +12 -0
- package/dist/backends/acp.js +1424 -0
- package/dist/backends/claude.js +890 -0
- package/dist/backends/cli-version.js +112 -0
- package/dist/backends/codex-app.js +1539 -0
- package/dist/backends/codex-daybreak.js +75 -0
- package/dist/backends/codex-env.js +656 -0
- package/dist/backends/codex-network.js +304 -0
- package/dist/backends/codex-pin.js +345 -0
- package/dist/backends/codex-shell-policy.js +182 -0
- package/dist/backends/codex-stage2.js +998 -0
- package/dist/backends/codex-subagents.js +47 -0
- package/dist/backends/codex.js +641 -0
- package/dist/backends/copilot.js +246 -0
- package/dist/backends/env.js +147 -0
- package/dist/backends/gemini.js +607 -0
- package/dist/backends/grok.js +337 -0
- package/dist/backends/index.js +8 -0
- package/dist/backends/native-temp.js +187 -0
- package/dist/backends/never-admission.js +90 -0
- package/dist/backends/run.js +67 -0
- package/dist/backends/stream.js +230 -0
- package/dist/backends/tool-discovery.js +15 -0
- package/dist/backends/types.js +264 -0
- package/dist/build-info.json +5 -0
- package/dist/cli.js +344 -0
- package/dist/confine/bridge.js +113 -0
- package/dist/confine/broker-core.js +76 -0
- package/dist/confine/broker-http.js +650 -0
- package/dist/confine/broker-names.js +9 -0
- package/dist/confine/broker.js +258 -0
- package/dist/confine/canary.js +380 -0
- package/dist/confine/diagnostics.js +122 -0
- package/dist/confine/gemini-tools-main.js +8 -0
- package/dist/confine/gemini-tools.js +181 -0
- package/dist/confine/hardlinks.js +58 -0
- package/dist/confine/harness-config.js +16 -0
- package/dist/confine/index.js +117 -0
- package/dist/confine/leases.js +217 -0
- package/dist/confine/paths.js +6 -0
- package/dist/confine/peer.js +115 -0
- package/dist/confine/port-policy.js +8 -0
- package/dist/confine/ports.js +365 -0
- package/dist/confine/private-root.js +208 -0
- package/dist/confine/probe-stage2.js +501 -0
- package/dist/confine/probe.js +1109 -0
- package/dist/confine/proxy.js +783 -0
- package/dist/confine/sbcheck.js +208 -0
- package/dist/confine/seatbelt-never.js +41 -0
- package/dist/confine/seatbelt-stage2.js +139 -0
- package/dist/confine/seatbelt.js +1129 -0
- package/dist/confine/sockets.js +36 -0
- package/dist/confine/turn-probe.js +19 -0
- package/dist/confine/turn.js +86 -0
- package/dist/core/adoption.js +124 -0
- package/dist/core/api-keys.js +423 -0
- package/dist/core/approvals.js +740 -0
- package/dist/core/build-identity.js +248 -0
- package/dist/core/caller.js +749 -0
- package/dist/core/calls.js +102 -0
- package/dist/core/claude-settings.js +1045 -0
- package/dist/core/config.js +453 -0
- package/dist/core/context.js +186 -0
- package/dist/core/db.js +753 -0
- package/dist/core/dispatch.js +110 -0
- package/dist/core/env-broker.js +505 -0
- package/dist/core/env-policy.js +182 -0
- package/dist/core/escalation-authority.js +76 -0
- package/dist/core/escalation-contract.js +13 -0
- package/dist/core/escalation-person-path.js +131 -0
- package/dist/core/escalation-policy.js +79 -0
- package/dist/core/escalation-runtime.js +135 -0
- package/dist/core/escalation-state.js +42 -0
- package/dist/core/escalations.js +191 -0
- package/dist/core/events.js +235 -0
- package/dist/core/executables.js +147 -0
- package/dist/core/extensions.js +645 -0
- package/dist/core/families.js +204 -0
- package/dist/core/git.js +657 -0
- package/dist/core/identity.js +113 -0
- package/dist/core/liveness.js +68 -0
- package/dist/core/mediated-network-provider.js +81 -0
- package/dist/core/never-checkpoint.js +76 -0
- package/dist/core/never-coverage.js +97 -0
- package/dist/core/never-network.js +49 -0
- package/dist/core/never-policy.js +302 -0
- package/dist/core/never-proxy-policy.js +109 -0
- package/dist/core/never-schema.js +61 -0
- package/dist/core/never-tools.js +56 -0
- package/dist/core/notices.js +48 -0
- package/dist/core/ops.js +959 -0
- package/dist/core/outcome.js +224 -0
- package/dist/core/params.js +32 -0
- package/dist/core/presence.js +174 -0
- package/dist/core/procs.js +546 -0
- package/dist/core/prompts.js +363 -0
- package/dist/core/protected-config.js +238 -0
- package/dist/core/raw-network.js +192 -0
- package/dist/core/redact.js +152 -0
- package/dist/core/refusal.js +33 -0
- package/dist/core/relay-command.js +310 -0
- package/dist/core/reported.js +3 -0
- package/dist/core/restart-overlay.js +651 -0
- package/dist/core/retention.js +1135 -0
- package/dist/core/secrets.js +329 -0
- package/dist/core/session-token.js +175 -0
- package/dist/core/session.js +744 -0
- package/dist/core/shell.js +2 -0
- package/dist/core/shipped-pin.js +47 -0
- package/dist/core/shown.js +42 -0
- package/dist/core/slots.js +67 -0
- package/dist/core/stage2-executors.js +453 -0
- package/dist/core/stage2-switch.js +5 -0
- package/dist/core/steering.js +149 -0
- package/dist/core/storage.js +358 -0
- package/dist/core/toml.js +175 -0
- package/dist/core/views.js +324 -0
- package/dist/core/wait.js +114 -0
- package/dist/core/wake.js +207 -0
- package/dist/core/watch.js +247 -0
- package/dist/core/worktree.js +213 -0
- package/dist/hosts/claude-desktop.js +274 -0
- package/dist/hosts/claude.js +249 -0
- package/dist/hosts/codex.js +345 -0
- package/dist/hosts/desktop-shared.js +20 -0
- package/dist/hosts/index.js +11 -0
- package/dist/hosts/types.js +4 -0
- package/dist/install/basics.js +18 -0
- package/dist/install/claude-init.js +133 -0
- package/dist/install/common.js +655 -0
- package/dist/install/doctor.js +635 -0
- package/dist/install/qualify-codex.js +205 -0
- package/dist/install.js +524 -0
- package/dist/mcp/elicit.js +209 -0
- package/dist/mcp/gateway.js +218 -0
- package/dist/mcp/host.js +253 -0
- package/dist/mcp/server.js +1124 -0
- package/dist/mcp/stdio.js +37 -0
- package/dist/modes/discussion.js +393 -0
- package/dist/modes/review.js +722 -0
- package/dist/native/relay-sbcheck +0 -0
- package/dist/targets/briefs.js +86 -0
- package/dist/targets/claude.js +94 -0
- package/dist/targets/codex.js +66 -0
- package/dist/targets/copilot.js +93 -0
- package/dist/targets/gemini.js +119 -0
- package/dist/targets/grok.js +126 -0
- package/dist/targets/index.js +192 -0
- package/dist/targets/types.js +18 -0
- package/dist/targets/verified.js +35 -0
- package/dist/worker.js +113 -0
- package/docs/UPGRADING.md +1518 -0
- package/docs/pinned-codex.md +333 -0
- package/experiments/stage2-redteam/lib/oracles.mjs +214 -0
- package/experiments/stage2-redteam/lib/report.mjs +35 -0
- package/npm-shrinkwrap.json +1632 -0
- package/package.json +82 -4
- package/scripts/codex-qualify/codex-pin-store.mjs +353 -0
- package/scripts/codex-qualify/codex-qualifier-process.mjs +265 -0
- package/scripts/codex-qualify/codex-qualifier.example.json +5 -0
- package/scripts/codex-qualify/codex-qualifier.mjs +281 -0
- package/scripts/codex-qualify/codex-shipped-pin.mjs +158 -0
- package/scripts/codex-qualify/codex-stage2-pin.mjs +48 -0
- package/scripts/codex-qualify/codex-stage2.mjs +2381 -0
- package/scripts/codex-qualify/install-codex-qualifier.mjs +98 -0
- package/scripts/codex-qualify/main-module.mjs +14 -0
- package/scripts/codex-qualify/relay-codex-qualifier.plist +37 -0
- package/scripts/codex-qualify/scratch-env.mjs +31 -0
- package/scripts/codex-qualify/session.mjs +96 -0
- package/scripts/codex-qualify/stage2-escalation-cases.mjs +125 -0
- package/test/codex-permissions.test.ts +875 -0
- package/test/fixtures/boundary-probes.mjs +17 -0
- package/test/fixtures/denial-stream-host.mjs +7 -0
- package/test/fixtures/families.json +246 -0
- package/test/fixtures/install-snapshots/claude-desktop-foreign.txt +158 -0
- package/test/fixtures/install-snapshots/claude-desktop-fresh.txt +101 -0
- package/test/fixtures/install-snapshots/claude-desktop-installed.txt +161 -0
- package/test/fixtures/install-snapshots/claude-foreign.txt +133 -0
- package/test/fixtures/install-snapshots/claude-fresh.txt +77 -0
- package/test/fixtures/install-snapshots/claude-installed.txt +133 -0
- package/test/fixtures/install-snapshots/codex-foreign.txt +159 -0
- package/test/fixtures/install-snapshots/codex-fresh.txt +107 -0
- package/test/fixtures/install-snapshots/codex-installed.txt +161 -0
- package/test/fixtures/link-parent.mjs +6 -0
- package/test/fixtures/mediated-command.cjs +72 -0
- package/test/fixtures/native-skill-isolation.json +280 -0
- package/test/fixtures/pinned-codex-app-server.mjs +25 -0
- package/test/fixtures/qualified-ext-adapters.mjs +36 -0
- package/test/fixtures/refusals/README.md +52 -0
- package/test/fixtures/refusals/claude-source-result.json +7 -0
- package/test/fixtures/refusals/openai-app-capacity.json +24 -0
- package/test/fixtures/refusals/openai-app-cyberPolicy.json +24 -0
- package/test/fixtures/refusals/openai-gpt-6-astra-max.json +12 -0
- package/test/fixtures/refusals/openai-gpt-6.1-sol-xhigh.json +12 -0
- package/test/fixtures/refusals/openai-review-capacity.json +24 -0
- package/test/fixtures/relay-0.2.0.sql +57 -0
- package/test/fixtures/relay-0.9.1.gen.mjs +212 -0
- package/test/fixtures/relay-0.9.1.sql +340 -0
- package/test/fixtures/slow-boundary-probes.mjs +37 -0
- package/test/fixtures/stable-surfaces/config.json +1122 -0
- package/test/fixtures/stable-surfaces/escalation.json +128 -0
- package/test/fixtures/stable-surfaces/events.json +37 -0
- package/test/fixtures/stable-surfaces/gemini-native-resume.json +4 -0
- package/test/fixtures/stable-surfaces/inbox.jsonl +2 -0
- package/test/fixtures/stable-surfaces/notice.txt +1 -0
- package/test/fixtures/stable-surfaces/refusal-item.json +28 -0
- package/test/fixtures/stable-surfaces/refusal-review.json +23 -0
- package/test/fixtures/stable-surfaces/registry.json +49 -0
- package/test/fixtures/stable-surfaces/tools-desktop.json +575 -0
- package/test/fixtures/stable-surfaces/tools.json +716 -0
- package/test/fixtures/stable-surfaces/usage.txt +46 -0
- package/test/fixtures/stage2-acp-native.mjs +138 -0
- package/test/fixtures/stage2-app-server.mjs +23 -0
- package/test/fixtures/stage2-catalog.json +91 -0
- package/test/fixtures/stage2-hostile-web.mjs +35 -0
- package/test/fixtures/stage2-native-network.mjs +62 -0
- package/test/fixtures/stage2-worker.ts +87 -0
- package/test/fixtures/status-views/expected.json +7825 -0
- package/test/fixtures/status-views/registries.json +1 -0
- package/test/fixtures/steering.json +209 -0
- package/test/helpers.ts +740 -0
- package/test/host-env.ts +7 -0
- package/test/keychain-decoy.ts +197 -0
- package/test/live-scope.ts +44 -0
- package/test/mediated-network.test.ts +192 -0
- package/test/mediated-proxy.test.ts +264 -0
- package/test/native-temp-alias.ts +10 -0
- package/test/never-policy.test.ts +629 -0
- package/test/never-tools.test.ts +136 -0
- package/test/process-home.ts +18 -0
- package/test/proxy.test.ts +531 -0
- package/test/restart-overlay-live.test.ts +85 -0
- package/test/restart-overlay-profile.test.ts +66 -0
- package/test/restart-overlay.test.ts +416 -0
- package/test/stable-surfaces.test.ts +249 -0
- package/test/stage2-escalation-live.test.ts +544 -0
- package/test/stage2-escalation-qualification.test.ts +170 -0
- package/test/stage2-escalation.test.ts +747 -0
- package/test/stage2-executor.test.ts +849 -0
- package/test/stage2-grant.test.ts +603 -0
- package/test/stage2-native-live.test.ts +647 -0
- package/test/stage2-network-decisions.test.ts +70 -0
- package/test/stage2-probe.test.ts +845 -0
- package/test/stage2-standing-live.test.ts +203 -0
- package/test/stubs/broker-host.mjs +59 -0
- package/test/stubs/broker-peer.mjs +20 -0
- package/test/stubs/confined-harness.mjs +91 -0
- package/test/stubs/ext-broken-server.mjs +2 -0
- package/test/stubs/ext-odd-server.mjs +21 -0
- package/test/stubs/ext-server.mjs +31 -0
- package/test/stubs/fake-host-cli.mjs +218 -0
- package/test/stubs/procargs.mjs +30 -0
- package/test/stubs/stub-acp +4 -0
- package/test/stubs/stub-agent.mjs +322 -0
- package/test/stubs/stub-claude +4 -0
- package/test/stubs/stub-codex +4 -0
- package/test/stubs/targets/acp.mjs +307 -0
- package/test/stubs/targets/claude.mjs +149 -0
- package/test/stubs/targets/codex.mjs +479 -0
- package/test/stubs/targets/gemini.mjs +604 -0
- package/test/temp-root.ts +11 -0
- package/test/wp4-adapters.test.ts +353 -0
- package/test/wp4-interlock.test.ts +136 -0
|
@@ -0,0 +1,845 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import crypto from "node:crypto";
|
|
4
|
+
import dgram from "node:dgram";
|
|
5
|
+
import { EventEmitter } from "node:events";
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import net, { connect as netConnect } from "node:net";
|
|
8
|
+
import os from "node:os";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { test } from "node:test";
|
|
11
|
+
import type { CanaryStep, ListenPortAttempt, ListenPortOutcome } from "../dist/confine/canary.js";
|
|
12
|
+
import { ConfinementRefused, prepareLaunch, type Confinement, type ConfinementPolicy, type ProbeReport } from "../dist/confine/index.js";
|
|
13
|
+
import { decoyNetwork, localDestinations as allLocalDestinations, planStage2Network, stage2Port0RetryBudget, stage2ProbeExpectations, type ProbePlanner } from "../dist/confine/probe-stage2.js";
|
|
14
|
+
import { STATIC_DENIED_TCP, STATIC_DENIED_UDP } from "../dist/confine/ports.js";
|
|
15
|
+
import { canonical, dirIdentity, seatbelt, SANDBOX_EXEC } from "../dist/confine/seatbelt.js";
|
|
16
|
+
import { stage2NetworkRules, type Stage2Network } from "../dist/confine/seatbelt-stage2.js";
|
|
17
|
+
import { neverPathIdentity, resolveNeverPolicy } from "../dist/core/never-policy.js";
|
|
18
|
+
// Also for its side effect: the test process gets a scratch HOME (see helpers.ts).
|
|
19
|
+
import { REAL_HOME, scratchOnly, until } from "./helpers.ts";
|
|
20
|
+
import { TEST_HOME_PARENT } from "./process-home.ts";
|
|
21
|
+
|
|
22
|
+
// macOS rotates AirDrop's link-local address (awdl0, llw0) by itself, so a probe may not see the one listed here, and the reverse.
|
|
23
|
+
const rotating = (n: string) => /%(awdl|llw)\d+$/.test(n);
|
|
24
|
+
const localDestinations = () => allLocalDestinations().filter((h: string) => !rotating(h));
|
|
25
|
+
|
|
26
|
+
// Stage 2's probe mode (docs/codex-confinement-design.md §7.1, §13.2 WP-B): every stage-2 network
|
|
27
|
+
// check runs against relay's own decoys, passes under a stage-2 profile, and fails when the rule it
|
|
28
|
+
// stands for is missing (the negative controls).
|
|
29
|
+
|
|
30
|
+
const macOS = process.platform === "darwin" && fs.existsSync(SANDBOX_EXEC);
|
|
31
|
+
const sha = (s: string) => crypto.createHash("sha256").update(s).digest("hex");
|
|
32
|
+
|
|
33
|
+
/** The real ports a stage-2 turn would get (static list plus a snapshot port, relay's range and a lease); never probed. */
|
|
34
|
+
const BLOCK = [47204, 47205, 47206, 47207];
|
|
35
|
+
const REAL: Stage2Network = {
|
|
36
|
+
mode: "stage2",
|
|
37
|
+
deniedTcp: [...STATIC_DENIED_TCP, 51125],
|
|
38
|
+
deniedUdp: [...STATIC_DENIED_UDP],
|
|
39
|
+
relayRange: Array.from({ length: 64 }, (_, i) => 47200 + i).filter((p) => !BLOCK.includes(p)),
|
|
40
|
+
execPort: 47200,
|
|
41
|
+
bindPorts: BLOCK,
|
|
42
|
+
worktreeSockets: false,
|
|
43
|
+
};
|
|
44
|
+
const REAL_PORTS = new Set([...REAL.deniedTcp, ...REAL.deniedUdp, ...REAL.relayRange, ...REAL.bindPorts, REAL.execPort]);
|
|
45
|
+
/** The person's own services: no probe may aim at them, whatever the profile (the WP-B brief). */
|
|
46
|
+
const NEVER = [22, 5900, 3283, 3031, 445, 548, 631];
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Design §5.1's rules, one per form, for the probes until WP-A's stage2NetworkRules lands: a stand-in,
|
|
50
|
+
* not the generator. Every port and path is a parameter, as there.
|
|
51
|
+
*/
|
|
52
|
+
function section51(n: Stage2Network, param: (name: string, value: string) => string, diag: string, paths: { worktree: string }): string {
|
|
53
|
+
const L = ["; --- stage 2 network (test stand-in for WP-A, design §5.1)", '(allow network-outbound (remote ip4 "*:*") (remote ip6 "*:*"))'];
|
|
54
|
+
// Review R1: IPv4 at this Mac's addresses, IPv6 at every host (the IPv4-mapped spellings), never a family-less "ip".
|
|
55
|
+
const deny = (q: string) => `(deny network-outbound (remote ip4 (string-append "localhost:" ${q})) ${diag})\n(deny network-outbound (remote ip6 (string-append "*:" ${q})) ${diag})`;
|
|
56
|
+
n.deniedTcp.forEach((p, i) => L.push(deny(param(`DENY_PORT_${i}`, String(p)))));
|
|
57
|
+
n.relayRange.forEach((p, i) => L.push(deny(param(`RELAY_PORT_${i}`, String(p)))));
|
|
58
|
+
n.deniedUdp.forEach((p, i) => L.push(`(deny network-outbound (remote udp (string-append "*:" ${param(`UDP_DENY_${i}`, String(p))})) ${diag})`));
|
|
59
|
+
L.push(
|
|
60
|
+
"(allow system-socket (require-all (socket-domain AF_SYSTEM) (socket-protocol 2)))",
|
|
61
|
+
'(allow mach-lookup (global-name "com.apple.dnssd.service") (global-name "com.apple.mDNSResponder") (global-name "com.apple.SystemConfiguration.configd") (global-name "com.apple.SystemConfiguration.DNSConfiguration") (global-name "com.apple.networkd") (global-name "com.apple.nehelper"))',
|
|
62
|
+
'(allow network-outbound (literal "/private/var/run/mDNSResponder"))',
|
|
63
|
+
);
|
|
64
|
+
const tcpLocal = (p: string) => `(local tcp (string-append "localhost:" ${p}))`;
|
|
65
|
+
const exec = param("EXEC_PORT", String(n.execPort));
|
|
66
|
+
L.push(`(allow network-bind ${tcpLocal(exec)})`, `(allow network-inbound ${tcpLocal(exec)})`);
|
|
67
|
+
n.bindPorts.forEach((p, i) => {
|
|
68
|
+
const b = param(`BIND_PORT_${i}`, String(p));
|
|
69
|
+
L.push(`(allow network-bind ${tcpLocal(b)})`, `(allow network-inbound ${tcpLocal(b)})`);
|
|
70
|
+
});
|
|
71
|
+
L.push('(allow network-bind (local udp "localhost:*"))');
|
|
72
|
+
L.push('(allow network-bind (local unix-socket (subpath (param "TMPDIR"))))', '(allow network-outbound (remote unix-socket (subpath (param "TMPDIR"))))');
|
|
73
|
+
if (n.worktreeSockets) {
|
|
74
|
+
const w = param("WORKTREE", paths.worktree);
|
|
75
|
+
L.push(`(allow network-bind (local unix-socket (subpath ${w})))`, `(allow network-outbound (remote unix-socket (subpath ${w})))`);
|
|
76
|
+
}
|
|
77
|
+
return L.join("\n");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** relay's Seatbelt with design §5.1's rules in place of the network-on block, for stage-2 policies. */
|
|
81
|
+
const standIn: Confinement = {
|
|
82
|
+
...seatbelt,
|
|
83
|
+
wrap(policy, command, args) {
|
|
84
|
+
if (policy.network.mode !== "stage2") return seatbelt.wrap(policy, command, args);
|
|
85
|
+
const l = seatbelt.wrap({ ...policy, network: { mode: "on" } }, command, args);
|
|
86
|
+
const extra: string[] = [];
|
|
87
|
+
const param = (name: string, value: string) => (extra.push("-D", `${name}=${value}`), `(param "${name}")`);
|
|
88
|
+
const text = section51(policy.network, param, '(with message (param "DIAG_TAG"))', { worktree: canonical(policy.worktree) });
|
|
89
|
+
const start = l.args[1].indexOf("; --- network on");
|
|
90
|
+
const last = '(allow network-outbound (literal "/private/var/run/mDNSResponder"))';
|
|
91
|
+
const end = l.args[1].indexOf(last, start);
|
|
92
|
+
assert.ok(start >= 0 && end > start, "the network-on block is where the stand-in expects it");
|
|
93
|
+
const profile = l.args[1].slice(0, start) + text + l.args[1].slice(end + last.length);
|
|
94
|
+
const fix = (a: string[]) => ["-p", profile, ...extra, ...a.slice(2)];
|
|
95
|
+
return { ...l, args: fix(l.args), rewrap: (c, a) => ({ ...l.rewrap(c, a), args: fix(l.rewrap(c, a).args) }), rules: sha(profile), fingerprint: sha(JSON.stringify({ args: fix(l.args), env: l.env })) };
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/** WP-A's generator, once it is in this build: the probes then run under it too. */
|
|
100
|
+
const wpaReady = (() => {
|
|
101
|
+
try {
|
|
102
|
+
stage2NetworkRules(REAL, (n) => `(param "${n}")`, "", { tmpDir: "/tmp", worktree: "/tmp" });
|
|
103
|
+
return true;
|
|
104
|
+
} catch (err) {
|
|
105
|
+
if (/not implemented/.test((err as Error).message)) return false;
|
|
106
|
+
throw err;
|
|
107
|
+
}
|
|
108
|
+
})();
|
|
109
|
+
const MECHANISMS: [string, Confinement][] = [["design §5.1 stand-in", standIn], ...(wpaReady ? [["WP-A's rules", seatbelt] as [string, Confinement]] : [])];
|
|
110
|
+
|
|
111
|
+
/** The top-level forms of a profile kept by `keep` (comments and strings respected); the rest dropped. */
|
|
112
|
+
function keepForms(profile: string, keep: (form: string) => boolean): string {
|
|
113
|
+
let out = "";
|
|
114
|
+
let i = 0;
|
|
115
|
+
while (i < profile.length) {
|
|
116
|
+
const ch = profile[i];
|
|
117
|
+
if (ch === ";") {
|
|
118
|
+
const e = profile.indexOf("\n", i);
|
|
119
|
+
out += profile.slice(i, e < 0 ? profile.length : e);
|
|
120
|
+
i = e < 0 ? profile.length : e;
|
|
121
|
+
} else if (ch === "(") {
|
|
122
|
+
let depth = 0;
|
|
123
|
+
let j = i;
|
|
124
|
+
for (; j < profile.length; j++) {
|
|
125
|
+
const c = profile[j];
|
|
126
|
+
if (c === '"') {
|
|
127
|
+
for (j++; profile[j] !== '"'; j++) if (profile[j] === "\\") j++;
|
|
128
|
+
} else if (c === ";") {
|
|
129
|
+
while (j < profile.length && profile[j] !== "\n") j++;
|
|
130
|
+
} else if (c === "(") depth++;
|
|
131
|
+
else if (c === ")" && --depth === 0) break;
|
|
132
|
+
}
|
|
133
|
+
const form = profile.slice(i, j + 1);
|
|
134
|
+
if (keep(form)) out += form;
|
|
135
|
+
i = j + 1;
|
|
136
|
+
} else {
|
|
137
|
+
out += ch;
|
|
138
|
+
i++;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return out;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* A mechanism whose every wrap (the turn's and the decoy's alike, so the rules hashes still agree)
|
|
146
|
+
* has its profile edited: what a generator bug would look like.
|
|
147
|
+
*/
|
|
148
|
+
function edited(base: Confinement, edit: (profile: string, params: Map<string, string>, policy: ConfinementPolicy) => string): Confinement {
|
|
149
|
+
return {
|
|
150
|
+
...base,
|
|
151
|
+
wrap(policy, command, args) {
|
|
152
|
+
const l = base.wrap(policy, command, args);
|
|
153
|
+
const params = new Map<string, string>();
|
|
154
|
+
for (let i = 2; l.args[i] === "-D"; i += 2) {
|
|
155
|
+
const kv = l.args[i + 1];
|
|
156
|
+
params.set(kv.slice(0, kv.indexOf("=")), kv.slice(kv.indexOf("=") + 1));
|
|
157
|
+
}
|
|
158
|
+
const profile = edit(l.args[1], params, policy);
|
|
159
|
+
assert.notEqual(profile, l.args[1], "the edit changed the profile");
|
|
160
|
+
const fix = (a: string[]) => ["-p", profile, ...a.slice(2)];
|
|
161
|
+
return { ...l, args: fix(l.args), rewrap: (c, a) => ({ ...l.rewrap(c, a), args: fix(l.rewrap(c, a).args) }), rules: sha(profile), fingerprint: sha(JSON.stringify({ args: fix(l.args), env: l.env })) };
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Drops the rules (top-level forms) matching `kind` that name a parameter whose value is one of `values(network)`. */
|
|
167
|
+
const without = (base: Confinement, kind: RegExp, values: (n: Stage2Network, p: ConfinementPolicy) => (string | number)[]) =>
|
|
168
|
+
edited(base, (profile, params, policy) => {
|
|
169
|
+
const want = new Set(values(policy.network as Stage2Network, policy).map(String));
|
|
170
|
+
const names = new Set([...params].filter(([, v]) => want.has(v)).map(([k]) => k));
|
|
171
|
+
return keepForms(profile, (form) => {
|
|
172
|
+
const drop = kind.test(form) && [...form.matchAll(/\(param "([^"]+)"\)/g)].some((m) => names.has(m[1]));
|
|
173
|
+
return !drop;
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
/** Drops the rules matching `kind`, whatever they name. */
|
|
177
|
+
const withoutForms = (base: Confinement, kind: RegExp) => edited(base, (profile) => keepForms(profile, (form) => !kind.test(form)));
|
|
178
|
+
/** Adds a rule at the end, where it wins. */
|
|
179
|
+
const plus = (base: Confinement, rule: (p: ConfinementPolicy) => string) => edited(base, (profile, _params, policy) => `${profile}\n${rule(policy)}\n`);
|
|
180
|
+
/**
|
|
181
|
+
* Adds a rule naming a parameter of its own, set per wrap to `value(policy)`: a rule about the turn's
|
|
182
|
+
* own paths (its cwd, say) that stays the same text for the turn and its decoy, as the generator's would.
|
|
183
|
+
*/
|
|
184
|
+
function plusParam(base: Confinement, name: string, value: (p: ConfinementPolicy) => string, rule: string): Confinement {
|
|
185
|
+
return {
|
|
186
|
+
...base,
|
|
187
|
+
wrap(policy, command, args) {
|
|
188
|
+
const l = base.wrap(policy, command, args);
|
|
189
|
+
const profile = `${l.args[1]}\n${rule}\n`;
|
|
190
|
+
const fix = (a: string[]) => ["-p", profile, "-D", `${name}=${value(policy)}`, ...a.slice(2)];
|
|
191
|
+
return { ...l, args: fix(l.args), rewrap: (c, a) => ({ ...l.rewrap(c, a), args: fix(l.rewrap(c, a).args) }), rules: sha(profile), fingerprint: sha(JSON.stringify({ args: fix(l.args), env: l.env })) };
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** A run directory as relay lays it out (as test/probe.test.ts's): this turn's worktree and a sibling's, a control dir, a temp dir, a scratch home and harness. */
|
|
197
|
+
function scratch() {
|
|
198
|
+
// This fixture adds /home below the scratch root, unlike process-home.ts.
|
|
199
|
+
const example = path.join(TEST_HOME_PARENT, "s2p-XXXXXX", "home", ".relay-t/s/relay-probe-XXXXXX/relay.sock");
|
|
200
|
+
const parent = Buffer.byteLength(example) <= 103 ? TEST_HOME_PARENT : fs.realpathSync("/tmp");
|
|
201
|
+
const root = fs.realpathSync(fs.mkdtempSync(path.join(parent, "s2p-")));
|
|
202
|
+
const run = path.join(root, "worktrees", "r_1");
|
|
203
|
+
const wt = path.join(run, "j_this");
|
|
204
|
+
const sibling = path.join(run, "j_sibling");
|
|
205
|
+
const checkout = path.join(root, "checkout");
|
|
206
|
+
const control = path.join(root, "control");
|
|
207
|
+
const tmp = path.join(root, "turn-tmp");
|
|
208
|
+
for (const d of [wt, sibling, checkout, control, tmp]) fs.mkdirSync(d, { recursive: true });
|
|
209
|
+
fs.writeFileSync(path.join(wt, ".git"), "gitdir: /nowhere\n");
|
|
210
|
+
fs.writeFileSync(path.join(control, "relay.db"), "secret\n");
|
|
211
|
+
process.env.RELAY_HOME = control;
|
|
212
|
+
const realHomeVar = process.env.HOME;
|
|
213
|
+
const home = path.join(root, "home");
|
|
214
|
+
fs.mkdirSync(home);
|
|
215
|
+
process.env.HOME = home;
|
|
216
|
+
const harness = path.join(root, "bin", "harness");
|
|
217
|
+
fs.mkdirSync(path.dirname(harness));
|
|
218
|
+
fs.writeFileSync(harness, `#!/bin/sh\nexec ${JSON.stringify(process.execPath)} "$@"\n`, { mode: 0o755 });
|
|
219
|
+
return {
|
|
220
|
+
root, wt, checkout, control, tmp, harness,
|
|
221
|
+
done: () => {
|
|
222
|
+
process.env.HOME = realHomeVar;
|
|
223
|
+
// Every process the probes started is gone: none still names the run directory.
|
|
224
|
+
const left = spawnSync("/usr/bin/pgrep", ["-f", root], { encoding: "utf8" }).stdout.trim();
|
|
225
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
226
|
+
assert.equal(left, "", `processes left running: ${left}`);
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
type Scratch = ReturnType<typeof scratch>;
|
|
231
|
+
|
|
232
|
+
/** The turn kinds of §2.3 and C4: a write turn in relay's worktree, one in a worktree relay did not make, a read turn in relay's worktree, a read turn in the person's checkout. */
|
|
233
|
+
const TURNS = {
|
|
234
|
+
write: (s: Scratch): ConfinementPolicy => ({ worktree: s.wt, worktreePin: dirIdentity(s.wt), worktreeWritable: true, tmpDir: s.tmp, denied: [s.control], network: { ...REAL, worktreeSockets: true } }),
|
|
235
|
+
/** A write turn in a worktree relay did not make (no pin): no sockets there (C4). */
|
|
236
|
+
"write-unpinned": (s: Scratch): ConfinementPolicy => ({ worktree: s.wt, worktreeWritable: true, tmpDir: s.tmp, denied: [s.control], network: REAL }),
|
|
237
|
+
"read-relay-worktree": (s: Scratch): ConfinementPolicy => ({ worktree: s.wt, worktreePin: dirIdentity(s.wt), worktreeWritable: false, tmpDir: s.tmp, denied: [s.control], network: REAL }),
|
|
238
|
+
"read-checkout": (s: Scratch): ConfinementPolicy => ({ worktree: s.checkout, worktreeWritable: false, tmpDir: s.tmp, denied: [s.control], network: REAL }),
|
|
239
|
+
} as const;
|
|
240
|
+
|
|
241
|
+
const launched = (m: Confinement, policy: ConfinementPolicy, s: Scratch) => prepareLaunch(m, policy, scratchOnly(s.harness, "harness"), []);
|
|
242
|
+
const byName = (r: ProbeReport) => Object.fromEntries(r.results.map((x) => [x.name, x]));
|
|
243
|
+
const REVERSED = ["tcp-loopback", "tcp-loopback-v6", "tcp-loopback-link-local", "unix-listen-worktree", "listen-loopback", "listen-any"];
|
|
244
|
+
|
|
245
|
+
/** No probe aimed at a real port of the turn, at the person's services, at the real home or outside the scratch tree with a write. */
|
|
246
|
+
function assertTargets(r: ProbeReport) {
|
|
247
|
+
for (const x of r.results) {
|
|
248
|
+
const m = x.target && /:(\d+)$/.exec(x.target);
|
|
249
|
+
if (m && x.name.startsWith("stage2-")) {
|
|
250
|
+
assert.ok(!REAL_PORTS.has(Number(m[1])) && !NEVER.includes(Number(m[1])), `${x.name} aimed at a real port: ${x.target}`);
|
|
251
|
+
}
|
|
252
|
+
if (x.target) assert.ok(!x.target.includes(REAL_HOME + "/"), `${x.name} aimed at the real home: ${x.target}`);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** Nothing the probes made is left in the worktree, the checkout or the temp dir. */
|
|
257
|
+
function assertClean(s: Scratch) {
|
|
258
|
+
for (const d of [s.wt, s.checkout, s.tmp]) {
|
|
259
|
+
assert.deepEqual(fs.readdirSync(d).filter((n) => n.startsWith(".relay-probe-") || n.endsWith(".sock")), [], `nothing left in ${d}`);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** A fake planner: what planStage2Network asks for, by name. */
|
|
264
|
+
function fakePlanner() {
|
|
265
|
+
const plan: Record<string, { expect: "allow" | "deny"; step?: unknown; skip?: string; decoy?: boolean; judge?: (g: string) => boolean }> = {};
|
|
266
|
+
let decoyPolicy: (ConfinementPolicy & { network: Stage2Network }) | undefined;
|
|
267
|
+
const p: ProbePlanner = {
|
|
268
|
+
allow: (n, step) => void (plan[n] = { expect: "allow", step }),
|
|
269
|
+
deny: (n, step) => void (plan[n] = { expect: "deny", step }),
|
|
270
|
+
skip: (n, expect, why) => void (plan[n] = { expect, skip: why }),
|
|
271
|
+
created: [], closers: [], servers: [],
|
|
272
|
+
decoy(dp) {
|
|
273
|
+
assert.equal(decoyPolicy, undefined, "one decoy per probe");
|
|
274
|
+
decoyPolicy = dp;
|
|
275
|
+
return { allow: (name, step, judge) => void (plan[name] = { expect: "allow", step, decoy: true, judge }), deny: (name, step, judge) => void (plan[name] = { expect: "deny", step, decoy: true, judge }) };
|
|
276
|
+
},
|
|
277
|
+
};
|
|
278
|
+
return { p, plan, decoyPolicy: () => decoyPolicy!, network: () => decoyPolicy!.network, close: () => (p.servers.forEach((x) => x.close()), p.closers.forEach(c => c()), p.created.forEach((c) => fs.rmSync(c, { force: true }))) };
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const fiveAttemptBudget = { longestDeniedRun: 1, maxAttempts: 5 };
|
|
282
|
+
|
|
283
|
+
/** Exercise the real canary entry point with injected listen events; no host sockets are opened. */
|
|
284
|
+
function listenCanary(step: CanaryStep, outcomes: ListenPortAttempt[]) {
|
|
285
|
+
const preload = `
|
|
286
|
+
import assert from "node:assert/strict";
|
|
287
|
+
import net from "node:net";
|
|
288
|
+
const outcomes = ${JSON.stringify(outcomes)};
|
|
289
|
+
const servers = new Set();
|
|
290
|
+
const addresses = new WeakMap();
|
|
291
|
+
let calls = 0, closed = 0;
|
|
292
|
+
net.Server.prototype.listen = function(port, host, ready) {
|
|
293
|
+
assert.ok(!servers.has(this), "each attempt uses a fresh server");
|
|
294
|
+
servers.add(this);
|
|
295
|
+
const result = outcomes[calls++] ?? outcomes.at(-1);
|
|
296
|
+
addresses.set(this, result.port === null ? null : { port: result.port });
|
|
297
|
+
queueMicrotask(() => result.errorCode ? this.emit("error", Object.assign(new Error(result.errorCode), { code: result.errorCode })) : ready());
|
|
298
|
+
return this;
|
|
299
|
+
};
|
|
300
|
+
net.Server.prototype.address = function() { return addresses.get(this); };
|
|
301
|
+
net.Server.prototype.close = function(done) {
|
|
302
|
+
closed++;
|
|
303
|
+
queueMicrotask(done);
|
|
304
|
+
return this;
|
|
305
|
+
};
|
|
306
|
+
process.on("exit", () => process.stderr.write(JSON.stringify({ calls, closed, servers: servers.size })));
|
|
307
|
+
`;
|
|
308
|
+
const r = spawnSync(process.execPath, ["--import", `data:text/javascript,${encodeURIComponent(preload)}`,
|
|
309
|
+
path.resolve(import.meta.dirname, "../dist/confine/canary.js"), JSON.stringify({ listen: step })], { encoding: "utf8", timeout: 5000 });
|
|
310
|
+
assert.equal(r.error, undefined, String(r.error));
|
|
311
|
+
assert.equal(r.status, 0, r.stderr);
|
|
312
|
+
const stats = JSON.parse(r.stderr) as { calls: number; closed: number; servers: number };
|
|
313
|
+
assert.equal(stats.servers, stats.calls);
|
|
314
|
+
assert.equal(stats.closed, stats.calls, "every attempt closes its server before continuing");
|
|
315
|
+
return { got: JSON.parse(r.stdout).listen as string, calls: stats.calls };
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
test("stage-2 port-0 canary: EPERM then a successful listen records both attempts and the assigned port", () => {
|
|
319
|
+
const attempts = [{ errorCode: "EPERM", port: null }, { errorCode: null, port: 54321 }];
|
|
320
|
+
for (const host of ["127.0.0.1", "0.0.0.0"]) {
|
|
321
|
+
const { got, calls } = listenCanary({ kind: "listen-port", host, port: 0, connect: false, retryOnEperm: fiveAttemptBudget }, attempts);
|
|
322
|
+
assert.equal(calls, 2);
|
|
323
|
+
assert.deepEqual(JSON.parse(got), { outcome: "allowed", attemptCount: 2, attempts, retryBudget: fiveAttemptBudget });
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
test("stage-2 port-0 canary: five EPERMs fail and preserve unavailable and reported assigned ports", () => {
|
|
328
|
+
const attempts = Array.from({ length: 5 }, (_, i) => ({ errorCode: "EPERM", port: i === 0 ? 54320 : null }));
|
|
329
|
+
const { got, calls } = listenCanary({ kind: "listen-port", host: "127.0.0.1", port: 0, connect: false, retryOnEperm: fiveAttemptBudget }, attempts);
|
|
330
|
+
assert.equal(calls, 5);
|
|
331
|
+
assert.deepEqual(JSON.parse(got), { outcome: "EPERM", attemptCount: 5, attempts, retryBudget: fiveAttemptBudget });
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
test("stage-2 port-0 canary: errors other than EPERM are never retried", () => {
|
|
335
|
+
for (const errorCode of ["EACCES", "EADDRINUSE"]) {
|
|
336
|
+
const attempts = [{ errorCode, port: null }];
|
|
337
|
+
const { got, calls } = listenCanary({ kind: "listen-port", host: "127.0.0.1", port: 0, connect: false, retryOnEperm: fiveAttemptBudget }, attempts);
|
|
338
|
+
assert.equal(calls, 1);
|
|
339
|
+
assert.deepEqual(JSON.parse(got), { outcome: errorCode, attemptCount: 1, attempts, retryBudget: fiveAttemptBudget });
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
test("stage-2 listen canary: negative port-0 checks, fixed ports and self-connect controls stay single-shot", () => {
|
|
344
|
+
const steps: CanaryStep[] = [
|
|
345
|
+
{ kind: "listen-port", host: "127.0.0.1", port: 0, connect: false },
|
|
346
|
+
{ kind: "listen-port", host: "127.0.0.1", port: 54321, connect: false },
|
|
347
|
+
{ kind: "listen-port", host: "127.0.0.1", port: 54321, connect: false, retryOnEperm: fiveAttemptBudget },
|
|
348
|
+
{ kind: "listen-port", host: "127.0.0.1", port: 0, connect: true, retryOnEperm: fiveAttemptBudget },
|
|
349
|
+
];
|
|
350
|
+
for (const step of steps) {
|
|
351
|
+
const { got, calls } = listenCanary(step, [{ errorCode: "EPERM", port: null }, { errorCode: null, port: 54322 }]);
|
|
352
|
+
assert.equal(calls, 1);
|
|
353
|
+
assert.equal("retryOnEperm" in step ? (JSON.parse(got) as ListenPortOutcome).outcome : got, "EPERM");
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
test("stage-2 port-0 canary: a sequential allocator clears a 69-port denied run, and exhaustion still fails", () => {
|
|
358
|
+
const retryBudget = stage2Port0RetryBudget({ ...REAL, deniedTcp: Array.from({ length: 69 }, (_, i) => 60000 + i) });
|
|
359
|
+
assert.deepEqual(retryBudget, { longestDeniedRun: 69, maxAttempts: 71 });
|
|
360
|
+
const refusals = Array.from({ length: 69 }, (_, i) => ({ errorCode: "EPERM", port: 60000 + i }));
|
|
361
|
+
const attempts = [...refusals, { errorCode: null, port: 60069 }];
|
|
362
|
+
for (const host of ["127.0.0.1", "0.0.0.0"]) {
|
|
363
|
+
const step: CanaryStep = { kind: "listen-port", host, port: 0, connect: false, retryOnEperm: retryBudget };
|
|
364
|
+
const success = listenCanary(step, attempts);
|
|
365
|
+
assert.equal(success.calls, 70);
|
|
366
|
+
assert.deepEqual(JSON.parse(success.got), { outcome: "allowed", attemptCount: 70, attempts, retryBudget });
|
|
367
|
+
const failed = listenCanary(step, [{ errorCode: "EPERM", port: null }]);
|
|
368
|
+
assert.equal(failed.calls, 71);
|
|
369
|
+
const report = JSON.parse(failed.got) as ListenPortOutcome;
|
|
370
|
+
assert.equal(report.outcome, "EPERM");
|
|
371
|
+
assert.equal(report.attemptCount, 71);
|
|
372
|
+
assert.equal(report.attempts.length, 71);
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
test("stage-2 port-0 retry budget: TCP never/control floors extend runs; UDP and own ports do not", () => {
|
|
377
|
+
const network = { ...REAL, deniedTcp: [49151, 50000, 50001, 50002, 50003],
|
|
378
|
+
relayRange: [50004, 50005, 50006, 50007, 50008], execPort: 50004, bindPorts: [50012], listenPorts: [50002] };
|
|
379
|
+
const floor = { ...resolveNeverPolicy({ builtins: false, never: { ports: [
|
|
380
|
+
{ port: 50009, transport: "both" }, { port: 50010, transport: "tcp" }, { port: 50011, transport: "udp" },
|
|
381
|
+
] } }), authorityPorts: [50004, 50012, 50013, 50014] };
|
|
382
|
+
assert.deepEqual(stage2Port0RetryBudget(network, floor), { longestDeniedRun: 6, maxAttempts: 8 });
|
|
383
|
+
const snapshot = { ...REAL, deniedTcp: Array.from({ length: 6 }, (_, i) => 50000 + i), listenPorts: [50003] };
|
|
384
|
+
assert.deepEqual(stage2Port0RetryBudget(snapshot), { longestDeniedRun: 3, maxAttempts: 5 });
|
|
385
|
+
const override = resolveNeverPolicy({ builtins: false, never: { ports: [{ port: 50003, transport: "tcp" }] } });
|
|
386
|
+
assert.deepEqual(stage2Port0RetryBudget(snapshot, override), { longestDeniedRun: 6, maxAttempts: 8 }, "final never denies beat exact-listen exceptions");
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
test("stage-2 port-0 retry budget: joins runs across ephemeral wrap, ignores other ports and stays finite", () => {
|
|
390
|
+
assert.deepEqual(stage2Port0RetryBudget({ ...REAL, deniedTcp: [...STATIC_DENIED_TCP] }), { longestDeniedRun: 0, maxAttempts: 5 }, "the real 47200-47263 reserved range is outside the ephemeral range");
|
|
391
|
+
assert.deepEqual(stage2Port0RetryBudget({ ...REAL, deniedTcp: [49151, 49152, 49153, 49154, 65533, 65534, 65535] }), { longestDeniedRun: 6, maxAttempts: 8 });
|
|
392
|
+
assert.deepEqual(stage2Port0RetryBudget({ ...REAL, deniedTcp: Array.from({ length: 16384 }, (_, i) => 49152 + i) }), { longestDeniedRun: 16384, maxAttempts: 16386 });
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
test("stage-2 overlay expectation table: port0 changes bind only; localhost connects, listen and writes add no raw authority", () => {
|
|
396
|
+
for (const egress of [undefined, "raw", "none"] as const) for (const broadBind of [false, true]) {
|
|
397
|
+
const block = egress !== "none" || broadBind;
|
|
398
|
+
const network = { ...REAL, egress, broadBind, bindPorts: block ? REAL.bindPorts : [] };
|
|
399
|
+
const expected = { egress: egress === "none" ? "deny" : "allow", outsideListen: broadBind ? "allow" : "deny", blockListen: block ? "allow" : "deny", connectBlock: egress !== "none" && block };
|
|
400
|
+
assert.deepEqual(stage2ProbeExpectations(network), expected);
|
|
401
|
+
assert.deepEqual(stage2ProbeExpectations({ ...network, bindPorts: REAL.bindPorts, listenPorts: [51132] }), { ...expected, blockListen: "allow" }, "exact listen authorizes the reserved block without raw outbound");
|
|
402
|
+
assert.deepEqual(stage2ProbeExpectations({ ...network, connectPorts: [51133] }), expected, "localhost connect changes no bind expectation");
|
|
403
|
+
}
|
|
404
|
+
const real = { ...REAL, egress: "none" as const, broadBind: true, listenPorts: [51132], connectPorts: [51133] };
|
|
405
|
+
const decoys = { deniedTcp: REAL.deniedTcp.map((_, i) => 50000 + i), deniedUdp: [50100, 50101], relayRange: REAL.relayRange.map((_, i) => 50200 + i), bindPorts: [50300, 50301, 50302, 50303], execPort: 50200, listenPorts: [50400], connectPorts: [50401] };
|
|
406
|
+
const d = decoyNetwork(real, decoys);
|
|
407
|
+
assert.equal(d.egress, "none");
|
|
408
|
+
assert.equal(d.broadBind, true);
|
|
409
|
+
assert.deepEqual(d.listenPorts, [50400]);
|
|
410
|
+
assert.deepEqual(d.connectPorts, [50401]);
|
|
411
|
+
assert.throws(() => decoyNetwork(real, { ...decoys, listenPorts: [] }), /list length/);
|
|
412
|
+
assert.throws(() => decoyNetwork(real, { ...decoys, listenPorts: [51132] }), /one of the turn's real ports/);
|
|
413
|
+
assert.throws(() => decoyNetwork(real, { ...decoys, listenPorts: [900] }), /high range/);
|
|
414
|
+
assert.throws(() => decoyNetwork(real, { ...decoys, connectPorts: [] }), /list length/);
|
|
415
|
+
assert.throws(() => decoyNetwork(real, { ...decoys, connectPorts: [51133] }), /one of the turn's real ports/);
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
test("stage-2 overlay probe plan: trusted capabilities change only their own expectations, with scratch positive controls and unchanged final floors", async (t) => {
|
|
419
|
+
// This is a planner unit test: allocate synthetic high ports without opening sockets. The live
|
|
420
|
+
// controls below exercise real owned listeners and sandbox refusal, outside the test sandbox.
|
|
421
|
+
let nextPort = 52000;
|
|
422
|
+
// Force the random filler decoys to be contiguous: a worst-case layout that five tries cannot clear.
|
|
423
|
+
let nextFiller = 60000;
|
|
424
|
+
t.mock.method(Math, "random", () => (nextFiller++ - 49152 + 0.25) / 16384);
|
|
425
|
+
const bindings = new WeakMap<net.Server, number>();
|
|
426
|
+
t.mock.method(net.Server.prototype, "listen", function(this: net.Server, opts: { port: number }, ready: () => void) {
|
|
427
|
+
bindings.set(this, opts.port || nextPort++);
|
|
428
|
+
queueMicrotask(ready);
|
|
429
|
+
return this;
|
|
430
|
+
});
|
|
431
|
+
t.mock.method(net.Server.prototype, "address", function(this: net.Server) { return { address: "127.0.0.1", family: "IPv4", port: bindings.get(this) }; });
|
|
432
|
+
t.mock.method(net.Server.prototype, "close", function(this: net.Server, done?: () => void) { if (done) queueMicrotask(done); return this; });
|
|
433
|
+
t.mock.method(dgram, "createSocket", () => {
|
|
434
|
+
const port = nextPort++;
|
|
435
|
+
return Object.assign(new EventEmitter(), {
|
|
436
|
+
bind: (_port: number, _host: string, ready: () => void) => queueMicrotask(ready),
|
|
437
|
+
address: () => ({ port }), close: (done?: () => void) => { if (done) queueMicrotask(done); },
|
|
438
|
+
});
|
|
439
|
+
});
|
|
440
|
+
const s = scratch();
|
|
441
|
+
try {
|
|
442
|
+
const tree = path.join(s.root, "approved-tree");
|
|
443
|
+
const file = path.join(s.root, "approved-file");
|
|
444
|
+
const missing = path.join(s.root, "approved-missing-file");
|
|
445
|
+
fs.mkdirSync(tree);
|
|
446
|
+
fs.writeFileSync(file, "untouched\n");
|
|
447
|
+
const roots = [
|
|
448
|
+
{ root: tree, scope: "tree" as const, pins: neverPathIdentity(tree), existed: true },
|
|
449
|
+
{ root: file, scope: "file" as const, pins: neverPathIdentity(file), existed: true },
|
|
450
|
+
{ root: missing, scope: "file" as const, pins: neverPathIdentity(missing), existed: false },
|
|
451
|
+
];
|
|
452
|
+
const floor = resolveNeverPolicy({ builtins: false, never: { ports: [{ port: 51130, transport: "both", destinations: "this-machine" }] } });
|
|
453
|
+
// Control ports include our own executor/block (their existing exceptions must survive) and
|
|
454
|
+
// a different executor's assigned block (always denied), including an overlap with the range.
|
|
455
|
+
const neverPolicy = { ...floor, authorityPorts: [REAL.execPort, ...REAL.bindPorts, REAL.relayRange[1], 51131] };
|
|
456
|
+
for (const route of ["none", "raw", "mediated"] as const) for (const broadBind of [false, true]) for (const exact of [false, true]) {
|
|
457
|
+
const raw = route === "raw";
|
|
458
|
+
const f = fakePlanner();
|
|
459
|
+
const scr = fs.mkdtempSync(path.join(s.root, "overlay-scr-"));
|
|
460
|
+
const blockAllowed = raw || broadBind || exact;
|
|
461
|
+
const policy = { ...TURNS.write(s), writable: [tree], writablePins: [dirIdentity(tree)], overlayRoots: roots,
|
|
462
|
+
overlayFiles: roots.slice(1), neverPolicy,
|
|
463
|
+
network: { ...REAL, relayRange: blockAllowed ? REAL.relayRange : [...REAL.relayRange, ...REAL.bindPorts], bindPorts: blockAllowed ? REAL.bindPorts : [], ...(route === "mediated" ? { mediatedPort: REAL.relayRange[2] } : {}), worktreeSockets: true, egress: raw ? "raw" as const : "none" as const, broadBind, listenPorts: exact ? [51132] : [], connectPorts: exact ? [51133] : [] } };
|
|
464
|
+
try {
|
|
465
|
+
await planStage2Network(f.p, policy, { tag: ".relay-probe-0123456789ab", worktree: s.wt, tmpDir: s.tmp, scratch: scr });
|
|
466
|
+
assert.equal(f.plan["stage2-mediated-proxy"]?.expect, route === "mediated" ? "allow" : undefined);
|
|
467
|
+
if (route === "mediated") for (const name of ["stage2-mediated-proxy-ipv6", "stage2-mediated-proxy-mapped"]) assert.equal(f.plan[name]?.expect, "deny");
|
|
468
|
+
for (const name of ["stage2-tcp-open-port", "stage2-tcp-open-port@::ffff:127.0.0.1", "stage2-udp-bind", "stage2-udp-open-port"]) {
|
|
469
|
+
assert.equal(f.plan[name].expect, raw ? "allow" : "deny", name);
|
|
470
|
+
}
|
|
471
|
+
for (const name of ["stage2-listen-outside-block", "stage2-listen-port-0"]) assert.equal(f.plan[name].expect, broadBind ? "allow" : "deny", name);
|
|
472
|
+
assert.equal(f.plan["stage2-listen-block"].expect, blockAllowed ? "allow" : "deny");
|
|
473
|
+
assert.equal(f.plan["stage2-listen-block-any"].expect, blockAllowed ? "allow" : "deny");
|
|
474
|
+
assert.equal((f.plan["stage2-listen-block"].step as { connect: boolean }).connect, raw, "only raw authority adds an outbound self-connect");
|
|
475
|
+
assert.equal(f.plan["stage2-listen-overlay-0"]?.expect, exact ? "allow" : undefined);
|
|
476
|
+
assert.equal(f.plan["stage2-connect-overlay-0@127.0.0.1"]?.expect, exact ? "allow" : undefined);
|
|
477
|
+
if (exact && !raw) {
|
|
478
|
+
for (const host of ["127.0.0.2", "::1", "::ffff:127.0.0.1"]) assert.equal(f.plan[`stage2-connect-overlay-0-denied@${host}`].expect, "deny");
|
|
479
|
+
assert.equal(f.plan["stage2-connect-overlay-0-other-port"].expect, "deny");
|
|
480
|
+
}
|
|
481
|
+
assert.equal(f.plan["stage2-listen-port-0-any"]?.expect, broadBind ? "allow" : undefined);
|
|
482
|
+
for (const [name, check] of Object.entries(f.plan)) {
|
|
483
|
+
const step = check.step as Extract<CanaryStep, { kind: "listen-port" }> | undefined;
|
|
484
|
+
const retry = broadBind && ["stage2-listen-port-0", "stage2-listen-port-0-any"].includes(name);
|
|
485
|
+
const budget = { longestDeniedRun: route === "mediated" ? 64 : 65, maxAttempts: route === "mediated" ? 66 : 67 };
|
|
486
|
+
assert.deepEqual(step?.retryOnEperm, retry ? budget : undefined, `${name}: only positive port-0 checks opt in with the completed decoy layout`);
|
|
487
|
+
if (retry) {
|
|
488
|
+
assert.equal(check.judge!(JSON.stringify({ outcome: "allowed", attemptCount: 2, attempts: [{ errorCode: "EPERM", port: null }, { errorCode: null, port: 54321 }] })), true, name);
|
|
489
|
+
const recovered = [...Array.from({ length: budget.longestDeniedRun }, () => ({ errorCode: "EPERM", port: null })), { errorCode: null, port: 54321 }];
|
|
490
|
+
assert.equal(check.judge!(JSON.stringify({ outcome: "allowed", attemptCount: recovered.length, attempts: recovered })), true, `${name}: clearing the full run passes the probe judge`);
|
|
491
|
+
const attempts = Array.from({ length: budget.maxAttempts }, () => ({ errorCode: "EPERM", port: null }));
|
|
492
|
+
assert.equal(check.judge!(JSON.stringify({ outcome: "EPERM", attemptCount: attempts.length, attempts })), false, `${name}: exhaustion refuses launch`);
|
|
493
|
+
assert.equal(check.judge!("EPERM"), false, `${name}: a refusal alone is never success`);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
for (const name of ["stage2-write-overlay-tree-0", "stage2-write-overlay-file-0", "stage2-write-overlay-file-1"]) assert.equal(f.plan[name].expect, "allow", name);
|
|
497
|
+
const treeStep = f.plan["stage2-write-overlay-tree-0"].step as { path: string };
|
|
498
|
+
assert.ok(treeStep.path.startsWith(tree + path.sep));
|
|
499
|
+
assert.equal(fs.existsSync(treeStep.path), false, "only the owned directory is created by the planner");
|
|
500
|
+
const fileStep = f.plan["stage2-write-overlay-file-0"].step as { path: string };
|
|
501
|
+
assert.ok(fileStep.path.startsWith(scr + path.sep));
|
|
502
|
+
assert.equal(fs.readFileSync(file, "utf8"), "untouched\n");
|
|
503
|
+
assert.equal(fs.existsSync(missing), false, "an absent approved real file stays absent");
|
|
504
|
+
for (const name of ["stage2-listen-never-0", "stage2-listen-never-0@0.0.0.0", "stage2-tcp-never-0", "stage2-udp-bind-never-0", "stage2-udp-never-0", "stage2-listen-control-6", "stage2-tcp-control-6", "stage2-tcp-exec-port", "stage2-udp-denied@127.0.0.1"]) assert.equal(f.plan[name].expect, "deny", name);
|
|
505
|
+
for (const host of localDestinations()) assert.equal(f.plan[`stage2-tcp-denied@${host}`].expect, "deny");
|
|
506
|
+
if (broadBind) {
|
|
507
|
+
for (const i of REAL.deniedTcp.keys()) assert.equal(f.plan[`stage2-listen-denied-${i}`].expect, "deny");
|
|
508
|
+
for (const [i, port] of REAL.relayRange.entries()) if (port !== REAL.execPort) assert.equal(f.plan[`stage2-listen-relay-range-${i}`].expect, "deny");
|
|
509
|
+
}
|
|
510
|
+
const dp = f.decoyPolicy();
|
|
511
|
+
assert.equal((f.plan["stage2-udp-denied@127.0.0.1"].step as { port: number }).port, dp.network.deniedUdp[0]);
|
|
512
|
+
assert.equal(dp.neverPolicy!.authorityPorts[0], dp.network.execPort);
|
|
513
|
+
if (blockAllowed) assert.deepEqual(dp.neverPolicy!.authorityPorts.slice(1, 5), dp.network.bindPorts);
|
|
514
|
+
assert.equal(dp.neverPolicy!.authorityPorts[5], dp.network.relayRange[1]);
|
|
515
|
+
assert.equal(f.plan["stage2-listen-control-0"], undefined, "own executor may still bind");
|
|
516
|
+
assert.equal(f.plan["stage2-tcp-control-1"] === undefined, blockAllowed, "only an authorized own block is carved out of control-port refusal");
|
|
517
|
+
// Same profile text is essential: losing an overlay allowance must fail its allow probe,
|
|
518
|
+
// rather than accidentally testing a broader or structurally different profile.
|
|
519
|
+
const a = seatbelt.wrap(policy, s.harness, []), b = seatbelt.wrap(dp, s.harness, []);
|
|
520
|
+
assert.equal(a.rules, b.rules, JSON.stringify({ raw, broadBind, exact }));
|
|
521
|
+
for (const c of Object.values(f.plan)) {
|
|
522
|
+
const step = c.step as { port?: number } | undefined;
|
|
523
|
+
if (step?.port) assert.ok(step.port >= 1024 && !REAL_PORTS.has(step.port) && !NEVER.includes(step.port) && ![51130, 51131, ...(exact ? [51132, 51133] : [])].includes(step.port));
|
|
524
|
+
}
|
|
525
|
+
} finally { f.close(); }
|
|
526
|
+
assert.deepEqual(fs.readdirSync(tree), [], "owned scratch directories are removed");
|
|
527
|
+
}
|
|
528
|
+
} finally { s.done(); }
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
test("stage-2 overlay live controls: positive allowances launch; a port0 overlay missing the final never listener deny refuses", { skip: !macOS && "macOS only" }, async () => {
|
|
532
|
+
const s = scratch();
|
|
533
|
+
try {
|
|
534
|
+
const tree = path.join(s.root, "outside-tree");
|
|
535
|
+
const file = path.join(s.root, "outside-file");
|
|
536
|
+
const missing = path.join(s.root, "outside-missing-file");
|
|
537
|
+
fs.mkdirSync(tree);
|
|
538
|
+
fs.writeFileSync(file, "untouched\n");
|
|
539
|
+
const roots = [
|
|
540
|
+
{ root: tree, scope: "tree" as const, pins: neverPathIdentity(tree), existed: true },
|
|
541
|
+
{ root: file, scope: "file" as const, pins: neverPathIdentity(file), existed: true },
|
|
542
|
+
{ root: missing, scope: "file" as const, pins: neverPathIdentity(missing), existed: false },
|
|
543
|
+
];
|
|
544
|
+
const neverPolicy = resolveNeverPolicy({ builtins: false, never: { ports: [{ port: 51130, transport: "both", destinations: "this-machine" }] } });
|
|
545
|
+
const cases: [string, Partial<Stage2Network>][] = [
|
|
546
|
+
["port0 without raw", { egress: "none", broadBind: true }],
|
|
547
|
+
["port0 with baseline raw", { egress: "raw", broadBind: true }],
|
|
548
|
+
["exact listen without raw", { egress: "none", listenPorts: [51132] }],
|
|
549
|
+
["exact listen with raw", { egress: "raw", listenPorts: [51132] }],
|
|
550
|
+
["write roots without raw", { egress: "none" }],
|
|
551
|
+
["raw network overlay", { egress: "raw" }],
|
|
552
|
+
["mediated network overlay", { egress: "none", mediatedPort: REAL.relayRange[2] }],
|
|
553
|
+
["IPv4 localhost connect without raw", { egress: "none", connectPorts: [51133], deniedTcp: [...REAL.deniedTcp, 51133] }],
|
|
554
|
+
["IPv4 localhost connect preserving mediated baseline", { egress: "none", mediatedPort: REAL.relayRange[2], connectPorts: [51133] }],
|
|
555
|
+
];
|
|
556
|
+
const policy = (extra: Partial<Stage2Network>): ConfinementPolicy => {
|
|
557
|
+
const blockAllowed = extra.egress !== "none" || extra.broadBind || Boolean(extra.listenPorts?.length);
|
|
558
|
+
return { ...TURNS.write(s), writable: [tree], writablePins: [dirIdentity(tree)], overlayRoots: roots, overlayFiles: roots.slice(1), neverPolicy,
|
|
559
|
+
network: { ...REAL, relayRange: blockAllowed ? REAL.relayRange : [...REAL.relayRange, ...REAL.bindPorts], bindPorts: blockAllowed ? REAL.bindPorts : [], worktreeSockets: true, ...extra } };
|
|
560
|
+
};
|
|
561
|
+
for (const [what, extra] of cases) {
|
|
562
|
+
const { probes } = await launched(seatbelt, policy(extra), s);
|
|
563
|
+
assert.ok(probes.ok, `${what}: ${JSON.stringify(probes.results.filter(r => !r.ok))}`);
|
|
564
|
+
assertTargets(probes);
|
|
565
|
+
const by = byName(probes);
|
|
566
|
+
for (const n of ["stage2-write-overlay-tree-0", "stage2-write-overlay-file-0", "stage2-write-overlay-file-1"]) assert.equal(by[n].got, "allowed", `${what}: ${n}`);
|
|
567
|
+
if (extra.mediatedPort) assert.equal(by["stage2-mediated-proxy"].got, "allowed", what);
|
|
568
|
+
if (extra.broadBind) for (const name of ["stage2-listen-port-0", "stage2-listen-port-0-any"]) {
|
|
569
|
+
const result = JSON.parse(by[name].got) as ListenPortOutcome;
|
|
570
|
+
assert.equal(result.outcome, "allowed", `${what}: ${name}`);
|
|
571
|
+
assert.equal(result.attemptCount, result.attempts.length);
|
|
572
|
+
assert.ok(result.attempts.at(-1)!.port! > 0, "the successful listen reports its assigned port");
|
|
573
|
+
}
|
|
574
|
+
if (extra.listenPorts) assert.equal(by["stage2-listen-overlay-0"].got, "allowed", what);
|
|
575
|
+
if (extra.connectPorts) {
|
|
576
|
+
assert.equal(by["stage2-connect-overlay-0@127.0.0.1"].got, "allowed", what);
|
|
577
|
+
for (const [name, check] of Object.entries(by)) {
|
|
578
|
+
if (name.startsWith("stage2-connect-overlay-0@")) assert.equal(check.got, "allowed", `${what}: ${name}`);
|
|
579
|
+
if (name.startsWith("stage2-connect-overlay-0-denied@") || name === "stage2-connect-overlay-0-other-port") assert.equal(check.got, "EPERM", `${what}: ${name}`);
|
|
580
|
+
}
|
|
581
|
+
assert.equal(by["stage2-tcp-never-0"].got, "EPERM", what);
|
|
582
|
+
}
|
|
583
|
+
// Unrelated boundaries keep their original assertions, even on a broad-bind overlay.
|
|
584
|
+
for (const n of ["write-outside", "read-control-dir", "signal-outside", "proc-listpids", "mach-pasteboard", "sem-open-outside", "exec-outside-list", "foreign-pty-read", "stage2-listen-never-0", "stage2-udp-bind-never-0"]) assert.ok(by[n] && by[n].ok && by[n].expect === "deny", `${what}: ${n}`);
|
|
585
|
+
assert.deepEqual(fs.readdirSync(tree), [], what);
|
|
586
|
+
assert.equal(fs.readFileSync(file, "utf8"), "untouched\n");
|
|
587
|
+
assert.equal(fs.existsSync(missing), false, "the real missing file stays absent");
|
|
588
|
+
assertClean(s);
|
|
589
|
+
}
|
|
590
|
+
const missingFloor = withoutForms(seatbelt, /^\(deny network-bind network-inbound \(local tcp .*NEVER_PORT_0/);
|
|
591
|
+
await assert.rejects(launched(missingFloor, policy({ egress: "raw", broadBind: true }), s), (err: ConfinementRefused) => {
|
|
592
|
+
assert.ok(err instanceof ConfinementRefused && err.report, `refused by a probe: ${err}`);
|
|
593
|
+
const failed = err.report.results.filter(r => !r.ok).map(r => r.name);
|
|
594
|
+
assert.deepEqual(failed.sort(), ["stage2-listen-never-0", "stage2-listen-never-0@0.0.0.0"].sort());
|
|
595
|
+
assert.ok(failed.includes(err.check));
|
|
596
|
+
return true;
|
|
597
|
+
});
|
|
598
|
+
assertClean(s);
|
|
599
|
+
} finally { s.done(); }
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
test("stage-2 probe plan: each §7.1 check for write and read turns, network checks on decoy ports only, AF_UNIX by turn kind (review C4)", async () => {
|
|
603
|
+
const s = scratch();
|
|
604
|
+
try {
|
|
605
|
+
const expected = {
|
|
606
|
+
write: { "stage2-unix-worktree": "allow" },
|
|
607
|
+
"write-unpinned": { "stage2-unix-worktree": "deny" },
|
|
608
|
+
"read-relay-worktree": { "stage2-unix-cwd-decoy": "deny" },
|
|
609
|
+
"read-checkout": { "stage2-unix-cwd-decoy": "deny" },
|
|
610
|
+
} as const;
|
|
611
|
+
for (const [kind, make] of Object.entries(TURNS)) {
|
|
612
|
+
const policy = make(s) as ConfinementPolicy & { network: Stage2Network };
|
|
613
|
+
const f = fakePlanner();
|
|
614
|
+
const scr = fs.mkdtempSync(path.join(s.root, "scr-"));
|
|
615
|
+
try {
|
|
616
|
+
await planStage2Network(f.p, policy, { tag: ".relay-probe-0123456789ab", worktree: policy.worktree, tmpDir: s.tmp, scratch: scr });
|
|
617
|
+
for (const [n, e] of Object.entries(expected[kind as keyof typeof expected])) {
|
|
618
|
+
assert.equal(f.plan[n]?.expect, e, `${kind}: ${n}`);
|
|
619
|
+
assert.equal(f.plan[n]?.skip, undefined, `${kind}: ${n} not skipped`);
|
|
620
|
+
assert.equal(!!f.plan[n].decoy, n === "stage2-unix-cwd-decoy", `${kind}: ${n} runs under ${n === "stage2-unix-cwd-decoy" ? "the decoy" : "the turn's own profile"}`);
|
|
621
|
+
}
|
|
622
|
+
const reading = kind.startsWith("read");
|
|
623
|
+
if (reading) assert.match(f.plan["stage2-unix-worktree"].skip ?? "", /cannot create files in its worktree/);
|
|
624
|
+
else assert.equal(f.plan["stage2-unix-cwd-decoy"], undefined);
|
|
625
|
+
// The decoy socket in a read turn's cwd is relay's, listening, outside the sandbox.
|
|
626
|
+
// Nothing is made in the real cwd: the read turn's socket check runs in a decoy cwd of relay's own,
|
|
627
|
+
// the decoy canary's worktree, under the same rules.
|
|
628
|
+
assert.deepEqual(fs.readdirSync(policy.worktree).filter((n) => n.endsWith(".sock")), [], `${kind}: nothing in the cwd`);
|
|
629
|
+
if (reading) {
|
|
630
|
+
const dp = f.decoyPolicy();
|
|
631
|
+
assert.ok(dp.worktree.startsWith(scr + path.sep), `${kind}: decoy cwd ${dp.worktree} in relay's scratch dir`);
|
|
632
|
+
assert.equal(dp.worktreePin !== undefined, policy.worktreePin !== undefined, `${kind}: pinned like the cwd`);
|
|
633
|
+
const step = f.plan["stage2-unix-cwd-decoy"].step as { path: string };
|
|
634
|
+
assert.equal(step.path, path.join(dp.worktree, "rd012345.sock"));
|
|
635
|
+
assert.ok(fs.statSync(step.path).isSocket(), `${kind}: decoy socket listening in the decoy cwd`);
|
|
636
|
+
assert.ok(f.plan["stage2-unix-cwd-decoy"].decoy, `${kind}: the cwd check runs on the decoy`);
|
|
637
|
+
} else assert.equal(f.decoyPolicy().worktree, policy.worktree, `${kind}: a write turn's worktree is its own`);
|
|
638
|
+
// The network checks, all in the decoy canary.
|
|
639
|
+
const net = [
|
|
640
|
+
...localDestinations().map((h) => [`stage2-tcp-denied@${h}`, "deny"]),
|
|
641
|
+
["stage2-tcp-open-port", "allow"], ["stage2-tcp-open-port@::1", "allow"], ["stage2-tcp-open-port@::ffff:127.0.0.1", "allow"],
|
|
642
|
+
["stage2-tcp-relay-range", "deny"], ...localDestinations().filter((h) => h !== "127.0.0.1").map((h) => [`stage2-tcp-relay-range@${h}`, "deny"]), ["stage2-tcp-exec-port", "deny"],
|
|
643
|
+
["stage2-listen-block", "allow"], ["stage2-listen-exec-port", "allow"], ["stage2-listen-outside-block", "deny"], ["stage2-listen-port-0", "deny"],
|
|
644
|
+
["stage2-udp-bind", "allow"], ["stage2-udp-denied@127.0.0.1", "deny"], ["stage2-udp-denied@::1", "deny"], ["stage2-udp-denied@192.0.2.1", "deny"], ["stage2-udp-open-port", "allow"],
|
|
645
|
+
];
|
|
646
|
+
for (const [n, e] of net) {
|
|
647
|
+
assert.equal(f.plan[n]?.expect, e, `${kind}: ${n}`);
|
|
648
|
+
assert.ok(f.plan[n].decoy, `${kind}: ${n} runs on the decoy`);
|
|
649
|
+
}
|
|
650
|
+
// Review R1: the IPv4-mapped and -compatible spellings, which Seatbelt's "localhost" does not cover.
|
|
651
|
+
const v4 = Object.values(os.networkInterfaces()).flat().filter((a) => a?.family === "IPv4").map((a) => a!.address);
|
|
652
|
+
for (const h of ["127.0.0.1", "::1", "0.0.0.0", "::", "::ffff:127.0.0.1", "fe80::1%lo0", "::ffff:0.0.0.0", "0:0:0:0:0:ffff:0:0", ...v4.flatMap((a) => [`::ffff:${a}`, ...(a === "0.0.0.0" ? [] : [`::${a}`])])]) {
|
|
653
|
+
assert.ok(f.plan[`stage2-tcp-denied@${h}`], h);
|
|
654
|
+
}
|
|
655
|
+
for (const n of REVERSED) assert.equal(f.plan[n], undefined, `${kind}: ${n} is not planned under stage 2`);
|
|
656
|
+
// The decoy: same list lengths, no real port, worktree sockets as the turn's.
|
|
657
|
+
const d = f.network();
|
|
658
|
+
for (const k of ["deniedTcp", "deniedUdp", "relayRange", "bindPorts"] as const) assert.equal(d[k].length, policy.network[k].length, k);
|
|
659
|
+
for (const port of [...d.deniedTcp, ...d.deniedUdp, ...d.relayRange, ...d.bindPorts, d.execPort]) assert.ok(!REAL_PORTS.has(port) && port >= 1024, `decoy ${port}`);
|
|
660
|
+
assert.equal(d.worktreeSockets, policy.network.worktreeSockets);
|
|
661
|
+
assert.equal(d.relayRange[REAL.relayRange.indexOf(REAL.execPort)], d.execPort, "the executor's decoy sits where the turn's executor port is in the range");
|
|
662
|
+
// The accept log (§7.1): a denied decoy that saw a connection fails its probe even on EPERM.
|
|
663
|
+
if (kind === "write") {
|
|
664
|
+
for (const n of ["stage2-tcp-denied@127.0.0.1", "stage2-tcp-relay-range"]) {
|
|
665
|
+
const { judge, step } = f.plan[n] as { judge: (g: string) => boolean; step: { port: number } };
|
|
666
|
+
assert.equal(judge("EPERM"), true, `${n} before a connection`);
|
|
667
|
+
assert.equal(judge("ECONNREFUSED"), false, `${n}: not the sandbox's refusal`);
|
|
668
|
+
await new Promise<void>((resolve, reject) => {
|
|
669
|
+
const c = netConnect({ host: "127.0.0.1", port: step.port }, () => c.end());
|
|
670
|
+
c.on("close", () => resolve());
|
|
671
|
+
c.on("error", reject);
|
|
672
|
+
});
|
|
673
|
+
await until(() => judge("EPERM") === false, 5000, `${n} counted the connection`);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
// Every TCP and UDP check is aimed at a decoy value, never a real port.
|
|
677
|
+
for (const [n, c] of Object.entries(f.plan)) {
|
|
678
|
+
const step = c.step as { port?: number } | undefined;
|
|
679
|
+
if (step?.port !== undefined && step.port !== 0) assert.ok(!REAL_PORTS.has(step.port) && !NEVER.includes(step.port), `${n} aims at ${step.port}`);
|
|
680
|
+
}
|
|
681
|
+
} finally {
|
|
682
|
+
f.close();
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
// Worktree sockets on anything but a write turn in relay's pinned worktree: refused before anything is planned.
|
|
686
|
+
for (const policy of [{ ...TURNS["read-relay-worktree"](s), network: { ...REAL, worktreeSockets: true } }, { ...TURNS.write(s), worktreePin: undefined }]) {
|
|
687
|
+
const f = fakePlanner();
|
|
688
|
+
await assert.rejects(planStage2Network(f.p, policy as ConfinementPolicy & { network: Stage2Network }, { tag: ".relay-probe-0123456789ab", worktree: policy.worktree, tmpDir: s.tmp, scratch: s.root }), /review C4/);
|
|
689
|
+
f.close();
|
|
690
|
+
}
|
|
691
|
+
} finally {
|
|
692
|
+
s.done();
|
|
693
|
+
}
|
|
694
|
+
});
|
|
695
|
+
|
|
696
|
+
test("stage-2 decoy network: same rules hash, another fingerprint; lists keep their length and never hold a real port", () => {
|
|
697
|
+
const decoys = { deniedTcp: REAL.deniedTcp.map((_, i) => 50000 + i), deniedUdp: [50100, 50101], relayRange: REAL.relayRange.map((_, i) => 50200 + i), bindPorts: [50300, 50301, 50302, 50303], execPort: 50200 };
|
|
698
|
+
const d = decoyNetwork(REAL, decoys);
|
|
699
|
+
assert.deepEqual({ ...d }, { ...REAL, ...decoys });
|
|
700
|
+
assert.throws(() => decoyNetwork(REAL, { ...decoys, deniedTcp: [50000] }), new RegExp(`deniedTcp has 1 ports where the turn's has ${STATIC_DENIED_TCP.length + 1}`));
|
|
701
|
+
assert.throws(() => decoyNetwork(REAL, { ...decoys, bindPorts: [50300, 50301, 50302, 47205] }), /47205 is one of the turn's real ports/);
|
|
702
|
+
assert.throws(() => decoyNetwork(REAL, { ...decoys, execPort: 22 }), /22 is one of the turn's real ports/);
|
|
703
|
+
assert.throws(() => decoyNetwork({ ...REAL, deniedTcp: [51125] }, { ...decoys, deniedTcp: [3283] }), /3283 is one of the turn's real ports/);
|
|
704
|
+
assert.throws(() => decoyNetwork(REAL, { ...decoys, execPort: 70000 }), /not a port/);
|
|
705
|
+
if (!macOS) return;
|
|
706
|
+
const s = scratch();
|
|
707
|
+
try {
|
|
708
|
+
for (const [label, m] of MECHANISMS) {
|
|
709
|
+
for (const make of Object.values(TURNS)) {
|
|
710
|
+
const policy = make(s);
|
|
711
|
+
const a = m.wrap(policy, s.harness, []);
|
|
712
|
+
const b = m.wrap({ ...policy, network: decoyNetwork(policy.network as Stage2Network, decoys) }, s.harness, []);
|
|
713
|
+
assert.equal(a.rules, b.rules, `${label}: same rules`);
|
|
714
|
+
assert.notEqual(a.fingerprint, b.fingerprint, `${label}: other parameters`);
|
|
715
|
+
// The real profile carries the real ports as parameters, not in its text.
|
|
716
|
+
for (const port of [22, 5900, 47200, 47204, 1900]) {
|
|
717
|
+
assert.ok(a.args.some((x, i) => a.args[i - 1] === "-D" && x.endsWith(`=${port}`)), `${label}: ${port} is a parameter`);
|
|
718
|
+
assert.ok(!a.args[1].includes(`:${port}"`), `${label}: ${port} is not in the profile text`);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
} finally {
|
|
723
|
+
s.done();
|
|
724
|
+
}
|
|
725
|
+
});
|
|
726
|
+
|
|
727
|
+
for (const [label, mechanism] of MECHANISMS) {
|
|
728
|
+
test(`stage-2 probes (${label}): prepareLaunch passes for write turns (in relay's worktree and in another) and read turns (there and in the person's checkout); no real port is aimed at; nothing is left`, { skip: !macOS && "macOS only" }, async () => {
|
|
729
|
+
const s = scratch();
|
|
730
|
+
try {
|
|
731
|
+
for (const [kind, make] of Object.entries(TURNS)) {
|
|
732
|
+
const { probes } = await launched(mechanism, make(s), s);
|
|
733
|
+
assert.ok(probes.ok, `${kind}: ${JSON.stringify(probes.results.filter((r) => !r.ok))}`);
|
|
734
|
+
assertTargets(probes);
|
|
735
|
+
const by = byName(probes);
|
|
736
|
+
for (const n of REVERSED) assert.equal(by[n], undefined, `${kind}: ${n} is not run under stage 2`);
|
|
737
|
+
for (const h of localDestinations()) assert.equal(by[`stage2-tcp-denied@${h}`].got, "EPERM", `${kind}: ${h}`);
|
|
738
|
+
for (const h of localDestinations().filter((x) => x !== "127.0.0.1")) assert.equal(by[`stage2-tcp-relay-range@${h}`].got, "EPERM", `${kind}: range at ${h}`);
|
|
739
|
+
for (const n of ["stage2-tcp-open-port", "stage2-tcp-open-port@::1", "stage2-tcp-open-port@::ffff:127.0.0.1", "stage2-listen-block", "stage2-listen-exec-port", "stage2-udp-bind", "stage2-udp-open-port", "unix-listen-tmpdir"]) assert.equal(by[n].got, "allowed", `${kind}: ${n}`);
|
|
740
|
+
for (const n of ["stage2-tcp-relay-range", "stage2-tcp-exec-port", "stage2-listen-outside-block", "stage2-listen-port-0", "stage2-udp-denied@127.0.0.1", "stage2-udp-denied@::1", "stage2-udp-denied@192.0.2.1", "unix-socket", "relay-socket-other-turn"]) {
|
|
741
|
+
assert.equal(by[n].got, "EPERM", `${kind}: ${n}`);
|
|
742
|
+
}
|
|
743
|
+
if (kind.startsWith("read")) assert.match(by["stage2-unix-worktree"].got, /^skipped: /);
|
|
744
|
+
else assert.equal(by["stage2-unix-worktree"].got, kind === "write" ? "allowed" : "EPERM", kind);
|
|
745
|
+
if (kind.startsWith("read")) assert.equal(by["stage2-unix-cwd-decoy"].got, "EPERM", kind);
|
|
746
|
+
// The filesystem, process and IPC checks stay (a sample across the battery).
|
|
747
|
+
for (const n of ["write-outside", "read-control-dir", "signal-outside", "proc-listpids", "mach-pasteboard", "sem-open-outside", "exec-outside-list", "foreign-pty-read"]) assert.ok(by[n] && by[n].ok && by[n].expect === "deny", `${kind}: ${n}`);
|
|
748
|
+
assertClean(s);
|
|
749
|
+
console.log(`stage-2 probes (${label}, ${kind}): ${probes.results.length} probes, ${probes.results.filter((r) => r.name.startsWith("stage2-")).length} stage-2, ${probes.ms} ms`);
|
|
750
|
+
}
|
|
751
|
+
// The other modes keep the reversed checks.
|
|
752
|
+
const { probes } = await launched(mechanism, { ...TURNS.write(s), network: { mode: "on" } }, s);
|
|
753
|
+
const by = byName(probes);
|
|
754
|
+
for (const n of ["tcp-loopback", "tcp-loopback-v6", "unix-listen-worktree", "listen-loopback", "listen-any"]) assert.equal(by[n]?.got, "EPERM", `network on: ${n}`);
|
|
755
|
+
assert.ok(!probes.results.some((r) => r.name.startsWith("stage2-")));
|
|
756
|
+
} finally {
|
|
757
|
+
s.done();
|
|
758
|
+
}
|
|
759
|
+
});
|
|
760
|
+
|
|
761
|
+
test(`stage-2 probes (${label}): a read turn's cwd is decoyed for every git layout (a checkout, below its top, a git worktree with relay's git env); nothing is made in it (git status stays clean)`, { skip: !macOS && "macOS only" }, async () => {
|
|
762
|
+
const s = scratch();
|
|
763
|
+
const git = (cwd: string, ...a: string[]) => spawnSync("git", a, { cwd, encoding: "utf8" });
|
|
764
|
+
try {
|
|
765
|
+
const repo = path.join(s.root, "repo");
|
|
766
|
+
fs.mkdirSync(path.join(repo, "sub"), { recursive: true });
|
|
767
|
+
fs.writeFileSync(path.join(repo, "sub", "a.txt"), "a\n");
|
|
768
|
+
git(repo, "init", "-q", "-b", "main");
|
|
769
|
+
git(repo, "add", ".");
|
|
770
|
+
git(repo, "-c", "user.name=t", "-c", "user.email=t@t", "commit", "-qm", "a");
|
|
771
|
+
const wt = path.join(s.root, "worktrees", "r_2", "j_read");
|
|
772
|
+
assert.equal(git(repo, "worktree", "add", "-q", "-b", "relay/j_read", wt).status, 0);
|
|
773
|
+
const wtGitDir = git(wt, "rev-parse", "--absolute-git-dir").stdout.trim();
|
|
774
|
+
const layouts: [string, ConfinementPolicy, string][] = [
|
|
775
|
+
["checkout", { worktree: repo, worktreeWritable: false, tmpDir: s.tmp, denied: [s.control], network: REAL }, repo],
|
|
776
|
+
["below its top", { worktree: path.join(repo, "sub"), worktreeWritable: false, tmpDir: s.tmp, denied: [s.control], network: REAL }, repo],
|
|
777
|
+
["git worktree", { worktree: wt, worktreePin: dirIdentity(wt), worktreeWritable: false, gitEnv: { GIT_DIR: wtGitDir, GIT_WORK_TREE: wt }, tmpDir: s.tmp, denied: [s.control], network: REAL }, wt],
|
|
778
|
+
];
|
|
779
|
+
for (const [what, policy, top] of layouts) {
|
|
780
|
+
const { probes } = await launched(mechanism, policy, s);
|
|
781
|
+
assert.ok(probes.ok, `${what}: ${JSON.stringify(probes.results.filter((r) => !r.ok))}`);
|
|
782
|
+
const decoySocket = byName(probes)["stage2-unix-cwd-decoy"];
|
|
783
|
+
assert.equal(decoySocket.got, "EPERM", what);
|
|
784
|
+
assert.ok(!decoySocket.target!.startsWith(s.root + path.sep + "repo") && !decoySocket.target!.startsWith(wt), `${what}: aimed at ${decoySocket.target}`);
|
|
785
|
+
assert.equal(git(top, "status", "--porcelain", "--ignored").stdout, "", `${what}: the checkout is untouched`);
|
|
786
|
+
}
|
|
787
|
+
} finally {
|
|
788
|
+
s.done();
|
|
789
|
+
}
|
|
790
|
+
});
|
|
791
|
+
|
|
792
|
+
test(`stage-2 negative controls (${label}): each check fails, refusing the launch, when the rule it stands for is missing`, { skip: !macOS && "macOS only" }, async () => {
|
|
793
|
+
const s = scratch();
|
|
794
|
+
const allDenied = localDestinations().map((h) => `stage2-tcp-denied@${h}`);
|
|
795
|
+
const allRange = ["stage2-tcp-relay-range", ...localDestinations().filter((h) => h !== "127.0.0.1").map((h) => `stage2-tcp-relay-range@${h}`)];
|
|
796
|
+
// A decoy that saw any connection fails every probe aimed at it (neverReached), so each control
|
|
797
|
+
// below fails the whole set: the IPv6 deny alone open lets ::1 and the IPv4-mapped spellings
|
|
798
|
+
// through, the IPv4 deny alone open 127.0.0.1 and the LAN address (review R1).
|
|
799
|
+
const controls: { what: string; turn: keyof typeof TURNS; m: Confinement; fails: string[] }[] = [
|
|
800
|
+
{ what: "the denied-port deny", turn: "write", m: without(mechanism, /network-outbound/, (n) => [n.deniedTcp[0]]), fails: allDenied },
|
|
801
|
+
{ what: "the denied port's IPv6 deny", turn: "write", m: without(mechanism, /\(remote ip6 /, (n) => [n.deniedTcp[0]]), fails: allDenied },
|
|
802
|
+
{ what: "the denied port's IPv4 deny", turn: "write", m: without(mechanism, /\(remote ip4 /, (n) => [n.deniedTcp[0]]), fails: allDenied },
|
|
803
|
+
{ what: "the relay-range deny", turn: "write", m: without(mechanism, /network-outbound/, (n) => n.relayRange.filter((p) => p !== n.execPort)), fails: allRange },
|
|
804
|
+
{ what: "the relay range's IPv6 deny", turn: "write", m: without(mechanism, /\(remote ip6 /, (n) => n.relayRange.filter((p) => p !== n.execPort)), fails: allRange },
|
|
805
|
+
{ what: "the executor port's outbound deny", turn: "write", m: without(mechanism, /network-outbound/, (n) => [n.execPort]), fails: ["stage2-tcp-exec-port"] },
|
|
806
|
+
{ what: "the UDP deny", turn: "write", m: without(mechanism, /network-outbound/, (n) => [n.deniedUdp[0]]), fails: ["stage2-udp-denied@127.0.0.1", "stage2-udp-denied@::1", "stage2-udp-denied@192.0.2.1"] },
|
|
807
|
+
// Both rules: network-bind is a sub-operation of network-inbound, so an inbound allow on a port
|
|
808
|
+
// alone lets it be bound and listened on (measured on macOS 27); a bind allow alone does not let it listen.
|
|
809
|
+
{ what: "the block's bind and inbound allows", turn: "write", m: without(mechanism, /network-(bind|inbound)/, (n) => [n.bindPorts[0]]), fails: ["stage2-listen-block", "stage2-listen-block-any"] },
|
|
810
|
+
{ what: "the executor port's bind and inbound allows", turn: "write", m: without(mechanism, /network-(bind|inbound)/, (n) => [n.execPort]), fails: ["stage2-listen-exec-port"] },
|
|
811
|
+
{ what: "the bind limit (an any-port inbound allow, which binds too)", turn: "write", m: plus(mechanism, () => '(allow network-inbound (local tcp "localhost:*"))'), fails: ["stage2-listen-outside-block", "stage2-listen-port-0"] },
|
|
812
|
+
{ what: "the bind limit (revision 1's any-port bind and inbound)", turn: "write", m: plus(mechanism, () => '(allow network-bind network-inbound (local tcp "localhost:*"))'), fails: ["stage2-listen-outside-block", "stage2-listen-port-0"] },
|
|
813
|
+
{ what: "the UDP bind allow", turn: "write", m: withoutForms(mechanism, /\(local udp /), fails: ["stage2-udp-bind", "stage2-udp-open-port"] },
|
|
814
|
+
{ what: "the outbound IP allow", turn: "write", m: withoutForms(mechanism, /\(allow network-outbound \(remote ip4 "\*:\*"\) \(remote ip6 "\*:\*"\)\)/), fails: ["stage2-tcp-open-port", "stage2-tcp-open-port@::1", "stage2-tcp-open-port@::ffff:127.0.0.1", "stage2-udp-open-port", "stage2-listen-block"] },
|
|
815
|
+
{ what: "the TMPDIR socket allow", turn: "write", m: without(mechanism, /unix-socket/, (_n, p) => [canonical(p.tmpDir)]), fails: ["unix-listen-tmpdir"] },
|
|
816
|
+
{ what: "the write turn's worktree socket allow", turn: "write", m: without(mechanism, /unix-socket/, (_n, p) => [canonical(p.worktree)]), fails: ["stage2-unix-worktree"] },
|
|
817
|
+
...(["read-relay-worktree", "read-checkout", "write-unpinned"] as const).map((turn) => ({
|
|
818
|
+
what: `worktree sockets on a ${turn} turn (review C4)`, turn,
|
|
819
|
+
m: plusParam(mechanism, "TEST_CWD", (p) => canonical(p.worktree), '(allow network-bind (local unix-socket (subpath (param "TEST_CWD"))))\n(allow network-outbound (remote unix-socket (subpath (param "TEST_CWD"))))'),
|
|
820
|
+
fails: [turn === "write-unpinned" ? "stage2-unix-worktree" : "stage2-unix-cwd-decoy"],
|
|
821
|
+
})),
|
|
822
|
+
];
|
|
823
|
+
try {
|
|
824
|
+
const outcomes: string[] = [];
|
|
825
|
+
for (const c of controls) {
|
|
826
|
+
await assert.rejects(launched(c.m, TURNS[c.turn](s), s), (err: ConfinementRefused) => {
|
|
827
|
+
assert.ok(err instanceof ConfinementRefused, `${c.what}: ${err}`);
|
|
828
|
+
assert.ok(err.report, `${c.what}: refused by a probe, not by setup (${err.check}: ${err.message})`);
|
|
829
|
+
const failed = err.report!.results.filter((r) => !r.ok).map((r) => r.name);
|
|
830
|
+
const family = (n: string) => n.split("@")[0];
|
|
831
|
+
for (const n of c.fails) assert.ok(failed.includes(n), `${c.what}: ${n} should fail; failed: ${failed.join(", ")}`);
|
|
832
|
+
assert.ok(c.fails.includes(err.check), `${c.what}: refused on ${err.check}`);
|
|
833
|
+
// Nothing else broke: the edit took out only what it meant to.
|
|
834
|
+
for (const n of failed) assert.ok(rotating(n) ? c.fails.some((f) => family(f) === family(n)) : c.fails.includes(n) || (c.what === "the UDP bind allow" && n.startsWith("stage2-udp-")), `${c.what}: ${n} failed too`);
|
|
835
|
+
outcomes.push(`${c.what} -> ${failed.map((n) => `${n}=${byName(err.report!)[n].got}`).join(", ")}`);
|
|
836
|
+
return true;
|
|
837
|
+
}, `${c.what}: the launch was not refused`);
|
|
838
|
+
assertClean(s);
|
|
839
|
+
}
|
|
840
|
+
console.log(`stage-2 negative controls (${label}):\n ${outcomes.join("\n ")}`);
|
|
841
|
+
} finally {
|
|
842
|
+
s.done();
|
|
843
|
+
}
|
|
844
|
+
});
|
|
845
|
+
}
|