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

Side by Side Diff: chrome/browser/safe_browsing/malware_details.cc

Issue 923263002: Report HTTPS links in MalwareDetails (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Lint nits Created 5 years, 10 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 // Implementation of the MalwareDetails class. 5 // Implementation of the MalwareDetails class.
6 6
7 #include "chrome/browser/safe_browsing/malware_details.h" 7 #include "chrome/browser/safe_browsing/malware_details.h"
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 bool MalwareDetails::OnMessageReceived(const IPC::Message& message) { 89 bool MalwareDetails::OnMessageReceived(const IPC::Message& message) {
90 bool handled = true; 90 bool handled = true;
91 IPC_BEGIN_MESSAGE_MAP(MalwareDetails, message) 91 IPC_BEGIN_MESSAGE_MAP(MalwareDetails, message)
92 IPC_MESSAGE_HANDLER(SafeBrowsingHostMsg_MalwareDOMDetails, 92 IPC_MESSAGE_HANDLER(SafeBrowsingHostMsg_MalwareDOMDetails,
93 OnReceivedMalwareDOMDetails) 93 OnReceivedMalwareDOMDetails)
94 IPC_MESSAGE_UNHANDLED(handled = false) 94 IPC_MESSAGE_UNHANDLED(handled = false)
95 IPC_END_MESSAGE_MAP() 95 IPC_END_MESSAGE_MAP()
96 return handled; 96 return handled;
97 } 97 }
98 98
99 bool MalwareDetails::IsPublicUrl(const GURL& url) const { 99 bool MalwareDetails::IsReportableUrl(const GURL& url) const {
100 return url.SchemeIs("http"); // TODO(panayiotis): also skip internal urls. 100 // TODO(panayiotis): also skip internal urls.
101 return url.SchemeIs("http") || url.SchemeIs("https");
101 } 102 }
102 103
103 // Looks for a Resource for the given url in resources_. If found, it 104 // Looks for a Resource for the given url in resources_. If found, it
104 // updates |resource|. Otherwise, it creates a new message, adds it to 105 // updates |resource|. Otherwise, it creates a new message, adds it to
105 // resources_ and updates |resource| to point to it. 106 // resources_ and updates |resource| to point to it.
107 //
106 ClientMalwareReportRequest::Resource* MalwareDetails::FindOrCreateResource( 108 ClientMalwareReportRequest::Resource* MalwareDetails::FindOrCreateResource(
107 const GURL& url) { 109 const GURL& url) {
108 safe_browsing::ResourceMap::iterator it = resources_.find(url.spec()); 110 safe_browsing::ResourceMap::iterator it = resources_.find(url.spec());
109 if (it != resources_.end()) 111 if (it != resources_.end())
110 return it->second.get(); 112 return it->second.get();
111 113
112 // Create the resource for |url|. 114 // Create the resource for |url|.
113 int id = resources_.size(); 115 int id = resources_.size();
114 linked_ptr<ClientMalwareReportRequest::Resource> new_resource( 116 linked_ptr<ClientMalwareReportRequest::Resource> new_resource(
115 new ClientMalwareReportRequest::Resource()); 117 new ClientMalwareReportRequest::Resource());
116 new_resource->set_url(url.spec()); 118 new_resource->set_url(url.spec());
117 new_resource->set_id(id); 119 new_resource->set_id(id);
118 resources_[url.spec()] = new_resource; 120 resources_[url.spec()] = new_resource;
119 return new_resource.get(); 121 return new_resource.get();
120 } 122 }
121 123
122 void MalwareDetails::AddUrl(const GURL& url, 124 void MalwareDetails::AddUrl(const GURL& url,
123 const GURL& parent, 125 const GURL& parent,
124 const std::string& tagname, 126 const std::string& tagname,
125 const std::vector<GURL>* children) { 127 const std::vector<GURL>* children) {
126 if (!url.is_valid() || !IsPublicUrl(url)) 128 if (!url.is_valid() || !IsReportableUrl(url))
127 return; 129 return;
128 130
129 // Find (or create) the resource for the url. 131 // Find (or create) the resource for the url.
130 ClientMalwareReportRequest::Resource* url_resource = 132 ClientMalwareReportRequest::Resource* url_resource =
131 FindOrCreateResource(url); 133 FindOrCreateResource(url);
132 if (!tagname.empty()) 134 if (!tagname.empty())
133 url_resource->set_tag_name(tagname); 135 url_resource->set_tag_name(tagname);
134 if (!parent.is_empty() && IsPublicUrl(parent)) { 136 if (!parent.is_empty() && IsReportableUrl(parent)) {
135 // Add the resource for the parent. 137 // Add the resource for the parent.
136 ClientMalwareReportRequest::Resource* parent_resource = 138 ClientMalwareReportRequest::Resource* parent_resource =
137 FindOrCreateResource(parent); 139 FindOrCreateResource(parent);
138 // Update the parent-child relation 140 // Update the parent-child relation
139 url_resource->set_parent_id(parent_resource->id()); 141 url_resource->set_parent_id(parent_resource->id());
140 } 142 }
141 if (children) { 143 if (children) {
142 for (std::vector<GURL>::const_iterator it = children->begin(); 144 for (std::vector<GURL>::const_iterator it = children->begin();
143 it != children->end(); ++it) { 145 it != children->end(); ++it) {
144 ClientMalwareReportRequest::Resource* child_resource = 146 ClientMalwareReportRequest::Resource* child_resource =
145 FindOrCreateResource(*it); 147 FindOrCreateResource(*it);
146 url_resource->add_child_ids(child_resource->id()); 148 url_resource->add_child_ids(child_resource->id());
147 } 149 }
148 } 150 }
149 } 151 }
150 152
151 void MalwareDetails::StartCollection() { 153 void MalwareDetails::StartCollection() {
152 DVLOG(1) << "Starting to compute malware details."; 154 DVLOG(1) << "Starting to compute malware details.";
153 report_.reset(new ClientMalwareReportRequest()); 155 report_.reset(new ClientMalwareReportRequest());
154 156
155 if (IsPublicUrl(resource_.url)) 157 if (IsReportableUrl(resource_.url))
156 report_->set_malware_url(resource_.url.spec()); 158 report_->set_malware_url(resource_.url.spec());
157 159
158 GURL page_url = web_contents()->GetURL(); 160 GURL page_url = web_contents()->GetURL();
159 if (IsPublicUrl(page_url)) 161 if (IsReportableUrl(page_url))
160 report_->set_page_url(page_url.spec()); 162 report_->set_page_url(page_url.spec());
161 163
162 GURL referrer_url; 164 GURL referrer_url;
163 NavigationEntry* nav_entry = web_contents()->GetController().GetActiveEntry(); 165 NavigationEntry* nav_entry = web_contents()->GetController().GetActiveEntry();
164 if (nav_entry) { 166 if (nav_entry) {
165 referrer_url = nav_entry->GetReferrer().url; 167 referrer_url = nav_entry->GetReferrer().url;
166 if (IsPublicUrl(referrer_url)) { 168 if (IsReportableUrl(referrer_url)) {
167 report_->set_referrer_url(referrer_url.spec()); 169 report_->set_referrer_url(referrer_url.spec());
168 } 170 }
169 } 171 }
170 172
171 // Add the nodes, starting from the page url. 173 // Add the nodes, starting from the page url.
172 AddUrl(page_url, GURL(), std::string(), NULL); 174 AddUrl(page_url, GURL(), std::string(), NULL);
173 175
174 // Add the resource_url and its original url, if non-empty and different. 176 // Add the resource_url and its original url, if non-empty and different.
175 if (!resource_.original_url.is_empty() && 177 if (!resource_.original_url.is_empty() &&
176 resource_.url != resource_.original_url) { 178 resource_.url != resource_.original_url) {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 } 284 }
283 285
284 void MalwareDetails::OnCacheCollectionReady() { 286 void MalwareDetails::OnCacheCollectionReady() {
285 DVLOG(1) << "OnCacheCollectionReady."; 287 DVLOG(1) << "OnCacheCollectionReady.";
286 // Add all the urls in our |resources_| maps to the |report_| protocol buffer. 288 // Add all the urls in our |resources_| maps to the |report_| protocol buffer.
287 for (safe_browsing::ResourceMap::const_iterator it = resources_.begin(); 289 for (safe_browsing::ResourceMap::const_iterator it = resources_.begin();
288 it != resources_.end(); ++it) { 290 it != resources_.end(); ++it) {
289 ClientMalwareReportRequest::Resource* pb_resource = 291 ClientMalwareReportRequest::Resource* pb_resource =
290 report_->add_resources(); 292 report_->add_resources();
291 pb_resource->CopyFrom(*(it->second)); 293 pb_resource->CopyFrom(*(it->second));
294 const GURL url(pb_resource->url());
295 if (url.SchemeIs("https")) {
296 // Don't report headers of HTTPS requests since they may contain private
297 // cookies. We still retain the full URL.
298 DVLOG(1) << "Clearing out HTTPS resource: " << pb_resource->url();
299 pb_resource->clear_request();
300 pb_resource->clear_response();
301 // Keep id, parent_id, child_ids, and tag_name.
302 }
292 } 303 }
293
294 report_->set_complete(cache_result_); 304 report_->set_complete(cache_result_);
295 305
296 // Send the report, using the SafeBrowsingService. 306 // Send the report, using the SafeBrowsingService.
297 std::string serialized; 307 std::string serialized;
298 if (!report_->SerializeToString(&serialized)) { 308 if (!report_->SerializeToString(&serialized)) {
299 DLOG(ERROR) << "Unable to serialize the malware report."; 309 DLOG(ERROR) << "Unable to serialize the malware report.";
300 return; 310 return;
301 } 311 }
302 312
303 ui_manager_->SendSerializedMalwareDetails(serialized); 313 ui_manager_->SendSerializedMalwareDetails(serialized);
304 } 314 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/malware_details.h ('k') | chrome/browser/safe_browsing/malware_details_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698