0

Use the standard-compliant forbidden character '^' as an invalid URL

Currently, in the rewriting rule of the test runners, "~NOTFOUND" is
used as an invalid URL. However, '~' is NOT a forbidden character
according to the URL standard.

Chromium is addressing [1] this non-compliant behavior and will permit
'~' character in URL hosts. Thus, we can no longer use "~NOTFOUND" as
it will become a valid URL.

As an alternative, any invalid character is acceptable. Let's use '^'
because '^' is a forbidden character both before and after the CL [1].

The PR for WPT Chrome runner is:
https://github.com/web-platform-tests/wpt/pull/41840/

[1]: https://crrev.com/c/4823237

Bug: 1416013
Change-Id: Id8767ab49b54e778da53113aa4995e098bdbee59
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4845589
Reviewed-by: Yoav Weiss <yoavweiss@chromium.org>
Commit-Queue: Hayato Ito <hayato@chromium.org>
Reviewed-by: Mathias Bynens <mathias@chromium.org>
Reviewed-by: Adam Rice <ricea@chromium.org>
Reviewed-by: Chidera Olibie <colibie@google.com>
Reviewed-by: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1194658}
This commit is contained in:
Hayato Ito
2023-09-11 02:38:41 +00:00
committed by Chromium LUCI CQ
parent 54445cc380
commit 33c9a1f7a5
15 changed files with 20 additions and 19 deletions

@ -561,7 +561,7 @@ class ChromeDriverTestWithCustomCapability(ChromeDriverBaseTestWithWebServer):
# Block DNS resolution for all hosts so that the navigation results
# in a DNS lookup error.
driver = self.CreateDriver(
chrome_switches=['--host-resolver-rules=MAP * ~NOTFOUND'])
chrome_switches=['--host-resolver-rules=MAP * ^NOTFOUND'])
self.assertRaises(chromedriver.ChromeDriverException,
driver.Load, 'http://invalid/')
self.assertEqual('http://invalid/', driver.GetCurrentUrl())

@ -136,7 +136,7 @@ class PerfTest : public CronetTestBase,
NSString* rules = base::SysUTF8ToNSString(
base::StringPrintf("MAP test.example.com 127.0.0.1:%d,"
"MAP notfound.example.com ~NOTFOUND",
"MAP notfound.example.com ^NOTFOUND",
net::QuicSimpleTestServer::GetPort()));
[Cronet setHostResolverRulesForTesting:rules];
// This is the end of the behavior normally performed by StartCronet()

