@jbkjr/relay 0.0.0-stage → 1.2.1
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 +386 -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 +1525 -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 +320 -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 +637 -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 +329 -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 +629 -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 +1502 -0
- package/docs/pinned-codex.md +321 -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,264 @@
|
|
|
1
|
+
import "./helpers.ts";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { test } from "node:test";
|
|
4
|
+
import { EventEmitter } from "node:events";
|
|
5
|
+
import http from "node:http";
|
|
6
|
+
import net from "node:net";
|
|
7
|
+
import dns from "node:dns";
|
|
8
|
+
import { Resolver } from "node:dns/promises";
|
|
9
|
+
import { openProxy } from "../dist/confine/proxy.js";
|
|
10
|
+
import { resolveNeverPolicy, neverEndpointProblem } from "../dist/core/never-policy.js";
|
|
11
|
+
|
|
12
|
+
class Socket extends EventEmitter {
|
|
13
|
+
destroyed = false; written = "";
|
|
14
|
+
pause() {} resume() {} setTimeout() {} pipe() {} unshift() {}
|
|
15
|
+
write(b) { this.written += String(b); }
|
|
16
|
+
end(b = "") { this.write(b); this.destroy(); }
|
|
17
|
+
destroy() { if (!this.destroyed) { this.destroyed = true; this.emit("close"); } }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Exercise the production HTTP/CONNECT/SOCKS handlers and teardown without a kernel bind.
|
|
21
|
+
async function harness(t, resolve = async () => ["8.8.8.8"], options = {}) {
|
|
22
|
+
let requestHandler, accept, connected = 0;
|
|
23
|
+
const bindings = [];
|
|
24
|
+
const server = Object.assign(new EventEmitter(), {
|
|
25
|
+
listen(port, host, cb) { bindings.push({ host, port }); cb(); },
|
|
26
|
+
address: () => ({ port: 49202 }), close(cb) { cb(); },
|
|
27
|
+
});
|
|
28
|
+
t.mock.method(http, "createServer", fn => { requestHandler = fn; return server; });
|
|
29
|
+
const listener = () => Object.assign(new EventEmitter(), {
|
|
30
|
+
listen(o, cb) { bindings.push(o); cb(); },
|
|
31
|
+
address: () => ({ port: 49202 }), close(cb) { cb(); },
|
|
32
|
+
});
|
|
33
|
+
t.mock.method(net, "createServer", fn => { accept = fn; return listener(); });
|
|
34
|
+
const upstreams = [];
|
|
35
|
+
t.mock.method(net, "connect", o => { connected++; assert.equal(o.host, options.modelStub ? "127.0.0.1" : "8.8.8.8"); const s = new Socket(); upstreams.push(s); return s; });
|
|
36
|
+
const proxy = await openProxy({ mode: "public", allow: [], listen: { port: 49202, ipv4Only: true }, ...(resolve ? { publicPolicy: { resolve } } : {}), testing: { local: new Set(), subnets: [] }, ...options });
|
|
37
|
+
const client = () => { const c = new Socket(); if (options.mode === "allowlist") server.emit("connection", c); else accept(c); return c; };
|
|
38
|
+
return { proxy, upstreams, bindings, connected: () => connected, client,
|
|
39
|
+
connect(c = client(), target = "allowed.test:443", token = false) {
|
|
40
|
+
const headers = token ? { "proxy-authorization": `Basic ${Buffer.from(`relay:${proxy.token}`).toString("base64")}` } : {};
|
|
41
|
+
server.emit("connect", { headers, url: target }, c, Buffer.alloc(0)); return c;
|
|
42
|
+
},
|
|
43
|
+
async http(url, host, token = false) {
|
|
44
|
+
const req = Object.assign(new Socket(), { url, headers: { host, ...(token ? { "proxy-authorization": `Basic ${Buffer.from(`relay:${proxy.token}`).toString("base64")}` } : {}) }, method: "GET" });
|
|
45
|
+
const res = Object.assign(new Socket(), { status: 0, writeHead(status) { this.status = status; return this; } });
|
|
46
|
+
await requestHandler(req, res); return res;
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const tick = () => new Promise(r => setImmediate(r));
|
|
51
|
+
|
|
52
|
+
test("public proxy fakes: mismatched HTTP Host refused before policy/DNS/dial", async t => {
|
|
53
|
+
let screens = 0; const h = await harness(t, async () => { screens++; return ["8.8.8.8"]; });
|
|
54
|
+
try {
|
|
55
|
+
const res = await h.http("http://allowed.test/path", "forbidden.test");
|
|
56
|
+
assert.equal(res.status, 400); assert.match(res.written, /disagree/);
|
|
57
|
+
assert.equal(screens, 0); assert.equal(h.connected(), 0);
|
|
58
|
+
} finally { await h.proxy.close(); }
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("public proxy fakes: close during pending DNS never dials", async t => {
|
|
62
|
+
let finish;
|
|
63
|
+
const h = await harness(t, () => new Promise(resolve => finish = resolve));
|
|
64
|
+
const c = h.connect(); await h.proxy.close(); finish(["8.8.8.8"]); await tick();
|
|
65
|
+
assert.equal(c.destroyed, true); assert.equal(h.connected(), 0);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("public proxy fakes: close destroys pending connects and live tunnels", async t => {
|
|
69
|
+
const h = await harness(t);
|
|
70
|
+
const pending = h.connect(); await tick();
|
|
71
|
+
const live = h.connect(); await tick(); h.upstreams[1].emit("connect"); await tick();
|
|
72
|
+
assert.match(live.written, /200 Connection Established/);
|
|
73
|
+
assert.equal(pending.destroyed, false); assert.equal(live.destroyed, false);
|
|
74
|
+
await h.proxy.close(); await tick();
|
|
75
|
+
assert.equal(pending.destroyed, true); assert.equal(live.destroyed, true);
|
|
76
|
+
assert.ok(h.upstreams.every(s => s.destroyed));
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test("public proxy fakes: new CONNECT and SOCKS requests each screen the requested port", async t => {
|
|
80
|
+
const seen = [];
|
|
81
|
+
const h = await harness(t, async (host, port) => { seen.push([host, port]); throw new Error("never"); });
|
|
82
|
+
try {
|
|
83
|
+
const c = h.connect(); await tick(); assert.match(c.written, /403/);
|
|
84
|
+
const socks = h.client(); socks.read = () => Buffer.from([5, 1, 0, 5, 1, 0, 1, 8, 8, 8, 8, 0xc1, 0x24]);
|
|
85
|
+
socks.emit("readable"); await tick();
|
|
86
|
+
assert.deepEqual(seen, [["allowed.test", 443], ["8.8.8.8", 49444]]);
|
|
87
|
+
assert.equal(h.connected(), 0);
|
|
88
|
+
} finally { await h.proxy.close(); }
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// Exercise the standalone adapter path with production DNS traversal, faking only DNS answers
|
|
92
|
+
// and sockets. No request reaches a real host or any protected service port.
|
|
93
|
+
function dnsFixture(t, lookup = async host => host === "forbidden.test" ? ["1.1.1.1"] : ["8.8.8.8"]) {
|
|
94
|
+
t.mock.method(Resolver.prototype, "resolveCname", async host => host === "cname.test" ? ["forbidden-alias.test"] : host === "forbidden.test" ? ["forbidden-alias.test"] : []);
|
|
95
|
+
t.mock.method(Resolver.prototype, "resolve4", lookup);
|
|
96
|
+
t.mock.method(Resolver.prototype, "resolve6", async () => []);
|
|
97
|
+
}
|
|
98
|
+
const floor = (never = {}) => resolveNeverPolicy({ builtins: false, never });
|
|
99
|
+
|
|
100
|
+
for (const [label, never, allowed] of [
|
|
101
|
+
["positive mapping", {}, true],
|
|
102
|
+
["forbidden authority", { hosts: ["model.relay-test.invalid"] }, false],
|
|
103
|
+
["forbidden mapped port", { ports: [{ port: 49555, transport: "tcp", destinations: "this-machine" }] }, false],
|
|
104
|
+
["forbidden address alias", { hosts: ["127.0.0.1"] }, false],
|
|
105
|
+
]) test(`synthetic model endpoint: ${label} retains never without DNS`, async t => {
|
|
106
|
+
t.mock.method(dns.promises, "lookup", () => assert.fail("synthetic model mapping must not use DNS"));
|
|
107
|
+
t.mock.method(Resolver.prototype, "resolveCname", () => assert.fail("synthetic model mapping must not use CNAME DNS"));
|
|
108
|
+
t.mock.method(http, "request", () => new Socket());
|
|
109
|
+
const host = "model.relay-test.invalid";
|
|
110
|
+
const h = await harness(t, null, { modelStub: { host, port: 49555 }, neverPolicy: floor(never) });
|
|
111
|
+
try {
|
|
112
|
+
const result = h.http(`http://${host}/messages`, host, true);
|
|
113
|
+
await tick();
|
|
114
|
+
if (allowed) { assert.equal(h.connected(), 1); h.upstreams[0].emit("connect"); }
|
|
115
|
+
const response = await result;
|
|
116
|
+
assert.equal(h.connected(), allowed ? 1 : 0);
|
|
117
|
+
if (!allowed) assert.equal(response.status, 403);
|
|
118
|
+
} finally { await h.proxy.close(); }
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test("Claude public proxy: never screens host, port, every resolved address and CNAME without requiring a token", async t => {
|
|
122
|
+
dnsFixture(t, async host => host === "forbidden-alias.test" || host === "address-alias.test" ? ["1.1.1.1"]
|
|
123
|
+
: host === "mixed.test" ? ["8.8.8.8", "::ffff:909:909"] : ["8.8.8.8"]);
|
|
124
|
+
const h = await harness(t, null, { listen: undefined, neverPolicy: floor({ hosts: ["forbidden.test", "9.9.9.9"], ports: [{ port: 49444 }] }) });
|
|
125
|
+
try {
|
|
126
|
+
assert.deepEqual(h.bindings.map(b => b.host), ["127.0.0.1", "::1"]);
|
|
127
|
+
const allowed = h.connect(); await tick();
|
|
128
|
+
assert.equal(h.connected(), 1); h.upstreams[0].emit("connect"); await tick();
|
|
129
|
+
assert.match(allowed.written, /200 Connection Established/);
|
|
130
|
+
assert.equal(h.proxy.authenticated(), false, "Claude sandbox callers need no token");
|
|
131
|
+
for (const target of ["forbidden.test:443", "allowed.test:49444", "address-alias.test:443", "9.9.9.9:443", "mixed.test:443", "cname.test:443"]) {
|
|
132
|
+
const denied = h.connect(undefined, target); await tick();
|
|
133
|
+
assert.match(denied.written, /403/, target);
|
|
134
|
+
}
|
|
135
|
+
for (const url of ["http://forbidden.test/", "http://allowed.test:49444/"]) {
|
|
136
|
+
const res = await h.http(url, new URL(url).host); assert.equal(res.status, 403);
|
|
137
|
+
}
|
|
138
|
+
const socks = h.client();
|
|
139
|
+
socks.read = () => Buffer.from([5, 1, 0, 5, 1, 0, 1, 9, 9, 9, 9, 1, 187]);
|
|
140
|
+
socks.emit("readable"); await tick();
|
|
141
|
+
assert.equal(socks.written, String(Buffer.from([5, 0])) + String(Buffer.from([5, 2, 0, 1, 0, 0, 0, 0, 0, 0])));
|
|
142
|
+
assert.equal(h.connected(), 1, "denials never dial");
|
|
143
|
+
} finally { await h.proxy.close(); }
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("ACP allowlist proxy: never refuses allowlisted authorities and address aliases; authentication and allowlist still apply", async t => {
|
|
147
|
+
dnsFixture(t, async host => host === "address-alias.test" ? ["9.9.9.9"] : host === "forbidden-alias.test" ? ["1.1.1.1"] : ["8.8.8.8"]);
|
|
148
|
+
const h = await harness(t, null, { mode: "allowlist", allow: ["allowed.test", "forbidden.test", "address-alias.test"], neverPolicy: floor({ hosts: ["forbidden.test", "9.9.9.9"] }) });
|
|
149
|
+
try {
|
|
150
|
+
const missingToken = h.connect(); assert.match(missingToken.written, /407/);
|
|
151
|
+
for (const target of ["forbidden.test:443", "address-alias.test:443", "not-allowlisted.test:443", "allowed.test:444"]) {
|
|
152
|
+
const denied = h.connect(undefined, target, true); await tick(); assert.match(denied.written, /403/, target);
|
|
153
|
+
}
|
|
154
|
+
assert.equal(h.connected(), 0);
|
|
155
|
+
const allowed = h.connect(undefined, "allowed.test:443", true); await tick();
|
|
156
|
+
assert.equal(h.connected(), 1); h.upstreams[0].emit("connect"); await tick();
|
|
157
|
+
assert.match(allowed.written, /200 Connection Established/);
|
|
158
|
+
assert.equal(h.proxy.authenticated(), true);
|
|
159
|
+
} finally { await h.proxy.close(); }
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test("ACP allowlist proxy: an allowlisted model API still passes never port checks", async t => {
|
|
163
|
+
dnsFixture(t);
|
|
164
|
+
const h = await harness(t, null, { mode: "allowlist", allow: ["allowed.test"], neverPolicy: floor({ ports: [{ port: 443 }] }) });
|
|
165
|
+
try {
|
|
166
|
+
const denied = h.connect(undefined, "allowed.test:443", true); await tick();
|
|
167
|
+
assert.match(denied.written, /403/); assert.equal(h.connected(), 0);
|
|
168
|
+
} finally { await h.proxy.close(); }
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
for (const mode of ["public", "allowlist"]) test(`WP6 ${mode} proxy: built-in service ports never dial, positive allowed-port control works`, async t => {
|
|
172
|
+
dnsFixture(t);
|
|
173
|
+
t.mock.method(dns.promises, "lookup", async () => [{ address: "8.8.8.8", family: 4 }]);
|
|
174
|
+
// These are rules-only fake socket requests. No kernel listener or real service is contacted.
|
|
175
|
+
const builtins = resolveNeverPolicy({ home: "/owned/scratch/home" });
|
|
176
|
+
const h = await harness(t, null, { mode, allow: mode === "allowlist" ? ["allowed.test"] : [], neverPolicy: builtins });
|
|
177
|
+
try {
|
|
178
|
+
for (const port of [22, 5900]) {
|
|
179
|
+
assert.ok(builtins.ports.some(p => p.port === port));
|
|
180
|
+
assert.match(neverEndpointProblem(builtins, { host: "127.0.0.1", port, transport: "tcp" })!, /never/);
|
|
181
|
+
const denied = h.connect(undefined, `127.0.0.1:${port}`, true); await tick();
|
|
182
|
+
assert.match(denied.written, /403/); assert.equal(h.connected(), 0);
|
|
183
|
+
}
|
|
184
|
+
const allowed = h.connect(undefined, "allowed.test:443", true); await tick();
|
|
185
|
+
assert.equal(h.connected(), 1); h.upstreams[0].emit("connect"); await tick();
|
|
186
|
+
assert.match(allowed.written, /200 Connection Established/);
|
|
187
|
+
} finally { await h.proxy.close(); }
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test("WP6 public proxy: alternative and mapped loopback spellings never dial", async t => {
|
|
191
|
+
t.mock.method(dns.promises, "lookup", async () => [{ address: "127.0.0.1", family: 4 }]);
|
|
192
|
+
const h = await harness(t, null, { neverPolicy: floor() });
|
|
193
|
+
try {
|
|
194
|
+
for (const target of ["2130706433:443", "0177.0.0.1:443", "0x7f000001:443", "[::ffff:127.0.0.1]:443", "127.1:443"]) {
|
|
195
|
+
const denied = h.connect(undefined, target); await tick();
|
|
196
|
+
assert.match(denied.written, /403|400/, target); assert.equal(h.connected(), 0);
|
|
197
|
+
}
|
|
198
|
+
} finally { await h.proxy.close(); }
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
for (const mode of ["public", "allowlist"]) {
|
|
202
|
+
test(`${mode} never proxy: failed/stale forbidden DNS fails closed; rebinding retains earlier endpoints`, async t => {
|
|
203
|
+
let forbidden = "1.1.1.1", broken = false, stale = false, time = 0;
|
|
204
|
+
t.mock.method(Date, "now", () => time);
|
|
205
|
+
dnsFixture(t, async host => {
|
|
206
|
+
if (broken) throw new Error("DNS unavailable");
|
|
207
|
+
if (stale && host === "allowed.test") time += 60_000;
|
|
208
|
+
return [host === "forbidden-alias.test" ? forbidden : host === "old-address.test" ? "1.1.1.1" : "8.8.8.8"];
|
|
209
|
+
});
|
|
210
|
+
const h = await harness(t, null, { mode, allow: mode === "allowlist" ? ["allowed.test", "old-address.test"] : [], neverPolicy: floor({ hosts: ["forbidden.test"] }) });
|
|
211
|
+
try {
|
|
212
|
+
forbidden = "9.9.9.9";
|
|
213
|
+
const rebound = h.connect(undefined, "old-address.test:443", true); await tick();
|
|
214
|
+
assert.match(rebound.written, /403/);
|
|
215
|
+
forbidden = "1.1.1.1";
|
|
216
|
+
const retained = h.connect(undefined, "old-address.test:443", true); await tick();
|
|
217
|
+
assert.match(retained.written, /403/);
|
|
218
|
+
broken = true;
|
|
219
|
+
const failed = h.connect(undefined, "allowed.test:443", true); await tick(); assert.match(failed.written, /403/);
|
|
220
|
+
broken = false; stale = true;
|
|
221
|
+
const expired = h.connect(undefined, "allowed.test:443", true); await tick(); assert.match(expired.written, /403/);
|
|
222
|
+
assert.equal(h.connected(), 0);
|
|
223
|
+
} finally { await h.proxy.close(); }
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
test("standalone never proxy: unresolvable forbidden hosts fail before binding", async t => {
|
|
228
|
+
dnsFixture(t, async () => []);
|
|
229
|
+
t.mock.method(net, "createServer", () => { assert.fail("must not bind before forbidden DNS is validated"); });
|
|
230
|
+
await assert.rejects(openProxy({ mode: "public", allow: [], neverPolicy: floor({ hosts: ["unresolvable.test"] }) }), /no numeric endpoint/);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
test("standalone never proxy: close cancels pending DNS and prevents subsequent requests", async t => {
|
|
234
|
+
let entered, rejectPending, cancels = 0;
|
|
235
|
+
const started = new Promise(resolve => entered = resolve);
|
|
236
|
+
t.mock.method(Resolver.prototype, "resolveCname", () => { entered(); return new Promise((_ok, reject) => rejectPending = reject); });
|
|
237
|
+
t.mock.method(Resolver.prototype, "cancel", () => { cancels++; rejectPending?.(new Error("DNS cancelled")); });
|
|
238
|
+
const h = await harness(t, null, { neverPolicy: floor({ hosts: ["9.9.9.9"] }) });
|
|
239
|
+
const client = h.connect(); await started; await h.proxy.close(); await tick();
|
|
240
|
+
assert.ok(cancels > 0); assert.equal(client.destroyed, true); assert.equal(h.connected(), 0);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
test("standalone never proxy without hosts: OS lookup preserves underscore names and screens every address and port", async t => {
|
|
244
|
+
const lookups = [];
|
|
245
|
+
t.mock.method(Resolver.prototype, "resolveCname", () => assert.fail("no forbidden hosts need CNAME DNS"));
|
|
246
|
+
t.mock.method(dns.promises, "lookup", async (host, options) => {
|
|
247
|
+
lookups.push(host); assert.deepEqual(options, { all: true, verbatim: true });
|
|
248
|
+
return (host === "mixed_name.test" ? ["8.8.8.8", "::ffff:909:909"] : ["8.8.8.8"]).map(address => ({ address }));
|
|
249
|
+
});
|
|
250
|
+
const p = { ...floor({ ports: [{ port: 49444, destinations: "any" }, { port: 49445, destinations: "this-machine" }] }), localAddresses: ["9.9.9.9"] };
|
|
251
|
+
const h = await harness(t, null, { neverPolicy: p });
|
|
252
|
+
try {
|
|
253
|
+
const allowed = h.connect(undefined, "os_name.test:443"); await tick();
|
|
254
|
+
assert.equal(h.connected(), 1); h.upstreams[0].emit("connect"); await tick();
|
|
255
|
+
assert.match(allowed.written, /200 Connection Established/);
|
|
256
|
+
const deniedPort = h.connect(undefined, "os_name.test:49444"); await tick();
|
|
257
|
+
assert.match(deniedPort.written, /403/);
|
|
258
|
+
const deniedAddress = h.connect(undefined, "mixed_name.test:49445"); await tick();
|
|
259
|
+
assert.match(deniedAddress.written, /403/);
|
|
260
|
+
const invalid = h.connect(undefined, "-invalid.test:443"); await tick(); assert.match(invalid.written, /403/);
|
|
261
|
+
assert.deepEqual(lookups, ["os_name.test", "mixed_name.test"]);
|
|
262
|
+
assert.equal(h.connected(), 1);
|
|
263
|
+
} finally { await h.proxy.close(); }
|
|
264
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
/** Only unlink our scratch home's alias, never follow it or remove another fixture's entry. */
|
|
5
|
+
export function removeTestNativeTempAlias(home: string, parent = "/Users/Shared"): void {
|
|
6
|
+
const me = process.getuid?.() ?? 0;
|
|
7
|
+
const alias = path.join(parent, `.rn-${me}`);
|
|
8
|
+
const st = fs.lstatSync(alias, { throwIfNoEntry: false });
|
|
9
|
+
if (st?.isSymbolicLink() && st.uid === me && fs.readlinkSync(alias) === path.join(home, ".rn")) fs.unlinkSync(alias);
|
|
10
|
+
}
|