Skip to content

fix(gateway): honor mapped IPv4 CIDR ranges - #137668

Merged
obviyus merged 2 commits into
openclaw:mainfrom
elbourne12345:fix/net-policy-mapped-cidr-prefix
Sep 8, 2026
Merged

obviyus merged 2 commits into
openclaw:mainfrom
elbourne12345:fix/net-policy-mapped-cidr-prefix

Conversation

@elbourne12345

@elbourne12345 elbourne12345 commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Closes #137665
Related: #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.

…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)
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime commands Command implementations size: S labels Sep 3, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 8, 2026, 2:13 PM ET / 18:13 UTC (Revision 3).

ClawSweeper review

What this changes

Corrects 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
Reviewed head: c7dc8dcc2e8e3a1f5357e1f8b93020009f0fea9f

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused shared-owner repair with strong runtime evidence and useful boundary regressions; no actionable patch defect remains.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The captured body maps the repaired shared matcher to real protected HTTP requests and signed node/SSH pairing, with observed after-fix acceptance and nearby forbidden-case rejection. Restart and restricted-scope controls complement existing source-level approval revalidation; the proof uses a declared newer-main tree with an identical repaired matcher.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured body maps the repaired shared matcher to real protected HTTP requests and signed node/SSH pairing, with observed after-fix acceptance and nearby forbidden-case rejection. Restart and restricted-scope controls complement existing source-level approval revalidation; the proof uses a declared newer-main tree with an identical repaired matcher.
Evidence reviewed 10 items Introduced repair and dependency boundary: The pinned introduced delta changes only the IPv4 branch of isIpInCidr: mapped bases use max(0, prefixLength - 96) before the existing match call. Exact-address and native IPv6 branches remain intact. This module directly imports ipaddr.js, pinned to 2.5.0 by its package; no Codex runtime or protocol dependency is involved.
Published dependency contract independently inspected: The npm 2.5.0 metadata identifies whitequark/ipaddr.js and gitHead dc55282780d8702bac31ef012ca52e4a77fbca1f. Published lib/ipaddr.js:108-130 compares successive fixed-width parts, :229-241 passes IPv4 octets with width 8, and :915-930 retains IPv6 prefixes through 128. Passing 104 to IPv4 matching compares all four octets instead of implementing /8. This resolves the prior dependency-inspection rank-up.
Current main still needs the repair: Fetched main still normalizes the mapped base to IPv4 and forwards the unchanged IPv6 prefix to IPv4.match. The central bug therefore remains present independently of branch drift.
Findings None None.
Security None None.

How this fits together

Gateway 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
Loading

Before merge

  • Resolve merge risk (P1) - Existing mapped allowlists become effective over their declared ranges across proxy trust and node pairing; deployments relying on the former exact-base behavior will trust more peers, including all IPv4 for mapped prefixes at or below /96.
Agent review details

Security

None.

PR surface

Source +5, Tests +60, Docs +1. Total +66 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 1 6 1 +5
Tests 3 61 1 +60
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 68 2 +66

Review metrics

Metric Value Why it matters
Production versus regression coverage Production net +5; tests net +60; documentation +1 Production growth is confined to the required prefix conversion and its invariant comments, without a parallel matcher.
Existing configuration semantics 3 CIDR settings affected; 0 settings added Proxy trust, automatic node approval, and SSH verification ranges all consume the repaired matcher.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #137665
Summary: This PR is the active candidate repair for the paired mapped-CIDR report; the earlier wizard/parser change explicitly deferred this defect.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Accept the documented CIDR semantics (recommended)
    Retain the shared repair with awareness that existing mapped allowlists now authorize their full declared IPv4 ranges.

Technical review

Best 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.

Labels

Label justifications:

  • P2: This repairs a reproducible, configuration-specific rejection of valid proxy and pairing peers.
  • merge-risk: 🚨 security-boundary: Previously ineffective mapped CIDRs will authorize their full configured ranges in proxy and pairing decisions.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured body maps the repaired shared matcher to real protected HTTP requests and signed node/SSH pairing, with observed after-fix acceptance and nearby forbidden-case rejection. Restart and restricted-scope controls complement existing source-level approval revalidation; the proof uses a declared newer-main tree with an identical repaired matcher.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured body maps the repaired shared matcher to real protected HTTP requests and signed node/SSH pairing, with observed after-fix acceptance and nearby forbidden-case rejection. Restart and restricted-scope controls complement existing source-level approval revalidation; the proof uses a declared newer-main tree with an identical repaired matcher.

Evidence

