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

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

Issue 786423002: Get rid of net::DO_NOT_PROMPT_FOR_LOGIN (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: delete flag from iOS code Created 5 years, 11 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 // 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 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 } 588 }
589 589
590 DownloadInterruptReason ResourceDispatcherHostImpl::BeginDownload( 590 DownloadInterruptReason ResourceDispatcherHostImpl::BeginDownload(
591 scoped_ptr<net::URLRequest> request, 591 scoped_ptr<net::URLRequest> request,
592 const Referrer& referrer, 592 const Referrer& referrer,
593 bool is_content_initiated, 593 bool is_content_initiated,
594 ResourceContext* context, 594 ResourceContext* context,
595 int child_id, 595 int child_id,
596 int route_id, 596 int route_id,
597 bool prefer_cache, 597 bool prefer_cache,
598 bool do_not_prompt_for_login,
598 scoped_ptr<DownloadSaveInfo> save_info, 599 scoped_ptr<DownloadSaveInfo> save_info,
599 uint32 download_id, 600 uint32 download_id,
600 const DownloadStartedCallback& started_callback) { 601 const DownloadStartedCallback& started_callback) {
601 if (is_shutdown_) 602 if (is_shutdown_)
602 return CallbackAndReturn(started_callback, 603 return CallbackAndReturn(started_callback,
603 DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN); 604 DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN);
604 605
605 const GURL& url = request->original_url(); 606 const GURL& url = request->original_url();
606 607
607 // http://crbug.com/90971 608 // http://crbug.com/90971
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 const net::URLRequestContext* request_context = context->GetRequestContext(); 651 const net::URLRequestContext* request_context = context->GetRequestContext();
651 if (!request_context->job_factory()->IsHandledURL(url)) { 652 if (!request_context->job_factory()->IsHandledURL(url)) {
652 VLOG(1) << "Download request for unsupported protocol: " 653 VLOG(1) << "Download request for unsupported protocol: "
653 << url.possibly_invalid_spec(); 654 << url.possibly_invalid_spec();
654 return CallbackAndReturn(started_callback, 655 return CallbackAndReturn(started_callback,
655 DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST); 656 DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST);
656 } 657 }
657 658
658 ResourceRequestInfoImpl* extra_info = 659 ResourceRequestInfoImpl* extra_info =
659 CreateRequestInfo(child_id, route_id, true, context); 660 CreateRequestInfo(child_id, route_id, true, context);
661 extra_info->set_do_not_prompt_for_login(do_not_prompt_for_login);
660 extra_info->AssociateWithRequest(request.get()); // Request takes ownership. 662 extra_info->AssociateWithRequest(request.get()); // Request takes ownership.
661 663
662 if (request->url().SchemeIs(url::kBlobScheme)) { 664 if (request->url().SchemeIs(url::kBlobScheme)) {
663 ChromeBlobStorageContext* blob_context = 665 ChromeBlobStorageContext* blob_context =
664 GetChromeBlobStorageContextForResourceContext(context); 666 GetChromeBlobStorageContextForResourceContext(context);
665 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( 667 storage::BlobProtocolHandler::SetRequestedBlobDataHandle(
666 request.get(), 668 request.get(),
667 blob_context->context()->GetBlobDataFromPublicURL(request->url())); 669 blob_context->context()->GetBlobDataFromPublicURL(request->url()));
668 } 670 }
669 671
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 1145
1144 // Allow the observer to block/handle the request. 1146 // Allow the observer to block/handle the request.
1145 if (delegate_ && !delegate_->ShouldBeginRequest(request_data.method, 1147 if (delegate_ && !delegate_->ShouldBeginRequest(request_data.method,
1146 request_data.url, 1148 request_data.url,
1147 request_data.resource_type, 1149 request_data.resource_type,
1148 resource_context)) { 1150 resource_context)) {
1149 AbortRequestBeforeItStarts(filter_, sync_result, request_id); 1151 AbortRequestBeforeItStarts(filter_, sync_result, request_id);
1150 return; 1152 return;
1151 } 1153 }
1152 1154
1153 bool is_sync_load = sync_result != NULL;
1154 int load_flags =
1155 BuildLoadFlagsForRequest(request_data, child_id, is_sync_load);
1156
1157 // Sync loads should have maximum priority and should be the only
1158 // requets that have the ignore limits flag set.
1159 if (is_sync_load) {
1160 DCHECK_EQ(request_data.priority, net::MAXIMUM_PRIORITY);
1161 DCHECK_NE(load_flags & net::LOAD_IGNORE_LIMITS, 0);
1162 } else {
1163 DCHECK_EQ(load_flags & net::LOAD_IGNORE_LIMITS, 0);
1164 }
1165
1166 // Construct the request. 1155 // Construct the request.
1167 net::CookieStore* cookie_store = 1156 net::CookieStore* cookie_store =
1168 GetContentClient()->browser()->OverrideCookieStoreForRenderProcess( 1157 GetContentClient()->browser()->OverrideCookieStoreForRenderProcess(
1169 child_id); 1158 child_id);
1170 scoped_ptr<net::URLRequest> new_request; 1159 scoped_ptr<net::URLRequest> new_request;
1171 new_request = request_context->CreateRequest( 1160 new_request = request_context->CreateRequest(
1172 request_data.url, request_data.priority, NULL, cookie_store); 1161 request_data.url, request_data.priority, NULL, cookie_store);
1173 1162
1174 new_request->set_method(request_data.method); 1163 new_request->set_method(request_data.method);
1175 new_request->set_first_party_for_cookies( 1164 new_request->set_first_party_for_cookies(
1176 request_data.first_party_for_cookies); 1165 request_data.first_party_for_cookies);
1177 1166
1178 // If the request is a MAIN_FRAME request, the first-party URL gets updated on 1167 // If the request is a MAIN_FRAME request, the first-party URL gets updated on
1179 // redirects. 1168 // redirects.
1180 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME) { 1169 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME) {
1181 new_request->set_first_party_url_policy( 1170 new_request->set_first_party_url_policy(
1182 net::URLRequest::UPDATE_FIRST_PARTY_URL_ON_REDIRECT); 1171 net::URLRequest::UPDATE_FIRST_PARTY_URL_ON_REDIRECT);
1183 } 1172 }
1184 1173
1185 const Referrer referrer(request_data.referrer, request_data.referrer_policy); 1174 const Referrer referrer(request_data.referrer, request_data.referrer_policy);
1186 SetReferrerForRequest(new_request.get(), referrer); 1175 SetReferrerForRequest(new_request.get(), referrer);
1187 1176
1188 net::HttpRequestHeaders headers; 1177 net::HttpRequestHeaders headers;
1189 headers.AddHeadersFromString(request_data.headers); 1178 headers.AddHeadersFromString(request_data.headers);
1190 new_request->SetExtraRequestHeaders(headers); 1179 new_request->SetExtraRequestHeaders(headers);
1191 1180
1192 new_request->SetLoadFlags(load_flags);
1193
1194 storage::BlobStorageContext* blob_context = 1181 storage::BlobStorageContext* blob_context =
1195 GetBlobStorageContext(filter_->blob_storage_context()); 1182 GetBlobStorageContext(filter_->blob_storage_context());
1196 // Resolve elements from request_body and prepare upload data. 1183 // Resolve elements from request_body and prepare upload data.
1197 if (request_data.request_body.get()) { 1184 if (request_data.request_body.get()) {
1198 // |blob_context| could be null when the request is from the plugins because 1185 // |blob_context| could be null when the request is from the plugins because
1199 // ResourceMessageFilters created in PluginProcessHost don't have the blob 1186 // ResourceMessageFilters created in PluginProcessHost don't have the blob
1200 // context. 1187 // context.
1201 if (blob_context) { 1188 if (blob_context) {
1202 // Attaches the BlobDataHandles to request_body not to free the blobs and 1189 // Attaches the BlobDataHandles to request_body not to free the blobs and
1203 // any attached shareable files until upload completion. These data will 1190 // any attached shareable files until upload completion. These data will
1204 // be used in UploadDataStream and ServiceWorkerURLRequestJob. 1191 // be used in UploadDataStream and ServiceWorkerURLRequestJob.
1205 AttachRequestBodyBlobDataHandles( 1192 AttachRequestBodyBlobDataHandles(
1206 request_data.request_body.get(), 1193 request_data.request_body.get(),
1207 blob_context); 1194 blob_context);
1208 } 1195 }
1209 new_request->set_upload(UploadDataStreamBuilder::Build( 1196 new_request->set_upload(UploadDataStreamBuilder::Build(
1210 request_data.request_body.get(), 1197 request_data.request_body.get(),
1211 blob_context, 1198 blob_context,
1212 filter_->file_system_context(), 1199 filter_->file_system_context(),
1213 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE) 1200 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)
1214 .get())); 1201 .get()));
1215 } 1202 }
1216 1203
1217 bool allow_download = request_data.allow_download && 1204 bool allow_download = request_data.allow_download &&
1218 IsResourceTypeFrame(request_data.resource_type); 1205 IsResourceTypeFrame(request_data.resource_type);
1206 bool do_not_prompt_for_login = request_data.do_not_prompt_for_login;
1207 bool is_sync_load = sync_result != NULL;
1208 int load_flags =
1209 BuildLoadFlagsForRequest(request_data, child_id, is_sync_load);
1210 if (request_data.resource_type == RESOURCE_TYPE_PREFETCH ||
1211 request_data.resource_type == RESOURCE_TYPE_FAVICON) {
1212 do_not_prompt_for_login = true;
1213 }
1214 if (request_data.resource_type == RESOURCE_TYPE_IMAGE &&
1215 HTTP_AUTH_RELATION_BLOCKED_CROSS ==
1216 HttpAuthRelationTypeOf(request_data.url,
1217 request_data.first_party_for_cookies)) {
1218 // Prevent third-party image content from prompting for login, as this
1219 // is often a scam to extract credentials for another domain from the user.
1220 // Only block image loads, as the attack applies largely to the "src"
1221 // property of the <img> tag. It is common for web properties to allow
1222 // untrusted values for <img src>; this is considered a fair thing for an
1223 // HTML sanitizer to do. Conversely, any HTML sanitizer that didn't
1224 // filter sources for <script>, <link>, <embed>, <object>, <iframe> tags
1225 // would be considered vulnerable in and of itself.
1226 do_not_prompt_for_login = true;
1227 load_flags |= net::LOAD_DO_NOT_USE_EMBEDDED_IDENTITY;
1228 }
1229
1230 // Sync loads should have maximum priority and should be the only
1231 // requets that have the ignore limits flag set.
1232 if (is_sync_load) {
1233 DCHECK_EQ(request_data.priority, net::MAXIMUM_PRIORITY);
1234 DCHECK_NE(load_flags & net::LOAD_IGNORE_LIMITS, 0);
1235 } else {
1236 DCHECK_EQ(load_flags & net::LOAD_IGNORE_LIMITS, 0);
1237 }
1238 new_request->SetLoadFlags(load_flags);
1219 1239
1220 // Make extra info and read footer (contains request ID). 1240 // Make extra info and read footer (contains request ID).
1221 ResourceRequestInfoImpl* extra_info = 1241 ResourceRequestInfoImpl* extra_info =
1222 new ResourceRequestInfoImpl( 1242 new ResourceRequestInfoImpl(
1223 process_type, 1243 process_type,
1224 child_id, 1244 child_id,
1225 route_id, 1245 route_id,
1226 request_data.origin_pid, 1246 request_data.origin_pid,
1227 request_id, 1247 request_id,
1228 request_data.render_frame_id, 1248 request_data.render_frame_id,
1229 request_data.is_main_frame, 1249 request_data.is_main_frame,
1230 request_data.parent_is_main_frame, 1250 request_data.parent_is_main_frame,
1231 request_data.parent_render_frame_id, 1251 request_data.parent_render_frame_id,
1232 request_data.resource_type, 1252 request_data.resource_type,
1233 request_data.transition_type, 1253 request_data.transition_type,
1234 request_data.should_replace_current_entry, 1254 request_data.should_replace_current_entry,
1235 false, // is download 1255 false, // is download
1236 false, // is stream 1256 false, // is stream
1237 allow_download, 1257 allow_download,
1238 request_data.has_user_gesture, 1258 request_data.has_user_gesture,
1239 request_data.enable_load_timing, 1259 request_data.enable_load_timing,
1240 request_data.enable_upload_progress, 1260 request_data.enable_upload_progress,
1261 do_not_prompt_for_login,
1241 request_data.referrer_policy, 1262 request_data.referrer_policy,
1242 request_data.visiblity_state, 1263 request_data.visiblity_state,
1243 resource_context, 1264 resource_context,
1244 filter_->GetWeakPtr(), 1265 filter_->GetWeakPtr(),
1245 !is_sync_load); 1266 !is_sync_load);
1246 // Request takes ownership. 1267 // Request takes ownership.
1247 extra_info->AssociateWithRequest(new_request.get()); 1268 extra_info->AssociateWithRequest(new_request.get());
1248 1269
1249 if (new_request->url().SchemeIs(url::kBlobScheme)) { 1270 if (new_request->url().SchemeIs(url::kBlobScheme)) {
1250 // Hang on to a reference to ensure the blob is not released prior 1271 // Hang on to a reference to ensure the blob is not released prior
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1474 int route_id, 1495 int route_id,
1475 bool download, 1496 bool download,
1476 ResourceContext* context) { 1497 ResourceContext* context) {
1477 return new ResourceRequestInfoImpl( 1498 return new ResourceRequestInfoImpl(
1478 PROCESS_TYPE_RENDERER, 1499 PROCESS_TYPE_RENDERER,
1479 child_id, 1500 child_id,
1480 route_id, 1501 route_id,
1481 0, 1502 0,
1482 request_id_, 1503 request_id_,
1483 MSG_ROUTING_NONE, // render_frame_id 1504 MSG_ROUTING_NONE, // render_frame_id
1484 false, // is_main_frame 1505 false, // is_main_frame
1485 false, // parent_is_main_frame 1506 false, // parent_is_main_frame
1486 -1, // parent_render_frame_id 1507 -1, // parent_render_frame_id
1487 RESOURCE_TYPE_SUB_RESOURCE, 1508 RESOURCE_TYPE_SUB_RESOURCE,
1488 ui::PAGE_TRANSITION_LINK, 1509 ui::PAGE_TRANSITION_LINK,
1489 false, // should_replace_current_entry 1510 false, // should_replace_current_entry
1490 download, // is_download 1511 download, // is_download
1491 false, // is_stream 1512 false, // is_stream
1492 download, // allow_download 1513 download, // allow_download
1493 false, // has_user_gesture 1514 false, // has_user_gesture
1494 false, // enable_load_timing 1515 false, // enable_load_timing
1495 false, // enable_upload_progress 1516 false, // enable_upload_progress
1517 false, // do_not_prompt_for_login
1496 blink::WebReferrerPolicyDefault, 1518 blink::WebReferrerPolicyDefault,
1497 blink::WebPageVisibilityStateVisible, 1519 blink::WebPageVisibilityStateVisible,
1498 context, 1520 context,
1499 base::WeakPtr<ResourceMessageFilter>(), // filter 1521 base::WeakPtr<ResourceMessageFilter>(), // filter
1500 true); // is_async 1522 true); // is_async
1501 } 1523 }
1502 1524
1503 void ResourceDispatcherHostImpl::OnRenderViewHostCreated(int child_id, 1525 void ResourceDispatcherHostImpl::OnRenderViewHostCreated(int child_id,
1504 int route_id, 1526 int route_id,
1505 bool is_visible, 1527 bool is_visible,
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
1940 params.transition, 1962 params.transition,
1941 // should_replace_current_entry. This was only maintained at layer for 1963 // should_replace_current_entry. This was only maintained at layer for
1942 // request transfers and isn't needed for browser-side navigations. 1964 // request transfers and isn't needed for browser-side navigations.
1943 false, 1965 false,
1944 false, // is download 1966 false, // is download
1945 false, // is stream 1967 false, // is stream
1946 params.allow_download, 1968 params.allow_download,
1947 info.navigation_params.has_user_gesture, 1969 info.navigation_params.has_user_gesture,
1948 true, // enable_load_timing 1970 true, // enable_load_timing
1949 false, // enable_upload_progress 1971 false, // enable_upload_progress
1972 false, // do_not_prompt_for_login
1950 params.referrer.policy, 1973 params.referrer.policy,
1951 // TODO(davidben): This is only used for prerenders. Replace 1974 // TODO(davidben): This is only used for prerenders. Replace
1952 // is_showing with something for that. Or maybe it just comes from the 1975 // is_showing with something for that. Or maybe it just comes from the
1953 // same mechanism as the cookie one. 1976 // same mechanism as the cookie one.
1954 blink::WebPageVisibilityStateVisible, 1977 blink::WebPageVisibilityStateVisible,
1955 resource_context, 1978 resource_context,
1956 base::WeakPtr<ResourceMessageFilter>(), // filter 1979 base::WeakPtr<ResourceMessageFilter>(), // filter
1957 true); 1980 true);
1958 // Request takes ownership. 1981 // Request takes ownership.
1959 extra_info->AssociateWithRequest(new_request.get()); 1982 extra_info->AssociateWithRequest(new_request.get());
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
2314 // Although EV status is irrelevant to sub-frames and sub-resources, we have 2337 // Although EV status is irrelevant to sub-frames and sub-resources, we have
2315 // to perform EV certificate verification on all resources because an HTTP 2338 // to perform EV certificate verification on all resources because an HTTP
2316 // keep-alive connection created to load a sub-frame or a sub-resource could 2339 // keep-alive connection created to load a sub-frame or a sub-resource could
2317 // be reused to load a main frame. 2340 // be reused to load a main frame.
2318 load_flags |= net::LOAD_VERIFY_EV_CERT; 2341 load_flags |= net::LOAD_VERIFY_EV_CERT;
2319 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME) { 2342 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME) {
2320 load_flags |= net::LOAD_MAIN_FRAME; 2343 load_flags |= net::LOAD_MAIN_FRAME;
2321 } else if (request_data.resource_type == RESOURCE_TYPE_SUB_FRAME) { 2344 } else if (request_data.resource_type == RESOURCE_TYPE_SUB_FRAME) {
2322 load_flags |= net::LOAD_SUB_FRAME; 2345 load_flags |= net::LOAD_SUB_FRAME;
2323 } else if (request_data.resource_type == RESOURCE_TYPE_PREFETCH) { 2346 } else if (request_data.resource_type == RESOURCE_TYPE_PREFETCH) {
2324 load_flags |= (net::LOAD_PREFETCH | net::LOAD_DO_NOT_PROMPT_FOR_LOGIN); 2347 load_flags |= net::LOAD_PREFETCH;
2325 } else if (request_data.resource_type == RESOURCE_TYPE_FAVICON) {
2326 load_flags |= net::LOAD_DO_NOT_PROMPT_FOR_LOGIN;
2327 } else if (request_data.resource_type == RESOURCE_TYPE_IMAGE) {
2328 // Prevent third-party image content from prompting for login, as this
2329 // is often a scam to extract credentials for another domain from the user.
2330 // Only block image loads, as the attack applies largely to the "src"
2331 // property of the <img> tag. It is common for web properties to allow
2332 // untrusted values for <img src>; this is considered a fair thing for an
2333 // HTML sanitizer to do. Conversely, any HTML sanitizer that didn't
2334 // filter sources for <script>, <link>, <embed>, <object>, <iframe> tags
2335 // would be considered vulnerable in and of itself.
2336 HttpAuthRelationType relation_type = HttpAuthRelationTypeOf(
2337 request_data.url, request_data.first_party_for_cookies);
2338 if (relation_type == HTTP_AUTH_RELATION_BLOCKED_CROSS) {
2339 load_flags |= (net::LOAD_DO_NOT_USE_EMBEDDED_IDENTITY |
2340 net::LOAD_DO_NOT_PROMPT_FOR_LOGIN);
2341 }
2342 } 2348 }
2343 2349
2344 if (is_sync_load) 2350 if (is_sync_load)
2345 load_flags |= net::LOAD_IGNORE_LIMITS; 2351 load_flags |= net::LOAD_IGNORE_LIMITS;
2346 2352
2347 ChildProcessSecurityPolicyImpl* policy = 2353 ChildProcessSecurityPolicyImpl* policy =
2348 ChildProcessSecurityPolicyImpl::GetInstance(); 2354 ChildProcessSecurityPolicyImpl::GetInstance();
2349 if (!policy->CanSendCookiesForOrigin(child_id, request_data.url)) { 2355 if (!policy->CanSendCookiesForOrigin(child_id, request_data.url)) {
2350 load_flags |= (net::LOAD_DO_NOT_SEND_COOKIES | 2356 load_flags |= (net::LOAD_DO_NOT_SEND_COOKIES |
2351 net::LOAD_DO_NOT_SEND_AUTH_DATA | 2357 net::LOAD_DO_NOT_SEND_AUTH_DATA |
(...skipping 10 matching lines...) Expand all
2362 2368
2363 // Add a flag to selectively bypass the data reduction proxy if the resource 2369 // Add a flag to selectively bypass the data reduction proxy if the resource
2364 // type is not an image. 2370 // type is not an image.
2365 if (request_data.resource_type != RESOURCE_TYPE_IMAGE) 2371 if (request_data.resource_type != RESOURCE_TYPE_IMAGE)
2366 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY; 2372 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY;
2367 2373
2368 return load_flags; 2374 return load_flags;
2369 } 2375 }
2370 2376
2371 } // namespace content 2377 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/resource_dispatcher_host_impl.h ('k') | content/browser/loader/resource_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698