OLD | NEW |
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 // Implementation of the ThreatDetails class. | 5 // Implementation of the ThreatDetails class. |
6 | 6 |
7 #include "chrome/browser/safe_browsing/threat_details.h" | 7 #include "components/safe_browsing/browser/threat_details.h" |
8 | 8 |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 #include <stdint.h> | 10 #include <stdint.h> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "chrome/browser/safe_browsing/threat_details_cache.h" | |
17 #include "chrome/browser/safe_browsing/threat_details_history.h" | |
18 #include "components/history/core/browser/history_service.h" | 16 #include "components/history/core/browser/history_service.h" |
19 #include "components/safe_browsing/base_ui_manager.h" | 17 #include "components/safe_browsing/base_ui_manager.h" |
| 18 #include "components/safe_browsing/browser/threat_details_cache.h" |
| 19 #include "components/safe_browsing/browser/threat_details_history.h" |
20 #include "components/safe_browsing/common/safebrowsing_messages.h" | 20 #include "components/safe_browsing/common/safebrowsing_messages.h" |
21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
22 #include "content/public/browser/navigation_controller.h" | 22 #include "content/public/browser/navigation_controller.h" |
23 #include "content/public/browser/navigation_entry.h" | 23 #include "content/public/browser/navigation_entry.h" |
24 #include "content/public/browser/render_frame_host.h" | 24 #include "content/public/browser/render_frame_host.h" |
25 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
26 #include "net/url_request/url_request_context_getter.h" | 26 #include "net/url_request/url_request_context_getter.h" |
27 | 27 |
28 using content::BrowserThread; | 28 using content::BrowserThread; |
29 using content::NavigationEntry; | 29 using content::NavigationEntry; |
(...skipping 15 matching lines...) Expand all Loading... |
45 // A set of HTTPS headers that are allowed to be collected. Contains both | 45 // A set of HTTPS headers that are allowed to be collected. Contains both |
46 // request and response headers. All entries in this list should be lower-case | 46 // request and response headers. All entries in this list should be lower-case |
47 // to support case-insensitive comparison. | 47 // to support case-insensitive comparison. |
48 struct WhitelistedHttpsHeadersTraits | 48 struct WhitelistedHttpsHeadersTraits |
49 : base::internal::DestructorAtExitLazyInstanceTraits<StringSet> { | 49 : base::internal::DestructorAtExitLazyInstanceTraits<StringSet> { |
50 static StringSet* New(void* instance) { | 50 static StringSet* New(void* instance) { |
51 StringSet* headers = | 51 StringSet* headers = |
52 base::internal::DestructorAtExitLazyInstanceTraits<StringSet>::New( | 52 base::internal::DestructorAtExitLazyInstanceTraits<StringSet>::New( |
53 instance); | 53 instance); |
54 headers->insert({"google-creative-id", "google-lineitem-id", "referer", | 54 headers->insert({"google-creative-id", "google-lineitem-id", "referer", |
55 "content-type", "content-length", "date", "server", "cache-control", | 55 "content-type", "content-length", "date", "server", |
56 "pragma", "expires"}); | 56 "cache-control", "pragma", "expires"}); |
57 return headers; | 57 return headers; |
58 } | 58 } |
59 }; | 59 }; |
60 base::LazyInstance<StringSet, WhitelistedHttpsHeadersTraits> | 60 base::LazyInstance<StringSet, WhitelistedHttpsHeadersTraits> |
61 g_https_headers_whitelist = LAZY_INSTANCE_INITIALIZER; | 61 g_https_headers_whitelist = LAZY_INSTANCE_INITIALIZER; |
62 | 62 |
63 // Helper function that converts SBThreatType to | 63 // Helper function that converts SBThreatType to |
64 // ClientSafeBrowsingReportRequest::ReportType. | 64 // ClientSafeBrowsingReportRequest::ReportType. |
65 ClientSafeBrowsingReportRequest::ReportType GetReportTypeFromSBThreatType( | 65 ClientSafeBrowsingReportRequest::ReportType GetReportTypeFromSBThreatType( |
66 SBThreatType threat_type) { | 66 SBThreatType threat_type) { |
(...skipping 17 matching lines...) Expand all Loading... |
84 | 84 |
85 // Clears the specified HTTPS resource of any sensitive data, only retaining | 85 // Clears the specified HTTPS resource of any sensitive data, only retaining |
86 // data that is whitelisted for collection. | 86 // data that is whitelisted for collection. |
87 void ClearHttpsResource(ClientSafeBrowsingReportRequest::Resource* resource) { | 87 void ClearHttpsResource(ClientSafeBrowsingReportRequest::Resource* resource) { |
88 // Make a copy of the original resource to retain all data. | 88 // Make a copy of the original resource to retain all data. |
89 ClientSafeBrowsingReportRequest::Resource orig_resource(*resource); | 89 ClientSafeBrowsingReportRequest::Resource orig_resource(*resource); |
90 | 90 |
91 // Clear the request headers and copy over any whitelisted ones. | 91 // Clear the request headers and copy over any whitelisted ones. |
92 resource->clear_request(); | 92 resource->clear_request(); |
93 for (int i = 0; i < orig_resource.request().headers_size(); ++i) { | 93 for (int i = 0; i < orig_resource.request().headers_size(); ++i) { |
94 ClientSafeBrowsingReportRequest::HTTPHeader* orig_header = orig_resource | 94 ClientSafeBrowsingReportRequest::HTTPHeader* orig_header = |
95 .mutable_request()->mutable_headers(i); | 95 orig_resource.mutable_request()->mutable_headers(i); |
96 if (g_https_headers_whitelist.Get().count( | 96 if (g_https_headers_whitelist.Get().count( |
97 base::ToLowerASCII(orig_header->name())) > 0) { | 97 base::ToLowerASCII(orig_header->name())) > 0) { |
98 resource->mutable_request()->add_headers()->Swap(orig_header); | 98 resource->mutable_request()->add_headers()->Swap(orig_header); |
99 } | 99 } |
100 } | 100 } |
101 // Also copy some other request fields. | 101 // Also copy some other request fields. |
102 resource->mutable_request()->mutable_bodydigest()->swap( | 102 resource->mutable_request()->mutable_bodydigest()->swap( |
103 *orig_resource.mutable_request()->mutable_bodydigest()); | 103 *orig_resource.mutable_request()->mutable_bodydigest()); |
104 resource->mutable_request()->set_bodylength( | 104 resource->mutable_request()->set_bodylength( |
105 orig_resource.request().bodylength()); | 105 orig_resource.request().bodylength()); |
106 | 106 |
107 // ...repeat for response headers. | 107 // ...repeat for response headers. |
108 resource->clear_response(); | 108 resource->clear_response(); |
109 for (int i = 0; i < orig_resource.response().headers_size(); ++i) { | 109 for (int i = 0; i < orig_resource.response().headers_size(); ++i) { |
110 ClientSafeBrowsingReportRequest::HTTPHeader* orig_header = orig_resource | 110 ClientSafeBrowsingReportRequest::HTTPHeader* orig_header = |
111 .mutable_response()->mutable_headers(i); | 111 orig_resource.mutable_response()->mutable_headers(i); |
112 if (g_https_headers_whitelist.Get().count( | 112 if (g_https_headers_whitelist.Get().count( |
113 base::ToLowerASCII(orig_header->name())) > 0) { | 113 base::ToLowerASCII(orig_header->name())) > 0) { |
114 resource->mutable_response()->add_headers()->Swap(orig_header); | 114 resource->mutable_response()->add_headers()->Swap(orig_header); |
115 } | 115 } |
116 } | 116 } |
117 // Also copy some other response fields. | 117 // Also copy some other response fields. |
118 resource->mutable_response()->mutable_bodydigest()->swap( | 118 resource->mutable_response()->mutable_bodydigest()->swap( |
119 *orig_resource.mutable_response()->mutable_bodydigest()); | 119 *orig_resource.mutable_response()->mutable_bodydigest()); |
120 resource->mutable_response()->set_bodylength( | 120 resource->mutable_response()->set_bodylength( |
121 orig_resource.response().bodylength()); | 121 orig_resource.response().bodylength()); |
122 resource->mutable_response()->mutable_remote_ip()->swap( | 122 resource->mutable_response()->mutable_remote_ip()->swap( |
123 *orig_resource.mutable_response()->mutable_remote_ip()); | 123 *orig_resource.mutable_response()->mutable_remote_ip()); |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 // Send the report, using the SafeBrowsingService. | 593 // Send the report, using the SafeBrowsingService. |
594 std::string serialized; | 594 std::string serialized; |
595 if (!report_->SerializeToString(&serialized)) { | 595 if (!report_->SerializeToString(&serialized)) { |
596 DLOG(ERROR) << "Unable to serialize the threat report."; | 596 DLOG(ERROR) << "Unable to serialize the threat report."; |
597 return; | 597 return; |
598 } | 598 } |
599 ui_manager_->SendSerializedThreatDetails(serialized); | 599 ui_manager_->SendSerializedThreatDetails(serialized); |
600 } | 600 } |
601 | 601 |
602 } // namespace safe_browsing | 602 } // namespace safe_browsing |
OLD | NEW |