Title: [294487] trunk
Revision
294487
Author
[email protected]
Date
2022-05-19 09:28:06 -0700 (Thu, 19 May 2022)

Log Message

importedScript service worker loads should not have ServiceWorker headers
https://bugs.webkit.org/show_bug.cgi?id=240571

Patch by Youenn Fablet <[email protected]> on 2022-05-19
Reviewed by Chris Dumez.

In case of update, we were reloading imported scripts with ServiceWorker header.
Prevent this as this is not as per spec.

Test: http/wpt/service-workers/update-with-importScripts.html

* Source/WebCore/workers/service/ServiceWorkerJob.cpp:
(WebCore::scriptResourceRequest):
(WebCore::ServiceWorkerJob::ImportedScriptsLoader::load):
(WebCore::ServiceWorkerJob::fetchScriptWithContext):
* Source/WebCore/workers/service/server/SWServer.cpp:
(WebCore::SWServer::createScriptRequest):
(WebCore::SWServer::startScriptFetch):
* LayoutTests/http/wpt/service-workers/resources/update-with-importScripts-script.py: Added.
(main):
* LayoutTests/http/wpt/service-workers/resources/update-with-importScripts-worker.js: Added.
* LayoutTests/http/wpt/service-workers/update-with-importScripts-expected.txt: Added.
* LayoutTests/http/wpt/service-workers/update-with-importScripts.html: Added.
* LayoutTests/platform/mac/TestExpectations:

Canonical link: https://commits.webkit.org/250746@main

Modified Paths

Added Paths

Diff

Added: trunk/LayoutTests/http/wpt/service-workers/resources/update-with-importScripts-script.py (0 => 294487)


--- trunk/LayoutTests/http/wpt/service-workers/resources/update-with-importScripts-script.py	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/service-workers/resources/update-with-importScripts-script.py	2022-05-19 16:28:06 UTC (rev 294487)
@@ -0,0 +1,9 @@
+def main(request, response):
+    service_worker_header = request.headers.get(b'service-worker')
+
+    headers = [(b'Cache-Control', b'no-cache, must-revalidate'),
+               (b'Pragma', b'no-cache'),
+               (b'Content-Type', b'application/_javascript_')]
+
+    body = b'/* This is a service worker script */\n' if service_worker_header != b'script' else b'/* Bad Request */'
+    return 200, headers, body

Added: trunk/LayoutTests/http/wpt/service-workers/resources/update-with-importScripts-worker.js (0 => 294487)


--- trunk/LayoutTests/http/wpt/service-workers/resources/update-with-importScripts-worker.js	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/service-workers/resources/update-with-importScripts-worker.js	2022-05-19 16:28:06 UTC (rev 294487)
@@ -0,0 +1,2 @@
+importScripts("update-with-importScripts-script.py");
+

Added: trunk/LayoutTests/http/wpt/service-workers/update-with-importScripts-expected.txt (0 => 294487)


--- trunk/LayoutTests/http/wpt/service-workers/update-with-importScripts-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/service-workers/update-with-importScripts-expected.txt	2022-05-19 16:28:06 UTC (rev 294487)
@@ -0,0 +1,3 @@
+
+PASS A request to fetch service worker imported script should not have a Service-Worker header
+

Added: trunk/LayoutTests/http/wpt/service-workers/update-with-importScripts.html (0 => 294487)


--- trunk/LayoutTests/http/wpt/service-workers/update-with-importScripts.html	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/service-workers/update-with-importScripts.html	2022-05-19 16:28:06 UTC (rev 294487)
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+<script src=""
+</head>
+<body>
+<script>
+promise_test(async t => {
+    const registration = await navigator.serviceWorker.register("resources/update-with-importScripts-worker.js");
+    if (registration.installing)
+        await waitForState(registration.installing, "activated");
+
+    await registration.update();
+    assert_equals(registration.installing, null);
+}, 'A request to fetch service worker imported script should not have a Service-Worker header');
+</script>
+</body>
+</html>

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerJob.cpp (294486 => 294487)


