⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 276193 in webkit


Ignore:
Timestamp:
Apr 16, 2021, 8:22:00 PM (5 years ago)
Author:
Brent Fulgham
Message:

Perform port blocking earlier in the load
https://bugs.webkit.org/show_bug.cgi?id=224525
<rdar://problem/75440591>

Reviewed by Darin Adler.

Source/WebCore:

WebKit blocks loads to URLs with any of the prohibited ports defined in
the engine. This blocking happens late in the load process, allowing
connections to be made (and observed). Instead, we should stop the load
early, at the same time we perform other checks.

Test: http/tests/security/form-blocked-port.html

  • html/HTMLMediaElement.cpp:

(WebCore::HTMLMediaElement::isSafeToLoadURL): Add a check for prohibited ports,
and block (with relevant logging) if a load to a denied port is attempted.

  • loader/DocumentLoader.cpp:

(WebCore::DocumentLoader::willSendRequest): Ditto.

  • loader/FrameLoader.cpp:

(WebCore::FrameLoader::loadFrameRequest): Ditto.
(WebCore::FrameLoader::reportBlockedLoadFailed): Ditto.

  • loader/FrameLoader.h:
  • loader/PingLoader.cpp:

(WebCore::PingLoader::loadImage): Ditto.

  • loader/ResourceLoader.cpp:

(WebCore::ResourceLoader::init): Ditto.

  • loader/SubframeLoader.cpp:

(WebCore::FrameLoader::SubframeLoader::pluginIsLoadable): Ditto.
(WebCore::FrameLoader::SubframeLoader::loadSubframe): Ditto.

  • loader/cache/CachedResourceLoader.cpp:

(WebCore::CachedResourceLoader::canRequest): Ditto.
(WebCore::CachedResourceLoader::canRequestAfterRedirection const): Ditto.

Tools:

Update URLScheme test to use a non-prohibited port for the test. Tests of
failed fetches are already handled in WPT and other tests, so using a valid
port here should continue to be a valid test.

  • TestWebKitAPI/Tests/WebKitCocoa/WKURLSchemeHandler-1.mm:

(-[FrameSchemeHandler webView:startURLSchemeTask:]): Use allowed port or the test
instead of 123.

LayoutTests:

WebKit blocks loads to URLs with any of the prohibited ports defined in
the engine. This blocking happens late in the load process, allowing
connections to be made (and observed). Instead, we should stop the load
early, at the same time we perform other checks.

Note: The fact that we now block loads earlier means that we do not fire
'willSendRequestForFrame' for blocked ports, so WebKitTestRunner no longer
outputs a message to stdout. Those errors are reported in the JS console,
but since some test paths are specified to always output JS console messages
to stderrr (for example the WPT tests), we have to revise out test expectations
for a few cases.

  • fast/loader/cancel-load-during-port-block-timer.html: Revised expectation to reflect new console error message.
  • http/tests/cache/cancel-during-failure-crash-expected.txt: Ditto.
  • http/tests/preload/download_resources_from_invalid_headers-expected.txt: Update to reflect a preflight is not executed for a blocked port.
  • http/tests/preload/resources/nph-invalid_resources_from_header.pl: Update to reflect that we do not preload from restricted ports.
  • http/tests/security/blocked-on-redirect-expected.txt: Revised expectation to match revised error message.
  • http/tests/security/form-blocked-port.html: Added.
  • http/tests/security/form-blocked-port-expected.txt: Added.
  • http/tests/xmlhttprequest/cross-origin-redirect-responseURL-expected.txt: Revised expectation for revised error message.
  • http/tests/xmlhttprequest/redirect-cross-origin-2-expected.txt: Ditto.
  • http/tests/xmlhttprequest/redirect-cross-origin-expected.txt: Ditto.
  • http/tests/xmlhttprequest/simple-cross-origin-denied-events.html: Instead of using a port WebKit blocks (7), use one that is not blocked but is unlikely to be active (as originally intended). This retains the expected test behavior since we now block loads to restricted ports earlier in the load process.
  • http/tests/xmlhttprequest/simple-cross-origin-denied-events-post.html: Ditto.
  • http/tests/xmlhttprequest/simple-cross-origin-denied-events-post-expected.txt: Update test output to reflect that we are attempting to load from port 8 instead of port 7.
  • http/wpt/beacon/beacon-async-error-logging-expected.txt: Ditto.
  • http/wpt/beacon/beacon-async-error-logging.html: Update to reflect a preflight is not executed for a blocked port.
  • imported/w3c/web-platform-tests/fetch/api/request/request-bad-port.any-expected.txt: Since we block before executing the load, TestRunner no longer outputs an error message to stdout. Instead, they appear in stderr (since all 'wpt' tests are marked to dump console.log output to stderr).
  • imported/w3c/web-platform-tests/fetch/api/request/request-bad-port.any.worker-expected.txt: Ditto.
  • platform/mac-wk1/http/tests/xmlhttprequest/redirect-cross-origin-post-expected.txt: Revise to reflect change in console logging (the functional test results are identical).
  • platform/mac-wk1/http/tests/xmlhttprequest/simple-cross-origin-denied-events-post-expected.txt: Ditto.
  • platform/win/http/tests/xmlhttprequest/redirect-cross-origin-post-expected.txt: Ditto.
  • platform/win/http/tests/xmlhttprequest/simple-cross-origin-denied-events-post-expected.txt: Ditto.
  • platform/wk2/http/tests/security/blocked-on-redirect-expected.txt: Ditto.
