Skip to content

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

Closed

Description

@elbourne12345

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

A gateway.trustedProxies entry written as an IPv4-mapped IPv6 CIDR such as ::ffff:10.0.0.0/104 is accepted by config validation and by the onboarding wizard, but the runtime matcher never matches any address in that range except the exact base address. Every request arriving through that proxy with forwarded headers is rejected with HTTP 403 proxy_attribution_required.

The same matcher backs gateway.nodes.pairing.autoApproveCidrs and gateway.nodes.pairing.sshVerify.cidrs, so those silently stop matching too.

Steps to reproduce

  1. Run OpenClaw from source at main (6d8d67fae).
  2. Put a reverse proxy at 10.1.2.3 and set gateway.trustedProxies: ["::ffff:10.0.0.0/104"], the mapped spelling of 10.0.0.0/8. The openclaw configure trusted-proxy prompt accepts this value.
  3. Send any request through the proxy so it reaches the gateway with X-Forwarded-For.
  4. Observe HTTP 403 with body Proxy client attribution is required. Configure gateway.trustedProxies narrowly and make the proxy overwrite or safely rebuild forwarded client headers.
  5. Change the entry to 10.0.0.0/8 and repeat: the request is attributed to the forwarded client and succeeds.

Unit-level reproduction against packages/net-policy/src/ip.ts and src/gateway/net.ts:

isIpInCidr("10.1.2.3", "::ffff:10.0.0.0/104");        // false, expected true
isIpInCidr("::ffff:10.1.2.3", "::ffff:10.0.0.0/104"); // false, expected true
isIpInCidr("::ffff:10.1.2.3", "::ffff:0:0/96");       // false, expected true
isIpInCidr("10.0.0.0", "::ffff:10.0.0.0/104");        // true  (only the exact base matches)
isIpInCidr("10.1.2.3", "10.0.0.0/8");                 // true  (control)

isTrustedProxyAddress("10.1.2.3", ["::ffff:10.0.0.0/104"]); // false

Expected behavior

::ffff:10.0.0.0/104 is the IPv4-mapped form of 10.0.0.0/8, so a proxy at 10.1.2.3 should be trusted exactly as it is with 10.0.0.0/8.

docs/gateway/trusted-proxy-auth.md:97 says the request's source IP "must match gateway.trustedProxies (CIDR-aware)". docs/cli/configure.md:43 says the wizard accepts "IPv4 or IPv6 addresses or CIDR ranges". The existing case in packages/net-policy/src/ip.test.ts:53 expects ::ffff:127.0.0.1/128 to be a valid mapped range, so mapped CIDRs are an intended input.

Actual behavior

isIpInCidr normalizes the mapped base ::ffff:10.0.0.0 to the IPv4 address 10.0.0.0 but passes the original 104-bit prefix length unchanged to ipaddr.js match(). On a four-octet address a prefix of 104 compares every octet in full, so the range degrades to an exact match on the base address. Any prefix from 96 to 127 behaves the same way, and ::ffff:0:0/96 (all of IPv4) matches only 0.0.0.0. The existing /128 case passes only because an exact match happens to be the right answer there.

Because the proxy is not trusted, the request is classified as unattributable-proxy and answered with 403 before any auth or rate-limit decision. The failure is fail-closed: no request is ever wrongly trusted.

OpenClaw version

2026.8.1 (source, main at 6d8d67fae). Present since 333fbb863 (2026-02-22, "refactor(net): consolidate IP checks with ipaddr.js"), which introduced isIpInCidr.

Operating system

Windows 11 (reproduced with vitest); the code path is platform-independent.

Install method

Source checkout

Model

n/a (gateway network policy, model-independent)

Provider / routing chain

n/a (reverse proxy to gateway; no model provider involved)

Additional provider/model setup details

No response

Logs

Scoped repro test at `main` `6d8d67fae`:


× 10.1.2.3 in ::ffff:10.0.0.0/104        → expected false to be true
× ::ffff:10.1.2.3 in ::ffff:10.0.0.0/104 → expected false to be true
× ::ffff:10.1.2.3 in ::ffff:0:0/96       → expected false to be true
× isTrustedProxyAddress("10.1.2.3", ["::ffff:10.0.0.0/104"]) → expected false to be true
✓ 10.0.0.0 exact in ::ffff:10.0.0.0/104
✓ 10.1.2.3 in 10.0.0.0/8 (control)

