Changeset 47388 in webkit


Ignore:
Timestamp:
Aug 17, 2009 1:43:57 PM (15 years ago)
Author:
eric@webkit.org
Message:

2009-08-17 Aaron Boodman <aa@chromium.org>

Reviewed by Alexey Proskuryakov.

https://bugs.webkit.org/show_bug.cgi?id=28313: Combine ThreadableLoaderOptions::crossOriginRequestPolicy and
ThreadableLoaderOptions::crossOriginRedirectPolicy since they are always set the same way.

Also, tightened up behavior of XMLHttpRequest with cross-origin redirects and access control. We have not implemented redirects
for access control, so we should never redirect across origins. But in two edge cases, we were:

  • Asynchronous XHR: Script on origin A requests resource from origin B. Server redirects (without sending access control authorization headers) to a resource on origin A.
  • Synchronous XHR: Script on origin A requests resource from origin B. Server redirects (without sending access control authorization headers) to another resource on origin B (this time sending access control authorization headers).
  • http/tests/xmlhttprequest/access-control-and-redirects-expected.txt: Added.
  • http/tests/xmlhttprequest/access-control-and-redirects.html: Added.

2009-08-17 Aaron Boodman <aa@chromium.org>

Reviewed by Alexey Proskuryakov.

https://bugs.webkit.org/show_bug.cgi?id=28313: Combine ThreadableLoaderOptions::crossOriginRequestPolicy and
ThreadableLoaderOptions::crossOriginRedirectPolicy since they are always set the same way.

Also, tightened up behavior of XMLHttpRequest with cross-origin redirects and access control. We have not implemented
redirects access control, so we should never redirect across origins. But in two edge cases, we were:

  • Asynchronous XHR: Script on origin A requests resource from origin B. Server redirects (without sending access control authorization headers) to a resource on origin A.
  • Synchronous XHR: Script on origin A requests resource from origin B. Server redirects (without sending access control authorization headers) to another resource on origin B (this time sending access control authorization headers).

Test: http/tests/xmlhttprequest/access-control-and-redirects.html

  • loader/DocumentThreadableLoader.cpp: (WebCore::DocumentThreadableLoader::willSendRequest): Refactor redirect checking code into shared location. (WebCore::DocumentThreadableLoader::loadRequest): Ditto. (WebCore::DocumentThreadableLoader::isAllowedRedirect): Ditto.
  • loader/DocumentThreadableLoader.h:
  • loader/ThreadableLoader.h: (WebCore::ThreadableLoaderOptions::ThreadableLoaderOptions): Remove ThreadableLoaderOptions::crossOriginRedirectPolicy.
  • page/EventSource.cpp: (WebCore::EventSource::connect): Ditto.
  • workers/Worker.cpp: Ditto. (WebCore::Worker::Worker): Ditto.
  • workers/WorkerContext.cpp: Ditto. (WebCore::WorkerContext::importScripts): Ditto.
  • workers/WorkerScriptLoader.cpp: (WebCore::WorkerScriptLoader::loadSynchronously): Ditto. (WebCore::WorkerScriptLoader::loadAsynchronously): Ditto.
  • workers/WorkerScriptLoader.h:
  • xml/XMLHttpRequest.cpp: (WebCore::XMLHttpRequest::createRequest): Ditto.
