Repository navigation
fix(gateway): honor mapped IPv4 CIDR ranges - #137668
Conversation
…never matched `isIpInCidr` normalized an IPv4-mapped IPv6 CIDR base (`::ffff:a.b.c.d/N`) to its IPv4 form but kept the prefix length in 128-bit space, so any mapped range degraded to an exact match on the base address. A `gateway.trustedProxies` entry such as `::ffff:10.0.0.0/104`, which the configure wizard and config validation accept, therefore never trusted the proxy and every proxied request was rejected with 403 `proxy_attribution_required`. The same matcher backs `gateway.nodes.pairing.autoApproveCidrs` and `sshVerify.cidrs`. Treat a mapped base as the IPv4 range it denotes: rebase prefixes of 96 or more by 96 onto the IPv4 address, and let shorter prefixes (which contain the whole `::ffff:0:0/96` block) match every IPv4 peer. IPv6 peers still never match a mapped range; native IPv4 and IPv6 matching is unchanged. Cover the repair at the gateway ingress boundary as well as in the matcher: `prepareGatewayIngressAttribution` now has cases proving a proxy trusted by a mapped CIDR attributes its forwarded client identically to the plain IPv4 spelling, and that a proxy outside the range is still rejected. The configure wizard test that pinned `::ffff:0:0/96` as "cannot match loopback" now expects that catch-all to prompt for loopback consent and to behave like `0.0.0.0/0`, where the forwarded client is consumed as a trusted hop. Document the accepted spellings on `gateway.trustedProxies`, which previously said only "IP addresses (or CIDRs)". Related: openclaw#131475 (listed "mapped-IPv4 CIDR prefix interpretation" as a follow-up)
|
Codex review: blocked before merge. Reviewed September 8, 2026, 2:13 PM ET / 18:13 UTC (Revision 3). ClawSweeper reviewWhat this changesCorrects shared IP-range matching so IPv4-mapped CIDRs work for trusted proxies and node pairing, with regression coverage and documentation. Merge readiness⛔ Blocked before merge - 1 item remains The fix remains necessary: current main and v2026.9.3 retain the prefix mismatch. No introduced correctness defect was found, and the updated runtime evidence addresses the affected authorization paths. Priority: P2 Review scores
Verification
How this fits togetherGateway network policy compares connecting peers against configured IP ranges before accepting forwarded identities or considering automatic node pairing. The shared matcher feeds those decisions while separate authentication, scope, and approval checks remain authoritative. flowchart TD
A[Connecting peer] --> C[Shared IP range matcher]
B[Configured trusted ranges] --> C
C --> D[Proxy attribution]
C --> E[Node pairing eligibility]
D --> F[Identity and scope checks]
E --> G[Current policy and device verification]
F --> H[Accept or reject request]
G --> H
Before merge
Agent review detailsSecurityNone. PR surfaceSource +5, Tests +60, Docs +1. Total +66 across 5 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the correction in the shared matcher with narrow documented allowlists; its five added production lines express the dependency-required prefix conversion and explain the security-relevant boundary. Do we have a high-confidence way to reproduce the issue? Yes: current main passes a mapped /104 prefix into an IPv4 octet matcher, making 10.1.2.3 fail against ::ffff:10.0.0.0/104. Source and the published dependency establish the defect; this review did not execute a reproduction. Is this the best way to solve the issue? Yes: converting the prefix within the existing shared IPv4 branch repairs every affected caller without duplicating matching or changing downstream authorization policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b824b72ce284. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
Added the live behaviour proof requested in the review; PR body updated with the full section. A real Gateway on this branch, behind a real reverse proxy, exercised over real HTTP rather than a fabricated
The middle row is the tell before the fix: two spellings of the same range, one trusted and one not. After the fix the mapped form accepts the matching peer and still rejects the nearby non-matching one. Verbatim 403 body in both rejecting cases: {"error":{"message":"Proxy client attribution is required. Configure gateway.trustedProxies narrowly and make the proxy overwrite or safely rebuild forwarded client headers.","type":"proxy_attribution_required"}}Nothing is redacted because nothing sensitive appears: the only addresses are loopback and On the remaining P1 about the ipaddr.js contract: that item records that ClawSweeper's own worktree had no installed dependency source and its network fetch failed, so I could not act on it from here. For reference, CI note: the six red checks on this PR are pre-existing and unrelated — |
|
Thanks @elbourne12345! Proof: The real Gateway, reverse proxy, node CLI, and SSH identity path reproduce the mapped-range rejection on pinned main and accept the same configured ranges after the repair. Nearby ranges remain rejected. The final contributor-based build and 120 focused tests pass; the main integration passes 355 focused tests. Independent source-blind validation exercised 47 fresh runtime cases without an observed defect, with its source/historical/interface limitations retained.
Loopback consent, forwarded-client checks, identity/header restrictions, origins, scopes, signature verification, and SSH host/device identity checks remain enforced. Role upgrades and scoped/browser node requests still require approval. A manually approved read-only operator can read after restart but cannot perform an administrative write. CIDR device pairing leaves node command approval separate: a lookup was blocked before capability approval and succeeded after the normal owner approval. Prefixes at or below Runtime proof is pinned main Landed in |
Closes openclaw#137665 Related: openclaw#131475 ## What Problem This Solves Fixes an issue where an accepted IPv4-mapped CIDR such as `::ffff:10.0.0.0/104` rejected proxy addresses that belong to the equivalent `10.0.0.0/8` range. Proxied requests returned HTTP 403 `proxy_attribution_required`. The same matcher left eligible node pairing requests pending for mapped `autoApproveCidrs` and `sshVerify.cidrs` entries. ## Why This Change Was Made Normalize the prefix into IPv4's bit space before the existing IPv4 match. The shared matcher now handles plain and mapped ranges in one path, without a second mapped-address matcher. Exact addresses, native IPv6, parsing, and downstream authorization keep their existing paths. ## User Impact Mapped `/104`, `/120`, and `/128` ranges behave like IPv4 `/8`, `/24`, and exact addresses. Prefixes at or below `/96` cover all IPv4, including loopback; the wizard keeps its explicit loopback-consent prompt. Native IPv6 peers do not match mapped ranges. Keep proxy allowlists narrow: a catch-all still consumes every IPv4 forwarded hop and cannot attribute a client through that chain. Automatic pairing still requires a fresh, signed, scopeless node request. Roles, scopes, browser requests, manual approval, and SSH host/device identity checks retain their own gates. No configuration field, schema, dependency, or permission policy is added. ## Evidence Real source Gateway and CLI runs use isolated documentation-address peers, a real overwriting loopback reverse proxy, TLS, and actual SSH reading `openclaw node identity --json`. | Caller | Pinned main | Repair | | --- | --- | --- | | Matching mapped proxy range | HTTP 403 | HTTP 200 from protected `/v1/models` | | Plain equivalent proxy range | HTTP 200 | HTTP 200 | | Nearby nonmatching proxy range | HTTP 403 | HTTP 403 | | Matching mapped node auto-approval range | Manual pending | Approved via trusted CIDR and connected | | Matching mapped SSH-verification range | Manual pending | SSH verified and connected | Additional real controls cover `/64`, `/95`, `/96`, `/104`, `/128`, exact nonmatches, native IPv6, loopback consent, missing/disallowed identities, missing headers, invalid/loopback forwarded clients, origin allow/deny, scope caps, and SSH identity/key failures. Signed WebSocket checks retain manual role upgrades, scoped/browser requests, signature rejection, and manual read-only enrollment. The enrolled operator can read after restart and cannot invoke an administrative write. CIDR device pairing retains separate capability approval. The three focused regression files show nine intended failures on main and 123 passes with the repair. Another 232 focused network/pairing/SSH tests pass. The exact installed ipaddr.js 2.5.0 source was inspected: IPv4 matching consumes 32 bits, so mapped prefixes must subtract 96. Paired runtime proof uses main `db7fff94b0f516759efdb04f47fc4d2fc65996a7` plus this repair, preserving newer Gateway callers. The changed matcher has exact byte identity with the candidate; the old contributor branch retains its ancestry. The contributor-based tree separately passes its own runtime build, formatter check, and 120 focused tests with its pinned dependencies. An independent validator completed 47 fresh runtime cases without an observed defect; source, historical, wizard-presentation, broader-policy and cleanup observations are assessed separately rather than claimed as independent passes. Historical setup and probe-assumption corrections remain recorded privately. AI-assisted. Co-authored-by: Ayaan Zaidi <[email protected]>
Closes openclaw#137665 Related: openclaw#131475 ## What Problem This Solves Fixes an issue where an accepted IPv4-mapped CIDR such as `::ffff:10.0.0.0/104` rejected proxy addresses that belong to the equivalent `10.0.0.0/8` range. Proxied requests returned HTTP 403 `proxy_attribution_required`. The same matcher left eligible node pairing requests pending for mapped `autoApproveCidrs` and `sshVerify.cidrs` entries. ## Why This Change Was Made Normalize the prefix into IPv4's bit space before the existing IPv4 match. The shared matcher now handles plain and mapped ranges in one path, without a second mapped-address matcher. Exact addresses, native IPv6, parsing, and downstream authorization keep their existing paths. ## User Impact Mapped `/104`, `/120`, and `/128` ranges behave like IPv4 `/8`, `/24`, and exact addresses. Prefixes at or below `/96` cover all IPv4, including loopback; the wizard keeps its explicit loopback-consent prompt. Native IPv6 peers do not match mapped ranges. Keep proxy allowlists narrow: a catch-all still consumes every IPv4 forwarded hop and cannot attribute a client through that chain. Automatic pairing still requires a fresh, signed, scopeless node request. Roles, scopes, browser requests, manual approval, and SSH host/device identity checks retain their own gates. No configuration field, schema, dependency, or permission policy is added. ## Evidence Real source Gateway and CLI runs use isolated documentation-address peers, a real overwriting loopback reverse proxy, TLS, and actual SSH reading `openclaw node identity --json`. | Caller | Pinned main | Repair | | --- | --- | --- | | Matching mapped proxy range | HTTP 403 | HTTP 200 from protected `/v1/models` | | Plain equivalent proxy range | HTTP 200 | HTTP 200 | | Nearby nonmatching proxy range | HTTP 403 | HTTP 403 | | Matching mapped node auto-approval range | Manual pending | Approved via trusted CIDR and connected | | Matching mapped SSH-verification range | Manual pending | SSH verified and connected | Additional real controls cover `/64`, `/95`, `/96`, `/104`, `/128`, exact nonmatches, native IPv6, loopback consent, missing/disallowed identities, missing headers, invalid/loopback forwarded clients, origin allow/deny, scope caps, and SSH identity/key failures. Signed WebSocket checks retain manual role upgrades, scoped/browser requests, signature rejection, and manual read-only enrollment. The enrolled operator can read after restart and cannot invoke an administrative write. CIDR device pairing retains separate capability approval. The three focused regression files show nine intended failures on main and 123 passes with the repair. Another 232 focused network/pairing/SSH tests pass. The exact installed ipaddr.js 2.5.0 source was inspected: IPv4 matching consumes 32 bits, so mapped prefixes must subtract 96. Paired runtime proof uses main `1a7224b69f09b8e7a9edb8d9de27c3c534397f1e` plus this repair, preserving newer Gateway callers. The changed matcher has exact byte identity with the candidate; the old contributor branch retains its ancestry. The contributor-based tree separately passes its own runtime build, formatter check, and 120 focused tests with its pinned dependencies. An independent validator completed 47 fresh runtime cases without an observed defect; source, historical, wizard-presentation, broader-policy and cleanup observations are assessed separately rather than claimed as independent passes. Historical setup and probe-assumption corrections remain recorded privately. AI-assisted. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 7069a47)
Closes #137665
Related: #131475
What Problem This Solves
Fixes an issue where an accepted IPv4-mapped CIDR such as
::ffff:10.0.0.0/104rejected proxy addresses that belong to the equivalent10.0.0.0/8range. Proxied requests returned HTTP 403proxy_attribution_required. The same matcher left eligible node pairing requests pending for mappedautoApproveCidrsandsshVerify.cidrsentries.Why This Change Was Made
Normalize the prefix into IPv4's bit space before the existing IPv4 match. The shared matcher now handles plain and mapped ranges in one path, without a second mapped-address matcher. Exact addresses, native IPv6, parsing, and downstream authorization keep their existing paths.
User Impact
Mapped
/104,/120, and/128ranges behave like IPv4/8,/24, and exact addresses. Prefixes at or below/96cover all IPv4, including loopback; the wizard keeps its explicit loopback-consent prompt. Native IPv6 peers do not match mapped ranges. Keep proxy allowlists narrow: a catch-all still consumes every IPv4 forwarded hop and cannot attribute a client through that chain.Automatic pairing still requires a fresh, signed, scopeless node request. Roles, scopes, browser requests, manual approval, and SSH host/device identity checks retain their own gates. No configuration field, schema, dependency, or permission policy is added.
Evidence
Real source Gateway and CLI runs use isolated documentation-address peers, a real overwriting loopback reverse proxy, TLS, and actual SSH reading
openclaw node identity --json./v1/modelsAdditional real controls cover
/64,/95,/96,/104,/128, exact nonmatches, native IPv6, loopback consent, missing/disallowed identities, missing headers, invalid/loopback forwarded clients, origin allow/deny, scope caps, and SSH identity/key failures. Signed WebSocket checks retain manual role upgrades, scoped/browser requests, signature rejection, and manual read-only enrollment. The enrolled operator can read after restart and cannot invoke an administrative write. CIDR device pairing retains separate capability approval.The three focused regression files show nine intended failures on main and 123 passes with the repair. Another 232 focused network/pairing/SSH tests pass. The exact installed ipaddr.js 2.5.0 source was inspected: IPv4 matching consumes 32 bits, so mapped prefixes must subtract 96.
Paired runtime proof uses main
1a7224b69f09b8e7a9edb8d9de27c3c534397f1eplus this repair, preserving newer Gateway callers. The changed matcher has exact byte identity with the candidate; the old contributor branch retains its ancestry. The contributor-based tree separately passes its own runtime build, formatter check, and 120 focused tests with its pinned dependencies. An independent validator completed 47 fresh runtime cases without an observed defect; source, historical, wizard-presentation, broader-policy and cleanup observations are assessed separately rather than claimed as independent passes. Historical setup and probe-assumption corrections remain recorded privately.AI-assisted.