Screenshots, recordings, and evidence

  • packages/net-policy/src/ip.ts, isIpInCidr: comparableBase = normalizeIpv4MappedAddress(baseAddress) is followed by comparableIp.match([comparableBase, prefixLength]) with prefixLength still in 128-bit space.
  • src/commands/configure.gateway.ts:310 validates trusted-proxy entries with parseIpAddressOrCidr, which accepts the mapped form, so the wizard writes a value the runtime cannot honor.
  • src/gateway/net.ts:207 (isTrustedProxyAddress) is the trusted-proxy caller. src/gateway/node-pairing-auto-approve.ts:104 and src/gateway/node-pairing-ssh-verify.ts:129 reach the same helper for autoApproveCidrs and sshVerify.cidrs.
  • PR fix(onboard): probe remote gateways with saved TLS pins and validate trusted proxies #131475 lists "mapped-IPv4 CIDR prefix interpretation" among its Named follow-ups, not addressed there. Its parameterized test in src/commands/configure.gateway.test.ts ("does not ask for loopback consent when runtime cannot match loopback through %s", with ::ffff:0:0/96 as a case) pins the current behavior.
  • Verified against ipaddr.js 2.5.0, the version pinned by packages/net-policy: IPv4.match([10.0.0.0, 104]) is true only for 10.0.0.0, while match([10.0.0.0, 104 - 96]) behaves as /8.

Impact and severity

  • Affected: operators who write gateway.trustedProxies, gateway.nodes.pairing.autoApproveCidrs, or gateway.nodes.pairing.sshVerify.cidrs entries in IPv4-mapped CIDR form. src/infra/tailnet.ts is not affected; it uses fixed native CIDR constants.
  • Severity: low to medium. Fail-closed, no auth bypass. All proxied gateway traffic is rejected with 403, and CIDR-based node pairing auto-approval silently falls back to manual prompts.
  • Frequency: always, for any mapped CIDR with a prefix from 96 to 127.
  • Consequence: the wizard and schema accept a value the runtime never matches, with no warning at config load, openclaw doctor, or startup. The only signal is the 403 on the first proxied request, whose guidance points at "configure trustedProxies narrowly" rather than at the address family.

Additional information

Not a regression; the behavior has been the same since isIpInCidr was introduced.

