#21265: Security/Pairing: reject insecure non-loopback ws setup URLs
cli
size: S
Cluster:
Device Pairing and Gateway Fixes
## Summary
- reject setup-code generation when the resolved gateway URL is `ws://` on a non-loopback host
- keep loopback `ws://` support for local development
- add regression tests for rejected insecure remote URLs and allowed loopback URLs
- update existing pairing tests to use TLS where required by the new guard
## Why
Pairing setup payloads include gateway credentials. Allowing plaintext non-loopback WebSocket URLs can expose those credentials in transit.
## Testing
- `pnpm test src/pairing/setup-code.test.ts`
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Adds transport security validation to pairing setup, rejecting plaintext `ws://` connections to non-loopback hosts while preserving local development workflows. The implementation uses loopback detection covering standard patterns (`localhost`, `127.*`, `::1`, `::ffff:127.*`) and validates URLs before setup code generation.
- Implemented `isLoopbackHost()` helper to identify loopback addresses
- Added `validateTransportSecurity()` to enforce `wss://` for remote hosts
- Updated existing tests to use TLS where required by the new validation
- Added regression tests for both rejected insecure URLs and allowed loopback cases
<h3>Confidence Score: 4/5</h3>
- This security improvement is safe to merge with minor edge cases to consider
- The PR correctly implements transport security validation to prevent credential exposure over plaintext connections. The implementation has good test coverage and updates existing tests appropriately. One minor consideration is IPv6 loopback variant handling, but the current implementation covers standard cases. The security benefit significantly outweighs the small risk of edge case scenarios.
- No files require special attention - the implementation is straightforward and well-tested
<sub>Last reviewed commit: cd4268c</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#21697: fix(gateway): unblock local spawn pairing and gated private-LAN ws
by rjuanluis · 2026-02-20
82.4%
#22365: fix(gateway): auto-approve loopback scope upgrades
by AIflow-Labs · 2026-02-21
78.9%
#23690: fix(gateway): subagent sessions fail with pairing required on loopb...
by yinghaosang · 2026-02-22
78.9%
#22227: fix(security): harden gateway auth — audit logging, pairing, mode v...
by novalis133 · 2026-02-20
77.5%
#22347: Feature request: gateway.clientUrl config to decouple client URL
by AIflow-Labs · 2026-02-21
77.3%
#22712: fix(gateway): auto-approve all device pairing for localhost connect...
by NewdlDewdl · 2026-02-21
77.2%
#22381: Security/Gateway: block cross-origin silent auto-pairing in auth mo...
by bmendonca3 · 2026-02-21
76.4%
#22280: fix(gateway): silently auto-approve local paired-device scope upgrades
by abhishekp76 · 2026-02-21
75.4%
#17425: fix(gateway): auto-approve scope/role upgrades for already-paired d...
by sauerdaniel · 2026-02-15
75.3%
#23708: fix(gateway): auto-approve scope upgrades for loopback clients
by widingmarcus-cyber · 2026-02-22
74.9%