Changeset 103629 in webkit


Ignore:
Timestamp:
Dec 23, 2011, 8:36:18 AM (14 years ago)
Author:
[email protected]
Message:

Synchronous XHR in window context should not support new XHR responseTypes for HTTP(S) requests
https://bugs.webkit.org/show_bug.cgi?id=72154

Source/WebCore:

Per the latest W3C editor draft: http://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html
This is a spec-mandated attempt to thwart and otherwise discourage the use of synchronous XHR
in the window context by deliberately not exposing newer functionality. Here we are disabling
the use of responseType in synchronous HTTP(S) XHR requests from the window context.

When a user attempts this action, an InvalidAccessError exception is thrown and a message is
printed to the console to further explain.

Renamed reportUnsafeUsage to a more generic name, and hoisted it up so it would be defined
earlier and thus referenceable by setResponseType.

Reviewed by Alexey Proskuryakov.

Test: fast/xmlhttprequest/xmlhttprequest-responsetype-sync-request.html

  • xml/XMLHttpRequest.cpp:

(WebCore::logConsoleError):
reportUnsafeUsage -> logConsoleError
(WebCore::XMLHttpRequest::setResponseType):
(WebCore::XMLHttpRequest::setRequestHeader):
reportUnsafeUsage -> logConsoleError
(WebCore::XMLHttpRequest::getResponseHeader):
reportUnsafeUsage -> logConsoleError
(WebCore::XMLHttpRequest::didFail):
reportUnsafeUsage -> logConsoleError

LayoutTests:

New tests that validate synchronous HTTP(S) XHR requests from the window context
cannot use responseType, while other protocols continue to work.

Reviewed by Alexey Proskuryakov.

  • fast/xmlhttprequest/xmlhttprequest-responsetype-sync-request-expected.txt: Added.
  • fast/xmlhttprequest/xmlhttprequest-responsetype-sync-request.html: Added.
Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r103628 r103629  
     12011-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
    1142011-12-23  Ilya Tikhonovsky  <[email protected]>
    215
  • trunk/Source/WebCore/ChangeLog

    r103627 r103629  
     12011-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
    1322011-12-23  Alexander Pavlov  <[email protected]>
    233
  • trunk/Source/WebCore/xml/XMLHttpRequest.cpp

    r103502 r103629  
    144144}
    145145
     146static 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
    146155PassRefPtr<XMLHttpRequest> XMLHttpRequest::create(ScriptExecutionContext* context, PassRefPtr<SecurityOrigin> securityOrigin)
    147156{
     
    289298    }
    290299
     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
    291310    if (responseType == "")
    292311        m_responseTypeCode = ResponseTypeDefault;
     
    818837}
    819838
    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 
    829839void XMLHttpRequest::setRequestHeader(const AtomicString& name, const String& value, ExceptionCode& ec)
    830840{
     
    846856    // A privileged script (e.g. a Dashboard widget) can set any headers.
    847857    if (!securityOrigin()->canLoadLocalResources() && !isAllowedHTTPHeader(name)) {
    848         reportUnsafeUsage(scriptExecutionContext(), "Refused to set unsafe header \"" + name + "\"");
     858        logConsoleError(scriptExecutionContext(), "Refused to set unsafe header \"" + name + "\"");
    849859        return;
    850860    }
     
    908918    // See comment in getAllResponseHeaders above.
    909919    if (isSetCookieHeader(name) && !securityOrigin()->canLoadLocalResources()) {
    910         reportUnsafeUsage(scriptExecutionContext(), "Refused to get unsafe header \"" + name + "\"");
     920        logConsoleError(scriptExecutionContext(), "Refused to get unsafe header \"" + name + "\"");
    911921        return String();
    912922    }
    913923
    914924    if (!m_sameOriginRequest && !isOnAccessControlResponseHeaderWhitelist(name)) {
    915         reportUnsafeUsage(scriptExecutionContext(), "Refused to get unsafe header \"" + name + "\"");
     925        logConsoleError(scriptExecutionContext(), "Refused to get unsafe header \"" + name + "\"");
    916926        return String();
    917927    }
     
    983993    // Network failures are already reported to Web Inspector by ResourceLoader.
    984994    if (error.domain() == errorDomainWebKitInternal)
    985         reportUnsafeUsage(scriptExecutionContext(), "XMLHttpRequest cannot load " + error.failingURL() + ". " + error.localizedDescription());
     995        logConsoleError(scriptExecutionContext(), "XMLHttpRequest cannot load " + error.failingURL() + ". " + error.localizedDescription());
    986996
    987997    m_exceptionCode = XMLHttpRequestException::NETWORK_ERR;
Note: See TracChangeset for help on using the changeset viewer.