--- trunk/Source/WebCore/workers/service/ServiceWorkerJob.cpp	2022-05-19 16:06:36 UTC (rev 294486)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerJob.cpp	2022-05-19 16:28:06 UTC (rev 294487)
@@ -99,7 +99,6 @@
 {
     ResourceRequest request { url };
     request.setInitiatorIdentifier(context.resourceRequestIdentifier());
-    request.addHTTPHeaderField(HTTPHeaderName::ServiceWorker, "script"_s);
     return request;
 }
 
@@ -186,7 +185,10 @@
     auto source = m_jobData.workerType == WorkerType::Module ? WorkerScriptLoader::Source::ModuleScript : WorkerScriptLoader::Source::ClassicWorkerScript;
 
     m_scriptLoader = WorkerScriptLoader::create();
-    m_scriptLoader->loadAsynchronously(context, scriptResourceRequest(context, m_jobData.scriptURL), source, scriptFetchOptions(cachePolicy, FetchOptions::Destination::Serviceworker), ContentSecurityPolicyEnforcement::DoNotEnforce, ServiceWorkersMode::None, *this, WorkerRunLoop::defaultMode());
+    auto request = scriptResourceRequest(context, m_jobData.scriptURL);
+    request.addHTTPHeaderField(HTTPHeaderName::ServiceWorker, "script"_s);
+
+    m_scriptLoader->loadAsynchronously(context, WTFMove(request), source, scriptFetchOptions(cachePolicy, FetchOptions::Destination::Serviceworker), ContentSecurityPolicyEnforcement::DoNotEnforce, ServiceWorkersMode::None, *this, WorkerRunLoop::defaultMode());
 }
 
 ResourceError ServiceWorkerJob::validateServiceWorkerResponse(const ServiceWorkerJobData& jobData, const ResourceResponse& response)

Modified: trunk/Source/WebCore/workers/service/server/SWServer.cpp (294486 => 294487)


--- trunk/Source/WebCore/workers/service/server/SWServer.cpp	2022-05-19 16:06:36 UTC (rev 294486)
+++ trunk/Source/WebCore/workers/service/server/SWServer.cpp	2022-05-19 16:28:06 UTC (rev 294487)
@@ -523,7 +523,6 @@
     request.setFirstPartyForCookies(originURL(topOrigin));
 
     request.setHTTPHeaderField(HTTPHeaderName::Origin, origin->toString());
-    request.setHTTPHeaderField(HTTPHeaderName::ServiceWorker, "script"_s);
     request.setHTTPReferrer(originURL(origin).string());
     request.setHTTPUserAgent(serviceWorkerClientUserAgent(ClientOrigin { jobData.topOrigin, SecurityOrigin::create(jobData.scriptURL)->data() }));
     request.setPriority(ResourceLoadPriority::Low);
@@ -551,7 +550,9 @@
     if (jobData.connectionIdentifier() == Process::identifier()) {
         ASSERT(jobData.type == ServiceWorkerJobType::Update);
         // This is a soft-update job, create directly a network load to fetch the script.
-        m_softUpdateCallback(ServiceWorkerJobData { jobData }, shouldRefreshCache, createScriptRequest(jobData.scriptURL, jobData, registration), [weakThis = WeakPtr { *this }, jobDataIdentifier = jobData.identifier(), registrationKey = jobData.registrationKey()](auto&& result) {
+        auto request = createScriptRequest(jobData.scriptURL, jobData, registration);
+        request.setHTTPHeaderField(HTTPHeaderName::ServiceWorker, "script"_s);
+        m_softUpdateCallback(ServiceWorkerJobData { jobData }, shouldRefreshCache, WTFMove(request), [weakThis = WeakPtr { *this }, jobDataIdentifier = jobData.identifier(), registrationKey = jobData.registrationKey()](auto&& result) {
             if (weakThis)
                 weakThis->scriptFetchFinished(jobDataIdentifier, registrationKey, WTFMove(result));
         });
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to