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

Side by Side Diff: net/dns/host_resolver_impl.cc

Issue 1035803003: Fail DNS resolution if the result contains 127.0.53.53. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/dns/host_resolver_impl.h" 5 #include "net/dns/host_resolver_impl.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <Winsock2.h> 8 #include <Winsock2.h>
9 #elif defined(OS_POSIX) 9 #elif defined(OS_POSIX)
10 #include <netdb.h> 10 #include <netdb.h>
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 } 137 }
138 138
139 enum DnsResolveStatus { 139 enum DnsResolveStatus {
140 RESOLVE_STATUS_DNS_SUCCESS = 0, 140 RESOLVE_STATUS_DNS_SUCCESS = 0,
141 RESOLVE_STATUS_PROC_SUCCESS, 141 RESOLVE_STATUS_PROC_SUCCESS,
142 RESOLVE_STATUS_FAIL, 142 RESOLVE_STATUS_FAIL,
143 RESOLVE_STATUS_SUSPECT_NETBIOS, 143 RESOLVE_STATUS_SUSPECT_NETBIOS,
144 RESOLVE_STATUS_MAX 144 RESOLVE_STATUS_MAX
145 }; 145 };
146 146
147 // ICANN uses this localhost address to indicate a name collision.
148 //
149 // The policy in Chromium is to fail host resolving if it resolves to
150 // this special address.
151 //
152 // Not however that IP literals are exempt from this policy, so it is still
153 // possible to navigate to http://127.0.53.53/ directly.
154 //
155 // For more details: https://www.icann.org/news/announcement-2-2014-08-01-en
156 const unsigned char kIcanNameCollisionIp[] = {127, 0, 53, 53};
157
147 void UmaAsyncDnsResolveStatus(DnsResolveStatus result) { 158 void UmaAsyncDnsResolveStatus(DnsResolveStatus result) {
148 UMA_HISTOGRAM_ENUMERATION("AsyncDNS.ResolveStatus", 159 UMA_HISTOGRAM_ENUMERATION("AsyncDNS.ResolveStatus",
149 result, 160 result,
150 RESOLVE_STATUS_MAX); 161 RESOLVE_STATUS_MAX);
151 } 162 }
152 163
153 bool ResemblesNetBIOSName(const std::string& hostname) { 164 bool ResemblesNetBIOSName(const std::string& hostname) {
154 return (hostname.size() < 16) && (hostname.find('.') == std::string::npos); 165 return (hostname.size() < 16) && (hostname.find('.') == std::string::npos);
155 } 166 }
156 167
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 const uint32 attempt_number) { 667 const uint32 attempt_number) {
657 AddressList results; 668 AddressList results;
658 int os_error = 0; 669 int os_error = 0;
659 // Running on the worker thread 670 // Running on the worker thread
660 int error = params_.resolver_proc->Resolve(key_.hostname, 671 int error = params_.resolver_proc->Resolve(key_.hostname,
661 key_.address_family, 672 key_.address_family,
662 key_.host_resolver_flags, 673 key_.host_resolver_flags,
663 &results, 674 &results,
664 &os_error); 675 &os_error);
665 676
677 // Fail the resolution if the result contains 127.0.53.53. See the comment
678 // block of kIcanNameCollisionIp for details on why.
679 for (const auto& it : results) {
680 const IPAddressNumber& cur = it.address();
681 if (cur.size() == arraysize(kIcanNameCollisionIp) &&
682 0 == memcmp(&cur.front(), kIcanNameCollisionIp, cur.size())) {
683 error = ERR_ICANN_NAME_COLLISION;
684 break;
685 }
686 }
687
666 origin_loop_->PostTask( 688 origin_loop_->PostTask(
667 FROM_HERE, 689 FROM_HERE,
668 base::Bind(&ProcTask::OnLookupComplete, this, results, start_time, 690 base::Bind(&ProcTask::OnLookupComplete, this, results, start_time,
669 attempt_number, error, os_error)); 691 attempt_number, error, os_error));
670 } 692 }
671 693
672 // Makes next attempt if DoLookup() has not finished (runs on origin thread). 694 // Makes next attempt if DoLookup() has not finished (runs on origin thread).
673 void RetryIfNotComplete() { 695 void RetryIfNotComplete() {
674 DCHECK(origin_loop_->BelongsToCurrentThread()); 696 DCHECK(origin_loop_->BelongsToCurrentThread());
675 697
(...skipping 21 matching lines...) Expand all
697 UMA_HISTOGRAM_BOOLEAN("DNS.EmptyAddressListAndNoError", empty_list_on_ok); 719 UMA_HISTOGRAM_BOOLEAN("DNS.EmptyAddressListAndNoError", empty_list_on_ok);
698 if (empty_list_on_ok) 720 if (empty_list_on_ok)
699 error = ERR_NAME_NOT_RESOLVED; 721 error = ERR_NAME_NOT_RESOLVED;
700 722
701 bool was_retry_attempt = attempt_number > 1; 723 bool was_retry_attempt = attempt_number > 1;
702 724
703 // Ideally the following code would be part of host_resolver_proc.cc, 725 // Ideally the following code would be part of host_resolver_proc.cc,
704 // however it isn't safe to call NetworkChangeNotifier from worker threads. 726 // however it isn't safe to call NetworkChangeNotifier from worker threads.
705 // So we do it here on the IO thread instead. 727 // So we do it here on the IO thread instead.
706 if (error != OK && NetworkChangeNotifier::IsOffline()) 728 if (error != OK && NetworkChangeNotifier::IsOffline())
707 error = ERR_INTERNET_DISCONNECTED; 729 error = ERR_INTERNET_DISCONNECTED;
Ryan Sleevi 2015/03/26 00:32:29 Well this is weird -_- Swallows error codes.
708 730
709 // If this is the first attempt that is finishing later, then record data 731 // If this is the first attempt that is finishing later, then record data
710 // for the first attempt. Won't contaminate with retry attempt's data. 732 // for the first attempt. Won't contaminate with retry attempt's data.
711 if (!was_retry_attempt) 733 if (!was_retry_attempt)
712 RecordPerformanceHistograms(start_time, error, os_error); 734 RecordPerformanceHistograms(start_time, error, os_error);
713 735
714 RecordAttemptHistograms(start_time, attempt_number, error, os_error); 736 RecordAttemptHistograms(start_time, attempt_number, error, os_error);
715 737
716 if (was_canceled()) 738 if (was_canceled())
717 return; 739 return;
(...skipping 1645 matching lines...) Expand 10 before | Expand all | Expand 10 after
2363 dns_client_->SetConfig(dns_config); 2385 dns_client_->SetConfig(dns_config);
2364 num_dns_failures_ = 0; 2386 num_dns_failures_ = 0;
2365 if (dns_client_->GetConfig()) 2387 if (dns_client_->GetConfig())
2366 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); 2388 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true);
2367 } 2389 }
2368 2390
2369 AbortDnsTasks(); 2391 AbortDnsTasks();
2370 } 2392 }
2371 2393
2372 } // namespace net 2394 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698