Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(291)

Unified Diff: net/dns/host_resolver_impl.cc

Issue 938093003: Always treat .localhost as loopback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move constants, add a test case, style fix Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/dns/host_resolver_impl.cc
diff --git a/net/dns/host_resolver_impl.cc b/net/dns/host_resolver_impl.cc
index 6c0a154971a4fe2a4386051bef361ac7188046fc..07733f4cfe908b7c69a32c1a677a98bfdf100c49 100644
--- a/net/dns/host_resolver_impl.cc
+++ b/net/dns/host_resolver_impl.cc
@@ -72,6 +72,8 @@ const unsigned kNegativeCacheEntryTTLSeconds = 0;
// Minimum TTL for successful resolutions with DnsTask.
const unsigned kMinimumTTLSeconds = kCacheEntryTTLSeconds;
+const char kLocalhost[] = "localhost.";
+
// We use a separate histogram name for each platform to facilitate the
// display of error codes by their symbolic name (since each platform has
// different mappings).
@@ -1269,7 +1271,13 @@ class HostResolverImpl::Job : public PrioritizedDispatcher::Job,
}
void AddRequest(scoped_ptr<Request> req) {
- DCHECK_EQ(key_.hostname, req->info().hostname());
+ // .localhost queries are redirected to "localhost." to make sure
+ // that they are never sent out on the network, per RFC 6761.
+ if (IsLocalhostTLD(req->info().hostname())) {
+ DCHECK_EQ(key_.hostname, kLocalhost);
+ } else {
+ DCHECK_EQ(key_.hostname, req->info().hostname());
+ }
req->set_job(this);
priority_tracker_.Add(req->priority());
@@ -2192,7 +2200,13 @@ HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest(
}
}
- return Key(info.hostname(), effective_address_family, effective_flags);
+ std::string hostname = info.hostname();
+ // Redirect .localhost queries to "localhost." to make sure that they
+ // are never sent out on the network, per RFC 6761.
+ if (IsLocalhostTLD(info.hostname()))
+ hostname = kLocalhost;
+
+ return Key(hostname, effective_address_family, effective_flags);
}
void HostResolverImpl::AbortAllInProgressJobs() {

Powered by Google App Engine
This is Rietveld 408576698