Changeset 224019 in webkit


Ignore:
Timestamp:
Oct 26, 2017 8:14:33 AM (6 years ago)
Author:
Brent Fulgham
Message:

XMLHttpRequest should not treat file URLs as same origin
https://bugs.webkit.org/show_bug.cgi?id=178565
<rdar://problem/11115901>

Reviewed by Ryosuke Niwa.

Source/WebCore:

Do not treat file URLs as same-origin for XHR requests.

Test: fast/xmlhttprequest/xmlhttprequest-access-self-as-file.html

  • loader/DocumentThreadableLoader.cpp:

(WebCore::DocumentThreadableLoader::DocumentThreadableLoader): Use new helper method.

  • page/SecurityOrigin.cpp:

(WebCore::SecurityOrigin::requestIsSameOrigin): New method to recognize same-origin
requests, with special handling for XHR.

  • page/SecurityOrigin.h:

LayoutTests:

  • fast/xmlhttprequest/resources/xmlhttprequest-access-self-as-file-real.html: Added.
  • fast/xmlhttprequest/xmlhttprequest-access-self-as-file.html: Added.
  • fast/xmlhttprequest/xmlhttprequest-access-self-as-file-expected.txt: Added.
  • fast/xmlhttprequest/xmlhttprequest-access-self-as-blob-expected.txt: Added.
  • fast/xmlhttprequest/xmlhttprequest-access-self-as-blob.html: Added.
  • fast/xmlhttprequest/xmlhttprequest-nonexistent-file-expected.txt: Rebaseline test now that we reject XHR to local file URLs.
  • platform/ios/fast/xmlhttprequest/xmlhttprequest-nonexistent-file-expected.txt: Rebaselined.
  • platform/wk2/TestExpectations: Skip test since 'beginDragWithFiles' is not supported in WKTR.
