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

Side by Side Diff: content/browser/loader/resource_dispatcher_host_impl.cc

Issue 277903002: Sanitize referrers for programmatic downloads. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments and remove logs Created 6 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading
6 6
7 #include "content/browser/loader/resource_dispatcher_host_impl.h" 7 #include "content/browser/loader/resource_dispatcher_host_impl.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <set> 10 #include <set>
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 break; 187 break;
188 case blink::WebReferrerPolicyAlways: 188 case blink::WebReferrerPolicyAlways:
189 case blink::WebReferrerPolicyNever: 189 case blink::WebReferrerPolicyNever:
190 case blink::WebReferrerPolicyOrigin: 190 case blink::WebReferrerPolicyOrigin:
191 net_referrer_policy = net::URLRequest::NEVER_CLEAR_REFERRER; 191 net_referrer_policy = net::URLRequest::NEVER_CLEAR_REFERRER;
192 break; 192 break;
193 } 193 }
194 request->set_referrer_policy(net_referrer_policy); 194 request->set_referrer_policy(net_referrer_policy);
195 } 195 }
196 196
197 Referrer SanitizeReferrerForRequest(net::URLRequest* request,
198 const Referrer& referrer) {
davidben 2014/05/09 21:43:35 This would be the third copy of this logic that I
199 Referrer sanitized_referrer;
200 sanitized_referrer.url = referrer.url.GetAsReferrer();
201 sanitized_referrer.policy = referrer.policy;
202 switch (sanitized_referrer.policy) {
203 case blink::WebReferrerPolicyDefault:
204 if (sanitized_referrer.url.SchemeIsSecure() &&
205 !request->url().SchemeIsSecure()) {
206 sanitized_referrer.url = GURL();
207 }
208 break;
209 case blink::WebReferrerPolicyAlways:
210 break;
211 case blink::WebReferrerPolicyNever:
212 sanitized_referrer.url = GURL();
213 break;
214 case blink::WebReferrerPolicyOrigin:
215 sanitized_referrer.url = sanitized_referrer.url.GetOrigin();
216 break;
217 default:
218 NOTREACHED();
219 break;
220 }
221 return sanitized_referrer;
222 }
223
224
197 // Consults the RendererSecurity policy to determine whether the 225 // Consults the RendererSecurity policy to determine whether the
198 // ResourceDispatcherHostImpl should service this request. A request might be 226 // ResourceDispatcherHostImpl should service this request. A request might be
199 // disallowed if the renderer is not authorized to retrieve the request URL or 227 // disallowed if the renderer is not authorized to retrieve the request URL or
200 // if the renderer is attempting to upload an unauthorized file. 228 // if the renderer is attempting to upload an unauthorized file.
201 bool ShouldServiceRequest(int process_type, 229 bool ShouldServiceRequest(int process_type,
202 int child_id, 230 int child_id,
203 const ResourceHostMsg_Request& request_data, 231 const ResourceHostMsg_Request& request_data,
204 fileapi::FileSystemContext* file_system_context) { 232 fileapi::FileSystemContext* file_system_context) {
205 if (process_type == PROCESS_TYPE_PLUGIN) 233 if (process_type == PROCESS_TYPE_PLUGIN)
206 return true; 234 return true;
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN); 514 DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN);
487 515
488 const GURL& url = request->original_url(); 516 const GURL& url = request->original_url();
489 517
490 // http://crbug.com/90971 518 // http://crbug.com/90971
491 char url_buf[128]; 519 char url_buf[128];
492 base::strlcpy(url_buf, url.spec().c_str(), arraysize(url_buf)); 520 base::strlcpy(url_buf, url.spec().c_str(), arraysize(url_buf));
493 base::debug::Alias(url_buf); 521 base::debug::Alias(url_buf);
494 CHECK(ContainsKey(active_resource_contexts_, context)); 522 CHECK(ContainsKey(active_resource_contexts_, context));
495 523
496 SetReferrerForRequest(request.get(), referrer); 524 // Callers which create programmatic downloads do not necessarily sanitize
525 // the referrer, so do it here in a centralized location.
526 Referrer sanitized_referrer = SanitizeReferrerForRequest(request.get(),
527 referrer);
528 SetReferrerForRequest(request.get(), sanitized_referrer);
497 529
498 int extra_load_flags = net::LOAD_IS_DOWNLOAD; 530 int extra_load_flags = net::LOAD_IS_DOWNLOAD;
499 if (prefer_cache) { 531 if (prefer_cache) {
500 // If there is upload data attached, only retrieve from cache because there 532 // If there is upload data attached, only retrieve from cache because there
501 // is no current mechanism to prompt the user for their consent for a 533 // is no current mechanism to prompt the user for their consent for a
502 // re-post. For GETs, try to retrieve data from the cache and skip 534 // re-post. For GETs, try to retrieve data from the cache and skip
503 // validating the entry if present. 535 // validating the entry if present.
504 if (request->get_upload() != NULL) 536 if (request->get_upload() != NULL)
505 extra_load_flags |= net::LOAD_ONLY_FROM_CACHE; 537 extra_load_flags |= net::LOAD_ONLY_FROM_CACHE;
506 else 538 else
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after
1391 return; 1423 return;
1392 } 1424 }
1393 1425
1394 net::CookieStore* cookie_store = 1426 net::CookieStore* cookie_store =
1395 GetContentClient()->browser()->OverrideCookieStoreForRenderProcess( 1427 GetContentClient()->browser()->OverrideCookieStoreForRenderProcess(
1396 child_id); 1428 child_id);
1397 scoped_ptr<net::URLRequest> request( 1429 scoped_ptr<net::URLRequest> request(
1398 request_context->CreateRequest(url, net::DEFAULT_PRIORITY, NULL, 1430 request_context->CreateRequest(url, net::DEFAULT_PRIORITY, NULL,
1399 cookie_store)); 1431 cookie_store));
1400 1432
1401 request->set_method("GET");
1402 SetReferrerForRequest(request.get(), referrer); 1433 SetReferrerForRequest(request.get(), referrer);
1403 1434
1404 // So far, for saving page, we need fetch content from cache, in the 1435 // So far, for saving page, we need fetch content from cache, in the
1405 // future, maybe we can use a configuration to configure this behavior. 1436 // future, maybe we can use a configuration to configure this behavior.
1406 request->SetLoadFlags(net::LOAD_PREFERRING_CACHE); 1437 request->SetLoadFlags(net::LOAD_PREFERRING_CACHE);
1407 1438
1408 // No need to get offline load flags for save files, but make sure 1439 // No need to get offline load flags for save files, but make sure
1409 // we have an OfflinePolicy to receive request completions. 1440 // we have an OfflinePolicy to receive request completions.
1410 GlobalRoutingID id(child_id, route_id); 1441 GlobalRoutingID id(child_id, route_id);
1411 if (!offline_policy_map_[id]) 1442 if (!offline_policy_map_[id])
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
2034 if ((load_flags & net::LOAD_REPORT_RAW_HEADERS) 2065 if ((load_flags & net::LOAD_REPORT_RAW_HEADERS)
2035 && !policy->CanReadRawCookies(child_id)) { 2066 && !policy->CanReadRawCookies(child_id)) {
2036 VLOG(1) << "Denied unauthorized request for raw headers"; 2067 VLOG(1) << "Denied unauthorized request for raw headers";
2037 load_flags &= ~net::LOAD_REPORT_RAW_HEADERS; 2068 load_flags &= ~net::LOAD_REPORT_RAW_HEADERS;
2038 } 2069 }
2039 2070
2040 return load_flags; 2071 return load_flags;
2041 } 2072 }
2042 2073
2043 } // namespace content 2074 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698