| 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 { | 128 { |
| 129 return detail + " Origin '" + securityOrigin->toString() + "' is therefore n
ot allowed access."; | 129 return detail + " Origin '" + securityOrigin->toString() + "' is therefore n
ot allowed access."; |
| 130 } | 130 } |
| 131 | 131 |
| 132 bool passesAccessControlCheck(const ResourceResponse& response, StoredCredential
s includeCredentials, SecurityOrigin* securityOrigin, String& errorDescription,
WebURLRequest::RequestContext context) | 132 bool passesAccessControlCheck(const ResourceResponse& response, StoredCredential
s includeCredentials, SecurityOrigin* securityOrigin, String& errorDescription,
WebURLRequest::RequestContext context) |
| 133 { | 133 { |
| 134 DEFINE_THREAD_SAFE_STATIC_LOCAL(AtomicString, allowOriginHeaderName, (new At
omicString("access-control-allow-origin"))); | 134 DEFINE_THREAD_SAFE_STATIC_LOCAL(AtomicString, allowOriginHeaderName, (new At
omicString("access-control-allow-origin"))); |
| 135 DEFINE_THREAD_SAFE_STATIC_LOCAL(AtomicString, allowCredentialsHeaderName, (n
ew AtomicString("access-control-allow-credentials"))); | 135 DEFINE_THREAD_SAFE_STATIC_LOCAL(AtomicString, allowCredentialsHeaderName, (n
ew AtomicString("access-control-allow-credentials"))); |
| 136 DEFINE_THREAD_SAFE_STATIC_LOCAL(AtomicString, allowSuboriginHeaderName, (new
AtomicString("access-control-allow-suborigin"))); | 136 DEFINE_THREAD_SAFE_STATIC_LOCAL(AtomicString, allowSuboriginHeaderName, (new
AtomicString("access-control-allow-suborigin"))); |
| 137 | 137 |
| 138 // TODO(esprehn): This code is using String::append extremely inefficiently |
| 139 // causing tons of copies. It should pass around a StringBuilder instead. |
| 140 |
| 138 int statusCode = response.httpStatusCode(); | 141 int statusCode = response.httpStatusCode(); |
| 139 | 142 |
| 140 if (!statusCode) { | 143 if (!statusCode) { |
| 141 errorDescription = buildAccessControlFailureMessage("Invalid response.",
securityOrigin); | 144 errorDescription = buildAccessControlFailureMessage("Invalid response.",
securityOrigin); |
| 142 return false; | 145 return false; |
| 143 } | 146 } |
| 144 | 147 |
| 145 const AtomicString& allowOriginHeaderValue = response.httpHeaderField(allowO
riginHeaderName); | 148 const AtomicString& allowOriginHeaderValue = response.httpHeaderField(allowO
riginHeaderName); |
| 146 | 149 |
| 147 // Check Suborigins, unless the Access-Control-Allow-Origin is '*', | 150 // Check Suborigins, unless the Access-Control-Allow-Origin is '*', |
| (...skipping 17 matching lines...) Expand all Loading... |
| 165 | 168 |
| 166 if (context == WebURLRequest::RequestContextXMLHttpRequest) | 169 if (context == WebURLRequest::RequestContextXMLHttpRequest) |
| 167 errorDescription.append(" The credentials mode of an XMLHttpRequ
est is controlled by the withCredentials attribute."); | 170 errorDescription.append(" The credentials mode of an XMLHttpRequ
est is controlled by the withCredentials attribute."); |
| 168 | 171 |
| 169 return false; | 172 return false; |
| 170 } | 173 } |
| 171 } else if (allowOriginHeaderValue != securityOrigin->toAtomicString()) { | 174 } else if (allowOriginHeaderValue != securityOrigin->toAtomicString()) { |
| 172 if (allowOriginHeaderValue.isNull()) { | 175 if (allowOriginHeaderValue.isNull()) { |
| 173 errorDescription = buildAccessControlFailureMessage("No 'Access-Cont
rol-Allow-Origin' header is present on the requested resource.", securityOrigin)
; | 176 errorDescription = buildAccessControlFailureMessage("No 'Access-Cont
rol-Allow-Origin' header is present on the requested resource.", securityOrigin)
; |
| 174 | 177 |
| 175 if (isInterestingStatusCode(statusCode)) | 178 if (isInterestingStatusCode(statusCode)) { |
| 176 errorDescription.append(" The response had HTTP status code " +
String::number(statusCode) + "."); | 179 errorDescription.append(" The response had HTTP status code "); |
| 180 errorDescription.append(String::number(statusCode)); |
| 181 errorDescription.append('.'); |
| 182 } |
| 177 | 183 |
| 178 if (context == WebURLRequest::RequestContextFetch) | 184 if (context == WebURLRequest::RequestContextFetch) |
| 179 errorDescription.append(" If an opaque response serves your need
s, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
"); | 185 errorDescription.append(" If an opaque response serves your need
s, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
"); |
| 180 | 186 |
| 181 return false; | 187 return false; |
| 182 } | 188 } |
| 183 | 189 |
| 184 String detail; | 190 String detail; |
| 185 if (allowOriginHeaderValue.getString().find(isOriginSeparator, 0) != kNo
tFound) { | 191 if (allowOriginHeaderValue.getString().find(isOriginSeparator, 0) != kNo
tFound) { |
| 186 detail = "The 'Access-Control-Allow-Origin' header contains multiple
values '" + allowOriginHeaderValue + "', but only one is allowed."; | 192 detail = "The 'Access-Control-Allow-Origin' header contains multiple
values '" + allowOriginHeaderValue + "', but only one is allowed."; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 newRequest.setHTTPOrigin(securityOrigin); | 325 newRequest.setHTTPOrigin(securityOrigin); |
| 320 // If the user didn't request credentials in the first place, update our | 326 // If the user didn't request credentials in the first place, update our |
| 321 // state so we neither request them nor expect they must be allowed. | 327 // state so we neither request them nor expect they must be allowed. |
| 322 if (options.credentialsRequested == ClientDidNotRequestCredentials) | 328 if (options.credentialsRequested == ClientDidNotRequestCredentials) |
| 323 options.allowCredentials = DoNotAllowStoredCredentials; | 329 options.allowCredentials = DoNotAllowStoredCredentials; |
| 324 } | 330 } |
| 325 return true; | 331 return true; |
| 326 } | 332 } |
| 327 | 333 |
| 328 } // namespace blink | 334 } // namespace blink |
| OLD | NEW |