Activity

  1. added
    bug
    on Sep 3, 2026
  2. added
    bug:behavior
    on Sep 3, 2026
  3. added
    P2
    clawsweeper:linked-pr-open
    clawsweeper:needs-live-repro
    clawsweeper:needs-security-review
    clawsweeper:no-new-fix-pr
    impact:security
    issue-rating: 🐚 platinum hermit
    maturity:stable
    on Sep 4, 2026
  4. clawsweeper commented on Sep 4, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed September 3, 2026, 8:23 PM ET / September 4, 2026, 00:23 UTC.

    Summary
    Keep open: current main and v2026.8.2 retain the shared matcher defect, and the formally linked open PR is the active fix candidate.

    Reproducibility: no. executed reproduction was possible in this read-only review, but current source clearly routes accepted mapped CIDRs through a normalized IPv4 base with the unreduced prefix.

    Root-cause cluster
    Relationship: fixed_by_candidate
    Canonical: #137668
    Summary: The linked open PR is the single canonical implementation candidate for this source-proven matcher defect.

    Members:

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

    Ways to help us reproduce this

    • Add a screenshot or short recording showing the behavior.
    • Add expected vs actual behavior.
    • Include redacted logs or terminal output.

    Next step
    A linked open PR formally owns the bounded repair, so a second repair job would duplicate active work.

    Security
    Needs attention: The defect is security-sensitive trusted-proxy policy, but the reviewed current behavior fails closed and no bypass is evidenced.

    Review details

    Best possible solution:

    Review and land the linked PR if it corrects prefix rebasing in the shared matcher and retains boundary coverage for ingress, loopback consent, and pairing callers.

    Do we have a high-confidence way to reproduce the issue?

    No executed reproduction was possible in this read-only review, but current source clearly routes accepted mapped CIDRs through a normalized IPv4 base with the unreduced prefix.

    Is this the best way to solve the issue?

    Yes for the repair shape: fix the shared matcher’s prefix interpretation and cover ingress and pairing consumers rather than adding downstream exceptions.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • The exact ipaddr.js 2.5.0 implementation could not be inspected because this checkout has no installed dependency copy and github.com DNS was unavailable; no executable reproduction was run in this read-only review.

    Codex review notes: model internal, reasoning high; reviewed against cd8c74889d21.

    Label changes

    Label changes:

    • add P2: Accepted mapped CIDRs consistently fail closed for affected proxy and pairing configurations, but no authorization bypass is evidenced.
    • add impact:security: The mismatch occurs in trusted-proxy attribution and trusted-CIDR pairing policy before authentication or approval decisions.
    • add maturity:stable: The broken established trusted-proxy contract is primarily owned by the Gateway runtime, scored M4 Stable in qa/maturity-scores.yaml, under its Security Controls surface.
    • add issue-rating: 🐚 platinum hermit: Current issue advisory state selects this label.
    • add clawsweeper:needs-live-repro: Current issue advisory state selects this label.
    • add clawsweeper:linked-pr-open: Current issue advisory state selects this label.
    • add clawsweeper:no-new-fix-pr: Current issue advisory state selects this label.
    • add clawsweeper:needs-security-review: Current issue advisory state selects this label.

    Label justifications:

    • P2: Accepted mapped CIDRs consistently fail closed for affected proxy and pairing configurations, but no authorization bypass is evidenced.
    • impact:security: The mismatch occurs in trusted-proxy attribution and trusted-CIDR pairing policy before authentication or approval decisions.
    • maturity:stable: The broken established trusted-proxy contract is primarily owned by the Gateway runtime, scored M4 Stable in qa/maturity-scores.yaml, under its Security Controls surface.
    Evidence reviewed

    Security concerns:

    • [low] Accepted mapped CIDRs fail closed in trust policy — packages/net-policy/src/ip.ts:399
      Mapped IPv6 CIDR configuration accepted by the wizard can fail to trust intended IPv4 peers, blocking proxy attribution and configured CIDR pairing behavior.
      Confidence: 0.9

    What I checked:

    • Current matcher defect: The matcher normalizes a mapped IPv6 peer and CIDR base to IPv4, but passes the original IPv6-space prefix to the IPv4 matcher. (packages/net-policy/src/ip.ts:390, cd8c74889d21)
    • Gateway failure path: Gateway ingress calls the shared trusted-proxy matcher and emits unattributable-proxy when forwarded-header traffic does not match; HTTP handling returns the resulting authentication failure before normal routing. (src/gateway/ingress-attribution.ts:228, cd8c74889d21)
    • Accepted configuration and sibling consumers: The configure wizard accepts values through the same CIDR parser, while node auto-approval and SSH verification delegate their configured CIDRs to the same trusted-proxy helper. (src/commands/configure.gateway.ts:310, cd8c74889d21)
    • Shipped current behavior: The v2026.8.2 source contains the same mapped-address normalization and unchanged prefix handoff as current main, so the reported behavior is shipped as well as current. (packages/net-policy/src/ip.ts:390, 0965053fe6b9)
    • Existing contract and test gap: Docs promise CIDR-aware trusted-proxy source matching, while the existing mapped-CIDR unit case covers only exact /128 equality and does not cover mapped prefixes that denote ranges. Public docs: docs/gateway/trusted-proxy-auth.md. (docs/gateway/trusted-proxy-auth.md:97, cd8c74889d21)
    • Open canonical fix candidate: The linked PR explicitly uses closing syntax for this issue and describes boundary coverage at the matcher and gateway-ingress levels; it is open and therefore does not yet close the issue. (338a6bc74ed5)

    Likely related people:

    • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
    How this review workflow works
    • 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.
  5. self-assigned this
    on Sep 8, 2026
  6. added a commit that references this issue on Sep 8, 2026
    7069a47
  7. added a commit that references this issue on Sep 9, 2026
    649526e
  8. added a commit that references this issue on Sep 16, 2026
    5ece74d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2bugbug:behaviorclawsweeper:linked-pr-openclawsweeper:needs-live-reproclawsweeper:needs-security-reviewclawsweeper:no-new-fix-primpact:securityissue-rating: 🐚 platinum hermitmaturity:stable

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions