#21772: [Bug]: Allow ws:// to Tailscale CGNAT addresses
gateway
size: S
Cluster:
Gateway Resilience and Configuration
## Summary
This PR fixes #21760 where CLI commands fail after v2026.2.19 due a strict plaintext WebSocket check rejecting all non-loopback `ws://` URLs, including Tailscale tailnet IPs (`100.64.0.0/10`).
## What changed
- Relaxed the WebSocket security check in `src/gateway/net.ts`:
- `isSecureWebSocketUrl()` now treats Tailscale CGNAT IPv4 addresses (`100.64.0.0/10`) as secure for `ws://`.
- This path remains `wss://`-required for public/network-facing addresses.
- Added/updated regression tests:
- `src/gateway/net.test.ts`
- now asserts `ws://100.64.0.1` is considered secure.
- `src/gateway/call.test.ts`
- adjusted expectations for tailnet behavior and documented allowed `ws://` on Tailscale while retaining rejection for other non-loopback addresses.
- added explicit coverage for `bind=lan` resolving to a tailnet address.
## Why this is safe
- Keeps TLS requirement for non-loopback public hosts and non-Tailscale ranges.
- Restricts the relaxation to well-scoped 100.64.0.0/10 CGNAT addresses that are encrypted end-to-end by Tailscale.
- Does not alter authentication or credential paths; only changes URL trust heuristics used by existing gateway call/resolution flow.
## Confidence Score
- 10/10 confidence for merge readiness.
- Fix is deterministic and localized to one helper and existing call-path tests.
- Regression is covered by positive/negative tests that pin behavior for both allowed tailnet and denied non-tailnet `ws://` hosts.
- No unrelated behavior changes; no API surface changed.
## Validation
- `pnpm test src/gateway/net.test.ts src/gateway/call.test.ts`
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Relaxes WebSocket security check to allow `ws://` connections to Tailscale CGNAT IPv4 addresses (`100.64.0.0/10`) while maintaining TLS requirements for all other non-loopback addresses. The implementation correctly identifies Tailscale IPs and properly normalizes IPv6-mapped IPv4 addresses before validation.
Key changes:
- Added `isTailscaleIPv4Address()` helper that validates IPs in the `100.64.0.0/10` CGNAT range
- Updated `isSecureWebSocketUrl()` to treat Tailscale IPs as secure for `ws://` connections
- Added test coverage for the Tailscale range start (`100.64.0.1`)
- Updated integration tests in `call.test.ts` to reflect new behavior for tailnet and LAN bindings
The fix is well-scoped and addresses the regression from v2026.2.19 where CLI commands failed when connecting to Tailscale addresses.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The fix is well-implemented with correct CIDR range validation for Tailscale addresses (`100.64.0.0/10`), includes appropriate test coverage, and maintains security for non-Tailscale addresses. The logic is straightforward, properly handles IPv6-mapped IPv4 addresses, and is limited in scope to the specific security check function.
- No files require special attention
<sub>Last reviewed commit: 7743e2f</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#21256: fix: treat ws:// to Tailscale addresses as secure when bind=tailnet
by jessewunderlich · 2026-02-19
85.9%
#16300: fix(tui): respect gateway bind mode in TUI connection
by cortexuvula · 2026-02-14
81.1%
#22056: fix(gateway): use loopback for self-connections regardless of bind ...
by usedhonda · 2026-02-20
80.4%
#22110: fix(tools): prefer loopback for internal tool-to-gateway RPC calls
by pierreeurope · 2026-02-20
80.2%
#14564: fix(gateway): crashes on startup when tailscale meets non-loopback ...
by yinghaosang · 2026-02-12
79.2%
#21436: fix(gateway): plaintext ws:// blocked for Docker bind=lan (SECURITY...
by xinhuagu · 2026-02-19
79.0%
#22682: fix(gateway): [P0] status probe ignores gateway.tls.enabled — hardc...
by mahsumaktas · 2026-02-21
78.4%
#19026: fix(gateway): use loopback for local CLI-to-gateway connections
by Phineas1500 · 2026-02-17
78.0%
#21741: fix(gateway): allow plaintext ws:// for Docker/private network addr...
by Joe3112 · 2026-02-20
78.0%
#21635: Fix status --deep showing tailscale off while tailnet is active
by graysurf · 2026-02-20
77.8%