Skip to content

Commit 53aa523

Browse files
committed
docs: document guarded fetch net helpers
1 parent ba82257 commit 53aa523

11 files changed

Lines changed: 31 additions & 2 deletions

src/infra/net/configured-local-origin-bypass.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Configured local-origin bypass logic decides when managed proxy routing may
2+
// skip proxying a known loopback provider origin.
13
import { isLoopbackIpAddress } from "@openclaw/net-policy/ip";
24
import { getActiveManagedProxyLoopbackMode } from "./proxy/active-proxy-state.js";
35
import { SsrFBlockedError } from "./ssrf.js";

src/infra/net/fetch-guard.ssrf.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Guarded fetch SSRF tests cover redirect hardening, pinned dispatcher setup,
2+
// trusted proxy modes, and safe header retention.
13
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
24
import {
35
fetchConfiguredLocalOriginWithSsrFGuard,

src/infra/net/fetch-guard.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Guarded fetch runtime enforces SSRF checks, DNS pinning, redirect policy, and
2+
// trusted proxy modes around provider/network requests.
13
import type { Dispatcher } from "undici";
24
import { logWarn } from "../../logger.js";
35
import { buildTimeoutAbortSignal } from "../../utils/fetch-timeout.js";
@@ -143,6 +145,8 @@ export function withTrustedExplicitProxyGuardedFetchMode(
143145
}
144146

145147
function resolveGuardedFetchMode(params: GuardedFetchOptions): GuardedFetchMode {
148+
// Legacy proxy flags map to the explicit trusted env-proxy mode; strict is the
149+
// default for user-influenced URLs.
146150
if (params.mode) {
147151
return params.mode;
148152
}
@@ -212,6 +216,8 @@ async function assertExplicitProxyAllowed(
212216
lookupFn: LookupFn | undefined,
213217
policy: SsrFPolicy | undefined,
214218
): Promise<void> {
219+
// Explicit proxies are operator-configured, but the proxy host still needs
220+
// basic URL and private-network validation before target validation proceeds.
215221
if (!dispatcherPolicy || dispatcherPolicy.mode !== "explicit-proxy") {
216222
return;
217223
}

src/infra/net/hostname.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Hostname normalization tests cover DNS trailing dots, empty input, and
2+
// bracketed IPv6 literal handling.
13
import { describe, expect, it } from "vitest";
24
import { normalizeHostname } from "./hostname.js";
35

src/infra/net/hostname.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
// Hostname normalization helpers keep SSRF and proxy policy comparisons stable
2+
// across case, trailing dots, and bracketed IPv6 literals.
13
import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce";
24

3-
// Hostname normalization is intentionally display/compare-oriented: lowercase,
4-
// trim brackets for IPv6 literals, and remove trailing DNS dots.
55
/** Normalize a hostname for policy comparisons. */
66
export function normalizeHostname(hostname: string): string {
77
const normalized = normalizeLowercaseStringOrEmpty(hostname).replace(/\.+$/, "");

src/infra/net/runtime-fetch.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Runtime fetch tests cover header normalization and FormData conversion before
2+
// calls reach undici's dispatcher-aware fetch.
13
import { afterEach, describe, expect, it, vi } from "vitest";
24
import { fetchWithRuntimeDispatcher } from "./runtime-fetch.js";
35
import { TEST_UNDICI_RUNTIME_DEPS_KEY } from "./undici-runtime.js";

src/infra/net/runtime-fetch.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Runtime fetch adapter preserves undici dispatcher support and normalizes
2+
// headers/FormData before calling the runtime fetch implementation.
13
import type { Dispatcher } from "undici";
24
import { normalizeHeadersInitForFetch } from "../fetch-headers.js";
35
import { loadUndiciRuntimeDeps, type UndiciRuntimeDeps } from "./undici-runtime.js";
@@ -23,6 +25,8 @@ function normalizeRuntimeFormData(
2325
body: unknown,
2426
RuntimeFormData: RuntimeFormDataCtor | undefined,
2527
): BodyInit | null | undefined {
28+
// Node global FormData and undici runtime FormData can differ; rebuild into
29+
// the runtime constructor so multipart uploads stream correctly.
2630
if (!isFormDataLike(body) || typeof RuntimeFormData !== "function") {
2731
return body as BodyInit | null | undefined;
2832
}

src/infra/net/ssrf.dispatcher.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Pinned dispatcher tests cover undici family policy, pinned lookup injection,
2+
// timeout propagation, and proxy dispatcher construction.
13
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
24
import { TEST_UNDICI_RUNTIME_DEPS_KEY } from "./undici-runtime.js";
35

src/infra/net/ssrf.pinning.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// SSRF pinning tests cover DNS pinning behavior, blocked DNS results, hostname
2+
// allowlists, and IPv4/IPv6 address ordering.
13
import { describe, expect, it, vi } from "vitest";
24
import {
35
createPinnedLookup,

src/infra/net/ssrf.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// SSRF tests cover IP privacy classification and HTTP base URL policy builders.
12
import { describe, expect, it } from "vitest";
23
import { blockedIpv6MulticastLiterals } from "../../../packages/net-policy/src/ip-test-fixtures.js";
34
import {

0 commit comments

Comments
 (0)