Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

feat(security): judge a public-network address on the route the request dials

vastsa2062131f7b71
diff --git a/apps/desktop/electron/main/ipc/skills-ipc.ts b/apps/desktop/electron/main/ipc/skills-ipc.ts
index 4a09adbdf..1e64bde3e 100644
--- a/apps/desktop/electron/main/ipc/skills-ipc.ts
+++ b/apps/desktop/electron/main/ipc/skills-ipc.ts
@@ -79,6 +79,7 @@ export function registerSkillsIpc({
kind: detail.kind,
...(detail.reason ? { reason: detail.reason } : {}),
...(detail.addressKind ? { addressKind: detail.addressKind } : {}),
+ ...(detail.route ? { route: detail.route } : {}),
},
});
};
diff --git a/apps/desktop/electron/main/public-https-fetch.ts b/apps/desktop/electron/main/public-https-fetch.ts
index f23bb2e1f..8ae0544dd 100644
--- a/apps/desktop/electron/main/public-https-fetch.ts
+++ b/apps/desktop/electron/main/public-https-fetch.ts
@@ -3,11 +3,14 @@ import {
ErrorCodes,
PUBLIC_NETWORK_POLICY_ERROR,
classifyIpLiteral,
+ classifyProxyRoute,
+ isAcceptableResolvedAddress,
isPublicNetworkPolicyFailure,
isSafePublicHttpsUrl,
publicNetworkRefusalReason,
type PublicNetworkAddressKind,
type PublicNetworkRefusalReason,
+ type PublicNetworkRoute,
} from "@pi-desktop/shared";
const DEFAULT_TIMEOUT_MS = 8_000;
@@ -21,6 +24,15 @@ export type PublicHttpsFetch = (
export type PublicHttpsLookup = (host: string) => Promise<Array<{ address: string }>>;
+/**
+ * The route the transport will actually take for one URL, as the session that
+ * carries `fetchImpl` reports it (`Session.resolveProxy`). Injectable so this
+ * module stays free of Electron: a caller wires the same session whose `fetch`
+ * it passes in, and a caller that wires nothing keeps the strict verdict
+ * (ADR 0272).
+ */
+export type PublicHttpsRouteLookup = (url: string) => Promise<string>;
+
/** The resolver's own error code, for the log line. Never its message. */
function resolverCode(error: unknown): string {
const code = (error as { code?: unknown } | null | undefined)?.code;
@@ -36,6 +48,8 @@ export type PublicNetworkRefusal = {
address?: string;
/** That address's class — `benchmark` for a TUN fake-IP, `private` for RFC1918. */
addressKind?: PublicNetworkAddressKind;
+ /** The route the hop was judged on, when the transport could name one. */
+ route?: PublicNetworkRoute;
};
export class PublicNetworkPolicyError extends Error {
@@ -56,6 +70,8 @@ export class PublicNetworkPolicyError extends Error {
readonly address?: string;
/** The class of `address`, not just the address: it names the cause. */
readonly addressKind?: PublicNetworkAddressKind;
+ /** The route the refusal was judged on, when the guard could read one. */
+ readonly route?: PublicNetworkRoute;
constructor(message: string, refusal: PublicNetworkRefusal = { reason: "non-public-address" }) {
super(message);
this.name = PUBLIC_NETWORK_POLICY_ERROR;
@@ -63,6 +79,7 @@ export class PublicNetworkPolicyError extends Error {
this.host = refusal.host;
this.address = refusal.address;
this.addressKind = refusal.addressKind;
+ this.route = refusal.route;
this.errorCode =
refusal.reason === "resolve-failed"
? ErrorCodes.NETWORK_RESOLVE_FAILED
@@ -80,18 +97,27 @@ export type PublicHttpsClient = {
};
/**
- * Main-process HTTPS client: syntactic guard, DNS classification, and
- * per-hop re-validation of redirects. Fetch and lookup are injectable so
- * tests can exercise the policy without Electron or the network.
+ * Main-process HTTPS client: syntactic guard, per-hop route and address
+ * classification, and per-hop re-validation of redirects. Fetch, lookup, and
+ * route are injectable so tests can exercise the policy without Electron or the
+ * network.
*
* Every branch still fails closed. The structured `reason` and the
* `NETWORK_RESOLVE_FAILED` code change what the app can *say* about a block —
- * which host, and whether an address was judged at all — never whether it
- * blocks (issue #419).
+ * which host, which class of address, and which route it was judged on — never
+ * whether it blocks (issue #419).
+ *
+ * The address verdict follows the route the request will actually take. On a
+ * proxied route this app dials the proxy rather than the destination, so only
+ * the resolver-artifact class is tolerated there, and every class that names a
+ * real internal target still refuses. A route the transport cannot name keeps
+ * the strict verdict (ADR 0272).
*/
export function createPublicHttpsClient(options: {
fetchImpl: PublicHttpsFetch;
lookupImpl?: PublicHttpsLookup;
+ /** Must be the session that carries `fetchImpl`; absent stays strict. */
+ routeImpl?: PublicHttpsRouteLookup;
timeoutMs?: number;
} ): PublicHttpsClient {
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
@@ -99,6 +125,20 @@ export function createPublicHttpsClient(options: {
options.lookupImpl ??
(async (host: string) => dnsLookup(host, { all: true }));
+ /**
+ * The route for one hop, asked immediately before that hop is dialed. A
+ * transport that cannot answer, or answers something this policy cannot read,
+ * is `unknown`, which is never permission (ADR 0272).
+ */
+ async function hopRoute(url: string): Promise<PublicNetworkRoute> {
+ if (!options.routeImpl) return "unknown";
+ try {
+ return classifyProxyRoute(await options.routeImpl(url));
+ } catch {
+ return "unknown";
+ }
+ }
+
async function assertPublicUrl(url: string): Promise<void> {
if (!isSafePublicHttpsUrl(url)) {
throw new PublicNetworkPolicyError(`url rejected by the public-network policy: ${url}`, {
@@ -107,6 +147,7 @@ export function createPublicHttpsClient(options: {
}
const host = new URL(url).hostname.toLowerCase().replace(/\.+$/, "");
if (host.startsWith("[") || /^\d{1,3}(\.\d{1,3}){3}$/.test(host)) return;
+ const route = await hopRoute(url);
let addresses: Array<{ address: string }>;
try {
addresses = await lookupImpl(host);
@@ -118,23 +159,28 @@ export function createPublicHttpsClient(options: {
throw new PublicNetworkPolicyError(`hostname does not resolve: ${host}${resolverCode(error)}`, {
reason: "resolve-failed",
host,
+ route,
});
}
if (!addresses.length) {
throw new PublicNetworkPolicyError(`hostname does not resolve: ${host}`, {
reason: "resolve-failed",
host,
+ route,
});
}
for (const address of addresses) {
const addressKind = classifyIpLiteral(address.address);
- if (addressKind !== "public") {
+ if (!isAcceptableResolvedAddress(addressKind, route)) {
// The class travels with the refusal: `benchmark` is a TUN fake-IP
// (198.18.0.0/15) and `private` is a real RFC1918 target, and only the
- // class tells those apart in the log and in the panel.
+ // class tells those apart in the log and in the panel. The route travels
+ // with it too: a fake-IP answer is tolerated on a proxied route because
+ // this app never dials it, and refused on a direct or unreadable route
+ // because this app would (ADR 0272).
throw new PublicNetworkPolicyError(
- `hostname resolves to a non-public address: ${host} -> ${address.address} (${addressKind})`,
- { reason: "non-public-address", host, address: address.address, addressKind },
+ `hostname resolves to a non-public address: ${host} -> ${address.address} (${addressKind}, ${route} route)`,
+ { reason: "non-public-address", host, address: address.address, addressKind, route },
);
}
}
diff --git a/apps/desktop/electron/main/skill-market-catalog.ts b/apps/desktop/electron/main/skill-market-catalog.ts
index 67f525d25..c6d489ff0 100644
--- a/apps/desktop/electron/main/skill-market-catalog.ts
+++ b/apps/desktop/electron/main/skill-market-catalog.ts
@@ -6,7 +6,7 @@
* the same CSP reason; the actual write goes through the existing
* `skills.create` path on the renderer's side.
*/
-import { net } from "electron";
+import { net, session } from "electron";
import type { SkillCatalogEntry, SkillMarketSource } from "@pi-desktop/shared";
import { createPublicHttpsClient } from "./public-https-fetch";
import {
@@ -18,7 +18,16 @@ import {
export type { SkillMarketDocument, SkillMarketSearchResult } from "./skill-market-scan";
export { guessSkillCategories } from "./skill-market-scan";
-const client = createPublicHttpsClient({ fetchImpl: (url, init) => net.fetch(url, init) });
+/**
+ * `net.fetch` issues requests from the default session, so the guard asks that
+ * same session which route the request will take before it judges an address:
+ * a proxied hop dials the proxy, not the address a local resolver answered
+ * (ADR 0177, ADR 0272).
+ */
+const client = createPublicHttpsClient({
+ fetchImpl: (url, init) => net.fetch(url, init),
+ routeImpl: (url) => session.defaultSession.resolveProxy(url),
+});
const aggregator = createSkillMarketAggregator(client.request);
export function searchSkillMarket(
diff --git a/apps/desktop/electron/main/skill-market-scan.ts b/apps/desktop/electron/main/skill-market-scan.ts
index 35e6e9996..6d2b8b15f 100644
--- a/apps/desktop/electron/main/skill-market-scan.ts
+++ b/apps/desktop/electron/main/skill-market-scan.ts
@@ -13,6 +13,7 @@ import {
validateSkillCatalogFile,
type PublicNetworkAddressKind,
type PublicNetworkRefusalReason,
+ type PublicNetworkRoute,
type SkillCatalogCategory,
type SkillCatalogEntry,
type SkillMarketSource,
@@ -48,6 +49,13 @@ export type SkillMarketFailureDetail = {
* The address itself is deliberately not carried.
*/
addressKind?: PublicNetworkAddressKind;
+ /**
+ * The route the guard judged the failing address on, when the transport could
+ * name one. A fake-IP answer is tolerated on a proxied route because this app
+ * never dials it, and refused on a direct or unreadable one because it would
+ * (ADR 0272).
+ */
+ route?: PublicNetworkRoute;
};
export type SkillMarketSearchResult = {
@@ -132,6 +140,7 @@ export function skillMarketFailureDetail(
kind: classifySkillMarketFailure(error),
...(refusal ? { reason: refusal.reason } : {}),
...(refusal?.addressKind ? { addressKind: refusal.addressKind } : {}),
+ ...(refusal?.route ? { route: refusal.route } : {}),
};
}
@@ -311,6 +320,7 @@ export function createSkillMarketAggregator(request: CatalogRequest) {
...(host ? { host } : {}),
...(refusal ? { reason: refusal.reason } : {}),
...(refusal?.addressKind ? { addressKind: refusal.addressKind } : {}),
+ ...(refusal?.route ? { route: refusal.route } : {}),
});
return;
}
diff --git a/apps/desktop/src/lib/api.ts b/apps/desktop/src/lib/api.ts
index 6f09b3c3f..a16d45383 100644
--- a/apps/desktop/src/lib/api.ts
+++ b/apps/desktop/src/lib/api.ts
@@ -735,12 +735,19 @@ export const api = {
* refusal instead of reporting every source as merely unreachable.
*/
failureKinds?: Record<string, "policy" | "unresolved" | "network">;
+ /**
/**
* The host and the guard's own reason behind each failed source. Without
* it the panel can say a source was refused but not *what* was refused,
- * and a policy refusal is a statement about one address (issue #419).
+ * and a policy refusal is a statement about one address. `route` adds
+ * which route the guard judged that address on, so a fake-IP refusal on a
+ * direct route reads apart from one on a proxied route (issue #419,
+ * ADR 0272).
*/
- failureDetails?: Record<string, { host?: string; reason?: string; addressKind?: string }>;
+ failureDetails?: Record<
+ string,
+ { host?: string; reason?: string; addressKind?: string; route?: string }
+ >;
}>(IPC.invoke.skillMarketSearch, { query, sources }),
/** Fetch one catalog document (frontmatter split off) for preview/install. */
fetchSkillMarketDocument: (entry: SkillCatalogEntry) =>
diff --git a/apps/desktop/test/public-https-fetch-route.test.mjs b/apps/desktop/test/public-https-fetch-route.test.mjs
new file mode 100644
index 000000000..4fd61cfea
--- /dev/null
+++ b/apps/desktop/test/public-https-fetch-route.test.mjs
@@ -0,0 +1,232 @@
+import assert from "node:assert/strict";
+import { readFileSync } from "node:fs";
+import { dirname, join } from "node:path";
+import test from "node:test";
+import { fileURLToPath } from "node:url";
+import { ErrorCodes } from "@pi-desktop/shared";
+import {
+ createPublicHttpsClient,
+ PublicNetworkPolicyError,
+} from "../electron/main/public-https-fetch.ts";
+
+/**
+ * Connection-time route policy for the public-network guard (ADR 0272).
+ *
+ * The guard judged the address a *local* resolver returned for every request,
+ * while the request itself travels through the session's own proxy stack
+ * (ADR 0177, ADR 0243). Under a Clash-style TUN / fake-IP resolver that local
+ * answer is a synthesized `198.18.0.0/15` address — the address of a connection
+ * this app never makes — so a proxied user was refused for an address the
+ * transport never dials (issue #419).
+ *
+ * These tests pin the replacement: the verdict follows the route the transport
+ * will actually take. A proxied route tolerates only the resolver-artifact
+ * class, a direct route keeps the strict local verdict, and a route nobody can
+ * read keeps the strict verdict too.
+ */
+
+const FAKE_IP = "198.18.0.1";
+const LOOPBACK = "127.0.0.1";
+const PROXIED = "PROXY 127.0.0.1:7890";
+
+function response(status, body, location) {
+ return {
+ status,
+ ok: status >= 200 && status < 300,
+ headers: { get: (name) => (name.toLowerCase() === "location" ? location ?? null : null) },
+ json: async () => body,
+ text: async () => (typeof body === "string" ? body : JSON.stringify(body)),
+ };
+}
+
+/** A client whose session reports `route` and whose resolver answers `address`. */
+function clientFor({ route, address, fetchImpl }) {
+ return createPublicHttpsClient({
+ fetchImpl: fetchImpl ?? (async () => response(200, "# skill\n")),
+ lookupImpl: async () => (address ? [{ address }] : []),
+ ...(route === undefined ? {} : { routeImpl: async () => route }),
+ });
+}
+
+test("a proxied route stops treating a fake-IP answer as a refusal", async () => {
+ // The whole point of the change: `net.fetch` dials the proxy, so the local
+ // `198.18.0.1` describes no connection this app makes. Before ADR 0272 this
+ // exact case was a `NETWORK_POLICY_BLOCKED` refusal.
+ const seen = [];
+ const client = clientFor({
+ route: PROXIED,
+ address: FAKE_IP,
+ fetchImpl: async (url) => {
+ seen.push(url);
+ return response(200, "# skill\n");
+ },
+ });
+ const body = await client.request("https://cdn.jsdelivr.net/gh/x/SKILL.md", "text");
+ assert.equal(body, "# skill\n");
+ assert.deepEqual(seen, ["https://cdn.jsdelivr.net/gh/x/SKILL.md"]);
+});
+
+test("a proxied route still refuses an answer that names a real private target", async () => {
+ // Only the resolver-artifact class is tolerated on a proxied route: an answer
+ // that names an internal target is positive evidence of a split-horizon or
+ // hostile resolver, and the app cannot see which address the proxy would dial.
+ for (const address of ["10.0.0.8", LOOPBACK, "169.254.169.254"]) {
+ const client = clientFor({
+ route: PROXIED,
+ address,
+ fetchImpl: async () => {
+ throw new Error("a refused request must never reach the network");
+ },
+ });
+ await assert.rejects(
+ () => client.request("https://cdn.jsdelivr.net/gh/x/SKILL.md", "text"),
+ (error) =>
+ error instanceof PublicNetworkPolicyError &&
+ error.reason === "non-public-address" &&
+ error.addressKind !== "benchmark" &&
+ error.host === "cdn.jsdelivr.net",
+ `expected ${address} to stay refused on a proxied route`,
+ );
+ }
+});
+
+test("a proxied route still refuses an unanswered resolver", async () => {
+ const client = clientFor({ route: PROXIED, address: null });
+ await assert.rejects(
+ () => client.assertPublicUrl("https://cdn.jsdelivr.net/gh/x/SKILL.md"),
+ (error) =>
+ error instanceof PublicNetworkPolicyError &&
+ error.reason === "resolve-failed" &&
+ error.errorCode === ErrorCodes.NETWORK_RESOLVE_FAILED,
+ );
+});
+
+test("a direct route keeps the strict verdict for fake-IP and private answers alike", async () => {
+ for (const [address, addressKind] of [
+ [FAKE_IP, "benchmark"],
+ [LOOPBACK, "loopback"],
+ ]) {
+ const client = clientFor({
+ route: "DIRECT",
+ address,
+ fetchImpl: async () => {
+ throw new Error("a refused request must never reach the network");
+ },
+ });
+ await assert.rejects(
+ () => client.assertPublicUrl("https://cdn.jsdelivr.net/gh/x/SKILL.md"),
+ (error) =>
+ error instanceof PublicNetworkPolicyError &&
+ error.reason === "non-public-address" &&
+ error.addressKind === addressKind &&
+ error.route === "direct" &&
+ error.errorCode === ErrorCodes.NETWORK_POLICY_BLOCKED,
+ `expected ${address} to stay refused on a direct route`,
+ );
+ }
+});
+
+test("a route the transport cannot name falls back to the strict verdict", async () => {
+ // Fail-closed: no route resolver at all, a resolver that throws, an empty
+ // answer, and an answer Chromium could fall back to `DIRECT` from. Every one
+ // of them judges the fake-IP answer exactly as the app did before ADR 0272.
+ const unroutable = [
+ undefined,
+ () => Promise.reject(new Error("session unavailable")),
+ () => Promise.reject("not an error"),
+ async () => "",
+ async () => " ",
+ async () => "PROXY 127.0.0.1:7890; DIRECT",
+ async () => "DIRECT; PROXY 127.0.0.1:7890",
+ async () => "MAGIC 127.0.0.1:7890",
+ async () => null,
+ async () => 7890,
+ ];
+ for (const routeImpl of unroutable) {
+ const client = createPublicHttpsClient({
+ fetchImpl: async () => {
+ throw new Error("a refused request must never reach the network");
+ },
+ lookupImpl: async () => [{ address: FAKE_IP }],
+ ...(routeImpl ? { routeImpl } : {}),
+ });
+ await assert.rejects(
+ () => client.assertPublicUrl("https://cdn.jsdelivr.net/gh/x/SKILL.md"),
+ (error) =>
+ error instanceof PublicNetworkPolicyError &&
+ error.reason === "non-public-address" &&
+ error.addressKind === "benchmark" &&
+ error.route === "unknown",
+ "an unreadable route is never permission",
+ );
+ }
+});
+
+test("every redirect hop asks for its own route", async () => {
+ // The route is per hop, like the address verdict: a redirect can leave the
+ // proxied path, and the hop that would be dialed directly must be judged.
+ const seen = [];
+ const client = createPublicHttpsClient({
+ fetchImpl: async (url) => {
+ seen.push(url);
+ if (url === "https://start.example/catalog.json") {
+ return response(302, "", "https://next.example/catalog.json");
+ }
+ return response(200, { ok: true });
+ },
+ lookupImpl: async () => [{ address: FAKE_IP }],
+ routeImpl: async (url) =>
+ new URL(url).hostname === "start.example" ? PROXIED : "DIRECT",
+ });
+ await assert.rejects(
+ () => client.request("https://start.example/catalog.json", "json"),
+ (error) =>
+ error instanceof PublicNetworkPolicyError &&
+ error.reason === "non-public-address" &&
+ error.host === "next.example" &&
+ error.route === "direct",
+ );
+ assert.deepEqual(seen, ["https://start.example/catalog.json"]);
+});
+
+test("the route a hop is judged on travels with its refusal", async () => {
+ const client = clientFor({ route: PROXIED, address: null });
+ try {
+ await client.assertPublicUrl("https://cdn.jsdelivr.net/gh/x/SKILL.md");
+ assert.fail("expected a refusal");
+ } catch (error) {
+ assert.equal(error.route, "proxied");
+ }
+});
+
+test("too many redirects stays a policy refusal and is not retried", async () => {
+ let calls = 0;
+ const client = createPublicHttpsClient({
+ fetchImpl: async () => {
+ calls += 1;
+ return response(302, "", "https://next.example/hop");
+ },
+ lookupImpl: async () => [{ address: FAKE_IP }],
+ routeImpl: async () => PROXIED,
+ });
+ await assert.rejects(
+ () => client.request("https://start.example/catalog.json", "json"),
+ (error) =>
+ error instanceof PublicNetworkPolicyError &&
+ error.reason === "redirect-limit" &&
+ error.errorCode === ErrorCodes.NETWORK_POLICY_BLOCKED,
+ );
+ assert.equal(calls, 6);
+});
+
+test("the market catalog client asks the session that carries its fetch", async () => {
+ // The guard can only follow the route when its caller wires the session whose
+ // `fetch` it also passes in: `net.fetch` uses the default session (ADR 0272).
+ const source = readFileSync(
+ join(dirname(fileURLToPath(import.meta.url)), "../electron/main/skill-market-catalog.ts"),
+ "utf8",
+ );
+ assert.match(source, /import \{ net, session \} from "electron"/);
+ assert.match(source, /fetchImpl: \(url, init\) => net\.fetch\(url, init\)/);
+ assert.match(source, /routeImpl: \(url\) => session\.defaultSession\.resolveProxy\(url\)/);
+});
diff --git a/apps/desktop/test/skill-market-policy-refusal.test.mjs b/apps/desktop/test/skill-market-policy-refusal.test.mjs
index fee31d6bf..aa003aa41 100644
--- a/apps/desktop/test/skill-market-policy-refusal.test.mjs
+++ b/apps/desktop/test/skill-market-policy-refusal.test.mjs
@@ -19,6 +19,10 @@ import { createSkillMarketAggregator } from "../electron/main/skill-market-scan.
* Nothing here changes *whether* the guard blocks. Every case below is still
* refused, and the last test pins that. What is pinned is what the app says about
* it — which host, and which of the two causes.
+ *
+ * Every client here wires no route resolver, so every case below keeps the
+ * strict pre-ADR-0272 verdict by construction; the route-aware policy has its
+ * own cover in `public-https-fetch-route.test.mjs`.
*/
const composio = {
@@ -50,6 +54,9 @@ test("a resolver with no answer is not reported as an address-check refusal", as
kind: "unresolved",
reason: "resolve-failed",
host: SCAN_HOST,
+ // This client wires no route resolver, and an unreadable route is never
+ // permission: it keeps the strict verdict (ADR 0272).
+ route: "unknown",
});
});
@@ -77,11 +84,14 @@ test("a resolver that throws is unresolved too, and that one is retried", async
assert.equal(lookups, 3);
});
-test("a TUN fake-IP is still refused, and the refusal now names what it refused", async () => {
- // Clash's default fake-IP range. This *is* an address verdict, so the guard
- // keeps refusing it. What changed is the explanation: the refusal now carries
- // the host, the reason, and the class of address, instead of the one word
- // "private" that fit none of the benchmark/CGNAT/loopback cases.
+test("an unreadable route still refuses a TUN fake-IP, and names what it refused", async () => {
+ // Clash's default fake-IP range on a client that wires no route resolver at
+ // all. The address verdict still lands on the address this app would dial, so
+ // it stays a refusal; with a proxied route reported for the hop the same
+ // answer is the resolver's artifact and is tolerated (ADR 0272). Either way
+ // the refusal carries the host, the reason, the class of address, and the
+ // route it was judged on — instead of the one word "private" that fit none of
+ // the benchmark/CGNAT/loopback cases.
const client = createPublicHttpsClient({
fetchImpl: async () => {
throw new Error("a refused request must never reach the network");
@@ -97,6 +107,7 @@ test("a TUN fake-IP is still refused, and the refusal now names what it refused"
reason: "non-public-address",
host: SCAN_HOST,
addressKind: "benchmark",
+ route: "unknown",
});
});
diff --git a/apps/desktop/test/skill-market-scan.test.mjs b/apps/desktop/test/skill-market-scan.test.mjs
index 410cd6393..eebf833b3 100644
--- a/apps/desktop/test/skill-market-scan.test.mjs
+++ b/apps/desktop/test/skill-market-scan.test.mjs
@@ -105,8 +105,12 @@ test("main-process aggregator routes through the public-network client", async (
new URL("../electron/main/skill-market-catalog.ts", import.meta.url),
"utf8",
);
- assert.match(src, /import \{ createPublicHttpsClient \} from "\.\/public-https-fetch"/);
- assert.match(src, /createPublicHttpsClient\(\{ fetchImpl: \(url, init\) => net\.fetch\(url, init\) \}\)/);
+ assert.match(src, /import \{ net, session \} from "electron"/);
+ assert.match(src, /fetchImpl: \(url, init\) => net\.fetch\(url, init\)/);
+ assert.match(
+ src,
+ /routeImpl: \(url\) => session\.defaultSession\.resolveProxy\(url\)/,
+ );
assert.match(src, /createSkillMarketAggregator\(client\.request\)/);
assert.doesNotMatch(src, /node:https|node:http|axios|got\(/);
});
diff --git a/docs/adr/0272-connection-time-public-network-route.md b/docs/adr/0272-connection-time-public-network-route.md
new file mode 100644
index 000000000..455d62aab
--- /dev/null
+++ b/docs/adr/0272-connection-time-public-network-route.md
@@ -0,0 +1,184 @@
+# ADR 0272: Judge a public-network address on the route the request will dial
+
+- Status: Accepted for implementation
+- Date: 2026-09-17
+- Deciders: PI-Desktop core
+- Related: ADR 0177, ADR 0243, ADR 0245, D413, D414, issue #419, PR #473
+
+## Context
+
+`createPublicHttpsClient` guards every credential-free public HTTPS fetch the
+skill market makes from Electron main (ADR 0243). Before each hop it classified
+the target host with **Node's local resolver** (`node:dns`) and refused any hop
+whose answers were not public.
+
+The request itself never used that answer. `fetchImpl` is `net.fetch`, which
+dials through Chromium's proxy stack, and ADR 0177 points that stack at the
+configured proxy (System, or a Custom `http`/`https`/`socks` URL). Under an
+HTTP/HTTPS proxy the hostname travels in the `CONNECT` line and the *proxy*
+resolves it; nothing in this app resolves or dials the destination.
+
+The pre-check therefore judged an address no request would ever use, and a whole
+class of working setups was refused for it. Clash, Mihomo and Surge answer DNS
+with a synthesized fake-IP (`198.18.0.0/15` by default) while their TUN device or
+proxy carries the real connection: `classifyIpLiteral` reads `198.18.0.1` as
+`benchmark`, which is not public, so every catalog source failed with "the
+catalog source was blocked by the app's address check" even though the in-app
+browser and the transport itself worked (issue #419, reported on 0.14.8).
+
+PR #473 made that refusal legible — structured `reason`, `addressKind`,
+`NETWORK_RESOLVE_FAILED`, the market's `unresolved` kind — and left the boundary
+alone, because moving the classification out of the pre-check is a security
+boundary change. This ADR is that change.
+
+## Decision
+
+1. **The address verdict follows the route the request will actually take.** For
+ every hop, immediately before that hop is dialed, the client asks the session
+ that carries `fetchImpl` for its own proxy decision on exactly that URL
+ (`Session.resolveProxy`, wired beside `net.fetch` in `skill-market-catalog.ts`).
+ The shared `classifyProxyRoute` reduces the answer to `proxied`, `direct`, or
+ `unknown`.
+
+2. **A proxied route replaces the local address verdict; it does not remove it.**
+ On `proxied`, the shared `isAcceptableResolvedAddress` tolerates exactly one
+ class the old rule refused: `benchmark` — the RFC 2544 range a TUN fake-IP
+ resolver synthesizes, i.e. the resolver's own artifact rather than a target.
+ Every other non-public class (`private`, `loopback`, `link-local`, `cgnat`,
+ `multicast`, `reserved`, `documentation`, `ula`, `site-local`, `invalid`,
+ `unspecified`) still refuses, and an unanswered resolver still refuses as
+ `resolve-failed`. A local answer naming a real internal target stays evidence
+ of a split-horizon or hostile resolver, and this app cannot see what the proxy
+ would dial for it.
+
+3. **`direct` and `unknown` keep the pre-ADR rule byte for byte.** The app dials
+ the resolved address itself there, so only `public` passes. `unknown` covers no
+ route resolver wired at all, a resolver that throws, an empty or unparsable
+ answer, and a list that offers `DIRECT` anywhere — Chromium may fall back to a
+ direct connection, so an offered direct hop is never read as proxied. Fail
+ closed, exactly as before.
+
+4. **The syntactic guard is untouched.** `isSafePublicHttpsUrl` still runs first
+ for every hop and still refuses non-HTTPS, credential-bearing, non-public
+ literal, and `localhost` / `.local` / `.internal` URLs. Redirects stay
+ `manual` with a five-hop cap, and **every hop** re-runs the whole check, route
+ included.
+
+5. **The route travels with the refusal.** `PublicNetworkRefusal` /
+ `PublicNetworkRefusalDetail` gain `route`, so the diagnostics line and the
+ market's `failureDetails` say which route the address was judged on. A
+ `benchmark` refusal on a `direct` route means "the transport sees no proxy for
+ this URL and the app would dial the synthesized address itself"; the same
+ refusal on `unknown` means no route could be read at all.
+
+## Threat model
+
+What the guard stopped before this ADR:
+
+- Non-HTTPS, credential-bearing, and non-public-literal URLs — unchanged.
+- A hop whose **local** resolver answers with a private, loopback, link-local,
+ CGNAT, ULA, site-local, multicast, reserved, or documentation address. On a
+ direct route that is the address the app dials, so this was real protection and
+ stays exactly as it was.
+
+What changes:
+
+- **Still stopped:** everything above on `direct` / `unknown`, plus every address
+ class except `benchmark` on `proxied`.
+- **Weakened, precisely:** on a `proxied` route, a public hostname whose *local*
+ answer is inside `198.18.0.0/15` is no longer refused. Consequences:
+ - **SSRF to an internal service through the proxy.** If the proxy — or the TUN
+ capture behind a fake-IP answer — resolves that name to an internal address,
+ the app will have carried the request to it. The app cannot observe that hop:
+ the only peer it ever dialed is the proxy. Reaching internal targets is now
+ bounded by the proxy's own rule set (Clash's default rule set rejects LAN
+ targets; a permissive or corporate proxy will not).
+ - **Cloud metadata endpoints.** `169.254.169.254`, `fd00:ec2::254` and similar
+ are still refused whenever the *local* answer names them (link-local / ULA),
+ on both routes. The new hole is indirect: a name whose local answer is a
+ fake-IP address, which the proxy then resolves to a metadata endpoint, is no
+ longer judged.
+ - **`198.18.0.0/15` as an intranet range.** The range is reserved for
+ benchmarking and is not publicly allocated, but a lab or VPN could address
+ hosts there; a name answering from it is no longer refused on a proxied
+ route, and the TUN/proxy decides where it goes.
+ - **Chromium proxy fallback.** The route is read as the *resolved* proxy list.
+ Chromium may still retry a failed hop without the proxy, so `proxied` is a
+ property of the configured route, not a proof about the socket that was used.
+ A `DIRECT` entry anywhere in the list is therefore read as `unknown`.
+ - **Who controls the route.** The user does, through Settings → Network
+ (ADR 0177) or the OS/browser proxy configuration. Nothing in the renderer,
+ in a catalog entry, or in a plugin can influence it, and nothing in the
+ market path can write it.
+
+Why that is acceptable:
+
+- The property the guard protects is "this app never dials an internal address by
+ itself". On a proxied route that property is *stronger* than before rather than
+ weaker: the app's only possible peer is the user-configured proxy, and the
+ destination is chosen by that proxy instead of by a name whose resolution an
+ attacker may control. What the pre-check actually enforced on a proxied route
+ was a claim about a resolver the request did not use — it produced the false
+ positive in #419 without ever inspecting the dialed peer.
+- The one class now tolerated is *by construction* the signature of local
+ interception rather than of an internal target: `198.18.0.0/15` is RFC 2544
+ benchmarking space and hosts no service.
+- Everything the guard can still verify in-process — URL shape, per-hop
+ re-validation, every real internal address class, an unanswered resolver — is
+ still verified, and the verdict is now made about the object the request will
+ actually use.
+
+When to roll this back:
+
+- If Electron ever exposes the peer a request actually connected to, and it is
+ not the proxy, replace the route verdict with that peer check. The route
+ verdict exists only because the dialed peer is not observable.
+- If a report shows a proxied hop reaching a private or metadata target through a
+ fake-IP answer, or Chromium falling back to a direct connection the route list
+ did not advertise, restore the strict verdict for that case and keep the
+ fake-IP case behind an explicit user setting instead.
+- If `Session.resolveProxy` stops reporting the configured proxy, the route
+ collapses to `unknown` and the guard returns to the strict behavior by itself.
+ That failure direction — the pre-#419 false positive returns rather than a
+ private target being dialed — is the intended one.
+
+## Consequences
+
+- A proxied or fake-IP user's skill market works: no source is refused for an
+ address the request would never dial (issue #419).
+- A `direct`-route user keeps the old verdicts, so the change cannot be used to
+ reach an internal address by not being behind a proxy.
+- The MCP market is **not** covered by this change. It dials a pinned public
+ address with Node HTTPS (ADR 0245), so its guard already checks the address it
+ connects to, and it does not consult Chromium's proxy route; a fake-IP
+ environment still refuses MCP market sources. Fixing that means giving that
+ path a proxy-aware pinned dispatcher, which ADR 0245 already lists as open
+ work.
+- A TUN user who configured no proxy the app can see is still refused: the
+ transport reports `DIRECT` while the local resolver answers fake-IP. That case
+ is deliberately left strict (clause 3), and its remedy is to enable the system
+ proxy or set the app's Custom proxy, after which the route is proxied and the
+ market works.
+- The route is read once per hop, so the market pays one extra `resolveProxy`
+ round trip per hop — bounded by the same five-hop cap.
+
+## Alternatives
+
+- **Delete the DNS gate for every request.** Rejected: it removes the SSRF guard
+ for direct users too, and the guard would no longer stop a private answer from
+ being dialed by the app itself.
+- **Relax `198.18.0.0/15` unconditionally.** Rejected: it accepts an answer the
+ app cannot attribute to an interception layer, and it silently allows a
+ connection to a host addressed in that range on a direct route.
+- **Let the user allowlist a source.** Rejected: it moves a security decision to
+ a user who cannot see what the address would be used for, needs new settings
+ and UI for a case the app can decide, and would not have helped in #419, where
+ every source was refused at once.
+- **Check the peer after connecting.** Unavailable, and the honest reason this
+ ADR exists: Electron's `net.fetch` performs proxy resolution and dialing inside
+ the network service and exposes no peer address afterwards. The pre-ADR guard
+ could not do this either, which is why its proxied verdict was noise.
+- **Read the route from the app's own proxy settings only.** Rejected as
+ incomplete: it would miss PAC and OS-level proxy configuration, which is
+ exactly what a Clash-style "system proxy" setup uses. `Session.resolveProxy`
+ reports what the session will really use, PAC included.
diff --git a/docs/adr/README.md b/docs/adr/README.md
index 2b83ebdd1..a1075cf63 100644
--- a/docs/adr/README.md
+++ b/docs/adr/README.md
@@ -297,3 +297,4 @@ Each ADR includes:
| 0270 | [Builtin subagents can be switched off](0270-builtin-subagents-can-be-disabled.md) | Accepted for implementation (amends ADR 0063; ADR 0112) |
| 0269 | [Move capability documents between the global and project levels](0269-capability-level-transfer.md) | Accepted for implementation (amends ADR 0112) |
| 0268 | Remove quotes, annotations, and side chats | Accepted (supersedes message-quotes-and-side-chats / response-annotations / floating-annotation-index) |
+| 0272 | [Judge a public-network address on the route the request will dial](0272-connection-time-public-network-route.md) | Accepted for implementation (amends ADR 0243; issue #419 / PR #473) |
diff --git a/docs/spec/03-runtime/01-ipc-protocol.md b/docs/spec/03-runtime/01-ipc-protocol.md
index 2a25f74db..992838ec9 100644
--- a/docs/spec/03-runtime/01-ipc-protocol.md
+++ b/docs/spec/03-runtime/01-ipc-protocol.md
@@ -1469,9 +1469,11 @@ Desktop-only skill market channels (not host RPC) live on Electron IPC:
never left the process), `unresolved` (the local DNS lookup returned no answer,
so no address was judged — a resolver or proxy condition, not a verdict on the
source), or `network`. `failureDetails` carries the same keys with the host
- that actually failed, the guard's own `reason`, and the class of the refused
- address, which is what lets the panel name *what* was refused instead of only
- which source went quiet. A judged refusal also surfaces as
+ that actually failed, the guard's own `reason`, the class of the refused
+ address, and the route that address was judged on (`proxied`, `direct`, or
+ `unknown` when the transport reported no readable route, ADR 0272), which is
+ what lets the panel name *what* was refused instead of only which source went
+ quiet.
`NETWORK_POLICY_BLOCKED` and an unanswered resolver as `NETWORK_RESOLVE_FAILED`
(spec 08 §3.1); the install sheet classifies a failed preview on those two
codes.
diff --git a/docs/spec/03-runtime/09-logging-and-observability.md b/docs/spec/03-runtime/09-logging-and-observability.md
index 34d7f718d..14d7cb09c 100644
--- a/docs/spec/03-runtime/09-logging-and-observability.md
+++ b/docs/spec/03-runtime/09-logging-and-observability.md
@@ -55,18 +55,22 @@ The application categories are:
diagnostics. The skill market's two channels record one
`skillMarket.sourceFailed` / `skillMarket.documentFailed` record per source
or document that produced nothing, with `source`, `host`, `kind` and — for a
- guard refusal — `reason` and `addressKind` in `data`. `kind` is `policy` when
- the guard judged the target, `unresolved` when the local resolver returned no
- answer, and `network` otherwise; `code` is `NETWORK_POLICY_BLOCKED` for the
- first and `NETWORK_RESOLVE_FAILED` for the second, so one log line separates
- "the address is not public" from "the resolver answered nothing". `reason`
- names the guard's own branch (`url-syntax`, `resolve-failed`,
- `non-public-address`, `redirect-limit`) and `addressKind` the class of the
- refused address (`benchmark` for a TUN fake-IP, `private` for RFC1918). The
- record carries the host name and that class only — never the address, the URL,
- its path, query or credentials — because a catalog source URL is
- user-supplied, the refused host is the whole diagnostic value, and the class
- is what tells a resolver artifact from a real private target (issue #419).
+ guard refusal — `reason`, `addressKind` and `route` in `data`. `kind` is
+ `policy` when the guard judged the target, `unresolved` when the local
+ resolver returned no answer, and `network` otherwise; `code` is
+ `NETWORK_POLICY_BLOCKED` for the first and `NETWORK_RESOLVE_FAILED` for the
+ second, so one log line separates "the address is not public" from "the
+ resolver answered nothing". `reason` names the guard's own branch
+ (`url-syntax`, `resolve-failed`, `non-public-address`, `redirect-limit`),
+ `addressKind` the class of the refused address (`benchmark` for a TUN fake-IP,
+ `private` for RFC1918), and `route` the route that address was judged on
+ (`proxied`, `direct`, or `unknown` when the transport reported no readable
+ route), so a fake-IP refusal on a direct route reads apart from one on a route
+ nobody could read (ADR 0272). The record carries the host name, that class and
+ that route only — never the address, the URL, its path, query or credentials —
+ because a catalog source URL is user-supplied, the refused host is the whole
+ diagnostic value, and the class is what tells a resolver artifact from a real
+ private target (issue #419).
- `runtime` — host/sidecar lifecycle, uncategorized child output, and
main-process `uncaughtException` / `unhandledRejection` records
diff --git a/docs/spec/05-security/01-security.md b/docs/spec/05-security/01-security.md
index 66e0694bf..c307910aa 100644
--- a/docs/spec/05-security/01-security.md
+++ b/docs/spec/05-security/01-security.md
@@ -100,11 +100,17 @@ replace an artifact.
The renderer does not fetch skill catalogs or SKILL.md documents. Electron
main performs those HTTPS requests under the public-network policy (ADR 0243 /
-D413): `https` only, a shared syntactic public-host check, DNS classification
-of every resolved address, and `redirect: "manual"` with per-hop
-re-validation. Loopback, RFC1918, ULA, link-local, and mapped IPv6 targets
-are rejected. Install writes markdown only through `skills.create`. The host
-document cap remains 128 KiB after sibling markdown is inlined.
+D413, amended by ADR 0272 / D436): `https` only, a shared syntactic public-host
+check, `redirect: "manual"`, and a per-hop verdict that follows the route the
+request will actually take. Before each hop the client asks the session that
+carries `net.fetch` for its own proxy decision (`Session.resolveProxy`): on a
+proxied route the hop is judged on its route rather than on a local address the
+app would never dial, so only the resolver-artifact class (`benchmark`, a TUN
+fake-IP) is tolerated there, while a direct or unreadable route keeps the full
+local classification and rejects loopback, RFC1918, ULA, link-local, mapped
+IPv6, and every other non-public class. Install writes markdown only through
+`skills.create`. The host document cap remains 128 KiB after sibling markdown
+is inlined.
## 4.2 MCP market egress
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 3db47281a..a54026c12 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -12185,11 +12185,14 @@ plugin-form fixtures in an isolated temporary directory at runtime.
#### E2E-SKILL-MARKET-NET-BOUNDARY: Public-HTTPS skill sources reject private and loopback URLs
- **Preconditions**: Shared public-network helpers and the main-process
- public-HTTPS client with injectable fetch/DNS.
+ public-HTTPS client with injectable fetch/DNS/route.
- **Steps**: 1) Classify trailing-dot localhost, IPv4 loopback, IPv4-mapped
IPv6, ULA, link-local, RFC1918, and `http://` URLs. 2) Resolve a public
hostname to a private A record. 3) Follow a 302 whose Location is
- `https://127.0.0.1/`.
+ `https://127.0.0.1/`. 4) Report a proxied route and a TUN fake-IP answer
+ (`198.18.0.1`), the same answer on a `DIRECT` route, on an unreadable route,
+ and on a route list that offers `DIRECT`. 5) Let a first hop be proxied and
+ its redirect target direct.
- **Expected**: Every bypass form is rejected. A public CDN URL is accepted.
DNS that yields a private address and a redirect onto loopback both throw a
policy error without fetching the private target. A judged refusal is not
@@ -12197,16 +12200,21 @@ plugin-form fixtures in an isolated temporary directory at runtime.
`NETWORK_RESOLVE_FAILED` (`kind` `unresolved`) rather than as an address-check
refusal — the guard reached no verdict, so nothing may claim it did. Every
other refusal carries `NETWORK_POLICY_BLOCKED` (spec 08 §3.1) with its
- `reason` and the class of the refused address, so the install sheet can name
- the reason and offer a retry instead of leaving the install button disabled
- with no explanation, and the market list can tell a refused source apart from
- a merely unreachable one.
-- **Specs linked**: `05-security/01-security.md`, ADR 0243,
+ `reason`, the class of the refused address, and the route that address was
+ judged on, so the install sheet can name the reason and offer a retry instead
+ of leaving the install button disabled with no explanation, and the market
+ list can tell a refused source apart from a merely unreachable one. A proxied
+ hop whose answer is the RFC 2544 fake-IP class is refused on a direct or
+ unreadable route and accepted on the proxied one, every other non-public class
+ still refuses on all routes, and each redirect hop is judged on its own route
+ (ADR 0272).
+- **Specs linked**: `05-security/01-security.md`, ADR 0243, ADR 0272,
`03-runtime/01-ipc-protocol.md` §12b
- **Acceptance**: Security, Quality
- **Milestone**: M6+
- **Status**: Automated (`pnpm test:e2e:skill-market`,
`apps/desktop/test/public-https-fetch.test.mjs`,
+ `apps/desktop/test/public-https-fetch-route.test.mjs`,
`apps/desktop/test/skill-market-scan.test.mjs`,
`apps/desktop/test/skill-market-failure.test.mjs`,
`apps/desktop/test/skill-market-policy-refusal.test.mjs`,
diff --git a/docs/spec/08-meta/decisions-log.md b/docs/spec/08-meta/decisions-log.md
index 06521238c..6fbea634d 100644
--- a/docs/spec/08-meta/decisions-log.md
+++ b/docs/spec/08-meta/decisions-log.md
@@ -5629,3 +5629,27 @@ that was sitting at the bottom — including after the turn had finished.
file, and an unavailable host contributes no exclusions. See ADR 0270,
`04-ux/06-settings-ia.md` §2, `03-runtime/01-ipc-protocol.md` §12c, and
E2E-SUBAGENT-settings-lists-builtin-defaults.
+
+## 2026-09-17 — Judge a public-network address on the route the request will dial (D436)
+
+- The skill market's main-process guard classified the target host with a
+ *local* resolver while `net.fetch` dials through Chromium's proxy stack
+ (ADR 0177). Under a TUN / fake-IP resolver that answer is a synthesized
+ `198.18.0.0/15` address for a connection the app never makes, so every
+ catalog source was refused as "blocked by the app's address check"
+ (issue #419).
+- Each hop now asks the session that carries `net.fetch`
+ (`Session.resolveProxy`) for its own decision, and the shared
+ `classifyProxyRoute` reduces that answer to `proxied` / `direct` / `unknown`.
+ On a `proxied` route `isAcceptableResolvedAddress` tolerates only the
+ resolver-artifact class (`benchmark`); every real internal class and an
+ unanswered resolver still refuse. A `direct` route keeps the pre-change
+ semantics byte for byte, a `DIRECT` entry anywhere in the list is read as
+ `unknown` because Chromium may fall back to it, and `unknown` stays strict.
+- Refusals and the market's `failureDetails` now carry `route`, so a fake-IP
+ refusal on a direct route reads apart from one on an unreadable route.
+- The MCP market keeps its pinned Node HTTPS guard (ADR 0245) and is unchanged;
+ a fake-IP environment still refuses its sources.
+- See ADR 0272, `05-security/01-security.md` §4.1,
+ `03-runtime/09-logging-and-observability.md`, and
+ `06-delivery/04-e2e-test-plan.md` E2E-SKILL-MARKET-NET-BOUNDARY.
diff --git a/docs/zh-CN/adr/index.md b/docs/zh-CN/adr/index.md
index 6fba453c2..22ea64fa6 100644
--- a/docs/zh-CN/adr/index.md
+++ b/docs/zh-CN/adr/index.md
@@ -285,6 +285,7 @@ ADR 记录那些不应被静默改变的架构选择。中文入口与英文索
| 0253 | [移除子智能体轮次上限](/adr/0253-remove-subagent-turn-limit) | 已接受(取代 0062 / 0063 / 0119 / 0126 / 0166 / 0210 中关于 `maxTurns` 的条款) |
| 0265 | [排队队列的优先区块与行内操作](/adr/0265-turn-queue-priority-block-and-row-actions) | 已接受待实现(修订 ADR 0213 / 0118) |
| 0267 | [插件标签跟随应用语言](/adr/0267-plugin-labels-follow-the-app-language) | 已接受(修订 ADR 0160;ADR 0182) |
+ | 0272 | [按请求实际会走的线路判定公网地址](/adr/0272-connection-time-public-network-route) | 已接受待实现(修订 ADR 0243;issue #419 / PR #473) |
## 什么时候看 ADR
diff --git a/docs/zh-CN/spec/03-runtime/01-ipc-protocol.md b/docs/zh-CN/spec/03-runtime/01-ipc-protocol.md
index 98c777c3f..b1612ecc3 100644
--- a/docs/zh-CN/spec/03-runtime/01-ipc-protocol.md
+++ b/docs/zh-CN/spec/03-runtime/01-ipc-protocol.md
@@ -1214,10 +1214,10 @@ ASCII slug:frontmatter `name` 能 slugify 时用它,否则 `SKILL.md` 用技
- `pi-desktop/skill/market/search` — `{ query, sources[] }` →
`{ entries, failedSources, failureKinds, failureDetails }`。
主进程聚合目录 JSON 与 GitHub 仓库 SKILL.md 扫描。源 URL 必须通过公网 HTTPS 策略(ADR 0243)。单源失败只丢掉该源。
- `failureKinds` 把 `failedSources` 中的每个名字映射到 `policy`(公网策略守卫判定了目标并拒绝,请求从未离开进程)、`unresolved`(本地 DNS 解析没有返回答案,因此没有判定任何地址——这是解析器或代理的环境状况,不是对源的判定)或 `network`。`failureDetails` 以同样的键携带真正失败的主机、守卫自己的 `reason` 以及被拒地址的类别;面板据此说明**被拒的是什么**,而不只是哪个源没出结果。
+ `failureKinds` 把 `failedSources` 中的每个名字映射到 `policy`(公网策略守卫判定了目标并拒绝,请求从未离开进程)、`unresolved`(本地 DNS 解析没有返回答案,因此没有判定任何地址——这是解析器或代理的环境状况,不是对源的判定)或 `network`。`failureDetails` 以同样的键携带真正失败的主机、守卫自己的 `reason`、被拒地址的类别以及判定该地址的线路(`proxied`、`direct`,或传输层读不出线路时的 `unknown`,ADR 0272);面板据此说明**被拒的是什么**,而不只是哪个源没出结果。
判定型拒绝以 `NETWORK_POLICY_BLOCKED` 暴露,解析器无应答以 `NETWORK_RESOLVE_FAILED` 暴露(spec 08 §3.1);安装面板正是按这两个错误码分类。
- `pi-desktop/skill/market/fetch` — `{ entry }` → `{ name?, description?, body, resources? }`。
- 主进程按同一策略拉取文档、拆 frontmatter,并可能附上 jsDelivr 目录中的兄弟 `.md`。渲染层通过现有 `skills.create` 安装。该策略即主进程公网网络客户端:语法 URL 防护、DNS 分类、逐跳重定向复核与响应上限——渲染层绝不直接触网。目录 id 会净化为 host `valid_capability_id`。
+ 主进程按同一策略拉取文档、拆 frontmatter,并可能附上 jsDelivr 目录中的兄弟 `.md`。渲染层通过现有 `skills.create` 安装。该策略即主进程公网网络客户端:语法 URL 防护、按承载 `net.fetch` 的会话线路判定的逐跳 DNS 分类(ADR 0272)、逐跳重定向复核与响应上限——渲染层绝不直接触网。目录 id 会净化为 host `valid_capability_id`。
桌面专用 MCP 市场通道(不是 host RPC)走 Electron IPC:
diff --git a/docs/zh-CN/spec/03-runtime/09-logging-and-observability.md b/docs/zh-CN/spec/03-runtime/09-logging-and-observability.md
index a852c957a..77c8240b4 100644
--- a/docs/zh-CN/spec/03-runtime/09-logging-and-observability.md
+++ b/docs/zh-CN/spec/03-runtime/09-logging-and-observability.md
@@ -52,7 +52,7 @@ host 和 agent stderr 使用标记进行分类;无法分类的子进程输出
- `provider` — provider/model 发现、重试和缓存失败
- `persistence` — 成绩单和发件箱持久化失败
- `updater` — 更新器诊断和错误
-- `diagnostics` — 阻止导航、菜单、模板以及对外请求的诊断。技能市场的两个通道会为每个没有产出结果的源或文档各记录一条 `skillMarket.sourceFailed` / `skillMarket.documentFailed`:`data` 里带 `source`、`host`、`kind`,以及被守卫拒绝时的 `reason` 与 `addressKind`。`kind` 在守卫判定了目标时为 `policy`,本地解析没有返回答案时为 `unresolved`,其余为 `network`;`code` 前者为 `NETWORK_POLICY_BLOCKED`,后者为 `NETWORK_RESOLVE_FAILED`,因此一行日志即可区分「地址不是公网」与「解析器没有应答」。`reason` 记录守卫自己的分支(`url-syntax`、`resolve-failed`、`non-public-address`、`redirect-limit`),`addressKind` 记录被拒地址的类别(TUN fake-IP 为 `benchmark`,RFC1918 为 `private`)。记录中只保留主机名与该类别 —— 绝不包含地址、URL、其路径、查询串或凭据 —— 因为目录源 URL 由用户提供,被拒绝的主机正是全部诊断价值所在,而该类别正是区分解析器产物与真实私网目标的依据(issue #419)。
+- `diagnostics` — 阻止导航、菜单、模板以及对外请求的诊断。技能市场的两个通道会为每个没有产出结果的源或文档各记录一条 `skillMarket.sourceFailed` / `skillMarket.documentFailed`:`data` 里带 `source`、`host`、`kind`,以及被守卫拒绝时的 `reason`、`addressKind` 与 `route`。`kind` 在守卫判定了目标时为 `policy`,本地解析没有返回答案时为 `unresolved`,其余为 `network`;`code` 前者为 `NETWORK_POLICY_BLOCKED`,后者为 `NETWORK_RESOLVE_FAILED`,因此一行日志即可区分「地址不是公网」与「解析器没有应答」。`reason` 记录守卫自己的分支(`url-syntax`、`resolve-failed`、`non-public-address`、`redirect-limit`),`addressKind` 记录被拒地址的类别(TUN fake-IP 为 `benchmark`,RFC1918 为 `private`),`route` 记录该地址是在哪条线路上被判定的(`proxied`、`direct`,或传输层读不出线路时的 `unknown`),因此「直连线路上的 fake-IP 拒绝」与「读不出线路的拒绝」可以区分(ADR 0272)。记录中只保留主机名、该类别与该线路 —— 绝不包含地址、URL、其路径、查询串或凭据 —— 因为目录源 URL 由用户提供,被拒绝的主机正是全部诊断价值所在,而该类别正是区分解析器产物与真实私网目标的依据(issue #419)。
- `runtime` — host/sidecar 生命周期、未分类的子进程输出,以及主进程
`uncaughtException` / `unhandledRejection` 记录
diff --git a/docs/zh-CN/spec/05-security/01-security.md b/docs/zh-CN/spec/05-security/01-security.md
index c807e41e2..428ef1f03 100644
--- a/docs/zh-CN/spec/05-security/01-security.md
+++ b/docs/zh-CN/spec/05-security/01-security.md
@@ -96,7 +96,7 @@ CDP 插件工具在 Plan 中仍被拒绝)。 Bash 在 Plan 中仍然可用:
## 4.1 技能市场出网
-渲染层不拉取技能目录或 SKILL.md。Electron 主进程按公网策略发起 HTTPS 请求(ADR 0243 / D413):仅 `https`、共享的公网主机语法检查、对每个解析地址做 DNS 分类,以及 `redirect: "manual"` 的逐跳再校验。回环、RFC1918、ULA、link-local 与 mapped IPv6 一律拒绝。安装只通过 `skills.create` 写入 markdown。内联相邻 markdown 后仍受 128 KiB 宿主上限约束。
+渲染层不拉取技能目录或 SKILL.md。Electron 主进程按公网策略发起 HTTPS 请求(ADR 0243 / D413,由 ADR 0272 / D436 修订):仅 `https`、共享的公网主机语法检查、`redirect: "manual"`,以及按请求实际会走的线路逐跳判定。每一跳之前,客户端都会向承载 `net.fetch` 的会话询问它自己的代理判定(`Session.resolveProxy`):`proxied` 线路上按线路判定,而不是按应用永远不会拨打的本地地址判定,因此只容忍解析器自身产物的那一类(`benchmark`,TUN fake-IP);`direct` 或读不出线路时保留完整的本地分类,回环、RFC1918、ULA、link-local、mapped IPv6 以及其他所有非公网类别一律拒绝。安装只通过 `skills.create` 写入 markdown。内联相邻 markdown 后仍受 128 KiB 宿主上限约束。
## 4.2 MCP 市场出网
diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
index 43eecc554..72b4e4fff 100644
--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
@@ -7386,13 +7386,13 @@ runner 会在运行时的隔离临时目录中生成六个插件形态 fixture
#### E2E-SKILL-MARKET-NET-BOUNDARY:技能源公网 HTTPS 策略拒绝私网与回环
-- **前提条件**:共享 public-network helper,以及可注入 fetch/DNS 的主进程公网 HTTPS 客户端。
-- **步骤**:1)分类 trailing-dot localhost、IPv4 回环、IPv4-mapped IPv6、ULA、link-local、RFC1918 与 `http://`。2)将公网主机名解析到私网 A 记录。3)跟随 Location 为 `https://127.0.0.1/` 的 302。
-- **预期**:上述绕过形态全部拒绝;公共 CDN 放行。解析到私网地址或 redirect 到回环会抛出策略错误,且不会请求私网目标。判定型拒绝不重试;本地解析没有返回答案时会重试,并且报为 `NETWORK_RESOLVE_FAILED`(`kind` 为 `unresolved`),而不是报成地址校验拒绝——守卫并未得出判定,任何文案都不得声称它得出了。其余每次拒绝都带上 `NETWORK_POLICY_BLOCKED`(spec 08 §3.1)及其 `reason` 与被拒地址的类别,使安装面板能给出原因并提供重试,而不是让安装按钮无解释地保持禁用;市场列表也能把被拒绝的源与单纯不可达的源区分开。
-- **链接规格**:`05-security/01-security.md`、ADR 0243、`03-runtime/01-ipc-protocol.md` §12b
+- **前提条件**:共享 public-network helper,以及可注入 fetch/DNS/线路 的主进程公网 HTTPS 客户端。
+- **步骤**:1)分类 trailing-dot localhost、IPv4 回环、IPv4-mapped IPv6、ULA、link-local、RFC1918 与 `http://`。2)将公网主机名解析到私网 A 记录。3)跟随 Location 为 `https://127.0.0.1/` 的 302。4)报告 `proxied` 线路与 TUN fake-IP 答案(`198.18.0.1`),同一答案在 `DIRECT` 线路、读不出线路、以及列表中含 `DIRECT` 的线路上的表现。5)让第一跳为 `proxied`,其重定向目标为 `direct`。
+- **预期**:上述绕过形态全部拒绝;公共 CDN 放行。解析到私网地址或 redirect 到回环会抛出策略错误,且不会请求私网目标。判定型拒绝不重试;本地解析没有返回答案时会重试,并且报为 `NETWORK_RESOLVE_FAILED`(`kind` 为 `unresolved`),而不是报成地址校验拒绝——守卫并未得出判定,任何文案都不得声称它得出了。其余每次拒绝都带上 `NETWORK_POLICY_BLOCKED`(spec 08 §3.1)及其 `reason`、被拒地址的类别与判定该地址的线路,使安装面板能给出原因并提供重试,而不是让安装按钮无解释地保持禁用;市场列表也能把被拒绝的源与单纯不可达的源区分开。若 `proxied` 线路上的答案是 RFC 2544 的 fake-IP 类别,则在 `direct` 或读不出线路时拒绝、在 `proxied` 线路上放行;其他所有非公网类别在任何线路上都拒绝;每一个重定向跳都按自己的线路判定(ADR 0272)。
+- **链接规格**:`05-security/01-security.md`、ADR 0243、ADR 0272、`03-runtime/01-ipc-protocol.md` §12b
- **验收**:Security、Quality
- **里程碑**:M6+
-- **状态**:已自动化(`pnpm test:e2e:skill-market`、`apps/desktop/test/public-https-fetch.test.mjs`、`apps/desktop/test/skill-market-scan.test.mjs`、`apps/desktop/test/skill-market-failure.test.mjs`、`apps/desktop/test/skill-market-policy-refusal.test.mjs`、`packages/shared/src/public-network.test.ts`)
+- **状态**:已自动化(`pnpm test:e2e:skill-market`、`apps/desktop/test/public-https-fetch.test.mjs`、`apps/desktop/test/public-https-fetch-route.test.mjs`、`apps/desktop/test/skill-market-scan.test.mjs`、`apps/desktop/test/skill-market-failure.test.mjs`、`apps/desktop/test/skill-market-policy-refusal.test.mjs`、`packages/shared/src/public-network.test.ts`)
#### E2E-SKILL-MARKET-EXPANSION:相邻 markdown 资源在安装前内联
diff --git a/docs/zh-CN/spec/08-meta/decisions-log.md b/docs/zh-CN/spec/08-meta/decisions-log.md
index 92cd58e47..59d66c4e1 100644
--- a/docs/zh-CN/spec/08-meta/decisions-log.md
+++ b/docs/zh-CN/spec/08-meta/decisions-log.md
@@ -4271,3 +4271,11 @@ that amendment are retired by ADR 0268; the upstream work-panel lifecycle stays.
- 设置 > 智能体 > 子智能体把五个随应用发布的默认项列为只读行,而用户自建的文档带启用开关,于是有一个委派对象完全无法关闭:复制一个内置项再停用副本,随应用发布的定义仍留在目录里,因为被停用的用户文档在加载器合并前就被过滤掉,也就没有遮蔽任何东西。
- 每个内置行现在都带同一个开关。句柄存放在 `<data>/agent-capabilities/subagent-builtins.json` —— 一个独立文件,因为用户文档扫描会清理它永远看不到的 id 的状态 —— 并由 host-core 通过 `agents.disabledBuiltins` / `agents.setBuiltinEnabled` 暴露。Electron 主进程把被关闭的句柄交给 `loadSubagentDefinitions`,由它把它们从委派目录中剔除,而 `subagent/catalog` 仍会在其新增的 `builtins` 列表中返回该内置项,并标记 `enabled: false`。
- 被关闭的内置项保留自己的行并变暗,因此这个开关就是重新打开的入口。同名的用户文档继续生效并继续遮蔽随应用发布的定义,在文件夹中显示与删除仍然没有,因为内置不是文件;宿主不可用时也不会贡献任何排除项。见 ADR 0270、`04-ux/06-settings-ia.md` §2、`03-runtime/01-ipc-protocol.md` §12c 与 E2E-SUBAGENT-settings-lists-builtin-defaults。
+
+## 2026-09-17 —— 按请求实际会走的线路判定公网地址(D436)
+
+- 技能市场的主进程守卫此前用*本地*解析器判定目标主机,而 `net.fetch` 走的是 Chromium 的代理栈(ADR 0177)。在 TUN / fake-IP 解析器下,那个答案是应用永远不会建立的连接的合成地址(`198.18.0.0/15`),于是每个目录源都被判为「被应用的地址校验阻止」(issue #419)。
+- 现在每一跳都向承载 `net.fetch` 的会话询问它自己的判定(`Session.resolveProxy`),共享的 `classifyProxyRoute` 把该答案归为 `proxied` / `direct` / `unknown`。在 `proxied` 线路上,`isAcceptableResolvedAddress` 只容忍解析器自身产物的那一类(`benchmark`);所有真实内网类别与「解析器没有应答」仍然拒绝。`direct` 线路与改动前逐字一致;列表里任何位置出现 `DIRECT` 都按 `unknown` 处理(Chromium 可能回退到它),而 `unknown` 走严格路径。
+- 拒绝与市场的 `failureDetails` 现在都带 `route`,因此「直连线路上的 fake-IP 拒绝」与「读不出线路的拒绝」在诊断里可以区分。
+- MCP 市场仍使用自己的地址钉定 Node HTTPS 守卫(ADR 0245),本次不变;fake-IP 环境下它的源仍会被拒绝。
+- 见 ADR 0272、`05-security/01-security.md` §4.1、`03-runtime/09-logging-and-observability.md` 与 `06-delivery/04-e2e-test-plan.md` 的 E2E-SKILL-MARKET-NET-BOUNDARY。
diff --git a/packages/shared/src/public-network.test.ts b/packages/shared/src/public-network.test.ts
index 9d419ba0e..1ec3a466f 100644
--- a/packages/shared/src/public-network.test.ts
+++ b/packages/shared/src/public-network.test.ts
@@ -2,6 +2,8 @@ import { describe, expect, it } from "vitest";
import {
classifyIpAddress,
classifyIpLiteral,
+ classifyProxyRoute,
+ isAcceptableResolvedAddress,
isPublicHttpsUrl,
isPublicIpLiteral,
PUBLIC_NETWORK_POLICY_ERROR,
@@ -139,4 +141,96 @@ describe("public network address policy", () => {
expect(publicNetworkRefusalDetail(new Error("responded 502"))).toBeUndefined();
expect(publicNetworkRefusalDetail(undefined)).toBeUndefined();
});
+
+ it("reads the route a proxy list proves, and refuses to guess", () => {
+ // ADR 0272: the address verdict follows the route the request will take, so
+ // the route has to be read strictly. Only a list with a proxy chain and no
+ // `DIRECT` entry proves the app's socket can be a proxy: Chromium may fall
+ // back to `DIRECT`, so an offered direct connection is `unknown`, never
+ // `proxied`.
+ const cases: Array<[unknown, ReturnType<typeof classifyProxyRoute>]> = [
+ ["DIRECT", "direct"],
+ ["direct", "direct"],
+ ["PROXY 127.0.0.1:7890", "proxied"],
+ ["SOCKS5 127.0.0.1:1080", "proxied"],
+ ["SOCKS 127.0.0.1:1080", "proxied"],
+ ["HTTPS proxy.example:443", "proxied"],
+ ["SOCKS5 a.example:1, PROXY b.example:2", "proxied"],
+ ["PROXY 127.0.0.1:7890; PROXY 127.0.0.1:7891", "proxied"],
+ ["PROXY 127.0.0.1:7890; DIRECT", "unknown"],
+ ["DIRECT; PROXY 127.0.0.1:7890", "unknown"],
+ ["", "unknown"],
+ [" ", "unknown"],
+ ["MAGIC 127.0.0.1:7890", "unknown"],
+ ["PROXY", "unknown"],
+ ["PROXY 127.0.0.1:7890; MAGIC x", "unknown"],
+ [undefined, "unknown"],
+ [null, "unknown"],
+ [7890, "unknown"],
+ ];
+ for (const [proxyList, route] of cases) {
+ expect(classifyProxyRoute(proxyList), JSON.stringify(proxyList)).toBe(route);
+ }
+ });
+
+ it("accepts only the resolver artifact on a proxied route", () => {
+ // `benchmark` is a TUN fake-IP answer: an address this app never dials when
+ // it is dialing a proxy. Every class that names a real internal target still
+ // refuses on both routes, and a direct (or unreadable) route keeps the
+ // original rule for all of them.
+ expect(isAcceptableResolvedAddress("public", "direct")).toBe(true);
+ expect(isAcceptableResolvedAddress("public", "proxied")).toBe(true);
+ expect(isAcceptableResolvedAddress("public", "unknown")).toBe(true);
+ expect(isAcceptableResolvedAddress("benchmark", "proxied")).toBe(true);
+ expect(isAcceptableResolvedAddress("benchmark", "direct")).toBe(false);
+ expect(isAcceptableResolvedAddress("benchmark", "unknown")).toBe(false);
+ for (const kind of [
+ "invalid",
+ "unspecified",
+ "loopback",
+ "private",
+ "cgnat",
+ "link-local",
+ "multicast",
+ "reserved",
+ "documentation",
+ "ula",
+ "site-local",
+ ] as const) {
+ expect(isAcceptableResolvedAddress(kind, "proxied"), kind).toBe(false);
+ }
+ });
+
+ it("carries the judged route, and drops an unknown one", () => {
+ expect(
+ publicNetworkRefusalDetail({
+ name: PUBLIC_NETWORK_POLICY_ERROR,
+ reason: "non-public-address",
+ host: "cdn.jsdelivr.net",
+ address: "198.18.0.4",
+ addressKind: "benchmark",
+ route: "direct",
+ }),
+ ).toEqual({
+ reason: "non-public-address",
+ host: "cdn.jsdelivr.net",
+ addressKind: "benchmark",
+ route: "direct",
+ });
+ expect(
+ publicNetworkRefusalDetail({
+ name: PUBLIC_NETWORK_POLICY_ERROR,
+ reason: "resolve-failed",
+ host: "api.github.com",
+ route: "made-up",
+ }),
+ ).toEqual({ reason: "resolve-failed", host: "api.github.com" });
+ expect(
+ publicNetworkRefusalDetail({
+ name: PUBLIC_NETWORK_POLICY_ERROR,
+ reason: "url-syntax",
+ route: "proxied",
+ }),
+ ).toEqual({ reason: "url-syntax", route: "proxied" });
+ });
});
diff --git a/packages/shared/src/public-network.ts b/packages/shared/src/public-network.ts
index bcc2b3a9e..2b91f9ac4 100644
--- a/packages/shared/src/public-network.ts
+++ b/packages/shared/src/public-network.ts
@@ -1,7 +1,9 @@
/**
* Pure public-network policy shared by renderer validation and main-process
* request guards. This is deliberately syntactic; callers that make network
- * requests must also pin DNS resolution to the address they validate.
+ * requests must also pin DNS resolution to the address they validate, and ask
+ * the transport which route a request will take before judging that address
+ * (ADR 0272).
*/
export type PublicNetworkAddressKind =
@@ -136,6 +138,72 @@ export function isPublicHttpsUrl(value: string): boolean {
/** Backward-compatible descriptive alias for the generic public URL guard. */
export const isSafePublicHttpsUrl = isPublicHttpsUrl;
+/**
+ * The route the transport will actually take for a URL, as the Chromium session
+ * that carries the request reports it (`Session.resolveProxy`).
+ *
+ * `proxied` means this app dials a proxy rather than the destination, so the
+ * addresses the *local* resolver returns for that host describe no connection
+ * this app makes. `unknown` is never permission: a route the app cannot read
+ * keeps the strict local-DNS verdict (ADR 0272).
+ */
+export type PublicNetworkRoute = "direct" | "proxied" | "unknown";
+
+/** Entry types `resolveProxy` publishes, in its `TYPE host:port` list format. */
+const PROXY_LIST_TYPES = ["PROXY", "HTTP", "HTTPS", "SOCKS", "SOCKS4", "SOCKS5"];
+const PROXY_CHAIN_ENTRY = new RegExp(
+ `^(?:${PROXY_LIST_TYPES.join("|")})\\s+\\S+(?:\\s*,\\s*(?:${PROXY_LIST_TYPES.join("|")})\\s+\\S+)*$`,
+);
+
+/**
+ * Classify Chromium's proxy-list answer for one URL (`Session.resolveProxy`).
+ *
+ * Only a list that names at least one proxy chain and offers no `DIRECT` entry
+ * proves the app's socket can be a proxy rather than the destination. A list
+ * that also offers `DIRECT` stays `unknown`, because Chromium may fall back to
+ * it, and an empty or unparsable answer stays `unknown` too. Nothing here
+ * guesses in the permissive direction (ADR 0272).
+ */
+export function classifyProxyRoute(proxyList: unknown): PublicNetworkRoute {
+ if (typeof proxyList !== "string") return "unknown";
+ const entries = proxyList
+ .split(";")
+ .map((entry) => entry.trim())
+ .filter(Boolean);
+ if (!entries.length) return "unknown";
+ let direct = false;
+ let proxied = false;
+ for (const entry of entries) {
+ if (/^DIRECT$/i.test(entry)) {
+ direct = true;
+ continue;
+ }
+ if (!PROXY_CHAIN_ENTRY.test(entry)) return "unknown";
+ proxied = true;
+ }
+ if (proxied) return direct ? "unknown" : "proxied";
+ return direct ? "direct" : "unknown";
+}
+
+/**
+ * Whether a resolved address class may be connected to on this route.
+ *
+ * A direct (or unreadable) route keeps the rule the guard always had: the app
+ * dials the resolved address itself, so only a public address passes. On a
+ * proxied route the app dials the proxy, and the one class the local answer can
+ * then still carry is `benchmark` — the RFC 2544 range a TUN fake-IP resolver
+ * synthesizes, which no internal service is addressed by. Every class that
+ * names a real internal target (private, loopback, link-local, multicast, ULA,
+ * site-local) refuses on both routes (ADR 0272).
+ */
+export function isAcceptableResolvedAddress(
+ kind: PublicNetworkAddressKind,
+ route: PublicNetworkRoute,
+): boolean {
+ if (kind === "public") return true;
+ return route === "proxied" && kind === "benchmark";
+}
+
/**
* Name the public-network client stamps on its refusals. A caller that must
* stay free of that client's `node:dns` dependency — the skill market
@@ -184,12 +252,19 @@ export function publicNetworkRefusalReason(error: unknown): PublicNetworkRefusal
: undefined;
}
/** A refusal's own account of itself, extractable without importing the client. */
+/** A refusal's own account of itself, extractable without importing the client. */
export type PublicNetworkRefusalDetail = {
reason: PublicNetworkRefusalReason;
/** The hostname the guard was classifying, when it got that far. */
host?: string;
/** The class of the address that failed the policy, never the address. */
addressKind?: PublicNetworkAddressKind;
+ /**
+ * The route that hop was judged on, when the guard could read one. `direct`
+ * is why a fake-IP answer is still a refusal: the app would dial it itself
+ * (ADR 0272).
+ */
+ route?: PublicNetworkRoute;
};
const PUBLIC_NETWORK_ADDRESS_KINDS: ReadonlyArray<PublicNetworkAddressKind> = [
@@ -208,28 +283,35 @@ const PUBLIC_NETWORK_ADDRESS_KINDS: ReadonlyArray<PublicNetworkAddressKind> = [
"site-local",
];
+const PUBLIC_NETWORK_ROUTES: ReadonlyArray<PublicNetworkRoute> = ["direct", "proxied", "unknown"];
+
/**
- * What a refusal says about itself: why, which host, and which class of address
- * failed. Callers that must explain a block — the skill market's classifier and
- * its diagnostics — read this instead of parsing the message. `addressKind`
- * travels without the address: the class is what separates a resolver artifact
- * (`benchmark`, a TUN fake-IP) from a real private target (`private`, RFC1918),
- * and it is not a secret.
+ * What a refusal says about itself: why, which host, which class of address
+ * failed, and which route the guard judged that hop on. Callers that must
+ * explain a block — the skill market's classifier and its diagnostics — read
+ * this instead of parsing the message. `addressKind` travels without the
+ * address: the class is what separates a resolver artifact (`benchmark`, a TUN
+ * fake-IP) from a real private target (`private`, RFC1918), and it is not a
+ * secret.
*/
export function publicNetworkRefusalDetail(error: unknown): PublicNetworkRefusalDetail | undefined {
const reason = publicNetworkRefusalReason(error);
if (!reason) return undefined;
- const source = error as { host?: unknown; addressKind?: unknown };
+ const source = error as { host?: unknown; addressKind?: unknown; route?: unknown };
const host = typeof source.host === "string" && source.host ? source.host : undefined;
const addressKind = PUBLIC_NETWORK_ADDRESS_KINDS.includes(
source.addressKind as PublicNetworkAddressKind,
)
? (source.addressKind as PublicNetworkAddressKind)
: undefined;
+ const route = PUBLIC_NETWORK_ROUTES.includes(source.route as PublicNetworkRoute)
+ ? (source.route as PublicNetworkRoute)
+ : undefined;
return {
reason,
...(host ? { host } : {}),
...(addressKind ? { addressKind } : {}),
+ ...(route ? { route } : {}),
};
}