Title: [226087] trunk
Revision
226087
Author
[email protected]
Date
2017-12-18 16:48:06 -0800 (Mon, 18 Dec 2017)

Log Message

We should use "error" redirect mode for fetching service worker scripts
https://bugs.webkit.org/show_bug.cgi?id=180950

Reviewed by Youenn Fablet.

LayoutTests/imported/w3c:

Rebaseline test now that behavior has changed. Note that we are still failing becuase we reject
the registration promise with a TypeError instead of a SecurityError. I cannot find any reason
to throw a SecurityError here based on the specification though, so the test may not match the
specification.

* web-platform-tests/service-workers/service-worker/registration-security-error.https-expected.txt:

Source/WebCore:

We should use "error" redirect mode for fetching service worker scripts, as per:
- https://w3c.github.io/ServiceWorker/#update (Step 7.5)

No new tests, rebaselined existing test.

* loader/SubresourceLoader.cpp:
(WebCore::SubresourceLoader::willSendRequestInternal):
* workers/Worker.cpp:
(WebCore::Worker::create):
* workers/WorkerScriptLoader.cpp:
(WebCore::WorkerScriptLoader::loadAsynchronously):
* workers/WorkerScriptLoader.h:
* workers/service/ServiceWorkerJob.cpp:
(WebCore::ServiceWorkerJob::fetchScriptWithContext):

Modified Paths

Diff

Modified: trunk/LayoutTests/TestExpectations (226086 => 226087)


--- trunk/LayoutTests/TestExpectations	2017-12-19 00:28:44 UTC (rev 226086)
+++ trunk/LayoutTests/TestExpectations	2017-12-19 00:48:06 UTC (rev 226087)
@@ -207,6 +207,8 @@
 imported/w3c/web-platform-tests/workers/constructors/SharedWorker [ Skip ]
 imported/w3c/web-platform-tests/workers/SharedWorker_blobUrl.html [ Skip ]
 
+imported/w3c/web-platform-tests/fetch/api/redirect/redirect-mode.html [ DumpJSConsoleLogInStdErr ]
+
 # textarea.animate is not supported
 imported/w3c/web-platform-tests/css/css-ui-3/caret-color-018.html [ Skip ]
 imported/w3c/web-platform-tests/css/css-ui-3/caret-color-019.html [ Skip ]

Modified: trunk/LayoutTests/http/tests/fetch/redirectmode-and-preload-expected.txt (226086 => 226087)


--- trunk/LayoutTests/http/tests/fetch/redirectmode-and-preload-expected.txt	2017-12-19 00:28:44 UTC (rev 226086)
+++ trunk/LayoutTests/http/tests/fetch/redirectmode-and-preload-expected.txt	2017-12-19 00:48:06 UTC (rev 226087)
@@ -1,3 +1,5 @@
+CONSOLE MESSAGE: Fetch API cannot load http://127.0.0.1:8000/fetch/resources/redirect-with-cache.php?enableCaching&url="" Redirections are not allowed
+CONSOLE MESSAGE: Fetch API cannot load http://127.0.0.1:8000/fetch/resources/redirect-with-cache.php?enableCaching&url="" Redirections are not allowed
 
 PASS Fetch should check for redirections even if resource is preloaded (same fetch options except for redirect mode) 
 PASS Fetch should check for redirections even if resource is preloaded (different fetch mode, different redirect mode) 

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (226086 => 226087)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2017-12-19 00:28:44 UTC (rev 226086)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2017-12-19 00:48:06 UTC (rev 226087)
@@ -1,5 +1,19 @@
 2017-12-18  Chris Dumez  <[email protected]>
 
+        We should use "error" redirect mode for fetching service worker scripts
+        https://bugs.webkit.org/show_bug.cgi?id=180950
+
+        Reviewed by Youenn Fablet.
+
+        Rebaseline test now that behavior has changed. Note that we are still failing becuase we reject
+        the registration promise with a TypeError instead of a SecurityError. I cannot find any reason
+        to throw a SecurityError here based on the specification though, so the test may not match the
+        specification.
+
+        * web-platform-tests/service-workers/service-worker/registration-security-error.https-expected.txt:
+
+2017-12-18  Chris Dumez  <[email protected]>
+
         ExtendableMessageEvent constructor fails to initialize the 'source' attribute
         https://bugs.webkit.org/show_bug.cgi?id=180954
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/registration-security-error.https-expected.txt (226086 => 226087)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/registration-security-error.https-expected.txt	2017-12-19 00:28:44 UTC (rev 226086)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/registration-security-error.https-expected.txt	2017-12-19 00:48:06 UTC (rev 226087)
@@ -3,7 +3,7 @@
 FAIL Registration scope outside the script directory assert_unreached: Should have rejected: Registration scope outside the script directory should fail with SecurityError. Reached unreachable code
 PASS Registering scope outside domain 
 PASS Registering script outside domain 
