Title: [293607] trunk
Revision
293607
Author
[email protected]
Date
2022-04-29 00:14:29 -0700 (Fri, 29 Apr 2022)

Log Message

Make sure to fail importScripts as per https://w3c.github.io/ServiceWorker/#importscripts step 4
https://bugs.webkit.org/show_bug.cgi?id=239847

Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

* web-platform-tests/service-workers/service-worker/import-scripts-updated-flag.https-expected.txt:

Source/WebCore:

Once a service worker is installed, the service worker should not be able to call importScript on new URLs.
Covered by updated test.

* workers/WorkerScriptLoader.cpp:

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (293606 => 293607)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2022-04-29 05:18:09 UTC (rev 293606)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2022-04-29 07:14:29 UTC (rev 293607)
@@ -1,3 +1,12 @@
+2022-04-29  Youenn Fablet  <[email protected]>
+
+        Make sure to fail importScripts as per https://w3c.github.io/ServiceWorker/#importscripts step 4
+        https://bugs.webkit.org/show_bug.cgi?id=239847
+
+        Reviewed by Chris Dumez.
+
+        * web-platform-tests/service-workers/service-worker/import-scripts-updated-flag.https-expected.txt:
+
 2022-04-28  Oriol Brufau  <[email protected]>
 
         [css-cascade] Mark properties sharing a computed value as related

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/import-scripts-updated-flag.https-expected.txt (293606 => 293607)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/import-scripts-updated-flag.https-expected.txt	2022-04-29 05:18:09 UTC (rev 293606)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/import-scripts-updated-flag.https-expected.txt	2022-04-29 07:14:29 UTC (rev 293607)
@@ -2,6 +2,6 @@
 PASS initialize global state
 PASS import script previously imported at worker evaluation time
 PASS import script previously imported at worker install time
-FAIL import script not previously imported assert_equals: expected (string) "NetworkError" but got (object) null
+PASS import script not previously imported
 PASS Tests for importScripts: import scripts updated flag
 

Modified: trunk/Source/WebCore/ChangeLog (293606 => 293607)


--- trunk/Source/WebCore/ChangeLog	2022-04-29 05:18:09 UTC (rev 293606)
+++ trunk/Source/WebCore/ChangeLog	2022-04-29 07:14:29 UTC (rev 293607)
@@ -1,3 +1,15 @@
+2022-04-29  Youenn Fablet  <[email protected]>
+
+        Make sure to fail importScripts as per https://w3c.github.io/ServiceWorker/#importscripts step 4
+        https://bugs.webkit.org/show_bug.cgi?id=239847
+
+        Reviewed by Chris Dumez.
+
+        Once a service worker is installed, the service worker should not be able to call importScript on new URLs.
+        Covered by updated test.
+
+        * workers/WorkerScriptLoader.cpp:
+
 2022-04-28  Alex Christensen  <[email protected]>
 
         afterprint event should be scheduled on event loop

Modified: trunk/Source/WebCore/workers/WorkerScriptLoader.cpp (293606 => 293607)


--- trunk/Source/WebCore/workers/WorkerScriptLoader.cpp	2022-04-29 05:18:09 UTC (rev 293606)
+++ trunk/Source/WebCore/workers/WorkerScriptLoader.cpp	2022-04-29 07:14:29 UTC (rev 293607)
@@ -82,15 +82,17 @@
     m_isCOEPEnabled = scriptExecutionContext->settingsValues().crossOriginEmbedderPolicyEnabled;
 
 #if ENABLE(SERVICE_WORKER)
-    bool isServiceWorkerGlobalScope = is<ServiceWorkerGlobalScope>(workerGlobalScope);
-
-    if (isServiceWorkerGlobalScope) {
-        if (auto* scriptResource = downcast<ServiceWorkerGlobalScope>(workerGlobalScope).scriptResource(url)) {
+    auto* serviceWorkerGlobalScope = dynamicDowncast<ServiceWorkerGlobalScope>(workerGlobalScope);
+    if (serviceWorkerGlobalScope) {
+        if (auto* scriptResource = serviceWorkerGlobalScope->scriptResource(url)) {
             m_script = scriptResource->script;
             m_responseURL = scriptResource->responseURL;
             m_responseMIMEType = scriptResource->mimeType;
             return std::nullopt;
         }
+        auto state = serviceWorkerGlobalScope->serviceWorker().state();
+        if (state != ServiceWorkerState::Parsed && state != ServiceWorkerState::Installing)
+            return Exception { NetworkError, "Importing a script from a service worker that is past installing state"_s };
     }
 #endif
 
@@ -119,11 +121,11 @@
         return Exception { NetworkError, m_error.sanitizedDescription() };
 
 #if ENABLE(SERVICE_WORKER)
-    if (isServiceWorkerGlobalScope) {
+    if (serviceWorkerGlobalScope) {
         if (!MIMETypeRegistry::isSupportedJavaScriptMIMEType(responseMIMEType()))
             return Exception { NetworkError, "mime type is not a supported _javascript_ mime type"_s };
 
-        downcast<ServiceWorkerGlobalScope>(workerGlobalScope).setScriptResource(url, ServiceWorkerContextData::ImportedScript { script(), m_responseURL, m_responseMIMEType });
+        serviceWorkerGlobalScope->setScriptResource(url, ServiceWorkerContextData::ImportedScript { script(), m_responseURL, m_responseMIMEType });
     }
 #endif
     return std::nullopt;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to