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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 } | 184 } |
185 } | 185 } |
186 | 186 |
187 if (allowOriginHeaderValue == starAtom) { | 187 if (allowOriginHeaderValue == starAtom) { |
188 // A wildcard Access-Control-Allow-Origin can not be used if credentials are | 188 // A wildcard Access-Control-Allow-Origin can not be used if credentials are |
189 // to be sent, even with Access-Control-Allow-Credentials set to true. | 189 // to be sent, even with Access-Control-Allow-Credentials set to true. |
190 if (includeCredentials == DoNotAllowStoredCredentials) | 190 if (includeCredentials == DoNotAllowStoredCredentials) |
191 return true; | 191 return true; |
192 if (response.isHTTP()) { | 192 if (response.isHTTP()) { |
193 errorDescription = buildAccessControlFailureMessage( | 193 errorDescription = buildAccessControlFailureMessage( |
194 "A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' " | 194 "The value of the 'Access-Control-Allow-Origin' header in the " |
195 "header when the credentials flag is true.", | 195 "response must not be the wildcard '*' when the request's " |
| 196 "credentials mode is 'include'.", |
196 securityOrigin); | 197 securityOrigin); |
197 | 198 |
198 if (context == WebURLRequest::RequestContextXMLHttpRequest) { | 199 if (context == WebURLRequest::RequestContextXMLHttpRequest) { |
199 errorDescription.append( | 200 errorDescription.append( |
200 " The credentials mode of an XMLHttpRequest is controlled by the " | 201 " The credentials mode of requests initiated by the " |
201 "withCredentials attribute."); | 202 "XMLHttpRequest is controlled by the withCredentials attribute."); |
202 } | 203 } |
203 | 204 |
204 return false; | 205 return false; |
205 } | 206 } |
206 } else if (allowOriginHeaderValue != securityOrigin->toAtomicString()) { | 207 } else if (allowOriginHeaderValue != securityOrigin->toAtomicString()) { |
207 if (allowOriginHeaderValue.isNull()) { | 208 if (allowOriginHeaderValue.isNull()) { |
208 errorDescription = buildAccessControlFailureMessage( | 209 errorDescription = buildAccessControlFailureMessage( |
209 "No 'Access-Control-Allow-Origin' header is present on the requested " | 210 "No 'Access-Control-Allow-Origin' header is present on the requested " |
210 "resource.", | 211 "resource.", |
211 securityOrigin); | 212 securityOrigin); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 "'no-cors' to fetch the resource with CORS disabled."); | 254 "'no-cors' to fetch the resource with CORS disabled."); |
254 } | 255 } |
255 return false; | 256 return false; |
256 } | 257 } |
257 | 258 |
258 if (includeCredentials == AllowStoredCredentials) { | 259 if (includeCredentials == AllowStoredCredentials) { |
259 const AtomicString& allowCredentialsHeaderValue = | 260 const AtomicString& allowCredentialsHeaderValue = |
260 response.httpHeaderField(allowCredentialsHeaderName); | 261 response.httpHeaderField(allowCredentialsHeaderName); |
261 if (allowCredentialsHeaderValue != "true") { | 262 if (allowCredentialsHeaderValue != "true") { |
262 errorDescription = buildAccessControlFailureMessage( | 263 errorDescription = buildAccessControlFailureMessage( |
263 "Credentials flag is 'true', but the " | 264 "The value of the 'Access-Control-Allow-Credentials' header in " |
264 "'Access-Control-Allow-Credentials' header is '" + | 265 "the response is '" + |
265 allowCredentialsHeaderValue + | 266 allowCredentialsHeaderValue + |
266 "'. It must be 'true' to allow credentials.", | 267 "' which must " |
| 268 "be 'true' when the request's credentials mode is 'include'.", |
267 securityOrigin); | 269 securityOrigin); |
| 270 |
| 271 if (context == WebURLRequest::RequestContextXMLHttpRequest) { |
| 272 errorDescription.append( |
| 273 " The credentials mode of requests initiated by the " |
| 274 "XMLHttpRequest is controlled by the withCredentials attribute."); |
| 275 } |
| 276 |
268 return false; | 277 return false; |
269 } | 278 } |
270 } | 279 } |
271 | 280 |
272 return true; | 281 return true; |
273 } | 282 } |
274 | 283 |
275 bool passesPreflightStatusCheck(const ResourceResponse& response, | 284 bool passesPreflightStatusCheck(const ResourceResponse& response, |
276 String& errorDescription) { | 285 String& errorDescription) { |
277 // CORS preflight with 3XX is considered network error in | 286 // CORS preflight with 3XX is considered network error in |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 // | 433 // |
425 // This is equivalent to the step 2 in | 434 // This is equivalent to the step 2 in |
426 // https://fetch.spec.whatwg.org/#http-network-or-cache-fetch | 435 // https://fetch.spec.whatwg.org/#http-network-or-cache-fetch |
427 if (options.credentialsRequested == ClientDidNotRequestCredentials) | 436 if (options.credentialsRequested == ClientDidNotRequestCredentials) |
428 options.allowCredentials = DoNotAllowStoredCredentials; | 437 options.allowCredentials = DoNotAllowStoredCredentials; |
429 } | 438 } |
430 return true; | 439 return true; |
431 } | 440 } |
432 | 441 |
433 } // namespace blink | 442 } // namespace blink |
OLD | NEW |