Location:
trunk
Files:
6 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r224015 r224019  
     12017-10-25  Brent Fulgham  <bfulgham@apple.com>
     2
     3        XMLHttpRequest should not treat file URLs as same origin
     4        https://bugs.webkit.org/show_bug.cgi?id=178565
     5        <rdar://problem/11115901>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        * fast/xmlhttprequest/resources/xmlhttprequest-access-self-as-file-real.html: Added.
     10        * fast/xmlhttprequest/xmlhttprequest-access-self-as-file.html: Added.
     11        * fast/xmlhttprequest/xmlhttprequest-access-self-as-file-expected.txt: Added.
     12        * fast/xmlhttprequest/xmlhttprequest-access-self-as-blob-expected.txt: Added.
     13        * fast/xmlhttprequest/xmlhttprequest-access-self-as-blob.html: Added.
     14        * fast/xmlhttprequest/xmlhttprequest-nonexistent-file-expected.txt: Rebaseline test now that we reject
     15          XHR to local file URLs.
     16        * platform/ios/fast/xmlhttprequest/xmlhttprequest-nonexistent-file-expected.txt: Rebaselined.
     17        * platform/wk2/TestExpectations: Skip test since 'beginDragWithFiles' is not supported in WKTR.
     18
    1192017-10-26  Carlos Garcia Campos  <cgarcia@igalia.com>
    220
  • trunk/LayoutTests/fast/xmlhttprequest/xmlhttprequest-nonexistent-file-expected.txt

    r220751 r224019  
    1 CONSOLE MESSAGE: line 64: Not allowed to load local resource: nonexistent.html
    2 CONSOLE MESSAGE: line 64: XMLHttpRequest cannot load nonexistent.html. Not allowed to request resource
     1CONSOLE MESSAGE: line 64: XMLHttpRequest cannot load nonexistent.html. Cross origin requests are only supported for HTTP.
     2CONSOLE MESSAGE: line 42: XMLHttpRequest cannot load . Cross origin requests are only supported for HTTP.
    33
    44Bug 22475: REGRESSION: Async XMLHttpRequest never finishes on nonexistent files anymore
     
    1414ReadyState handler: readyState = 1
    1515ReadyState handler: readyState = 4
     16Error handler: readyState = 4
    1617
  • trunk/LayoutTests/platform/ios/fast/xmlhttprequest/xmlhttprequest-nonexistent-file-expected.txt

    r211125 r224019  
     1CONSOLE MESSAGE: line 64: XMLHttpRequest cannot load nonexistent.html. Cross origin requests are only supported for HTTP.
     2CONSOLE MESSAGE: line 42: XMLHttpRequest cannot load . Cross origin requests are only supported for HTTP.
    13
    24Bug 22475: REGRESSION: Async XMLHttpRequest never finishes on nonexistent files anymore
     
    1214ReadyState handler: readyState = 1
    1315ReadyState handler: readyState = 4
     16Error handler: readyState = 4
    1417
  • trunk/LayoutTests/platform/wk2/TestExpectations

    r223565 r224019  
    197197fast/events/ondrop-text-html.html
    198198editing/pasteboard/drag-drop-url-with-style.html
     199fast/xmlhttprequest/xmlhttprequest-access-self-as-blob.html
    199200
    200201# WTR needs an implementation for eventSender.continuousMouseScrollBy
  • trunk/Source/WebCore/ChangeLog

    r224018 r224019  
     12017-10-25  Brent Fulgham  <bfulgham@apple.com>
     2
     3        XMLHttpRequest should not treat file URLs as same origin
     4        https://bugs.webkit.org/show_bug.cgi?id=178565
     5        <rdar://problem/11115901>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Do not treat file URLs as same-origin for XHR requests.
     10
     11        Test: fast/xmlhttprequest/xmlhttprequest-access-self-as-file.html
     12
     13        * loader/DocumentThreadableLoader.cpp:
     14        (WebCore::DocumentThreadableLoader::DocumentThreadableLoader): Use new helper method.
     15        * page/SecurityOrigin.cpp:
     16        (WebCore::SecurityOrigin::requestIsSameOrigin): New method to recognize same-origin
     17        requests, with special handling for XHR.
     18        * page/SecurityOrigin.h:
     19
    1202017-10-26  Christopher Reid  <chris.reid@sony.com>
    221
  • trunk/Source/WebCore/loader/DocumentThreadableLoader.cpp

    r223994 r224019  
    9595    , m_origin(WTFMove(origin))
    9696    , m_referrer(WTFMove(referrer))
    97     , m_sameOriginRequest(securityOrigin().canRequest(request.url()))
     97    , m_sameOriginRequest(securityOrigin().requestIsSameOrigin(request))
    9898    , m_simpleRequest(true)
    9999    , m_async(blockingBehavior == LoadAsynchronously)
  • trunk/Source/WebCore/page/SecurityOrigin.cpp

    r221978 r224019  
    3232#include "BlobURL.h"
    3333#include "FileSystem.h"
     34#include "ResourceRequest.h"
    3435#include "URL.h"
    3536#include "SchemeRegistry.h"
     
    317318}
    318319
     320bool SecurityOrigin::requestIsSameOrigin(const ResourceRequest& request)
     321{
     322    if (m_universalAccess)
     323        return true;
     324
     325    if (!canRequest(request.url()))
     326        return false;
     327
     328    if (request.requester() != ResourceRequest::Requester::XHR)
     329        return true;
     330
     331    // XHR to a file URL should never be treated as same-origin.
     332    if (request.url().protocolIs("file"))
     333        return false;
     334
     335    if (auto blobOrigin = getCachedOrigin(request.url()))
     336        return blobOrigin->protocol() != "file";
     337
     338    return true;
     339}
     340
    319341bool SecurityOrigin::canReceiveDragData(const SecurityOrigin& dragInitiator) const
    320342{
  • trunk/Source/WebCore/page/SecurityOrigin.h

    r221392 r224019  
    3434namespace WebCore {
    3535
     36class ResourceRequest;
    3637class URL;
    3738
     
    149150    bool canRequestGeolocation() const { return !isUnique(); }
    150151    Policy canShowNotifications() const;
     152
     153    bool requestIsSameOrigin(const ResourceRequest&);
    151154
    152155    // The local SecurityOrigin is the most privileged SecurityOrigin.
Note: See TracChangeset for help on using the changeset viewer.