Bug 1686808 - Don't use regex to parse URIs in WebExecutor. r=owlish

The harmless looking regex

```
uri.matches("(http|blob).*")
```

has a flaw: it will not accept URLs that contain a new line character. In that
case GeckoWebExecutor errors out with "Unsupported URI scheme." when in reality
that's not the problem at all.

Since it has caused a bunch of headaches to the frontend already, let's just
replace that regex with a plain `startsWith` which should work in all cases.

Differential Revision: https://phabricator.services.mozilla.com/D102943
This commit is contained in:
Agi Sferro 2021-01-25 18:20:31 +00:00
Родитель 54cce40f63
Коммит d0ea404038
2 изменённых файлов: 18 добавлений и 1 удалений

Просмотреть файл

@ -445,5 +445,22 @@ class WebExecutorTest {
equalTo("Unsupported URI scheme: $truncated"))
}
}
val legal = listOf(
"http://$TEST_ENDPOINT\n",
"http://$TEST_ENDPOINT/🥲",
"http://$TEST_ENDPOINT/abc"
)
for (uri in legal) {
try {
fetch(WebRequest(uri))
throw IllegalStateException("fetch() should have thrown")
} catch (e: WebRequestError) {
assertThat("Request should pass initial validation.",
true,
equalTo(true))
}
}
}
}

Просмотреть файл

@ -141,7 +141,7 @@ public class GeckoWebExecutor {
final String uri = request.uri.toLowerCase(Locale.ROOT);
// We don't need to fully validate the URI here, just a sanity check
if (!uri.matches("(http|blob).*")) {
if (!uri.startsWith("http") && !uri.startsWith("blob")) {
throw new IllegalArgumentException("Unsupported URI scheme: " +
(uri.length() > 10 ? uri.substring(0, 10) : uri));
}