What I checked:

  • Introduced repair and dependency boundary: The pinned introduced delta changes only the IPv4 branch of isIpInCidr: mapped bases use max(0, prefixLength - 96) before the existing match call. Exact-address and native IPv6 branches remain intact. This module directly imports ipaddr.js, pinned to 2.5.0 by its package; no Codex runtime or protocol dependency is involved. (packages/net-policy/src/ip.ts:398, c7dc8dcc2e8e)
  • Published dependency contract independently inspected: The npm 2.5.0 metadata identifies whitequark/ipaddr.js and gitHead dc55282780d8702bac31ef012ca52e4a77fbca1f. Published lib/ipaddr.js:108-130 compares successive fixed-width parts, :229-241 passes IPv4 octets with width 8, and :915-930 retains IPv6 prefixes through 128. Passing 104 to IPv4 matching compares all four octets instead of implementing /8. This resolves the prior dependency-inspection rank-up. (lib/ipaddr.js:229, dc55282780d8)
  • Current main still needs the repair: Fetched main still normalizes the mapped base to IPv4 and forwards the unchanged IPv6 prefix to IPv4.match. The central bug therefore remains present independently of branch drift. (packages/net-policy/src/ip.ts, b824b72ce284)
  • Latest release retains the same behavior: Reading the v2026.9.3 file through GitHub confirmed the same unchanged-prefix call. Local retrieval of the historical blob failed, so release inspection used the read-only contents endpoint. (packages/net-policy/src/ip.ts, 1391f7cd2d40)
  • Proxy authorization and sibling callers: isTrustedProxyAddress delegates to the shared matcher; forwarded attribution walks past trusted hops and rejects an unresolved client. Trusted-proxy authentication separately checks loopback consent, local interfaces, required headers, and allowed users. Both node auto-approval and configured SSH probe ranges use the same matcher. Tailnet detection uses native constant ranges and is unaffected. (src/gateway/net.ts:196, c7dc8dcc2e8e)
  • Authority remains checked at approval: CIDR approval rechecks current configuration, device identity, and the actual pending scopeless request. SSH approval recomputes and compares the verification plan after the probe. The approval owner evaluates these guards after lock/state waits and before synchronous approval. Existing regression tests cover CIDR revocation and SSH policy changes, including while approval waits for its lock. (src/gateway/server/ws-connection/connect-node-pairing-ssh.ts:99, c7dc8dcc2e8e)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • obviyus: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-04T01:34:33.894Z sha 338a6bc :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-04T11:11:57.906Z sha 338a6bc :: blocked before merge. :: none

@elbourne12345

Copy link
Copy Markdown
Contributor Author

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 IncomingMessage. The proxy is loopback, which makes the accept/reject pair reproducible on a single host: ::ffff:127.0.0.0/104 is the mapped spelling of 127.0.0.0/8, so 127.0.0.1 is a peer inside the range, while ::ffff:126.0.0.0/104 is a nearby mapped range that does not contain it. Config is gateway.auth.mode: "trusted-proxy" with allowLoopback: true; each request is GET /__openclaw__/ from 127.0.0.1 carrying X-Forwarded-For: 203.0.113.9 and the configured x-forwarded-user header.

gateway.trustedProxies Peer Before (released build) After (this branch)
["::ffff:127.0.0.0/104"] matching HTTP 403 proxy_attribution_required HTTP 200, forwarded client attributed
["127.0.0.0/8"] (plain equivalent) matching HTTP 200 HTTP 200
["::ffff:126.0.0.0/104"] nearby, non-matching HTTP 403 HTTP 403, still rejected

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 203.0.113.9 from the RFC 5737 documentation range. This also covers the P1 merge-risk item about ::ffff:0:0/96 widening scope — the same mechanism is exercised here with a bounded loopback range, and the nearby-range row shows the boundary is still enforced rather than becoming a blanket allow.

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, packages/net-policy pins ipaddr.js 2.5.0, and the relevant contract is that IPv4.match([addr, prefix]) clamps the per-octet shift, so a 104-bit prefix against a 4-octet address compares every octet and degrades to an exact match — which is the defect this PR fixes by rebasing the prefix by 96.

CI note: the six red checks on this PR are pre-existing and unrelated — security-fast fails in "Audit production dependencies", and three node shards fail in subagent-spawn.authority, local-request-context.session-tools, and isolated-agent.session-identity. PR #137675, which is unrelated to this change, fails the same local-request-context.session-tools shard and the same audit step.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 4, 2026
@obviyus obviyus self-assigned this Sep 8, 2026
@obviyus obviyus changed the title fix(gateway): trusted proxies written as IPv4-mapped CIDR ranges are never matched fix(gateway): honor mapped IPv4 CIDR ranges Sep 8, 2026
@obviyus
obviyus merged commit 7069a47 into openclaw:main Sep 8, 2026
175 checks passed
@obviyus

obviyus commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

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.

  • Bug: An IPv6-width prefix was handed to the IPv4 matcher, reducing mapped ranges to exact-address matches.
  • Fix: Rebase the mapped prefix before the existing IPv4 match. The shared owner handles proxy attribution, node CIDR eligibility, and SSH CIDR eligibility in one path.
Before After
Matching mapped proxy range returns HTTP 403 Protected /v1/models request returns HTTP 200
Matching mapped node/SSH range leaves pairing pending Eligible node is approved and connects
Plain equivalent works; mapped equivalent fails Both spellings agree; adjacent ranges stay rejected

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 /96 cover all IPv4, so keep allowlists narrow. Native IPv6 does not match a mapped range. Broad proxy ranges still cannot identify a client when every forwarded IPv4 hop is itself trusted. Existing CIDR parser and HTTP scope hierarchy behavior is preserved.

Runtime proof is pinned main 1a7224b69f09b8e7a9edb8d9de27c3c534397f1e plus the exact repaired matcher, separately identified from final-branch validation. The configure prompt is covered by its maintained CLI-owner tests and source review; no interactive wizard recording or native-platform execution is claimed.

Landed in 7069a4772ff40602566afc686a41530dc76c8d2d after required CI passed and final review completed without findings.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 9, 2026
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]>
necromman pushed a commit to necromman/openclaw that referenced this pull request Sep 16, 2026
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: gateway.trustedProxies never matches IPv4-mapped IPv6 CIDR ranges (::ffff:a.b.c.d/N), so proxied requests get 403 proxy_attribution_required

2 participants