-FAIL Registering redirected script assert_throws: Registration of redirected script should fail. function "function () { throw e }" threw object "TypeError: Script URL https://localhost:9443/service-workers/service-worker/resources/redirect.py?Redirect=%2Fresources%2Fregistration-worker.js fetch resulted in error: Failed to load script" that is not a DOMException SecurityError: property "code" is equal to undefined, expected 18
+FAIL Registering redirected script assert_throws: Registration of redirected script should fail. function "function () { throw e }" threw object "TypeError: Script URL https://localhost:9443/service-workers/service-worker/resources/redirect.py?Redirect=%2Fresources%2Fregistration-worker.js fetch resulted in error: Redirections are not allowed" that is not a DOMException SecurityError: property "code" is equal to undefined, expected 18
 FAIL Scope including parent-reference and not under the script directory assert_unreached: Should have rejected: Scope not under the script directory should be rejected. Reached unreachable code
 FAIL Script URL including consecutive slashes assert_unreached: Should have rejected: Consecutive slashes in the script url should not be unified. Reached unreachable code
 FAIL Script URL is same-origin filesystem: URL assert_throws: Registering a script which has same-origin filesystem: URL should fail with SecurityError. function "function () { throw e }" threw object "TypeError: serviceWorker.register() must be called with a script URL whose protocol is either HTTP or HTTPS" that is not a DOMException SecurityError: property "code" is equal to undefined, expected 18

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/registration-tests-security-error.js (226086 => 226087)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/registration-tests-security-error.js	2017-12-19 00:28:44 UTC (rev 226086)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/resources/registration-tests-security-error.js	2017-12-19 00:48:06 UTC (rev 226087)
@@ -40,7 +40,7 @@
 
   promise_test(function(t) {
       var script = 'resources/redirect.py?Redirect=' +
-                    encodeURIComponent('/resources/registration-worker.js');
+                    encodeURIComponent('/service-workers/service-worker/resources/registration-worker.js');
       var scope = 'resources/scope/redirect/';
       return promise_rejects(t,
           check_error_types ? 'SecurityError' : null,

Modified: trunk/Source/WebCore/ChangeLog (226086 => 226087)


--- trunk/Source/WebCore/ChangeLog	2017-12-19 00:28:44 UTC (rev 226086)
+++ trunk/Source/WebCore/ChangeLog	2017-12-19 00:48:06 UTC (rev 226087)
@@ -1,5 +1,27 @@
 2017-12-18  Chris Dumez  <[email protected]>
 
+        We should use "error" redirect mode for fetching service worker scripts
+        https://bugs.webkit.org/show_bug.cgi?id=180950
+
+        Reviewed by Youenn Fablet.
+
+        We should use "error" redirect mode for fetching service worker scripts, as per:
+        - https://w3c.github.io/ServiceWorker/#update (Step 7.5)
+
+        No new tests, rebaselined existing test.
+
+        * loader/SubresourceLoader.cpp:
+        (WebCore::SubresourceLoader::willSendRequestInternal):
+        * workers/Worker.cpp:
+        (WebCore::Worker::create):
+        * workers/WorkerScriptLoader.cpp:
+        (WebCore::WorkerScriptLoader::loadAsynchronously):
+        * workers/WorkerScriptLoader.h:
+        * workers/service/ServiceWorkerJob.cpp:
+        (WebCore::ServiceWorkerJob::fetchScriptWithContext):
+
+2017-12-18  Chris Dumez  <[email protected]>
+
         ExtendableMessageEvent constructor fails to initialize the 'source' attribute
         https://bugs.webkit.org/show_bug.cgi?id=180954
 

Modified: trunk/Source/WebCore/loader/SubresourceLoader.cpp (226086 => 226087)


--- trunk/Source/WebCore/loader/SubresourceLoader.cpp	2017-12-19 00:28:44 UTC (rev 226086)
+++ trunk/Source/WebCore/loader/SubresourceLoader.cpp	2017-12-19 00:48:06 UTC (rev 226087)
@@ -206,7 +206,7 @@
     if (!redirectResponse.isNull()) {
         if (options().redirect != FetchOptions::Redirect::Follow) {
             if (options().redirect == FetchOptions::Redirect::Error) {
-                cancel();
+                cancel(ResourceError { errorDomainWebKitInternal, 0, redirectResponse.url(), "Redirections are not allowed", ResourceError::Type::AccessControl });
                 return completionHandler(WTFMove(newRequest));
             }
 

Modified: trunk/Source/WebCore/workers/Worker.cpp (226086 => 226087)


--- trunk/Source/WebCore/workers/Worker.cpp	2017-12-19 00:28:44 UTC (rev 226086)
+++ trunk/Source/WebCore/workers/Worker.cpp	2017-12-19 00:48:06 UTC (rev 226087)
@@ -101,7 +101,7 @@
 
     ResourceRequest request { scriptURL.releaseReturnValue() };
     request.setInitiatorIdentifier(worker->m_identifier);
-    worker->m_scriptLoader->loadAsynchronously(context, WTFMove(request), FetchOptions::Mode::SameOrigin, FetchOptions::Cache::Default, contentSecurityPolicyEnforcement, worker);
+    worker->m_scriptLoader->loadAsynchronously(context, WTFMove(request), FetchOptions::Mode::SameOrigin, FetchOptions::Cache::Default, FetchOptions::Redirect::Follow, contentSecurityPolicyEnforcement, worker);
     return WTFMove(worker);
 }
 

Modified: trunk/Source/WebCore/workers/WorkerScriptLoader.cpp (226086 => 226087)


--- trunk/Source/WebCore/workers/WorkerScriptLoader.cpp	2017-12-19 00:28:44 UTC (rev 226086)
+++ trunk/Source/WebCore/workers/WorkerScriptLoader.cpp	2017-12-19 00:48:06 UTC (rev 226087)
@@ -73,7 +73,7 @@
     WorkerThreadableLoader::loadResourceSynchronously(workerGlobalScope, WTFMove(*request), *this, options);
 }
 
-void WorkerScriptLoader::loadAsynchronously(ScriptExecutionContext& scriptExecutionContext, ResourceRequest&& scriptRequest, FetchOptions::Mode mode, FetchOptions::Cache cachePolicy, ContentSecurityPolicyEnforcement contentSecurityPolicyEnforcement, WorkerScriptLoaderClient& client)
+void WorkerScriptLoader::loadAsynchronously(ScriptExecutionContext& scriptExecutionContext, ResourceRequest&& scriptRequest, FetchOptions::Mode mode, FetchOptions::Cache cachePolicy, FetchOptions::Redirect redirectPolicy, ContentSecurityPolicyEnforcement contentSecurityPolicyEnforcement, WorkerScriptLoaderClient& client)
 {
     m_client = &client;
     m_url = scriptRequest.url();
@@ -92,6 +92,7 @@
     options.credentials = FetchOptions::Credentials::SameOrigin;
     options.mode = mode;
     options.cache = cachePolicy;
+    options.redirect = redirectPolicy;
     options.sendLoadCallbacks = SendCallbacks;
     options.contentSecurityPolicyEnforcement = contentSecurityPolicyEnforcement;
 #if ENABLE(SERVICE_WORKER)

Modified: trunk/Source/WebCore/workers/WorkerScriptLoader.h (226086 => 226087)


--- trunk/Source/WebCore/workers/WorkerScriptLoader.h	2017-12-19 00:28:44 UTC (rev 226086)
+++ trunk/Source/WebCore/workers/WorkerScriptLoader.h	2017-12-19 00:48:06 UTC (rev 226087)
@@ -53,7 +53,7 @@
     }
 
     void loadSynchronously(ScriptExecutionContext*, const URL&, FetchOptions::Mode, FetchOptions::Cache, ContentSecurityPolicyEnforcement, const String& initiatorIdentifier);
-    void loadAsynchronously(ScriptExecutionContext&, ResourceRequest&&, FetchOptions::Mode, FetchOptions::Cache, ContentSecurityPolicyEnforcement, WorkerScriptLoaderClient&);
+    void loadAsynchronously(ScriptExecutionContext&, ResourceRequest&&, FetchOptions::Mode, FetchOptions::Cache, FetchOptions::Redirect, ContentSecurityPolicyEnforcement, WorkerScriptLoaderClient&);
 
     void notifyError();
 

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerJob.cpp (226086 => 226087)


--- trunk/Source/WebCore/workers/service/ServiceWorkerJob.cpp	2017-12-19 00:28:44 UTC (rev 226086)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerJob.cpp	2017-12-19 00:48:06 UTC (rev 226087)
@@ -97,7 +97,7 @@
     request.setInitiatorIdentifier("serviceWorkerScriptLoad:");
     request.addHTTPHeaderField(ASCIILiteral("Service-Worker"), ASCIILiteral("script"));
 
-    m_scriptLoader->loadAsynchronously(context, WTFMove(request), FetchOptions::Mode::SameOrigin, cachePolicy, ContentSecurityPolicyEnforcement::DoNotEnforce, *this);
+    m_scriptLoader->loadAsynchronously(context, WTFMove(request), FetchOptions::Mode::SameOrigin, cachePolicy, FetchOptions::Redirect::Error, ContentSecurityPolicyEnforcement::DoNotEnforce, *this);
 }
 
 void ServiceWorkerJob::didReceiveResponse(unsigned long, const ResourceResponse& response)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to