fix(android): reject unsupported gateway schemes · openclaw/openclaw@d43f2f7
obviyus
·
2026-05-18
·
via Recent Commits to openclaw:main
File tree
main/java/ai/openclaw/app/ui
test/java/ai/openclaw/app/ui
| Original file line number | Diff line number | Diff line change |
|---|
@@ -143,27 +143,15 @@ internal fun parseGatewayEndpointResult(rawInput: String): GatewayEndpointParseR
|
143 | 143 | ?.trim() |
144 | 144 | ?.lowercase(Locale.US) |
145 | 145 | .orEmpty() |
146 | | -val tls = |
147 | | -when (scheme) { |
148 | | -"ws", "http" -> false |
149 | | -"wss", "https" -> true |
150 | | -else -> true |
151 | | - } |
| 146 | +if (scheme !in setOf("ws", "wss", "http", "https")) { |
| 147 | +return GatewayEndpointParseResult(error = GatewayEndpointValidationError.INVALID_URL) |
| 148 | + } |
| 149 | +val tls = scheme == "wss" || scheme == "https" |
152 | 150 | if (!tls && !isLoopbackGatewayHost(host)) { |
153 | 151 | return GatewayEndpointParseResult(error = GatewayEndpointValidationError.INSECURE_REMOTE_URL) |
154 | 152 | } |
155 | | -val defaultPort = |
156 | | -when (scheme) { |
157 | | -"wss", "https" -> 443 |
158 | | -"ws", "http" -> 18789 |
159 | | -else -> 443 |
160 | | - } |
161 | | -val displayPort = |
162 | | -when (scheme) { |
163 | | -"wss", "https" -> 443 |
164 | | -"ws", "http" -> 80 |
165 | | -else -> 443 |
166 | | - } |
| 153 | +val defaultPort = if (tls) 443 else 18789 |
| 154 | +val displayPort = if (tls) 443 else 80 |
167 | 155 | val port = uri.port.takeIf { it in 1..65535 } ?: defaultPort |
168 | 156 | val displayHost = if (host.contains(":")) "[$host]" else host |
169 | 157 | val displayUrl = |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -268,6 +268,14 @@ class GatewayConfigResolverTest {
|
268 | 268 | assertEquals(GatewayEndpointValidationError.INSECURE_REMOTE_URL, parsed.error) |
269 | 269 | } |
270 | 270 | |
| 271 | + @Test |
| 272 | +fun parseGatewayEndpointResultRejectsUnsupportedSchemes() { |
| 273 | +val parsed = parseGatewayEndpointResult("ftp://gateway.example:21") |
| 274 | + |
| 275 | + assertNull(parsed.config) |
| 276 | + assertEquals(GatewayEndpointValidationError.INVALID_URL, parsed.error) |
| 277 | + } |
| 278 | + |
271 | 279 | @Test |
272 | 280 | fun parseGatewayEndpointResultFlagsInsecureLanCleartextGateway() { |
273 | 281 | val parsed = parseGatewayEndpointResult("ws://192.168.1.20:18789") |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。