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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 bool passesAccessControlCheck(const ResourceResponse& response, StoredCredential
s includeCredentials, SecurityOrigin* securityOrigin, String& errorDescription) | 145 bool passesAccessControlCheck(const ResourceResponse& response, StoredCredential
s includeCredentials, SecurityOrigin* securityOrigin, String& errorDescription) |
146 { | 146 { |
147 AtomicallyInitializedStatic(AtomicString&, accessControlAllowOrigin = *new A
tomicString("access-control-allow-origin", AtomicString::ConstructFromLiteral)); | 147 AtomicallyInitializedStatic(AtomicString&, accessControlAllowOrigin = *new A
tomicString("access-control-allow-origin", AtomicString::ConstructFromLiteral)); |
148 AtomicallyInitializedStatic(AtomicString&, accessControlAllowCredentials = *
new AtomicString("access-control-allow-credentials", AtomicString::ConstructFrom
Literal)); | 148 AtomicallyInitializedStatic(AtomicString&, accessControlAllowCredentials = *
new AtomicString("access-control-allow-credentials", AtomicString::ConstructFrom
Literal)); |
149 | 149 |
150 if (!response.httpStatusCode()) { | 150 if (!response.httpStatusCode()) { |
151 errorDescription = "Received an invalid response. Origin '" + securityOr
igin->toString() + "' is therefore not allowed access."; | 151 errorDescription = "Received an invalid response. Origin '" + securityOr
igin->toString() + "' is therefore not allowed access."; |
152 return false; | 152 return false; |
153 } | 153 } |
154 | 154 |
155 // A wildcard Access-Control-Allow-Origin can not be used if credentials are
to be sent, | |
156 // even with Access-Control-Allow-Credentials set to true. | |
157 const AtomicString& accessControlOriginString = response.httpHeaderField(acc
essControlAllowOrigin); | 155 const AtomicString& accessControlOriginString = response.httpHeaderField(acc
essControlAllowOrigin); |
158 if (accessControlOriginString == starAtom && includeCredentials == DoNotAllo
wStoredCredentials) | 156 if (accessControlOriginString == starAtom) { |
159 return true; | 157 // A wildcard Access-Control-Allow-Origin can not be used if credentials
are to be sent, |
160 | 158 // even with Access-Control-Allow-Credentials set to true. |
161 if (accessControlOriginString != securityOrigin->toAtomicString()) { | 159 if (includeCredentials == DoNotAllowStoredCredentials) |
162 if (accessControlOriginString == starAtom) { | 160 return true; |
| 161 if (response.isHTTP()) { |
163 errorDescription = "A wildcard '*' cannot be used in the 'Access-Con
trol-Allow-Origin' header when the credentials flag is true. Origin '" + securit
yOrigin->toString() + "' is therefore not allowed access."; | 162 errorDescription = "A wildcard '*' cannot be used in the 'Access-Con
trol-Allow-Origin' header when the credentials flag is true. Origin '" + securit
yOrigin->toString() + "' is therefore not allowed access."; |
164 } else if (accessControlOriginString.isEmpty()) { | 163 return false; |
| 164 } |
| 165 } else if (accessControlOriginString != securityOrigin->toAtomicString()) { |
| 166 if (accessControlOriginString.isEmpty()) { |
165 errorDescription = "No 'Access-Control-Allow-Origin' header is prese
nt on the requested resource. Origin '" + securityOrigin->toString() + "' is the
refore not allowed access."; | 167 errorDescription = "No 'Access-Control-Allow-Origin' header is prese
nt on the requested resource. Origin '" + securityOrigin->toString() + "' is the
refore not allowed access."; |
166 } else if (accessControlOriginString.string().find(isOriginSeparator, 0)
!= kNotFound) { | 168 } else if (accessControlOriginString.string().find(isOriginSeparator, 0)
!= kNotFound) { |
167 errorDescription = "The 'Access-Control-Allow-Origin' header contain
s multiple values '" + accessControlOriginString + "', but only one is allowed.
Origin '" + securityOrigin->toString() + "' is therefore not allowed access."; | 169 errorDescription = "The 'Access-Control-Allow-Origin' header contain
s multiple values '" + accessControlOriginString + "', but only one is allowed.
Origin '" + securityOrigin->toString() + "' is therefore not allowed access."; |
168 } else { | 170 } else { |
169 KURL headerOrigin(KURL(), accessControlOriginString); | 171 KURL headerOrigin(KURL(), accessControlOriginString); |
170 if (!headerOrigin.isValid()) | 172 if (!headerOrigin.isValid()) |
171 errorDescription = "The 'Access-Control-Allow-Origin' header con
tains the invalid value '" + accessControlOriginString + "'. Origin '" + securit
yOrigin->toString() + "' is therefore not allowed access."; | 173 errorDescription = "The 'Access-Control-Allow-Origin' header con
tains the invalid value '" + accessControlOriginString + "'. Origin '" + securit
yOrigin->toString() + "' is therefore not allowed access."; |
172 else | 174 else |
173 errorDescription = "The 'Access-Control-Allow-Origin' header has
a value '" + accessControlOriginString + "' that is not equal to the supplied o
rigin. Origin '" + securityOrigin->toString() + "' is therefore not allowed acce
ss."; | 175 errorDescription = "The 'Access-Control-Allow-Origin' header has
a value '" + accessControlOriginString + "' that is not equal to the supplied o
rigin. Origin '" + securityOrigin->toString() + "' is therefore not allowed acce
ss."; |
174 } | 176 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 request.setHTTPOrigin(securityOrigin->toAtomicString()); | 266 request.setHTTPOrigin(securityOrigin->toAtomicString()); |
265 // If the user didn't request credentials in the first place, update our | 267 // If the user didn't request credentials in the first place, update our |
266 // state so we neither request them nor expect they must be allowed. | 268 // state so we neither request them nor expect they must be allowed. |
267 if (options.credentialsRequested == ClientDidNotRequestCredentials) | 269 if (options.credentialsRequested == ClientDidNotRequestCredentials) |
268 options.allowCredentials = DoNotAllowStoredCredentials; | 270 options.allowCredentials = DoNotAllowStoredCredentials; |
269 } | 271 } |
270 return true; | 272 return true; |
271 } | 273 } |
272 | 274 |
273 } // namespace WebCore | 275 } // namespace WebCore |
OLD | NEW |