OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple 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 | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 | 175 |
176 bool passesPreflightStatusCheck(const ResourceResponse& response, String& errorD escription) | 176 bool passesPreflightStatusCheck(const ResourceResponse& response, String& errorD escription) |
177 { | 177 { |
178 // CORS preflight with 3XX is considered network error in | 178 // CORS preflight with 3XX is considered network error in |
179 // Fetch API Spec: | 179 // Fetch API Spec: |
180 // https://fetch.spec.whatwg.org/#cors-preflight-fetch | 180 // https://fetch.spec.whatwg.org/#cors-preflight-fetch |
181 // CORS Spec: | 181 // CORS Spec: |
182 // http://www.w3.org/TR/cors/#cross-origin-request-with-preflight-0 | 182 // http://www.w3.org/TR/cors/#cross-origin-request-with-preflight-0 |
183 // https://crbug.com/452394 | 183 // https://crbug.com/452394 |
184 if (response.httpStatusCode() < 200 || response.httpStatusCode() >= 300) { | 184 if (response.httpStatusCode() < 200 || response.httpStatusCode() >= 300) { |
185 errorDescription = "Invalid HTTP status code " + String::number(response .httpStatusCode()); | 185 errorDescription = "Response for preflight has invalid HTTP status code " + String::number(response.httpStatusCode()); |
tyoshino (SeeGerritForStatus)
2015/06/30 05:30:08
Split this change into https://codereview.chromium
| |
186 return false; | 186 return false; |
187 } | 187 } |
188 | 188 |
189 return true; | 189 return true; |
190 } | 190 } |
191 | 191 |
192 void parseAccessControlExposeHeadersAllowList(const String& headerValue, HTTPHea derSet& headerSet) | 192 void parseAccessControlExposeHeadersAllowList(const String& headerValue, HTTPHea derSet& headerSet) |
193 { | 193 { |
194 Vector<String> headers; | 194 Vector<String> headers; |
195 headerValue.split(',', false, headers); | 195 headerValue.split(',', false, headers); |
(...skipping 13 matching lines...) Expand all Loading... | |
209 } | 209 } |
210 | 210 |
211 if (!(requestURL.user().isEmpty() && requestURL.pass().isEmpty())) { | 211 if (!(requestURL.user().isEmpty() && requestURL.pass().isEmpty())) { |
212 errorDescription = "The request was redirected to a URL ('" + requestURL .string() + "') containing userinfo, which is disallowed for cross-origin reques ts."; | 212 errorDescription = "The request was redirected to a URL ('" + requestURL .string() + "') containing userinfo, which is disallowed for cross-origin reques ts."; |
213 return false; | 213 return false; |
214 } | 214 } |
215 | 215 |
216 return true; | 216 return true; |
217 } | 217 } |
218 | 218 |
219 bool CrossOriginAccessControl::handleRedirect(SecurityOrigin* securityOrigin, Re sourceRequest& request, const ResourceResponse& redirectResponse, StoredCredenti als withCredentials, ResourceLoaderOptions& options, String& errorMessage) | 219 bool CrossOriginAccessControl::handleRedirect(SecurityOrigin* securityOrigin, Re sourceRequest& newRequest, const ResourceResponse& redirectResponse, StoredCrede ntials withCredentials, ResourceLoaderOptions& options, String& errorMessage) |
220 { | 220 { |
221 // http://www.w3.org/TR/cors/#redirect-steps terminology: | 221 // http://www.w3.org/TR/cors/#redirect-steps terminology: |
222 const KURL& originalURL = redirectResponse.url(); | 222 const KURL& originalURL = redirectResponse.url(); |
223 const KURL& requestURL = request.url(); | 223 const KURL& newURL = newRequest.url(); |
224 | 224 |
225 bool redirectCrossOrigin = !securityOrigin->canRequest(requestURL); | 225 bool redirectCrossOrigin = !securityOrigin->canRequest(newURL); |
226 | 226 |
227 // Same-origin request URLs that redirect are allowed without checking acces s. | 227 // Same-origin request URLs that redirect are allowed without checking acces s. |
228 if (!securityOrigin->canRequest(originalURL)) { | 228 if (!securityOrigin->canRequest(originalURL)) { |
229 // Follow http://www.w3.org/TR/cors/#redirect-steps | 229 // Follow http://www.w3.org/TR/cors/#redirect-steps |
230 String errorDescription; | 230 String errorDescription; |
231 | 231 |
232 // Steps 3 & 4 - check if scheme and other URL restrictions hold. | 232 // Steps 3 & 4 - check if scheme and other URL restrictions hold. |
233 bool allowRedirect = isLegalRedirectLocation(requestURL, errorDescriptio n); | 233 if (!isLegalRedirectLocation(newURL, errorDescription)) |
sof
2015/06/25 11:24:18
This generated a console error message before cont
tyoshino (SeeGerritForStatus)
2016/07/22 12:46:45
Good catch. Reverted.
| |
234 if (allowRedirect) { | 234 return false; |
235 // Step 5: perform resource sharing access check. | 235 |
236 allowRedirect = passesAccessControlCheck(redirectResponse, withCrede ntials, securityOrigin, errorDescription); | 236 // Step 5: perform resource sharing access check. |
237 if (allowRedirect) { | 237 if (!passesAccessControlCheck(redirectResponse, withCredentials, securit yOrigin, errorDescription)) { |
238 RefPtr<SecurityOrigin> originalOrigin = SecurityOrigin::create(o riginalURL); | |
239 // Step 6: if the request URL origin is not same origin as the o riginal URL's, | |
240 // set the source origin to a globally unique identifier. | |
241 if (!originalOrigin->canRequest(requestURL)) { | |
242 options.securityOrigin = SecurityOrigin::createUnique(); | |
243 securityOrigin = options.securityOrigin.get(); | |
244 } | |
245 } | |
246 } | |
247 if (!allowRedirect) { | |
248 const String& originalOrigin = SecurityOrigin::create(originalURL)-> toString(); | 238 const String& originalOrigin = SecurityOrigin::create(originalURL)-> toString(); |
249 errorMessage = "Redirect at origin '" + originalOrigin + "' has been blocked from loading by Cross-Origin Resource Sharing policy: " + errorDescript ion; | 239 errorMessage = "Redirect at origin '" + originalOrigin + "' has been blocked from loading by Cross-Origin Resource Sharing policy: " + errorDescript ion; |
250 return false; | 240 return false; |
251 } | 241 } |
242 | |
243 RefPtr<SecurityOrigin> originalOrigin = SecurityOrigin::create(originalU RL); | |
244 // Step 6: if the request URL origin is not same origin as the original URL's, | |
245 // set the source origin to a globally unique identifier. | |
246 if (!originalOrigin->canRequest(newURL)) { | |
247 options.securityOrigin = SecurityOrigin::createUnique(); | |
248 securityOrigin = options.securityOrigin.get(); | |
249 } | |
252 } | 250 } |
253 if (redirectCrossOrigin) { | 251 if (redirectCrossOrigin) { |
254 // If now to a different origin, update/set Origin:. | 252 // If now to a different origin, update/set Origin:. |
255 request.clearHTTPOrigin(); | 253 newRequest.clearHTTPOrigin(); |
256 request.setHTTPOrigin(securityOrigin->toAtomicString()); | 254 newRequest.setHTTPOrigin(securityOrigin->toAtomicString()); |
sof
2015/06/25 11:24:18
(This doesn't actually do what's intended, btw.)
| |
257 // If the user didn't request credentials in the first place, update our | 255 // If the user didn't request credentials in the first place, update our |
258 // state so we neither request them nor expect they must be allowed. | 256 // state so we neither request them nor expect they must be allowed. |
259 if (options.credentialsRequested == ClientDidNotRequestCredentials) | 257 if (options.credentialsRequested == ClientDidNotRequestCredentials) |
260 options.allowCredentials = DoNotAllowStoredCredentials; | 258 options.allowCredentials = DoNotAllowStoredCredentials; |
261 } | 259 } |
262 return true; | 260 return true; |
263 } | 261 } |
264 | 262 |
265 } // namespace blink | 263 } // namespace blink |
OLD | NEW |