π The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated
TypeScript agentic-aiagentic-frameworkagentic-workflowagentsai-agentsai-assistantai-skillsautonomous-agentsclaudecodexdsh-pluginharnessmcp-servermulti-agentmulti-agent-systemsnpmskillsswarmswarm-intelligencetypescript
dream(security): #4503 http_fetch SSRF bypass via IPv4-mapped IPv6 literals (evaluated, ACCEPT) (#4504)
rUv9d854ddb9c69
diff --git a/docs/dream-cycle/LEDGER.md b/docs/dream-cycle/LEDGER.mdindex 7b87569eef..2c0f998d29 100644--- a/docs/dream-cycle/LEDGER.md+++ b/docs/dream-cycle/LEDGER.md@@ -245,3 +245,4 @@ as a first-class, high-priority candidate, not a background note.| 2026-10-19 | swarm | `TopologyManager.electLeader()`'s hierarchical/centralized branches read the cached `queenNode`/`coordinatorNode`, nulled by `removeFromRoleIndex()` on death with no replacement, and silently fell through to generic mesh-style ranking β electing a leader without ever promoting its `.role`, so `getQueen()`/`getCoordinator()` returned `undefined` forever after exactly one death despite `failoverEnabled: true` (default) documenting failover; added `promoteToRole()`, gated on that same flag, re-using the existing role-index cache pair | #4285 | #4286 | yes | ACCEPT | 3 new discriminating tests, baseline-fails-2-of-3/candidate-passes-3-of-3 via stash isolation (1 correct non-discriminating `failoverEnabled:false` control); full `@claude-flow/swarm` suite 335/335 (332+3 new), 0 regressions, `tsc --noEmit` clean both ways; independent adversarial critique CONFIRMED-WITH-CAVEATS β 1 caveat (promotion doesn't rewire connections/adjacency, self-healing under default `autoRebalance:true`) disclosed in-source as a KNOWN LIMITATION comment, 2 others (insertion-order candidate pick, no new locking) confirmed to match pre-existing class-wide convention, none blocking; confirmed zero blast-radius into raft/byzantine/gossip consensus | 7cf5c70f... | 10-09/10-10/10-11/10-15 MERGED; 10-12/10-13/10-14/10-16/10-17/10-18 open/draft, none stale |**Note (2026-10-20):** trailing-7-night fates verified via GitHub MCP tools (`gh` CLI's `GH_TOKEN` invalid, MCP tools work fine β not FALLBACK) before tonight's own row: #4230 (10-16, security) **MERGED**; #4250 (10-17, intelligence) open/draft, not stale; #4271 (10-18, memory) **MERGED**; #4286 (10-19, swarm) **MERGED**. No no-run gaps in the trailing window. **Rotation override disclosed**: tonight's `SLOT=0` rotation assigns `DEEP=performance`, but the implemented candidate below came from the `security` SCAN surface instead (precedent: 2026-09-24 #3411/#3412) β it scored 5.0/5 on the same candidate rubric used for the two deferred performance findings (`CacheManager.estimateSize()` redundant stringify, score 4.85; `AttentionCoordinator` embedding-cache miss, score 4.70 β both documented in full in issue #4312/gist for a future night), vs. their 4.85 max, and was HIGH severity/live-exploitable rather than a latent inefficiency.| 2026-10-20 | security (SCAN override of performance DEEP, see note above) | `hooks_codemod` MCP tool's `resolveTargets()` path-containment check used an unanchored `abs.startsWith(cwd)` string-prefix comparison β since `path.resolve(cwd, p)` returns an already-absolute `p` unchanged, a sibling directory merely starting with the project directory's name (e.g. `cwd`-staging) passed containment, letting this live, CLAUDE.md-recommended Tier-1 tool read **and write** (dryRun defaults false) outside the project root (CWE-22); anchored both call sites (`file`/`files[]` and `glob` branches) at a path-separator boundary, matching the already-correct `isWithinPrefix()` pattern used elsewhere in this exact codebase (`@claude-flow/security`, `@claude-flow/hooks/workers`, `@claude-flow/plugins/security`) | #4312 | #4313 | yes | ACCEPT | 4 new tests (2 discriminating, real temp-dir fs I/O; 2 non-discriminating controls); stash-isolated baseline fails both escape tests exactly as predicted (file genuinely overwritten outside root, not simulated), candidate 4/4 pass β independently reproduced twice (session + a separate adversarial-critic subagent from scratch, which also built its own symlink-escape repro); related suites (`mcp-tools-deep`, `validate-input-*`, `codemod-*`) 229/229 both ways (twice-reproduced); `tsc --noEmit` byte-identical 9 pre-existing errors; full `@claude-flow/cli` suite ~480/503 both ways, same ~21-22 pre-existing-failure set by name untouched by this change (second full-suite run disclosed as contaminated mid-run by this session's own revert/restore cycle, not relied on); independent adversarial critique CONFIRMED-WITH-CAVEATS β 1 non-blocking caveat (symlink-based containment bypass, CWE-59, distinct/broader gap) disclosed in-source as a KNOWN LIMITATION comment rather than fixed, deferred to a future realpath-hardening night | d501ab48... | 10-09/10-10/10-11/10-15/10-16/10-18/10-19 MERGED (7/7 of trailing window with a decision); 10-17 #4250 open/draft, not stale |+| 2026-10-26 | security | `http_fetch`'s `isPrivateOrLoopback()` SSRF guard (`v3/@claude-flow/cli/src/mcp-tools/http-fetch-tools.ts`) never stripped the `[...]` brackets Node's URL parser keeps on IPv6 literals β silently dead-coding the existing `fc00::/7`/`fe80::/10` checks AND leaving IPv4-mapped-IPv6 literals (`::ffff:127.0.0.1`, `::ffff:169.254.169.254`) completely unchecked, a live reproduced SSRF bypass reaching loopback/cloud-metadata; fixed by stripping brackets once and decoding IPv4-mapped forms into the existing IPv4 rules (one root-cause fix, not two). SCAN: intelligence (EWC++ Fisher map in `SONAManager` never populated β `consolidateEWC()` has zero callers, "prevents forgetting" is a silent no-op; new finding, deferred), swarm (10-25's deferred `TopologyManager` role-bug finding confirmed already fixed by an external PR #4483 citing our own #4481). Architecture review also found `.harness/mcp-policy.json` falsely claims zero shell/network tool surface β `terminal_execute`/`http_fetch` both contradict it (score 4.55, deferred as a design question, not a unilateral patch) | #4503 | #4504 | yes | ACCEPT | 13 new tests (8 discriminating, 5 controls), stash-isolated baseline 8/8 fail exactly as predicted β candidate 37/37 pass, independently reproduced by a fresh-context adversarial critic; scoped-but-wider related-suite run (109 tests) 12 pre-existing failures confirmed byte-identical on the true pre-fix commit (unbuilt `@claude-flow/mcp` sibling, unrelated); full-suite run timed out at 300s (environmental); `tsc --noEmit` 0 errors touching changed files either way (raw aggregate count noisy, 80β510, same unbuilt-sibling cause, disclosed); independent adversarial critique CONFIRMED-WITH-CAVEATS β 2 non-blocking pre-existing gaps (IPv6 `::`/multicast/NAT64 unblocked) disclosed in-source as KNOWN LIMITATION | 9294b5d7... | 10-19/10-20 MERGED; 10-21/10-22/10-23/10-24/10-25 open/draft, none stale (<14d); merge rate 2/7 trailing window, not zero |diff --git a/docs/dream-cycle/dream-gist-2026-10-26.md b/docs/dream-cycle/dream-gist-2026-10-26.mdnew file mode 100644index 0000000000..d990a177af--- /dev/null+++ b/docs/dream-cycle/dream-gist-2026-10-26.md@@ -0,0 +1,77 @@+# Security SOTA Report β 2026-10-26++TL;DR: `http_fetch`'s SSRF guard (`isPrivateOrLoopback()` in `v3/@claude-flow/cli/src/mcp-tools/http-fetch-tools.ts`) never stripped the `[...]` brackets Node's URL parser keeps in `.hostname` for IPv6 literals. That silently broke two things at once: the existing `fc00::/7`/`fe80::/10` checks never matched anything (dead code since they tested `startsWith('fc'/'fe80:')` against a string starting with `[`), and IPv4-mapped IPv6 literals (`::ffff:127.0.0.1`, `::ffff:169.254.169.254`) sailed through untested β a live, reproduced SSRF bypass reaching loopback and cloud-metadata targets. Fixed by stripping brackets once and decoding IPv4-mapped forms back into the existing IPv4 rules. 13 new tests, independently critiqued (CONFIRMED-WITH-CAVEATS, two pre-existing out-of-scope gaps disclosed in-source). **Verdict: ACCEPT.** 4 deferred candidates (one architecturally significant β `.harness/mcp-policy.json` falsely claims zero shell/network tool surface) and 1 new intelligence-surface finding (EWC++ Fisher map never populated) carried forward.++## What's New in 2026++| Finding | Source | Grade |+|---|---|---|+| 5 independent 2025-2026 CVEs in MCP filesystem/git servers, all symlink/path-containment failures (unresolved-path check vs. symlink-following op) β the official `@modelcontextprotocol/server-filesystem` reference implementation among them | CVE-2025-53110/53109/67366/67364/11489, NVD/GitLab advisories | A |+| IPv4-mapped-IPv6 (`::ffff:a.b.c.d`) is a well-documented SSRF-filter-bypass technique class; reproduced live against Ruflo's own code this session | SSRF cheat sheets, recurring CVE pattern; direct PoC | A (technique, reproduced), B (external sourcing) |+| 2026 agent-framework RCE/SSRF disclosures: CrewAI's Code Interpreter sandbox-fallback chain (CVE-2026-2275/2285/2286/2287, CERT/CC VU#221883) and a later blocklist-bypass (CVE-2026-37008); Microsoft AutoGen Studio's "AutoJack" localhost-trust chain (MSRC-disclosed, no public CVE) | NVD, CERT/CC, BleepingComputer, CSOonline, TheHackerNews | A/B |+| LangGraph SDK path-building CVE (CVE-2026-48776, GHSA-w39p-vh2g-g8g5) and its SDK-level default-deny *authorization* pattern (resource access, not tool-execution sandboxing) | GHSA/NVD, LangGraph SDK docs | A/C |+| No major competitor (LangGraph, AutoGen/MS Agent Framework, CrewAI, OpenAI Agents SDK) publishes a declared, versioned, default-deny MCP/tool-authority manifest comparable to Ruflo's `.harness/mcp-policy.json` β genuine but narrow differentiator (closest analogs are cloud-IAM-layer or per-tool ad hoc sandbox manifests, not framework-level) | Targeted search across all 4 + CIS MCP Companion Guide + Google Cloud MCP IAM docs | B |+| EWC++ continual-learning correctness depends heavily on how Fisher information is estimated β directly relevant once Ruflo's SONA-path Fisher estimation (currently absent, see Scan Findings) is implemented | Van de Ven, ICLR 2025 (arXiv:2502.11756); arXiv:2603.18596 (2026, single preprint) | A / B |++## Ruflo Current Capability++`http_fetch` is ADR-164 Β§5.1.8's guarded HTTP probe primitive, documented as "DEFAULT-REFUSES private addresses + loopback." `validateUrl()` β `isPrivateOrLoopback()` pattern-matches the lowercased hostname against IPv4 RFC1918/loopback/link-local/CGNAT ranges and a couple of IPv6 special forms. The IPv6 branch was silently broken (bracket-prefix mismatch) and had no IPv4-mapped-IPv6 handling β both closed tonight by one root-cause fix (strip-then-match, with IPv4-mapped forms recursing into the already-correct IPv4 rules rather than duplicating them).++## Competitor Comparison++| Competitor | Approach | Grade |+|---|---|---|+| LangGraph | SDK auth module ships a default-deny code pattern for resource access; no first-party sandboxing/least-privilege doc for tool execution; CVE-2026-48776 (path-building, fixed 0.3.15) | A (CVE) / C (framing) |+| Microsoft AutoGen/Agent Framework | No documented default-deny tool-authority policy; "AutoJack" localhost-trust MCP chain disclosed pre-release, generalizable pattern per Microsoft's own statement | B |+| CrewAI | 4 chained CVEs in Code Interpreter's Docker-sandbox fallback + SSRF/file-read tools; later blocklist-vs-allowlist bypass (CVE-2026-37008); no default-deny policy found | A |+| OpenAI Agents SDK | April-2026 sandbox harness scopes filesystem via Unix-permission manifests β opt-in capability, not a declared default-deny posture | C (mechanism detail community-sourced) |+| MCP reference/community filesystem servers | 5 independent 2025 CVEs, all symlink/path-containment, official reference impl included | A |++## Hypothesis++> Given `http_fetch`'s `isPrivateOrLoopback()` SSRF guard, when IPv6 literals are normalized (brackets stripped) before pattern-matching and IPv4-mapped-IPv6 forms are decoded and re-checked against the existing IPv4 rules, then both the previously-dead ULA/link-local IPv6 checks and the undetected IPv4-mapped-IPv6 bypass should be correctly rejected, with every currently-passing public-hostname/public-IP case unaffected β subject to: zero change to the IPv4 dotted-decimal path, zero regression to existing http-fetch tests, deterministic $0 zero-LLM Vitest evaluation. Frozen before evaluation; not modified after.++**Deferred, not implemented tonight**: (a) `.harness/mcp-policy.json` declares `allowShell:false`/`allowNetwork:false` but `terminal_execute` (execSync) and `http_fetch` itself are live counterexamples β a real documentation-accuracy gap, scored 4.55, but a design question (restrict the tool? gate behind native-Bash approval? fix the doc?), not a clean patch β left for human review; (b) `http_fetch`'s unvalidated-redirect SSRF escalation (`redirect:'follow'` never re-validates `Location`), scored 4.35, same contract, distinct mechanism β fast-follow candidate; (c) terminal env-denylist gap for proxy/TLS-trust vars, scored 3.95; (d) MCP policy enforcement not wired into the HTTP/websocket transport, scored 3.65 (self-disclosed in-source already).++## Benchmarks++No agent-task benchmark corpus applies to a guard-function correctness fix β consistent with nearly every accepted security fix since 2026-08-18, which use stash-isolated discriminating unit tests instead.++## Evaluation++**evaluated: accepted.** Real evaluator: Vitest 4.1.8.++13 new tests in `__tests__/http-fetch-tools.test.ts` (8 discriminating, 5 non-discriminating controls β a public IPv4-mapped address, a public IPv6 literal, and the still-rejects-`::1` regression check). Stash-isolated baseline (`git stash` on just `http-fetch-tools.ts`): **8/8 discriminating tests fail exactly as predicted** (`isPrivateOrLoopback` returns `false`/`undefined`-equivalent for every bypass form); all controls and the 24 pre-existing tests pass both ways. Candidate: **37/37 pass**. Independently reproduced from a fresh context by an adversarial-critic subagent β identical result.++A full `@claude-flow/cli` suite run timed out at 300s with no partial output (environmental, not a hang in changed code). A scoped-but-wider run (5 other mcp/http/policy files, 109 tests) showed 12 failures, confirmed byte-identical on the true pre-fix commit via `git checkout <parent-commit> -- <files>` β all `Error: Failed to resolve entry for package "@claude-flow/mcp"` (unbuilt sibling package), unrelated to this diff. `tsc --noEmit`: zero errors reference either changed file, either before or after (raw aggregate count is noisy here β 80 vs. 510 across repeated runs on the same tree, same unbuilt-sibling cause β disclosed, not relied on).++**Independent adversarial critique: CONFIRMED-WITH-CAVEATS.** Independently reproduced the stash-isolated comparison from scratch, verified the diff is additive-only, confirmed the caller already lowercases input (no uppercase-hex bypass), confirmed the one-level recursion is bounded (not ReDoS-able), and manually re-derived the decode arithmetic against real Node normalization. Checked the IPv4-*compatible* (non-mapped) form `::a.b.c.d` and confirmed it correctly does **not** match the fix's narrow `::ffff:` regex β that deprecated form has no OS-level dual-stack reinterpretation, so leaving it alone is correct. Found two pre-existing, out-of-scope caveats, disclosed in-source: IPv6 `::` (unspecified, the analog of `0.0.0.0`) and multicast/NAT64 ranges remain unblocked.++## Darwin Results++Skipped β binary SSRF-guard correctness fix (bracket-stripping + a decode-and-recurse branch), no continuous/categorical parameter for Darwin's bounded-evolution interface to search over. Same skip class as nearly every accepted fix since 2026-08-18 that wasn't a routing/topology weight.++## SOTA Proof & Witness++Session commit: 631c1557b5f325163c4f9f029a397bb30a61c730+Candidate commit: (this branch's head)+Gist SHA-256 (pre-witness, witness block stripped to PENDING): 0426fc1e1510bada31087763642db85704ec686df8619297e60e8eca19899ae6+Witness stamp: 9294b5d7b79e44df3eff1a779796dfb813e764f79c1dd7dc7d51e30095b80ddc++Verifier: fetch this file, strip this block's filled-in values back to `PENDING`, SHA-256 the file, concatenate with the Session commit above, SHA-256 again β must equal the Witness stamp.++Evaluation receipt identity: 13 new tests in `__tests__/http-fetch-tools.test.ts`, stash-isolated 8/8-fail-baseline β 37/37-pass-candidate, independently reproduced by a fresh-context adversarial critic. Flywheel evidence identity: none (`.claude-flow/flywheel/` doesn't exist in this repo, confirmed, same as every prior night) β retained as this gist, the tests, the stash comparison, and the adversarial critique transcript. Darwin lineage identity: none (skipped, see above).++## Scan Findings: intelligence++EWC++ in `@claude-flow/neural`'s `SONAManager` never consolidates: `ewcState.fisher`/`.means` are initialized empty and never populated anywhere in `neural/src` (confirmed by repo-wide grep β no `.fisher.set(`/`.means.set(` call exists), and the one method that touches `fisher` post-init, `consolidateEWC()`, has zero callers. Every `computeEWCPenalty`/`computeEWCLoss` call therefore iterates a 0-entry map and returns 0 β the "prevents forgetting" EWC term is a silent no-op on every learning cycle, in the production SONA path (`SONAManager` is reachable from `cli/src/ruvector/index.ts` and `cli/src/memory/neural-package-bridge.ts`). Distinct from the already-correct CLI-level `cli/src/memory/ewc-consolidation.ts` heuristic β don't conflate the two. Not implemented tonight (DEEP surface was security); carried forward as a well-scoped candidate for an `intelligence` night.++## Scan Findings: swarm++The 2026-10-25 night's `TopologyManager.calculateInitialConnections()` raw-vs-resolved-role finding (scored 3.70) is **already fixed** β an external contributor's PR #4483 (merged 2026-10-25, citing our own #4481) resolved it the same night it was reported. Verified against current source: `addNode()` now resolves the role before both the connection calculation and the stored `.role` field. No new swarm finding surfaced tonight beyond re-confirming this closure.++## Recommended Next Steps++1. **Fix `http_fetch`'s unvalidated-redirect SSRF escalation** (score 4.35) β `fetch()`'s default `redirect:'follow'` never re-validates the `Location` target through `validateUrl()`, so a public allowed URL that 302s to a private/loopback/metadata address bypasses the entire allowlist. Same file/contract as tonight's fix; natural fast-follow.+2. **Resolve the `.harness/mcp-policy.json` accuracy gap** (score 4.55) β `terminal_execute` and `http_fetch` both exercise shell/network authority the policy's own `$comment` claims this MCP server doesn't expose, and `policy-enforcer.ts` deliberately doesn't enforce `allowShell`/`allowNetwork` against them. Needs a human design decision (restrict the tools, gate them behind native-Bash-equivalent approval, or correct the policy doc), not a unilateral nightly patch.+3. **Implement Fisher-information estimation for `SONAManager`'s EWC++ path** β wire `consolidateEWC()` (currently dead code) into `triggerLearning()`'s post-`learn()` path with a real Fisher/importance estimate, or drop the dead scaffolding and the "prevents forgetting" claim for this specific path.diff --git a/v3/@claude-flow/cli/__tests__/http-fetch-tools.test.ts b/v3/@claude-flow/cli/__tests__/http-fetch-tools.test.tsindex 3781c00e08..62f36d994e 100644--- a/v3/@claude-flow/cli/__tests__/http-fetch-tools.test.ts+++ b/v3/@claude-flow/cli/__tests__/http-fetch-tools.test.ts@@ -147,6 +147,66 @@ describe('http_fetch β URL allowlist (default-deny)', () => {});});+// ---------- IPv4-mapped-IPv6 SSRF bypass (regression) -------------++describe('http_fetch β IPv4-mapped IPv6 SSRF bypass', () => {+ it('rejects ::ffff:127.0.0.1 (loopback via IPv4-mapped IPv6, dotted form)', () => {+ expect(() => validateUrl('http://[::ffff:127.0.0.1]/foo')).toThrow(/loopback|private/i);+ });++ it('rejects the canonical hex form Node normalizes ::ffff:127.0.0.1 to', () => {+ // new URL('http://[::ffff:127.0.0.1]/').hostname === '[::ffff:7f00:1]'+ expect(() => validateUrl('http://[::ffff:7f00:1]/foo')).toThrow(/loopback|private/i);+ });++ it('rejects ::ffff:169.254.169.254 (cloud-metadata link-local via IPv4-mapped IPv6)', () => {+ expect(() => validateUrl('http://[::ffff:169.254.169.254]/latest/meta-data/')).toThrow(/loopback|private/i);+ });++ it('rejects a fully-expanded IPv4-mapped-IPv6 literal (Node collapses it to the same canonical form)', () => {+ expect(() => validateUrl('http://[0:0:0:0:0:ffff:169.254.169.254]/latest/meta-data/')).toThrow(/loopback|private/i);+ });++ it('rejects ::ffff:10.0.0.5 (RFC1918 via IPv4-mapped IPv6)', () => {+ expect(() => validateUrl('http://[::ffff:10.0.0.5]/foo')).toThrow(/loopback|private/i);+ });++ it('opt-in CLAUDE_FLOW_HTTP_FETCH_ALLOW_PRIVATE=1 also unlocks IPv4-mapped IPv6 private addresses', () => {+ process.env.CLAUDE_FLOW_HTTP_FETCH_ALLOW_PRIVATE = '1';+ expect(() => validateUrl('http://[::ffff:127.0.0.1]/foo')).not.toThrow();+ });++ it('does not reject an IPv4-mapped-IPv6 PUBLIC address (control β must not over-block)', () => {+ // 8.8.8.8 is Google public DNS β ::ffff:8.8.8.8 must remain allowed.+ expect(() => validateUrl('http://[::ffff:8.8.8.8]/foo')).not.toThrow();+ });+});++// ---------- IPv6 ULA / link-local bracket-stripping (regression) --++describe('http_fetch β IPv6 ULA/link-local checks (previously dead due to unstripped brackets)', () => {+ it('rejects fc00::/7 unique local address', () => {+ expect(() => validateUrl('http://[fc00::1]/foo')).toThrow(/loopback|private/i);+ });++ it('rejects fd00::/8 unique local address', () => {+ expect(() => validateUrl('http://[fd12:3456:789a::1]/foo')).toThrow(/loopback|private/i);+ });++ it('rejects fe80::/10 link-local address', () => {+ expect(() => validateUrl('http://[fe80::1]/foo')).toThrow(/loopback|private/i);+ });++ it('still rejects ::1 loopback (control β must not regress the existing check)', () => {+ expect(() => validateUrl('http://[::1]/foo')).toThrow(/loopback|private/i);+ });++ it('does not reject a public-looking IPv6 literal (control β must not over-block)', () => {+ // 2001:4860:4860::8888 is Google public DNS over IPv6.+ expect(() => validateUrl('http://[2001:4860:4860::8888]/foo')).not.toThrow();+ });+});+// ---------- header sanitization tests ----------------------------describe('http_fetch β header sanitization (default-deny auth)', () => {diff --git a/v3/@claude-flow/cli/src/mcp-tools/http-fetch-tools.ts b/v3/@claude-flow/cli/src/mcp-tools/http-fetch-tools.tsindex cc8a5833dc..9fa3df6ca9 100644--- a/v3/@claude-flow/cli/src/mcp-tools/http-fetch-tools.ts+++ b/v3/@claude-flow/cli/src/mcp-tools/http-fetch-tools.ts@@ -70,10 +70,35 @@ export function validateUrl(rawUrl: string): URL {function isPrivateOrLoopback(host: string): boolean {if (host === 'localhost' || host === 'localhost.localdomain') return true;- // IPv6 loopback- if (host === '::1' || host === '[::1]') return true;++ // Node's URL parser keeps brackets in `.hostname` for every IPv6 literal+ // (e.g. "[::1]", "[fc00::1]", "[::ffff:7f00:1]"). Strip them once so every+ // check below operates on the bare address β without this, the fc00::/7+ // and fe80::/10 checks further down never match anything (they test+ // `startsWith('fc'/'fe80:')` against a string starting with "["), and an+ // IPv4-mapped-IPv6 literal (`::ffff:a.b.c.d`, which Node normalizes to a+ // canonical `::ffff:xxxx:yyyy` hex form) sails through both the IPv4 and+ // IPv6 branches untested β a live SSRF bypass (e.g. `::ffff:127.0.0.1` or+ // `::ffff:169.254.169.254` reaching loopback / cloud-metadata targets).+ const bare = host.startsWith('[') && host.endsWith(']') ? host.slice(1, -1) : host;++ if (bare === '::1') return true; // IPv6 loopback++ // IPv4-mapped IPv6 β decode back to dotted-decimal and recurse into the+ // IPv4 check below so it inherits every existing private/loopback/+ // link-local/CGNAT rule instead of needing its own copy.+ const mappedHex = bare.match(/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/);+ if (mappedHex) {+ const hi = parseInt(mappedHex[1], 16);+ const lo = parseInt(mappedHex[2], 16);+ const decoded = `${(hi >> 8) & 0xff}.${hi & 0xff}.${(lo >> 8) & 0xff}.${lo & 0xff}`;+ return isPrivateOrLoopback(decoded);+ }+ const mappedDecimal = bare.match(/^::ffff:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/);+ if (mappedDecimal) return isPrivateOrLoopback(mappedDecimal[1]);+// IPv4 numeric checks- const m = host.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);+ const m = bare.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);if (m) {const a = Number(m[1]);const b = Number(m[2]);@@ -86,10 +111,16 @@ function isPrivateOrLoopback(host: string): boolean {if (a === 100 && b >= 64 && b <= 127) return true; // CGNATreturn false;}- // IPv6 bracketed addresses and other special forms β be conservative and- // accept only public-looking literals. Reject obvious private/local forms.- if (host.startsWith('fc') || host.startsWith('fd')) return true; // fc00::/7 ULA- if (host.startsWith('fe80:')) return true; // link-local+ // IPv6 special forms β be conservative and accept only public-looking+ // literals. Reject obvious private/local forms.+ if (bare.startsWith('fc') || bare.startsWith('fd')) return true; // fc00::/7 ULA+ if (bare.startsWith('fe80:')) return true; // link-local+ // KNOWN LIMITATION (pre-existing, not introduced by the bracket-stripping /+ // IPv4-mapped-IPv6 fix above; flagged by an independent adversarial review):+ // `::` (IPv6 unspecified/"any", the analog of 0.0.0.0, which the IPv4 branch+ // above does block), IPv6 multicast (ff00::/8), and NAT64 (64:ff9b::/96) are+ // not covered. Left as a follow-up hardening item rather than scope-creeping+ // this patch.return false;}