OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/safe_browsing/client_side_detection_service.h" | 5 #include "chrome/browser/safe_browsing/client_side_detection_service.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 const net::ResponseCookies& cookies, | 406 const net::ResponseCookies& cookies, |
407 const std::string& data) { | 407 const std::string& data) { |
408 ClientPhishingResponse response; | 408 ClientPhishingResponse response; |
409 scoped_ptr<ClientReportInfo> info(client_phishing_reports_[source]); | 409 scoped_ptr<ClientReportInfo> info(client_phishing_reports_[source]); |
410 bool is_phishing = false; | 410 bool is_phishing = false; |
411 if (status.is_success() && RC_REQUEST_OK == response_code && | 411 if (status.is_success() && RC_REQUEST_OK == response_code && |
412 response.ParseFromString(data)) { | 412 response.ParseFromString(data)) { |
413 // Cache response, possibly flushing an old one. | 413 // Cache response, possibly flushing an old one. |
414 cache_[info->phishing_url] = | 414 cache_[info->phishing_url] = |
415 make_linked_ptr(new CacheState(response.phishy(), base::Time::Now())); | 415 make_linked_ptr(new CacheState(response.phishy(), base::Time::Now())); |
416 is_phishing = response.phishy(); | 416 is_phishing = (response.phishy() && |
| 417 !IsFalsePositiveResponse(info->phishing_url, response)); |
417 } else { | 418 } else { |
418 DLOG(ERROR) << "Unable to get the server verdict for URL: " | 419 DLOG(ERROR) << "Unable to get the server verdict for URL: " |
419 << info->phishing_url << " status: " << status.status() << " " | 420 << info->phishing_url << " status: " << status.status() << " " |
420 << "response_code:" << response_code; | 421 << "response_code:" << response_code; |
421 } | 422 } |
422 if (info->callback.get()) { | 423 if (info->callback.get()) { |
423 info->callback->Run(info->phishing_url, is_phishing); | 424 info->callback->Run(info->phishing_url, is_phishing); |
424 } | 425 } |
425 client_phishing_reports_.erase(source); | 426 client_phishing_reports_.erase(source); |
426 delete source; | 427 delete source; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 return false; | 601 return false; |
601 } | 602 } |
602 } | 603 } |
603 for (int i = 0; i < model.page_word_size(); ++i) { | 604 for (int i = 0; i < model.page_word_size(); ++i) { |
604 if (model.page_word(i) < 0 || model.page_word(i) > max_index) { | 605 if (model.page_word(i) < 0 || model.page_word(i) > max_index) { |
605 return false; | 606 return false; |
606 } | 607 } |
607 } | 608 } |
608 return true; | 609 return true; |
609 } | 610 } |
| 611 |
| 612 // static |
| 613 bool ClientSideDetectionService::IsFalsePositiveResponse( |
| 614 const GURL& url, |
| 615 const ClientPhishingResponse& response) { |
| 616 if (!response.phishy() || response.whitelist_expression_size() == 0) { |
| 617 return false; |
| 618 } |
| 619 // This whitelist is special. A particular URL gets whitelisted if it |
| 620 // matches any of the expressions on the whitelist or if any of the whitelist |
| 621 // entries matches the URL. |
| 622 |
| 623 std::string host, path, query; |
| 624 safe_browsing_util::CanonicalizeUrl(url, &host, &path, &query); |
| 625 std::string canonical_url_as_pattern = host + path + query; |
| 626 |
| 627 std::vector<std::string> url_patterns; |
| 628 safe_browsing_util::GeneratePatternsToCheck(url, &url_patterns); |
| 629 |
| 630 for (int i = 0; i < response.whitelist_expression_size(); ++i) { |
| 631 GURL whitelisted_url(std::string("http://") + |
| 632 response.whitelist_expression(i)); |
| 633 if (!whitelisted_url.is_valid()) { |
| 634 UMA_HISTOGRAM_COUNTS("SBClientPhishing.InvalidWhitelistExpression", 1); |
| 635 continue; // Skip invalid whitelist expressions. |
| 636 } |
| 637 // First, we check whether the canonical URL matches any of the whitelisted |
| 638 // expressions. |
| 639 for (size_t j = 0; j < url_patterns.size(); ++j) { |
| 640 if (url_patterns[j] == response.whitelist_expression(i)) { |
| 641 return true; |
| 642 } |
| 643 } |
| 644 // Second, we consider the canonical URL as an expression and we check |
| 645 // whether any of the whitelist entries matches that expression. |
| 646 std::vector<std::string> whitelist_patterns; |
| 647 safe_browsing_util::GeneratePatternsToCheck(whitelisted_url, |
| 648 &whitelist_patterns); |
| 649 for (size_t j = 0; j < whitelist_patterns.size(); ++j) { |
| 650 if (whitelist_patterns[j] == canonical_url_as_pattern) { |
| 651 return true; |
| 652 } |
| 653 } |
| 654 } |
| 655 return false; |
| 656 } |
610 } // namespace safe_browsing | 657 } // namespace safe_browsing |
OLD | NEW |