#21102: Android/Security: require TLS for non-loopback gateway sessions
app: android
size: S
Cluster:
Security Enhancements and Fixes
This PR reopens the Android transport hardening from the previously closed PR after branch-name cleanup.
Summary:
- Require TLS for non-loopback Android gateway sessions.
- Keep plaintext WS limited to loopback development flows.
- Add/retain unit tests for transport-policy behavior.
Replaces: #21069
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR enforces TLS for non-loopback Android gateway connections by blocking plaintext WebSocket connections to remote hosts while preserving plaintext for loopback development flows.
**Key changes:**
- Added `isLoopbackHost` helper to detect localhost/127.x.x.x/::1/0.0.0.0/:: addresses
- `GatewaySession.connect()` now throws `IllegalStateException` if attempting non-loopback plaintext connection
- `ConnectionManager.resolveTlsParamsForEndpoint` enforces TLS requirements for manual and discovered non-loopback endpoints
- `NodeRuntime.connectManual()` validates TLS requirement before attempting connection
- Added comprehensive test coverage for loopback vs non-loopback TLS enforcement scenarios
**Minor issue:**
- The `isLoopbackHost` function is duplicated in both `GatewaySession.kt` and `ConnectionManager.kt` with identical implementations
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The security hardening logic is straightforward and well-tested. The PR includes comprehensive unit tests covering all critical scenarios (loopback vs non-loopback, manual vs discovered endpoints). The only issue is a minor code duplication that doesn't affect functionality or security.
- No files require special attention
<sub>Last reviewed commit: 920af39</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#23735: Gateway: add first-class wss validation and remote TLS guidance
by bmendonca3 · 2026-02-22
74.5%
#21103: Android/Security: exclude device identity from backups
by bmendonca3 · 2026-02-19
73.6%
#22682: fix(gateway): [P0] status probe ignores gateway.tls.enabled — hardc...
by mahsumaktas · 2026-02-21
72.4%
#5441: fix(android): resolve WebSocket handshake race condition (#1922)
by cortexuvula · 2026-01-31
72.3%
#21450: Android: allow HTTP for LAN hosts
by pedrochagasmaster · 2026-02-19
72.2%
#21233: docs: clarify bind=lan non-loopback access requires wss or tunnel (...
by saurabhchopade · 2026-02-19
72.1%
#23355: Gateway: fail closed on untrusted proxy headers
by bmendonca3 · 2026-02-22
71.9%
#21265: Security/Pairing: reject insecure non-loopback ws setup URLs
by bmendonca3 · 2026-02-19
71.9%
#23742: Gateway: add optional mTLS client-cert enforcement for non-loopback...
by bmendonca3 · 2026-02-22
71.4%
#11205: Android: fix gateway connection and canvas URL for Tailscale serve
by emonty · 2026-02-07
70.9%