@ -53,7 +53,7 @@ class QuicTest : public CronetTestBase {
// Add URL mapping to test server.
NSString* rules = base::SysUTF8ToNSString(
base::StringPrintf("MAP test.example.com 127.0.0.1:%d,"
"MAP notfound.example.com ~NOTFOUND",
"MAP notfound.example.com ^NOTFOUND",
net::QuicSimpleTestServer::GetPort()));
[Cronet setHostResolverRulesForTesting:rules];

@ -24,7 +24,7 @@ void StartCronet(int port) {
NSString* rules = base::SysUTF8ToNSString(
base::StringPrintf("MAP test.example.com 127.0.0.1:%d,"
"MAP notfound.example.com ~NOTFOUND",
"MAP notfound.example.com ^NOTFOUND",
port));
[Cronet setHostResolverRulesForTesting:rules];
}

@ -58,7 +58,7 @@ Cronet_EnginePtr CreateTestEngine(int quic_server_port) {
// Add Host Resolver Rules.
std::string host_resolver_rules = base::StringPrintf(
"MAP test.example.com 127.0.0.1:%d,"
"MAP notfound.example.com ~NOTFOUND",
"MAP notfound.example.com ^NOTFOUND",
quic_server_port);
Cronet_EngineParams_experimental_options_set(
engine_params,

@ -110,7 +110,7 @@ class BidirectionalStreamTestURLRequestContextGetter
if (!host_resolver())
return;
host_resolver()->SetRulesFromString(
base::StringPrintf("MAP notfound.example.com ~NOTFOUND,"
base::StringPrintf("MAP notfound.example.com ^NOTFOUND,"
"MAP test.example.com 127.0.0.1:%d",
test_server_port_));
}

@ -235,7 +235,7 @@ void WebTestBrowserMainRunner::Initialize() {
command_line.AppendSwitch(switches::kEnablePreciseMemoryInfo);
command_line.AppendSwitchASCII(network::switches::kHostResolverRules,
"MAP nonexistent.*.test ~NOTFOUND,"
"MAP nonexistent.*.test ^NOTFOUND,"
"MAP web-platform.test:443 127.0.0.1:8444,"
"MAP not-web-platform.test:443 127.0.0.1:8444,"
"MAP devtools.test:443 127.0.0.1:8443,"

@ -150,7 +150,7 @@ vpython3 third_party/blink/tools/run_blink_wptserve.py
Then start Content Shell with some additional flags:
```bash
out/Default/content_shell --enable-experimental-web-platform-features --ignore-certificate-errors --host-resolver-rules="MAP nonexistent.*.test ~NOTFOUND, MAP *.test. 127.0.0.1, MAP *.test 127.0.0.1"
out/Default/content_shell --enable-experimental-web-platform-features --ignore-certificate-errors --host-resolver-rules="MAP nonexistent.*.test ^NOTFOUND, MAP *.test. 127.0.0.1, MAP *.test 127.0.0.1"
```
You are also able to debug the inside of Chromium with a debugger for

@ -41,7 +41,7 @@ class NET_EXPORT_PRIVATE HostMappingRules {
// If `url` is rewritten, returns `kRewritten`. If no matching rule is found,
// returns `kNoMatchingRule` and `url` is not modified. If a matching rule is
// found but it results in an invalid URL, e.g. if the rule maps to
// "~NOTFOUND", returns `kInvalidRewrite` and `url` is not modified.
// "^NOTFOUND", returns `kInvalidRewrite` and `url` is not modified.
RewriteResult RewriteUrl(GURL& url) const;
// Adds a rule to this mapper. The format of the rule can be one of:

@ -177,11 +177,11 @@ TEST(HostMappingRulesTest, IgnoresInvalidReplacementUrls) {
EXPECT_EQ(url, GURL("http://initial.test"));
}
// Remapping to "~NOTFOUND" is documented as a special case for
// Remapping to "^NOTFOUND" is documented as a special case for
// MappedHostResolver usage. Ensure that it is handled as invalid as expected.
TEST(HostMappingRulesTest, NotFoundIgnoredAsInvalidUrl) {
HostMappingRules rules;
rules.AddRuleFromString("MAP initial.test ~NOTFOUND");
rules.AddRuleFromString("MAP initial.test ^NOTFOUND");
GURL url("http://initial.test");
EXPECT_EQ(rules.RewriteUrl(url),

@ -43,13 +43,13 @@ MappedHostResolver::CreateRequest(
switch (result) {
case HostMappingRules::RewriteResult::kRewritten:
DCHECK(rewritten_url.is_valid());
DCHECK_NE(rewritten_url.host_piece(), "~NOTFOUND");
DCHECK_NE(rewritten_url.host_piece(), "^NOTFOUND");
return impl_->CreateRequest(url::SchemeHostPort(rewritten_url),
std::move(network_anonymization_key),
std::move(source_net_log),
std::move(optional_parameters));
case HostMappingRules::RewriteResult::kInvalidRewrite:
// Treat any invalid mapping as if it was "~NOTFOUND" (which should itself
// Treat any invalid mapping as if it was "^NOTFOUND" (which should itself
// result in `kInvalidRewrite`).
return CreateFailingRequest(ERR_NAME_NOT_RESOLVED);
case HostMappingRules::RewriteResult::kNoMatchingRule:
@ -68,8 +68,9 @@ MappedHostResolver::CreateRequest(
HostPortPair rewritten = host;
rules_.RewriteHost(&rewritten);
if (rewritten.host() == "~NOTFOUND")
if (rewritten.host() == "^NOTFOUND") {
return CreateFailingRequest(ERR_NAME_NOT_RESOLVED);
}
return impl_->CreateRequest(rewritten, network_anonymization_key,
source_net_log, optional_parameters);

@ -41,7 +41,7 @@ class NET_EXPORT MappedHostResolver : public HostResolver {
// "EXCLUDE" <hostname_pattern>
//
// The <replacement_host> can be either a hostname, or an IP address literal,
// or "~NOTFOUND". If it is "~NOTFOUND" then all matched hostnames will fail
// or "^NOTFOUND". If it is "^NOTFOUND" then all matched hostnames will fail
// to be resolved with ERR_NAME_NOT_RESOLVED.
//
// Returns true if the rule was successfully parsed and added.

@ -349,7 +349,7 @@ TEST(MappedHostResolverTest, MapToError) {
std::make_unique<MappedHostResolver>(std::move(resolver_impl));
// Remap *.google.com to resolving failures.
EXPECT_TRUE(resolver->AddRuleFromString("MAP *.google.com ~NOTFOUND"));
EXPECT_TRUE(resolver->AddRuleFromString("MAP *.google.com ^NOTFOUND"));
// Try resolving www.google.com --> Should give an error.
TestCompletionCallback callback1;
@ -383,7 +383,7 @@ TEST(MappedHostResolverTest, MapHostWithSchemeToError) {
// Create a remapped resolver that uses `resolver_impl`.
auto resolver =
std::make_unique<MappedHostResolver>(std::move(resolver_impl));
ASSERT_TRUE(resolver->AddRuleFromString("MAP host.test ~NOTFOUND"));
ASSERT_TRUE(resolver->AddRuleFromString("MAP host.test ^NOTFOUND"));
std::unique_ptr<HostResolver::ResolveHostRequest> request =
resolver->CreateRequest(

@ -281,7 +281,7 @@ class WPTAdapter:
])
runner_options.binary_args.extend([
'--host-resolver-rules='
'MAP nonexistent.*.test ~NOTFOUND, MAP *.test 127.0.0.1',
'MAP nonexistent.*.test ^NOTFOUND, MAP *.test 127.0.0.1',
*self.port.additional_driver_flags(),
])
# Implicitly pass `--enable-blink-features=MojoJS,MojoJSTest` to Chrome.

@ -32,7 +32,7 @@ If you have an issue with ChromeDriver version mismatch, try one of the followin
Configure host remap rules in the [webview commandline file](https://cs.chromium.org/chromium/src/android_webview/docs/commandline-flags.md?l=57):
```
adb shell "echo '_ --host-resolver-rules=\"MAP nonexistent.*.test ~NOTFOUND, MAP *.test 127.0.0.1\"' > /data/local/tmp/webview-command-line"
adb shell "echo '_ --host-resolver-rules=\"MAP nonexistent.*.test ^NOTFOUND, MAP *.test 127.0.0.1\"' > /data/local/tmp/webview-command-line"
```
Ensure that `adb` can be found on your system's PATH.