Location:
trunk
Files:
2 added
29 edited
4 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r276188 r276193  
     12021-04-16  Brent Fulgham  <bfulgham@apple.com>
     2
     3        Perform port blocking earlier in the load
     4        https://bugs.webkit.org/show_bug.cgi?id=224525
     5        <rdar://problem/75440591>
     6
     7        Reviewed by Darin Adler.
     8
     9        WebKit blocks loads to URLs with any of the prohibited ports defined in
     10        the engine. This blocking happens late in the load process, allowing
     11        connections to be made (and observed). Instead, we should stop the load
     12        early, at the same time we perform other checks.
     13
     14        Note: The fact that we now block loads earlier means that we do not fire
     15        'willSendRequestForFrame' for blocked ports, so WebKitTestRunner no longer
     16        outputs a message to stdout. Those errors are reported in the JS console,
     17        but since some test paths are specified to always output JS console messages
     18        to stderrr (for example the WPT tests), we have to revise out test expectations
     19        for a few cases.
     20
     21        * fast/loader/cancel-load-during-port-block-timer.html: Revised expectation to reflect new console error message.
     22        * http/tests/cache/cancel-during-failure-crash-expected.txt: Ditto.
     23        * http/tests/preload/download_resources_from_invalid_headers-expected.txt: Update to reflect a preflight is not executed
     24          for a blocked port.
     25        * http/tests/preload/resources/nph-invalid_resources_from_header.pl: Update to reflect that we do not preload
     26          from restricted ports.
     27        * http/tests/security/blocked-on-redirect-expected.txt: Revised expectation to match revised error message.
     28        * http/tests/security/form-blocked-port.html: Added.
     29        * http/tests/security/form-blocked-port-expected.txt: Added.
     30        * http/tests/xmlhttprequest/cross-origin-redirect-responseURL-expected.txt: Revised expectation for revised error message.
     31        * http/tests/xmlhttprequest/redirect-cross-origin-2-expected.txt: Ditto.
     32        * http/tests/xmlhttprequest/redirect-cross-origin-expected.txt: Ditto.
     33        * http/tests/xmlhttprequest/simple-cross-origin-denied-events.html: Instead of using a port WebKit blocks (7), use one that
     34          is not blocked but is unlikely to be active (as originally intended). This retains the expected test behavior since we now
     35          block loads to restricted ports earlier in the load process.
     36        * http/tests/xmlhttprequest/simple-cross-origin-denied-events-post.html: Ditto.
     37        * http/tests/xmlhttprequest/simple-cross-origin-denied-events-post-expected.txt: Update test output to reflect that we
     38          are attempting to load from port 8 instead of port 7.
     39        * http/wpt/beacon/beacon-async-error-logging-expected.txt: Ditto.
     40        * http/wpt/beacon/beacon-async-error-logging.html: Update to reflect a preflight is not executed
     41          for a blocked port.
     42        * imported/w3c/web-platform-tests/fetch/api/request/request-bad-port.any-expected.txt: Since we block before executing the load,
     43          TestRunner no longer outputs an error message to stdout. Instead, they appear in stderr (since all 'wpt' tests are marked
     44          to dump console.log output to stderr).
     45        * imported/w3c/web-platform-tests/fetch/api/request/request-bad-port.any.worker-expected.txt: Ditto.
     46        * platform/mac-wk1/http/tests/xmlhttprequest/redirect-cross-origin-post-expected.txt: Revise to reflect change in console
     47          logging (the functional test results are identical).
     48        * platform/mac-wk1/http/tests/xmlhttprequest/simple-cross-origin-denied-events-post-expected.txt: Ditto.
     49        * platform/win/http/tests/xmlhttprequest/redirect-cross-origin-post-expected.txt: Ditto.
     50        * platform/win/http/tests/xmlhttprequest/simple-cross-origin-denied-events-post-expected.txt: Ditto.
     51        * platform/wk2/http/tests/security/blocked-on-redirect-expected.txt: Ditto.
     52
    1532021-04-16  Chris Dumez  <cdumez@apple.com>
    254
  • trunk/LayoutTests/fast/loader/cancel-load-during-port-block-timer-expected.txt

    r31434 r276193  
     1CONSOLE MESSAGE: Not allowed to use restricted network port 22: http://127.0.0.1:22/
    12If this does crash, the test has passed.
  • trunk/LayoutTests/http/tests/cache/cancel-during-failure-crash-expected.txt

    r115223 r276193  
     1CONSOLE MESSAGE: Not allowed to use restricted network port 7: http://localhost:7/
    12PASS
  • trunk/LayoutTests/http/tests/preload/download_resources_from_invalid_headers-expected.txt

    r231450 r276193  
    1919PASS internals.isPreloaded('../resources/dumm'); is false
    2020PASS internals.isPreloaded('http://localhost:8000/preload/resources/square.png'); is false
    21 PASS internals.isPreloaded('http://localhost:53/preload/resources/dummy.js'); is true
     21PASS internals.isPreloaded('http://localhost:53/preload/resources/dummy.js'); is false
    2222PASS internals.isPreloaded('#foobar'); is false
    2323PASS internals.isPreloaded('../resources/Ahem.ttf'); is false
  • trunk/LayoutTests/http/tests/preload/resources/nph-invalid_resources_from_header.pl

    r217962 r276193  
    4444    shouldBeFalse("internals.isPreloaded('../resources/dumm');");
    4545    shouldBeFalse("internals.isPreloaded('http://localhost:8000/preload/resources/square.png');");
    46     // Invalid ports get preloaded (and get terminated further down the stack).
    47     shouldBeTrue("internals.isPreloaded('http://localhost:53/preload/resources/dummy.js');");
     46    shouldBeFalse("internals.isPreloaded('http://localhost:53/preload/resources/dummy.js');");
    4847    shouldBeFalse("internals.isPreloaded('#foobar');");
    4948    shouldBeFalse("internals.isPreloaded('../resources/Ahem.ttf');");
  • trunk/LayoutTests/http/tests/security/blocked-on-redirect-expected.txt

    r272981 r276193  
    11http://127.0.0.1:8000/resources/redirect.py?code=307&url=http://localhost:25/security/resources/post-done.html - willSendRequest <NSURLRequest URL http://127.0.0.1:8000/resources/redirect.py?code=307&url=http://localhost:25/security/resources/post-done.html, main document URL http://127.0.0.1:8000/security/blocked-on-redirect.html, http method GET> redirectResponse (null)
    22http://127.0.0.1:8000/security/blocked-on-redirect.html - didFinishLoading
    3 CONSOLE MESSAGE: Not allowed to use restricted network port: http://localhost:25/security/resources/post-done.html
     3CONSOLE MESSAGE: Not allowed to use restricted network port 25: http://localhost:25/security/resources/post-done.html
    44http://127.0.0.1:8000/resources/redirect.py?code=307&url=http://localhost:25/security/resources/post-done.html - didFailLoadingWithError: <NSError domain WebKitErrorDomain, code 103, failing URL "http://localhost:25/security/resources/post-done.html">
    55This test produces output in the console. Only the initial URL should be logged.
  • trunk/LayoutTests/http/tests/xmlhttprequest/cross-origin-redirect-responseURL-expected.txt

    r267644 r276193  
     1CONSOLE MESSAGE: Not allowed to use restricted network port 7: http://localhost:7/
     2CONSOLE MESSAGE: Not allowed to use restricted network port 22: http://localhost:22/
    13Test XMLHttpRequest responseURL.
    24
  • trunk/LayoutTests/http/tests/xmlhttprequest/redirect-cross-origin-2-expected.txt

    r205473 r276193  
    11CONSOLE MESSAGE: Origin http://127.0.0.1:8000 is not allowed by Access-Control-Allow-Origin.
    22CONSOLE MESSAGE: XMLHttpRequest cannot load http://localhost:8000/xmlhttprequest/resources/reply.xml due to access control checks.
     3CONSOLE MESSAGE: Not allowed to use restricted network port 22: http://localhost:22/
    34Test that a cross-origin redirect to a server that responds is indistinguishable from one that does not. Should say PASS:
    45
  • trunk/LayoutTests/http/tests/xmlhttprequest/redirect-cross-origin-expected.txt

    r205473 r276193  
    11CONSOLE MESSAGE: Origin http://127.0.0.1:8000 is not allowed by Access-Control-Allow-Origin.
    22CONSOLE MESSAGE: XMLHttpRequest cannot load http://localhost:8000/xmlhttprequest/resources/reply.xml due to access control checks.
     3CONSOLE MESSAGE: Not allowed to use restricted network port 7: http://localhost:7/
    34Test that a cross-origin redirect to a server that responds is indistinguishable from one that does not. Should say PASS:
    45
  • trunk/LayoutTests/http/tests/xmlhttprequest/simple-cross-origin-denied-events-post-expected.txt

    r231056 r276193  
    11CONSOLE MESSAGE: Origin http://127.0.0.1:8000 is not allowed by Access-Control-Allow-Origin.
    22CONSOLE MESSAGE: XMLHttpRequest cannot load http://localhost:8000/xmlhttprequest/resources/reply.xml due to access control checks.
    3 CONSOLE MESSAGE: CORS-preflight request was blocked
    4 CONSOLE MESSAGE: XMLHttpRequest cannot load http://localhost:7/ due to access control checks.
     3CONSOLE MESSAGE: Could not connect to the server.
     4CONSOLE MESSAGE: XMLHttpRequest cannot load http://localhost:8/ due to access control checks.
    55Test that a simple cross-origin request to a server that responds (but does not permit cross-origin requests) is indistinguishable from one that does not exist. Should say PASS:
    66
  • trunk/LayoutTests/http/tests/xmlhttprequest/simple-cross-origin-denied-events-post.html

    r120167 r276193  
    3737        xhr.upload.onloadstart = function() { log("upload.onloadstart") }
    3838        xhr.upload.onprogress = function() { log("upload.onprogress") }
    39         xhr.open("POST", "http://localhost:7/", true); // A port that will likely refuse the connection.
     39        xhr.open("POST", "http://localhost:8/", true); // A port that will likely refuse the connection.
    4040        xhr.setRequestHeader("Content-Type", "text/plain");
    4141        xhr.send("Text");
  • trunk/LayoutTests/http/tests/xmlhttprequest/simple-cross-origin-denied-events.html

    r120167 r276193  
    3232        xhr.onprogress = function() { log("onprogress") }
    3333        xhr.onerror = function() { log("onerror"); setTimeout(doneMissing, 100); }
    34         xhr.open("GET", "http://localhost:7/", true); // A port that will likely refuse the connection.
     34        xhr.open("GET", "http://localhost:8/", true); // A port that will likely refuse the connection.
    3535        xhr.send();
    36     }
     36     }
    3737
    3838    function doneMissing()
  • trunk/LayoutTests/http/wpt/beacon/beacon-async-error-logging-expected.txt

    r267644 r276193  
     1CONSOLE MESSAGE: Not allowed to use restricted network port 1: http://localhost:1/
    12CONSOLE MESSAGE: Beacon API cannot load http://localhost:1/. Not allowed to use restricted network port
    23
  • trunk/LayoutTests/http/wpt/beacon/beacon-async-error-logging.html

    r244700 r276193  
    1616        }
    1717        let hostWithInvalidPort = "http://localhost:1";
    18         assert_true(navigator.sendBeacon(hostWithInvalidPort, 'test'), "sendBeacon should return true");
     18        assert_false(navigator.sendBeacon(hostWithInvalidPort, 'test'), "sendBeacon should return true");
    1919    }, "Should log an error message in the console");
    2020</script>
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-bad-port.any-expected.txt

    r275831 r276193  
    1 Blocked access to external URL http://example.com:1/
    2 Blocked access to external URL http://example.com:7/
    3 Blocked access to external URL http://example.com:9/
    4 Blocked access to external URL http://example.com:11/
    5 Blocked access to external URL http://example.com:13/
    6 Blocked access to external URL http://example.com:15/
    7 Blocked access to external URL http://example.com:17/
    8 Blocked access to external URL http://example.com:19/
    9 Blocked access to external URL http://example.com:20/
    10 Blocked access to external URL http://example.com:21/
    11 Blocked access to external URL http://example.com:22/
    12 Blocked access to external URL http://example.com:23/
    13 Blocked access to external URL http://example.com:25/
    14 Blocked access to external URL http://example.com:37/
    15 Blocked access to external URL http://example.com:42/
    16 Blocked access to external URL http://example.com:43/
    17 Blocked access to external URL http://example.com:53/
    18 Blocked access to external URL http://example.com:69/
    19 Blocked access to external URL http://example.com:77/
    20 Blocked access to external URL http://example.com:79/
    21 Blocked access to external URL http://example.com:87/
    22 Blocked access to external URL http://example.com:95/
    23 Blocked access to external URL http://example.com:101/
    24 Blocked access to external URL http://example.com:102/
    25 Blocked access to external URL http://example.com:103/
    26 Blocked access to external URL http://example.com:104/
    27 Blocked access to external URL http://example.com:109/
    28 Blocked access to external URL http://example.com:110/
    29 Blocked access to external URL http://example.com:111/
    30 Blocked access to external URL http://example.com:113/
    31 Blocked access to external URL http://example.com:115/
    32 Blocked access to external URL http://example.com:117/
    33 Blocked access to external URL http://example.com:119/
    34 Blocked access to external URL http://example.com:123/
    35 Blocked access to external URL http://example.com:135/
    36 Blocked access to external URL http://example.com:137/
    37 Blocked access to external URL http://example.com:139/
    38 Blocked access to external URL http://example.com:143/
    39 Blocked access to external URL http://example.com:161/
    40 Blocked access to external URL http://example.com:179/
    41 Blocked access to external URL http://example.com:389/
    42 Blocked access to external URL http://example.com:427/
    43 Blocked access to external URL http://example.com:465/
    44 Blocked access to external URL http://example.com:512/
    45 Blocked access to external URL http://example.com:513/
    46 Blocked access to external URL http://example.com:514/
    47 Blocked access to external URL http://example.com:515/
    48 Blocked access to external URL http://example.com:526/
    49 Blocked access to external URL http://example.com:530/
    50 Blocked access to external URL http://example.com:531/
    51 Blocked access to external URL http://example.com:532/
    52 Blocked access to external URL http://example.com:540/
    53 Blocked access to external URL http://example.com:548/
    54 Blocked access to external URL http://example.com:554/
    55 Blocked access to external URL http://example.com:556/
    56 Blocked access to external URL http://example.com:563/
    57 Blocked access to external URL http://example.com:587/
    58 Blocked access to external URL http://example.com:601/
    59 Blocked access to external URL http://example.com:636/
    60 Blocked access to external URL http://example.com:993/
    61 Blocked access to external URL http://example.com:995/
    62 Blocked access to external URL http://example.com:2049/
    63 Blocked access to external URL http://example.com:1719/
    64 Blocked access to external URL http://example.com:1720/
    65 Blocked access to external URL http://example.com:1723/
    66 Blocked access to external URL http://example.com:3659/
    67 Blocked access to external URL http://example.com:4045/
    68 Blocked access to external URL http://example.com:5060/
    69 Blocked access to external URL http://example.com:5061/
    70 Blocked access to external URL http://example.com:6000/
    71 Blocked access to external URL http://example.com:6566/
    72 Blocked access to external URL http://example.com:6665/
    73 Blocked access to external URL http://example.com:6666/
    74 Blocked access to external URL http://example.com:6667/
    75 Blocked access to external URL http://example.com:6668/
    76 Blocked access to external URL http://example.com:6669/
    77 Blocked access to external URL http://example.com:6697/
    78 Blocked access to external URL http://example.com:10080/
    791
    802PASS Request on bad port 1 should throw TypeError.
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-bad-port.any.worker-expected.txt

    r275831 r276193  
    1 Blocked access to external URL http://example.com:1/
    2 Blocked access to external URL http://example.com:7/
    3 Blocked access to external URL http://example.com:9/
    4 Blocked access to external URL http://example.com:11/
    5 Blocked access to external URL http://example.com:13/
    6 Blocked access to external URL http://example.com:15/
    7 Blocked access to external URL http://example.com:17/
    8 Blocked access to external URL http://example.com:19/
    9 Blocked access to external URL http://example.com:20/
    10 Blocked access to external URL http://example.com:21/
    11 Blocked access to external URL http://example.com:22/
    12 Blocked access to external URL http://example.com:23/
    13 Blocked access to external URL http://example.com:25/
    14 Blocked access to external URL http://example.com:37/
    15 Blocked access to external URL http://example.com:42/
    16 Blocked access to external URL http://example.com:43/
    17 Blocked access to external URL http://example.com:53/
    18 Blocked access to external URL http://example.com:69/
    19 Blocked access to external URL http://example.com:77/
    20 Blocked access to external URL http://example.com:79/
    21 Blocked access to external URL http://example.com:87/
    22 Blocked access to external URL http://example.com:95/
    23 Blocked access to external URL http://example.com:101/
    24 Blocked access to external URL http://example.com:102/
    25 Blocked access to external URL http://example.com:103/
    26 Blocked access to external URL http://example.com:104/
    27 Blocked access to external URL http://example.com:109/
    28 Blocked access to external URL http://example.com:110/
    29 Blocked access to external URL http://example.com:111/
    30 Blocked access to external URL http://example.com:113/
    31 Blocked access to external URL http://example.com:115/
    32 Blocked access to external URL http://example.com:117/
    33 Blocked access to external URL http://example.com:119/
    34 Blocked access to external URL http://example.com:123/
    35 Blocked access to external URL http://example.com:135/
    36 Blocked access to external URL http://example.com:137/
    37 Blocked access to external URL http://example.com:139/
    38 Blocked access to external URL http://example.com:143/
    39 Blocked access to external URL http://example.com:161/
    40 Blocked access to external URL http://example.com:179/
    41 Blocked access to external URL http://example.com:389/
    42 Blocked access to external URL http://example.com:427/
    43 Blocked access to external URL http://example.com:465/
    44 Blocked access to external URL http://example.com:512/
    45 Blocked access to external URL http://example.com:513/
    46 Blocked access to external URL http://example.com:514/
    47 Blocked access to external URL http://example.com:515/
    48 Blocked access to external URL http://example.com:526/
    49 Blocked access to external URL http://example.com:530/
    50 Blocked access to external URL http://example.com:531/
    51 Blocked access to external URL http://example.com:532/
    52 Blocked access to external URL http://example.com:540/
    53 Blocked access to external URL http://example.com:548/
    54 Blocked access to external URL http://example.com:554/
    55 Blocked access to external URL http://example.com:556/
    56 Blocked access to external URL http://example.com:563/
    57 Blocked access to external URL http://example.com:587/
    58 Blocked access to external URL http://example.com:601/
    59 Blocked access to external URL http://example.com:636/
    60 Blocked access to external URL http://example.com:993/
    61 Blocked access to external URL http://example.com:995/
    62 Blocked access to external URL http://example.com:2049/
    63 Blocked access to external URL http://example.com:1719/
    64 Blocked access to external URL http://example.com:1720/
    65 Blocked access to external URL http://example.com:1723/
    66 Blocked access to external URL http://example.com:3659/
    67 Blocked access to external URL http://example.com:4045/
    68 Blocked access to external URL http://example.com:5060/
    69 Blocked access to external URL http://example.com:5061/
    70 Blocked access to external URL http://example.com:6000/
    71 Blocked access to external URL http://example.com:6566/
    72 Blocked access to external URL http://example.com:6665/
    73 Blocked access to external URL http://example.com:6666/
    74 Blocked access to external URL http://example.com:6667/
    75 Blocked access to external URL http://example.com:6668/
    76 Blocked access to external URL http://example.com:6669/
    77 Blocked access to external URL http://example.com:6697/
    78 Blocked access to external URL http://example.com:10080/
    791
    802PASS Request on bad port 1 should throw TypeError.
  • trunk/LayoutTests/platform/mac-wk1/http/tests/xmlhttprequest/redirect-cross-origin-post-expected.txt

    r276192 r276193  
    11CONSOLE MESSAGE: Origin http://127.0.0.1:8000 is not allowed by Access-Control-Allow-Origin.
    22CONSOLE MESSAGE: XMLHttpRequest cannot load http://localhost:8000/xmlhttprequest/resources/reply.xml due to access control checks.
     3CONSOLE MESSAGE: Not allowed to use restricted network port 7: http://localhost:7/
    34Test that a cross-origin redirect to a server that responds is indistinguishable from one that does not. Should say PASS:
    45
  • trunk/LayoutTests/platform/mac-wk1/http/tests/xmlhttprequest/simple-cross-origin-denied-events-post-expected.txt

    r276192 r276193  
    22CONSOLE MESSAGE: XMLHttpRequest cannot load http://localhost:8000/xmlhttprequest/resources/reply.xml due to access control checks.
    33CONSOLE MESSAGE: CORS-preflight request was blocked
    4 CONSOLE MESSAGE: XMLHttpRequest cannot load http://localhost:7/ due to access control checks.
     4CONSOLE MESSAGE: XMLHttpRequest cannot load http://localhost:8/ due to access control checks.
    55Test that a simple cross-origin request to a server that responds (but does not permit cross-origin requests) is indistinguishable from one that does not exist. Should say PASS:
    66
  • trunk/LayoutTests/platform/win/http/tests/xmlhttprequest/redirect-cross-origin-post-expected.txt

    r276192 r276193  
    11CONSOLE MESSAGE: Origin http://127.0.0.1:8000 is not allowed by Access-Control-Allow-Origin.
    22CONSOLE MESSAGE: XMLHttpRequest cannot load http://localhost:8000/xmlhttprequest/resources/reply.xml due to access control checks.
     3CONSOLE MESSAGE: Not allowed to use restricted network port 7: http://localhost:7/
    34Test that a cross-origin redirect to a server that responds is indistinguishable from one that does not. Should say PASS:
    45
  • trunk/LayoutTests/platform/win/http/tests/xmlhttprequest/simple-cross-origin-denied-events-post-expected.txt

    r276192 r276193  
    22CONSOLE MESSAGE: XMLHttpRequest cannot load http://localhost:8000/xmlhttprequest/resources/reply.xml due to access control checks.
    33CONSOLE MESSAGE: CORS-preflight request was blocked
    4 CONSOLE MESSAGE: XMLHttpRequest cannot load http://localhost:7/ due to access control checks.
     4CONSOLE MESSAGE: XMLHttpRequest cannot load http://localhost:8/ due to access control checks.
    55Test that a simple cross-origin request to a server that responds (but does not permit cross-origin requests) is indistinguishable from one that does not exist. Should say PASS:
    66
  • trunk/LayoutTests/platform/wk2/http/tests/security/blocked-on-redirect-expected.txt

    r272981 r276193  
    11http://127.0.0.1:8000/security/blocked-on-redirect.html - didFinishLoading
    22http://127.0.0.1:8000/resources/redirect.py?code=307&url=http://localhost:25/security/resources/post-done.html - willSendRequest <NSURLRequest URL http://127.0.0.1:8000/resources/redirect.py?code=307&url=http://localhost:25/security/resources/post-done.html, main document URL http://127.0.0.1:8000/security/blocked-on-redirect.html, http method GET> redirectResponse (null)
    3 CONSOLE MESSAGE: Not allowed to use restricted network port: http://localhost:25/security/resources/post-done.html
     3CONSOLE MESSAGE: Not allowed to use restricted network port 25: http://localhost:25/security/resources/post-done.html
    44http://127.0.0.1:8000/resources/redirect.py?code=307&url=http://localhost:25/security/resources/post-done.html - didFailLoadingWithError: <NSError domain WebKitErrorDomain, code 103, failing URL "http://localhost:25/security/resources/post-done.html">
    55This test produces output in the console. Only the initial URL should be logged.
  • trunk/Source/WebCore/ChangeLog

    r276192 r276193  
     12021-04-16  Brent Fulgham  <bfulgham@apple.com>
     2
     3        Perform port blocking earlier in the load
     4        https://bugs.webkit.org/show_bug.cgi?id=224525
     5        <rdar://problem/75440591>
     6
     7        Reviewed by Darin Adler.
     8
     9        WebKit blocks loads to URLs with any of the prohibited ports defined in
     10        the engine. This blocking happens late in the load process, allowing
     11        connections to be made (and observed). Instead, we should stop the load
     12        early, at the same time we perform other checks.
     13
     14        Test: http/tests/security/form-blocked-port.html
     15
     16        * html/HTMLMediaElement.cpp:
     17        (WebCore::HTMLMediaElement::isSafeToLoadURL): Add a check for prohibited ports,
     18        and block (with relevant logging) if a load to a denied port is attempted.
     19        * loader/DocumentLoader.cpp:
     20        (WebCore::DocumentLoader::willSendRequest): Ditto.
     21        * loader/FrameLoader.cpp:
     22        (WebCore::FrameLoader::loadFrameRequest): Ditto.
     23        (WebCore::FrameLoader::reportBlockedLoadFailed): Ditto.
     24        * loader/FrameLoader.h:
     25        * loader/PingLoader.cpp:
     26        (WebCore::PingLoader::loadImage): Ditto.
     27        * loader/ResourceLoader.cpp:
     28        (WebCore::ResourceLoader::init): Ditto.
     29        * loader/SubframeLoader.cpp:
     30        (WebCore::FrameLoader::SubframeLoader::pluginIsLoadable): Ditto.
     31        (WebCore::FrameLoader::SubframeLoader::loadSubframe): Ditto.
     32        * loader/cache/CachedResourceLoader.cpp:
     33        (WebCore::CachedResourceLoader::canRequest): Ditto.
     34        (WebCore::CachedResourceLoader::canRequestAfterRedirection const): Ditto.
     35
    1362021-04-16  Basuke Suzuki  <basuke.suzuki@sony.com>
    237
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r275949 r276193  
    20152015    }
    20162016
     2017    if (!portAllowed(url)) {
     2018        if (actionIfInvalid == Complain) {
     2019            if (frame)
     2020                FrameLoader::reportBlockedLoadFailed(*frame, url);
     2021            ERROR_LOG(LOGIDENTIFIER, url , " was rejected because the port is not allowed");
     2022        }
     2023        return false;
     2024    }
     2025
    20172026    if (!isAllowedToLoadMediaURL(*this, url, isInUserAgentShadowTree())) {
    20182027        ERROR_LOG(LOGIDENTIFIER, url, " was rejected by Content Security Policy");
  • trunk/Source/WebCore/loader/DocumentLoader.cpp

    r275817 r276193  
    632632        }
    633633        if (!portAllowed(newRequest.url())) {
    634             RELEASE_LOG_IF_ALLOWED("willSendRequest: canceling - port not allowed");
    635             if (m_frame)
    636                 m_frame->document()->addConsoleMessage(MessageSource::Security, MessageLevel::Error, "Not allowed to use restricted network port: " + newRequest.url().string());
     634            RELEASE_LOG_IF_ALLOWED("willSendRequest: canceling - redirecting to a URL with a blocked port");
     635            FrameLoader::reportBlockedLoadFailed(*m_frame, newRequest.url());
    637636            cancelMainResourceLoad(frameLoader()->blockedError(newRequest));
    638637            return completionHandler(WTFMove(newRequest));
  • trunk/Source/WebCore/loader/FrameLoader.cpp

    r275078 r276193  
    12271227    ASSERT(m_frame.document());
    12281228    if (!request.requesterSecurityOrigin().canDisplay(url)) {
     1229        FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "loadFrameRequest: canceling - Not allowed to load local resource");
    12291230        reportLocalLoadFailed(&m_frame, url.stringCenterEllipsizedToLength());
    12301231        return;
    12311232    }
    12321233
     1234    if (!portAllowed(url)) {
     1235        FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "loadFrameRequest: canceling - port not allowed");
     1236        reportBlockedLoadFailed(m_frame, url);
     1237        return;
     1238    }
     1239   
    12331240    String argsReferrer = request.resourceRequest().httpReferrer();
    12341241    if (argsReferrer.isEmpty())
     
    16381645
    16391646    frame->document()->addConsoleMessage(MessageSource::Security, MessageLevel::Error, "Not allowed to load local resource: " + url);
     1647}
     1648
     1649void FrameLoader::reportBlockedLoadFailed(Frame& frame, const URL& url)
     1650{
     1651    ASSERT(!url.isEmpty());
     1652    auto message = makeString("Not allowed to use restricted network port ", url.port().value(), ": ", url.stringCenterEllipsizedToLength());
     1653    frame.document()->addConsoleMessage(MessageSource::Security, MessageLevel::Error, message);
    16401654}
    16411655
  • trunk/Source/WebCore/loader/FrameLoader.h

    r272122 r276193  
    142142
    143143    static void reportLocalLoadFailed(Frame*, const String& url);
     144    static void reportBlockedLoadFailed(Frame&, const URL&);
    144145
    145146    // FIXME: These are all functions which stop loads. We have too many.
  • trunk/Source/WebCore/loader/PingLoader.cpp

    r275078 r276193  
    9191    }
    9292
     93    if (!portAllowed(url)) {
     94        FrameLoader::reportBlockedLoadFailed(frame, url);
     95        return;
     96    }
     97
    9398    ResourceRequest request(url);
    9499#if ENABLE(CONTENT_EXTENSIONS)
  • trunk/Source/WebCore/loader/ResourceLoader.cpp

    r275563 r276193  
    149149    }
    150150
     151    if (!portAllowed(clientRequest.url())) {
     152        RELEASE_LOG_IF_ALLOWED("init: Cancelling load to a blocked port.");
     153        FrameLoader::reportBlockedLoadFailed(*m_frame, clientRequest.url());
     154        releaseResources();
     155        return completionHandler(false);
     156    }
     157
    151158    // The various plug-in implementations call directly to ResourceLoader::load() instead of piping requests
    152159    // through FrameLoader. As a result, they miss the FrameLoader::addExtraFieldsToRequest() step which sets
  • trunk/Source/WebCore/loader/SubframeLoader.cpp

    r271013 r276193  
    141141        }
    142142
     143        if (!portAllowed(url)) {
     144            FrameLoader::reportBlockedLoadFailed(m_frame, url);
     145            return false;
     146        }
     147
    143148        if (!MixedContentChecker::canRunInsecureContent(m_frame, document->securityOrigin(), url))
    144149            return false;
     
    261266    if (!document->securityOrigin().canDisplay(url)) {
    262267        FrameLoader::reportLocalLoadFailed(&m_frame, url.string());
     268        return nullptr;
     269    }
     270
     271    if (!portAllowed(url)) {
     272        FrameLoader::reportBlockedLoadFailed(m_frame, url);
    263273        return nullptr;
    264274    }
  • trunk/Source/WebCore/loader/SubresourceLoader.cpp

    r275563 r276193  
    283283        }
    284284
     285        if (!portAllowed(newRequest.url())) {
     286            RELEASE_LOG_IF_ALLOWED("willSendRequestInternal: resource load (redirect) canceled because it attempted to use a blocked port");
     287            if (m_frame)
     288                FrameLoader::reportBlockedLoadFailed(*m_frame, newRequest.url());
     289            cancel(frameLoader()->blockedError(newRequest));
     290            return completionHandler(WTFMove(newRequest));
     291        }
     292
    285293        auto accessControlCheckResult = checkRedirectionCrossOriginAccessControl(request(), redirectResponse, newRequest);
    286294        if (!accessControlCheckResult) {
  • trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp

    r273897 r276193  
    898898    }
    899899
     900    if (!portAllowed(url)) {
     901        if (forPreload == ForPreload::No)
     902            FrameLoader::reportBlockedLoadFailed(frame, url);
     903        RELEASE_LOG_IF_ALLOWED_WITH_FRAME("CachedResourceLoader::requestResource URL has a blocked port", frame);
     904        return makeUnexpected(frame.loader().blockedError(request.resourceRequest()));
     905    }
     906
    900907    request.updateReferrerPolicy(document() ? document()->referrerPolicy() : ReferrerPolicy::NoReferrerWhenDowngrade);
    901908
  • trunk/Tools/ChangeLog

    r276189 r276193  
     12021-04-16  Brent Fulgham  <bfulgham@apple.com>
     2
     3        Perform port blocking earlier in the load
     4        https://bugs.webkit.org/show_bug.cgi?id=224525
     5        <rdar://problem/75440591>
     6
     7        Reviewed by Darin Adler.
     8
     9        Update URLScheme test to use a non-prohibited port for the test. Tests of
     10        failed fetches are already handled in WPT and other tests, so using a valid
     11        port here should continue to be a valid test.
     12
     13        * TestWebKitAPI/Tests/WebKitCocoa/WKURLSchemeHandler-1.mm:
     14        (-[FrameSchemeHandler webView:startURLSchemeTask:]): Use allowed port or the test
     15        instead of 123.
     16
    1172021-04-16  Chris Dumez  <cdumez@apple.com>
    218
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKURLSchemeHandler-1.mm

    r276037 r276193  
    12541254    case 1:
    12551255        check(task, "frame://host1/main", true, "", "", "", 0);
    1256         respond(task, "<iframe src='//host2:123/iframe'></iframe>");
     1256        respond(task, "<iframe src='//host2:1234/iframe'></iframe>");
    12571257        return;
    12581258    case 2:
    1259         check(task, "frame://host2:123/iframe", false, "", "frame", "host1", 0);
     1259        check(task, "frame://host2:1234/iframe", false, "", "frame", "host1", 0);
    12601260        respond(task, "<script>fetch('subresource')</script>");
    12611261        return;
    12621262    case 3:
    1263         check(task, "frame://host2:123/subresource", false, "frame://host2:123/iframe", "frame", "host2", 123);
     1263        check(task, "frame://host2:1234/subresource", false, "frame://host2:1234/iframe", "frame", "host2", 1234);
    12641264        respond(task, "done!");
    12651265        return;
Note: See TracChangeset for help on using the changeset viewer.