Location:
trunk
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r47348 r47388  
     12009-08-17  Aaron Boodman  <aa@chromium.org>
     2
     3        Reviewed by Alexey Proskuryakov.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=28313: Combine ThreadableLoaderOptions::crossOriginRequestPolicy and
     6        ThreadableLoaderOptions::crossOriginRedirectPolicy since they are always set the same way.
     7
     8        Also, tightened up behavior of XMLHttpRequest with cross-origin redirects and access control. We have not implemented redirects
     9        for access control, so we should never redirect across origins. But in two edge cases, we were:
     10
     11        * Asynchronous XHR: Script on origin A requests resource from origin B. Server redirects (without sending access control
     12          authorization headers) to a resource on origin A.
     13        * Synchronous XHR: Script on origin A requests resource from origin B. Server redirects (without sending access control
     14          authorization headers) to another resource on origin B (this time sending access control authorization headers).
     15
     16        * http/tests/xmlhttprequest/access-control-and-redirects-expected.txt: Added.
     17        * http/tests/xmlhttprequest/access-control-and-redirects.html: Added.
     18
    1192009-08-16  Darin Adler  <darin@apple.com>
    220
  • trunk/WebCore/ChangeLog

    r47386 r47388  
     12009-08-17  Aaron Boodman  <aa@chromium.org>
     2
     3        Reviewed by Alexey Proskuryakov.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=28313: Combine ThreadableLoaderOptions::crossOriginRequestPolicy and
     6        ThreadableLoaderOptions::crossOriginRedirectPolicy since they are always set the same way.
     7
     8        Also, tightened up behavior of XMLHttpRequest with cross-origin redirects and access control. We have not implemented
     9        redirects access control, so we should never redirect across origins. But in two edge cases, we were:
     10
     11        * Asynchronous XHR: Script on origin A requests resource from origin B. Server redirects (without sending access control
     12          authorization headers) to a resource on origin A.
     13        * Synchronous XHR: Script on origin A requests resource from origin B. Server redirects (without sending access control
     14          authorization headers) to another resource on origin B (this time sending access control authorization headers).
     15
     16        Test: http/tests/xmlhttprequest/access-control-and-redirects.html
     17
     18        * loader/DocumentThreadableLoader.cpp:
     19        (WebCore::DocumentThreadableLoader::willSendRequest): Refactor redirect checking code into shared location.
     20        (WebCore::DocumentThreadableLoader::loadRequest): Ditto.
     21        (WebCore::DocumentThreadableLoader::isAllowedRedirect): Ditto.
     22        * loader/DocumentThreadableLoader.h:
     23        * loader/ThreadableLoader.h:
     24        (WebCore::ThreadableLoaderOptions::ThreadableLoaderOptions): Remove ThreadableLoaderOptions::crossOriginRedirectPolicy.
     25        * page/EventSource.cpp:
     26        (WebCore::EventSource::connect): Ditto.
     27        * workers/Worker.cpp: Ditto.
     28        (WebCore::Worker::Worker): Ditto.
     29        * workers/WorkerContext.cpp: Ditto.
     30        (WebCore::WorkerContext::importScripts): Ditto.
     31        * workers/WorkerScriptLoader.cpp:
     32        (WebCore::WorkerScriptLoader::loadSynchronously): Ditto.
     33        (WebCore::WorkerScriptLoader::loadAsynchronously): Ditto.
     34        * workers/WorkerScriptLoader.h:
     35        * xml/XMLHttpRequest.cpp:
     36        (WebCore::XMLHttpRequest::createRequest): Ditto.
     37
    1382009-08-17  Adam Langley  <agl@google.com>
    239
  • trunk/WebCore/loader/DocumentThreadableLoader.cpp

    r47291 r47388  
    170170    ASSERT_UNUSED(loader, loader == m_loader);
    171171
    172     // FIXME: This needs to be fixed to follow the redirect correctly even for cross-domain requests.
    173     if (m_options.crossOriginRedirectPolicy == DenyCrossOriginRedirect && !m_document->securityOrigin()->canRequest(request.url())) {
     172    if (!isAllowedRedirect(request.url())) {
    174173        RefPtr<DocumentThreadableLoader> protect(this);
    175174        m_client->didFailRedirectCheck();
     
    323322    }
    324323
    325     // FIXME: This check along with the one in willSendRequest is specific to xhr and
    326     // should be made more generic.
    327     if (m_sameOriginRequest && !m_document->securityOrigin()->canRequest(response.url())) {
     324    // FIXME: FrameLoader::loadSynchronously() does not tell us whether a redirect happened or not, so we guess by comparing the
     325    // request and response URLs. This isn't a perfect test though, since a server can serve a redirect to the same URL that was
     326    // requested.
     327    if (request.url() != response.url() && !isAllowedRedirect(response.url())) {
    328328        m_client->didFailRedirectCheck();
    329329        return;
     
    339339}
    340340
     341bool DocumentThreadableLoader::isAllowedRedirect(const KURL& url)
     342{
     343    if (m_options.crossOriginRequestPolicy == AllowCrossOriginRequests)
     344        return true;
     345
     346    // FIXME: We need to implement access control for each redirect. This will require some refactoring though, because the code
     347    // that processes redirects doesn't know about access control and expects a synchronous answer from its client about whether
     348    // a redirect should proceed.
     349    return m_sameOriginRequest && m_document->securityOrigin()->canRequest(url);
     350}
     351
    341352} // namespace WebCore
  • trunk/WebCore/loader/DocumentThreadableLoader.h

    r47291 r47388  
    4141namespace WebCore {
    4242    class Document;
     43    class KURL;
    4344    struct ResourceRequest;
    4445    class ThreadableLoaderClient;
     
    8687
    8788        void loadRequest(const ResourceRequest&, bool skipCanLoadCheck);
     89        bool isAllowedRedirect(const KURL&);
    8890
    8991        RefPtr<SubresourceLoader> m_loader;
  • trunk/WebCore/loader/ThreadableLoader.h

    r47291 r47388  
    5555    };
    5656   
    57     enum CrossOriginRedirectPolicy {
    58         DenyCrossOriginRedirect,
    59         AllowCrossOriginRedirect
    60     };
    61    
    6257    struct ThreadableLoaderOptions {
    63         ThreadableLoaderOptions() : sendLoadCallbacks(false), sniffContent(false), allowCredentials(false), forcePreflight(false), crossOriginRequestPolicy(DenyCrossOriginRequests), crossOriginRedirectPolicy(AllowCrossOriginRedirect) { }
     58        ThreadableLoaderOptions() : sendLoadCallbacks(false), sniffContent(false), allowCredentials(false), forcePreflight(false), crossOriginRequestPolicy(DenyCrossOriginRequests) { }
    6459        bool sendLoadCallbacks;
    6560        bool sniffContent;
     
    6762        bool forcePreflight;  // If AccessControl is used, whether to force a preflight.
    6863        CrossOriginRequestPolicy crossOriginRequestPolicy;
    69         CrossOriginRedirectPolicy crossOriginRedirectPolicy;
    7064    };
    7165
  • trunk/WebCore/page/EventSource.cpp

    r47323 r47388  
    9595    options.sniffContent = false;
    9696    options.allowCredentials = true;
    97     options.crossOriginRedirectPolicy = DenyCrossOriginRedirect;
    9897
    9998    m_loader = ThreadableLoader::create(scriptExecutionContext(), this, request, options);
  • trunk/WebCore/workers/Worker.cpp

    r46845 r47388  
    5959
    6060    m_scriptLoader = new WorkerScriptLoader();
    61     m_scriptLoader->loadAsynchronously(scriptExecutionContext(), scriptURL, DenyCrossOriginRedirect, this);
     61    m_scriptLoader->loadAsynchronously(scriptExecutionContext(), scriptURL, DenyCrossOriginRequests, this);
    6262    setPendingActivity(this);  // The worker context does not exist while loading, so we must ensure that the worker object is not collected, as well as its event listeners.
    6363}
  • trunk/WebCore/workers/WorkerContext.cpp

    r47056 r47388  
    257257    for (Vector<KURL>::const_iterator it = completedURLs.begin(); it != end; ++it) {
    258258        WorkerScriptLoader scriptLoader;
    259         scriptLoader.loadSynchronously(scriptExecutionContext(), *it, AllowCrossOriginRedirect);
     259        scriptLoader.loadSynchronously(scriptExecutionContext(), *it, AllowCrossOriginRequests);
    260260
    261261        // If the fetching attempt failed, throw a NETWORK_ERR exception and abort all these steps.
  • trunk/WebCore/workers/WorkerScriptLoader.cpp

    r47291 r47388  
    5151}
    5252
    53 void WorkerScriptLoader::loadSynchronously(ScriptExecutionContext* scriptExecutionContext, const KURL& url, CrossOriginRedirectPolicy crossOriginRedirectPolicy)
     53void WorkerScriptLoader::loadSynchronously(ScriptExecutionContext* scriptExecutionContext, const KURL& url, CrossOriginRequestPolicy crossOriginRequestPolicy)
    5454{
    5555    m_url = url;
     
    6363    ThreadableLoaderOptions options;
    6464    options.allowCredentials = true;
    65     options.crossOriginRequestPolicy = AllowCrossOriginRequests;
    66     options.crossOriginRedirectPolicy = crossOriginRedirectPolicy;
     65    options.crossOriginRequestPolicy = crossOriginRequestPolicy;
    6766
    6867    WorkerThreadableLoader::loadResourceSynchronously(static_cast<WorkerContext*>(scriptExecutionContext), *request, *this, options);
    6968}
    7069   
    71 void WorkerScriptLoader::loadAsynchronously(ScriptExecutionContext* scriptExecutionContext, const KURL& url, CrossOriginRedirectPolicy crossOriginRedirectPolicy, WorkerScriptLoaderClient* client)
     70void WorkerScriptLoader::loadAsynchronously(ScriptExecutionContext* scriptExecutionContext, const KURL& url, CrossOriginRequestPolicy crossOriginRequestPolicy, WorkerScriptLoaderClient* client)
    7271{
    7372    ASSERT(client);
     
    8180    ThreadableLoaderOptions options;
    8281    options.allowCredentials = true;
    83     options.crossOriginRequestPolicy = AllowCrossOriginRequests;
    84     options.crossOriginRedirectPolicy = crossOriginRedirectPolicy;
     82    options.crossOriginRequestPolicy = crossOriginRequestPolicy;
    8583
    8684    m_threadableLoader = ThreadableLoader::create(scriptExecutionContext, this, *request, options);
  • trunk/WebCore/workers/WorkerScriptLoader.h

    r46570 r47388  
    4747        WorkerScriptLoader();
    4848
    49         void loadSynchronously(ScriptExecutionContext*, const KURL&, CrossOriginRedirectPolicy);
    50         void loadAsynchronously(ScriptExecutionContext*, const KURL&, CrossOriginRedirectPolicy, WorkerScriptLoaderClient*);
     49        void loadSynchronously(ScriptExecutionContext*, const KURL&, CrossOriginRequestPolicy);
     50        void loadAsynchronously(ScriptExecutionContext*, const KURL&, CrossOriginRequestPolicy, WorkerScriptLoaderClient*);
    5151
    5252        void notifyError();
  • trunk/WebCore/xml/XMLHttpRequest.cpp

    r47291 r47388  
    499499    options.allowCredentials = m_sameOriginRequest || m_includeCredentials;
    500500    options.crossOriginRequestPolicy = UseAccessControl;
    501     options.crossOriginRedirectPolicy = DenyCrossOriginRedirect;
    502501
    503502    m_exceptionCode = 0;
Note: See TracChangeset for help on using the changeset viewer.