Commit f937604c authored by mef's avatar mef Committed by Commit bot

Throw IllegalArgumentException from Cronet...

Throw IllegalArgumentException from Cronet HttpUrlRequestFactoryConfig.addQuicHint if host param is URL.

This is needed to prevent invalid hosts from being added to HttpServerProperties and having Quic hints not working correctly.

HttpUrlRequestFactoryConfig is pure Java and doesn't depend on native library, so it only provides a rudimentary check, but URLRequestContextAdapter::InitRequestContextOnNetworkThread() performs IsCanonicalizedHostCompliant check and uses LOG(ERROR) for invalid hosts.

BUG=420464
TEST=build/android/test_runner.py instrumentation  --test-apk=CronetTestInstrumentation -f *Quic*

Review URL: https://codereview.chromium.org/642913004

Cr-Commit-Position: refs/heads/master@{#300363}
parent 8d99a849
......@@ -111,6 +111,10 @@ public class HttpUrlRequestFactoryConfig {
public HttpUrlRequestFactoryConfig addQuicHint(String host,
int port,
int alternatePort) {
if (host.contains("/")) {
throw new IllegalArgumentException("Illegal QUIC Hint Host: " +
host);
}
try {
JSONArray quicHints = mConfig.optJSONArray(
UrlRequestContextConfig.QUIC_HINTS);
......
......@@ -58,4 +58,17 @@ public class HttpUrlRequestFactoryTest extends CronetTestBase {
"HttpUrlConnection/\\d+\\.\\d+\\.\\d+\\.\\d+@\\w+",
factory.getName()));
}
@SmallTest
@Feature({"Cronet"})
public void testQuicHintHost() {
HttpUrlRequestFactoryConfig config = new HttpUrlRequestFactoryConfig();
config.addQuicHint("www.google.com", 443, 443);
try {
config.addQuicHint("https://www.google.com", 443, 443);
} catch (IllegalArgumentException e) {
return;
}
fail("IllegalArgumentException must be thrown");
}
}
......@@ -13,6 +13,7 @@
#include "components/cronet/url_request_context_config.h"
#include "net/base/net_errors.h"
#include "net/base/net_log_logger.h"
#include "net/base/net_util.h"
#include "net/cert/cert_verifier.h"
#include "net/http/http_auth_handler_factory.h"
#include "net/http/http_network_layer.h"
......@@ -173,6 +174,14 @@ void URLRequestContextAdapter::InitRequestContextOnNetworkThread() {
continue;
}
url::CanonHostInfo host_info;
std::string canon_host(net::CanonicalizeHost(quic_hint.host, &host_info));
if (!host_info.IsIPAddress() &&
!net::IsCanonicalizedHostCompliant(canon_host)) {
LOG(ERROR) << "Invalid QUIC hint host: " << quic_hint.host;
continue;
}
if (quic_hint.port <= std::numeric_limits<uint16>::min() ||
quic_hint.port > std::numeric_limits<uint16>::max()) {
LOG(ERROR) << "Invalid QUIC hint port: "
......@@ -187,7 +196,7 @@ void URLRequestContextAdapter::InitRequestContextOnNetworkThread() {
continue;
}
net::HostPortPair quic_hint_host_port_pair(quic_hint.host,
net::HostPortPair quic_hint_host_port_pair(canon_host,
quic_hint.port);
context_->http_server_properties()->SetAlternateProtocol(
quic_hint_host_port_pair,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment