← Back to PRs

#23688: fix(gateway): accept raw IP addresses in gateway.bind for backward compat

by arosstale open 2026-02-22 15:57 View on GitHub →
gateway size: XS experienced-contributor
## What broke The 2026.2.17 release added named bind modes (`loopback`, `lan`, `tailnet`, `custom`) to `gateway.bind`. The Zod schema was updated to a union of literals — but raw IP addresses that were valid before (e.g. Tailscale IPs like `100.64.0.1`) now fail validation and prevent gateway startup. ``` Config validation failed: gateway.bind: Invalid union value ``` ## Root cause `src/config/zod-schema.ts` — the bind union only allows the four string literals: ```ts z.union([ z.literal(lan), z.literal(loopback), z.literal(custom), z.literal(tailnet), // ← no raw IP branch ]) ``` ## Fix Add an IP address regex branch to the union for backward compat. The regex accepts dotted-decimal IPv4 and hex-colon IPv6. At startup, `net.ts` already resolves any unrecognised bind value as a custom host — the schema just needed to let it through. ```ts z.string().regex(/^(?:\d{1,3}\.){3}\d{1,3}$|^[0-9a-fA-F:]+$/) ``` ## Verification ```sh # Before: validation error openclaw gateway start # with gateway.bind: "100.64.0.1" # After: starts cleanly, binds to 100.64.0.1 pnpm test src/config/zod-schema.test.ts ``` Fixes #23686 [AI-assisted] <!-- greptile_comment --> <h3>Greptile Summary</h3> Restores backward compatibility for raw IP addresses in `gateway.bind` config by adding a regex branch to the Zod schema union and handling unrecognized bind modes as custom hosts in `resolveGatewayBindHost`. **Key changes:** - Added regex pattern to Zod schema to accept IP address strings alongside named bind modes - Modified `net.ts` to detect raw IP values and treat them as custom bind hosts - Updated CHANGELOG with fix entry **Issues found:** - Issue number mismatch in code comments (`#21504` vs `#23686`) - IPv4 regex allows invalid octets >255 (caught at runtime but not at config validation) - IPv6 regex is overly permissive and IPv6 addresses will fail at runtime since `isValidIPv4()` check rejects them <h3>Confidence Score: 3/5</h3> - Safe to merge with minor issues - backward compatibility is restored for IPv4 addresses but IPv6 support needs follow-up - The PR successfully fixes the immediate issue (Tailscale IPv4 addresses like `100.64.0.1` now pass validation and bind correctly). However, there are quality issues: issue number mismatches in comments, and the IPv6 regex branch won't work at runtime since `isValidIPv4()` will reject IPv6 addresses. The IPv4 regex also accepts out-of-range octets, though these are caught at runtime. These don't break the primary use case but should be addressed. - `src/config/zod-schema.ts` and `src/gateway/net.ts` need issue number corrections; IPv6 handling should be reconsidered <sub>Last reviewed commit: 954a705</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs