#23688: fix(gateway): accept raw IP addresses in gateway.bind for backward compat
gateway
size: XS
experienced-contributor
Cluster:
Config Fixes and Features
## 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
#19429: Fix/custom bind host validation
by frudas24 · 2026-02-17
81.2%
#12499: fix(config): add missing customBindHost to gateway Zod schema
by sfo2001 · 2026-02-09
79.4%
#19437: Gateway: respect custom bind host for local health/RPC target resol...
by frudas24 · 2026-02-17
77.0%
#21741: fix(gateway): allow plaintext ws:// for Docker/private network addr...
by Joe3112 · 2026-02-20
76.4%
#10807: fix(config): coerce numeric meta.lastTouchedAt to ISO string
by mcaxtr · 2026-02-07
74.6%
#14564: fix(gateway): crashes on startup when tailscale meets non-loopback ...
by yinghaosang · 2026-02-12
74.0%
#11098: Support dual-stack custom and LAN gateway binds
by zUZWqEHF · 2026-02-07
73.6%
#22056: fix(gateway): use loopback for self-connections regardless of bind ...
by usedhonda · 2026-02-20
73.0%
#16300: fix(tui): respect gateway bind mode in TUI connection
by cortexuvula · 2026-02-14
72.9%
#21772: [Bug]: Allow ws:// to Tailscale CGNAT addresses
by AIflow-Labs · 2026-02-20
72.6%