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

Side by Side Diff: Source/core/loader/DocumentThreadableLoader.cpp

Issue 14557011: Fix problems with cross-origin redirects. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fixed typo in numbering in a test. Created 7 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/loader/DocumentLoader.cpp ('k') | Source/core/loader/ResourceLoaderOptions.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 180
181 RefPtr<DocumentThreadableLoader> protect(this); 181 RefPtr<DocumentThreadableLoader> protect(this);
182 // Allow same origin requests to continue after allowing clients to audit th e redirect. 182 // Allow same origin requests to continue after allowing clients to audit th e redirect.
183 if (isAllowedRedirect(request.url())) { 183 if (isAllowedRedirect(request.url())) {
184 if (m_client->isDocumentThreadableLoaderClient()) 184 if (m_client->isDocumentThreadableLoaderClient())
185 static_cast<DocumentThreadableLoaderClient*>(m_client)->willSendRequ est(request, redirectResponse); 185 static_cast<DocumentThreadableLoaderClient*>(m_client)->willSendRequ est(request, redirectResponse);
186 return; 186 return;
187 } 187 }
188 188
189 // When using access control, only simple cross origin requests are allowed to redirect. The new request URL must have a supported 189 // When using access control, only simple cross origin requests are allowed to redirect. The new request URL must have a supported
190 // scheme and not contain the userinfo production. In addition, the redirect response must pass the access control check. 190 // scheme and not contain the userinfo production. In addition, the redirect response must pass the access control check if the
191 // original request was not same-origin.
191 if (m_options.crossOriginRequestPolicy == UseAccessControl) { 192 if (m_options.crossOriginRequestPolicy == UseAccessControl) {
192 bool allowRedirect = false; 193 bool allowRedirect = false;
193 if (m_simpleRequest) { 194 if (m_simpleRequest) {
194 String accessControlErrorDescription; 195 String accessControlErrorDescription;
195 allowRedirect = SchemeRegistry::shouldTreatURLSchemeAsCORSEnabled(re quest.url().protocol()) 196 allowRedirect = SchemeRegistry::shouldTreatURLSchemeAsCORSEnabled(re quest.url().protocol())
196 && request.url().user().isEmpty() 197 && request.url().user().isEmpty()
197 && request.url().pass().isEmpty() 198 && request.url().pass().isEmpty()
198 && passesAccessControlCheck(redirectResponse, m_opti ons.allowCredentials, securityOrigin(), accessControlErrorDescription); 199 && (m_sameOriginRequest || passesAccessControlCheck( redirectResponse, m_options.allowCredentials, securityOrigin(), accessControlErr orDescription));
199 } 200 }
200 201
201 if (allowRedirect) { 202 if (allowRedirect) {
202 if (m_resource) 203 if (m_resource)
203 clearResource(); 204 clearResource();
204 205
205 RefPtr<SecurityOrigin> originalOrigin = SecurityOrigin::createFromSt ring(redirectResponse.url()); 206 RefPtr<SecurityOrigin> originalOrigin = SecurityOrigin::createFromSt ring(redirectResponse.url());
206 RefPtr<SecurityOrigin> requestOrigin = SecurityOrigin::createFromStr ing(request.url()); 207 RefPtr<SecurityOrigin> requestOrigin = SecurityOrigin::createFromStr ing(request.url());
207 // If the request URL origin is not same origin with the original UR L origin, set source origin to a globally unique identifier. 208 // If the original request wasn't same-origin, then if the request U RL origin is not same origin with the original URL origin,
208 if (!originalOrigin->isSameSchemeHostPort(requestOrigin.get())) 209 // set the source origin to a globally unique identifier. (If the or iginal request was same-origin, the origin of the new request
210 // should be the original URL origin.)
211 if (!m_sameOriginRequest && !originalOrigin->isSameSchemeHostPort(re questOrigin.get()))
209 m_options.securityOrigin = SecurityOrigin::createUnique(); 212 m_options.securityOrigin = SecurityOrigin::createUnique();
210 // Force any subsequent requests to use these checks. 213 // Force any subsequent requests to use these checks.
211 m_sameOriginRequest = false; 214 m_sameOriginRequest = false;
212 215
216 // Since the request is no longer same-origin, if the user didn't re quest credentials in
217 // the first place, update our state so we neither request them nor expect they must be allowed.
218 if (m_options.credentialsRequested == ClientDidNotRequestCredentials )
219 m_options.allowCredentials = DoNotAllowStoredCredentials;
220
213 // Remove any headers that may have been added by the network layer that cause access control to fail. 221 // Remove any headers that may have been added by the network layer that cause access control to fail.
214 request.clearHTTPContentType(); 222 request.clearHTTPContentType();
215 request.clearHTTPReferrer(); 223 request.clearHTTPReferrer();
216 request.clearHTTPOrigin(); 224 request.clearHTTPOrigin();
217 request.clearHTTPUserAgent(); 225 request.clearHTTPUserAgent();
218 request.clearHTTPAccept(); 226 request.clearHTTPAccept();
219 makeCrossOriginAccessRequest(request); 227 makeCrossOriginAccessRequest(request);
220 return; 228 return;
221 } 229 }
222 } 230 }
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 442
435 return m_sameOriginRequest && securityOrigin()->canRequest(url); 443 return m_sameOriginRequest && securityOrigin()->canRequest(url);
436 } 444 }
437 445
438 SecurityOrigin* DocumentThreadableLoader::securityOrigin() const 446 SecurityOrigin* DocumentThreadableLoader::securityOrigin() const
439 { 447 {
440 return m_options.securityOrigin ? m_options.securityOrigin.get() : m_documen t->securityOrigin(); 448 return m_options.securityOrigin ? m_options.securityOrigin.get() : m_documen t->securityOrigin();
441 } 449 }
442 450
443 } // namespace WebCore 451 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/loader/DocumentLoader.cpp ('k') | Source/core/loader/ResourceLoaderOptions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698