Changeset 103629 in webkit
- Timestamp:
- Dec 23, 2011, 8:36:18 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r103628 r103629 1 2011-12-23 Jarred Nicholls <[email protected]> 2 3 Synchronous XHR in window context should not support new XHR responseTypes for HTTP(S) requests 4 https://bugs.webkit.org/show_bug.cgi?id=72154 5 6 New tests that validate synchronous HTTP(S) XHR requests from the window context 7 cannot use responseType, while other protocols continue to work. 8 9 Reviewed by Alexey Proskuryakov. 10 11 * fast/xmlhttprequest/xmlhttprequest-responsetype-sync-request-expected.txt: Added. 12 * fast/xmlhttprequest/xmlhttprequest-responsetype-sync-request.html: Added. 13 1 14 2011-12-23 Ilya Tikhonovsky <[email protected]> 2 15 -
trunk/Source/WebCore/ChangeLog
r103627 r103629 1 2011-12-23 Jarred Nicholls <[email protected]> 2 3 Synchronous XHR in window context should not support new XHR responseTypes for HTTP(S) requests 4 https://bugs.webkit.org/show_bug.cgi?id=72154 5 6 Per the latest W3C editor draft: http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html 7 This is a spec-mandated attempt to thwart and otherwise discourage the use of synchronous XHR 8 in the window context by deliberately not exposing newer functionality. Here we are disabling 9 the use of responseType in synchronous HTTP(S) XHR requests from the window context. 10 11 When a user attempts this action, an InvalidAccessError exception is thrown and a message is 12 printed to the console to further explain. 13 14 Renamed reportUnsafeUsage to a more generic name, and hoisted it up so it would be defined 15 earlier and thus referenceable by setResponseType. 16 17 Reviewed by Alexey Proskuryakov. 18 19 Test: fast/xmlhttprequest/xmlhttprequest-responsetype-sync-request.html 20 21 * xml/XMLHttpRequest.cpp: 22 (WebCore::logConsoleError): 23 reportUnsafeUsage -> logConsoleError 24 (WebCore::XMLHttpRequest::setResponseType): 25 (WebCore::XMLHttpRequest::setRequestHeader): 26 reportUnsafeUsage -> logConsoleError 27 (WebCore::XMLHttpRequest::getResponseHeader): 28 reportUnsafeUsage -> logConsoleError 29 (WebCore::XMLHttpRequest::didFail): 30 reportUnsafeUsage -> logConsoleError 31 1 32 2011-12-23 Alexander Pavlov <[email protected]> 2 33 -
trunk/Source/WebCore/xml/XMLHttpRequest.cpp
r103502 r103629 144 144 } 145 145 146 static void logConsoleError(ScriptExecutionContext* context, const String& message) 147 { 148 if (!context) 149 return; 150 // FIXME: It's not good to report the bad usage without indicating what source line it came from. 151 // We should pass additional parameters so we can tell the console where the mistake occurred. 152 context->addConsoleMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, message); 153 } 154 146 155 PassRefPtr<XMLHttpRequest> XMLHttpRequest::create(ScriptExecutionContext* context, PassRefPtr<SecurityOrigin> securityOrigin) 147 156 { … … 289 298 } 290 299 300 // Newer functionality is not available to synchronous requests in window contexts, as a spec-mandated 301 // attempt to discourage synchronous XHR use. responseType is one such piece of functionality. 302 // We'll only disable this functionality for HTTP(S) requests since sync requests for local protocols 303 // such as file: and data: still make sense to allow. 304 if (!m_async && scriptExecutionContext()->isDocument() && m_url.protocolIsInHTTPFamily()) { 305 logConsoleError(scriptExecutionContext(), "XMLHttpRequest.responseType cannot be changed for synchronous HTTP(S) requests made from the window context."); 306 ec = INVALID_ACCESS_ERR; 307 return; 308 } 309 291 310 if (responseType == "") 292 311 m_responseTypeCode = ResponseTypeDefault; … … 818 837 } 819 838 820 static void reportUnsafeUsage(ScriptExecutionContext* context, const String& message)821 {822 if (!context)823 return;824 // FIXME: It's not good to report the bad usage without indicating what source line it came from.825 // We should pass additional parameters so we can tell the console where the mistake occurred.826 context->addConsoleMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, message);827 }828 829 839 void XMLHttpRequest::setRequestHeader(const AtomicString& name, const String& value, ExceptionCode& ec) 830 840 { … … 846 856 // A privileged script (e.g. a Dashboard widget) can set any headers. 847 857 if (!securityOrigin()->canLoadLocalResources() && !isAllowedHTTPHeader(name)) { 848 reportUnsafeUsage(scriptExecutionContext(), "Refused to set unsafe header \"" + name + "\"");858 logConsoleError(scriptExecutionContext(), "Refused to set unsafe header \"" + name + "\""); 849 859 return; 850 860 } … … 908 918 // See comment in getAllResponseHeaders above. 909 919 if (isSetCookieHeader(name) && !securityOrigin()->canLoadLocalResources()) { 910 reportUnsafeUsage(scriptExecutionContext(), "Refused to get unsafe header \"" + name + "\"");920 logConsoleError(scriptExecutionContext(), "Refused to get unsafe header \"" + name + "\""); 911 921 return String(); 912 922 } 913 923 914 924 if (!m_sameOriginRequest && !isOnAccessControlResponseHeaderWhitelist(name)) { 915 reportUnsafeUsage(scriptExecutionContext(), "Refused to get unsafe header \"" + name + "\"");925 logConsoleError(scriptExecutionContext(), "Refused to get unsafe header \"" + name + "\""); 916 926 return String(); 917 927 } … … 983 993 // Network failures are already reported to Web Inspector by ResourceLoader. 984 994 if (error.domain() == errorDomainWebKitInternal) 985 reportUnsafeUsage(scriptExecutionContext(), "XMLHttpRequest cannot load " + error.failingURL() + ". " + error.localizedDescription());995 logConsoleError(scriptExecutionContext(), "XMLHttpRequest cannot load " + error.failingURL() + ". " + error.localizedDescription()); 986 996 987 997 m_exceptionCode = XMLHttpRequestException::NETWORK_ERR;
Note:
See TracChangeset
for help on using the changeset viewer.