Title: [287633] branches/safari-612-branch
Revision
287633
Author
[email protected]
Date
2022-01-05 10:21:25 -0800 (Wed, 05 Jan 2022)

Log Message

Cherry-pick r287353. rdar://problem/87125345

    Use requester when calling updateRequestAndAddExtraFields
    https://bugs.webkit.org/show_bug.cgi?id=234507
    <rdar://problem/85049490>

    Reviewed by Brent Fulgham.

    Source/WebCore:

    In case of navigation loads, the requester is the fetch request client.
    As such, it should be the one used to determine whether the request is cross-origin is not.
    Pass the requester to updateRequestAndAddExtraFields to do the correct computation.
    Validate that some request fields are now correctly observed in service workers.

    Test: http/wpt/service-workers/navigation-iframe-site.https.html

    * loader/FrameLoader.cpp:
    * loader/FrameLoader.h:
    * testing/ServiceWorkerInternals.cpp:
    * testing/ServiceWorkerInternals.h:
    * testing/ServiceWorkerInternals.idl:

    LayoutTests:

    * http/wpt/service-workers/navigation-iframe-site-worker.js: Added.
    * http/wpt/service-workers/navigation-iframe-site.https-expected.txt: Added.
    * http/wpt/service-workers/navigation-iframe-site.https.html: Added.
    * http/wpt/service-workers/resources/navigation-iframe-site-frame.html: Added.

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@287353 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Added Paths

Diff

Modified: branches/safari-612-branch/LayoutTests/ChangeLog (287632 => 287633)


--- branches/safari-612-branch/LayoutTests/ChangeLog	2022-01-05 18:21:20 UTC (rev 287632)
+++ branches/safari-612-branch/LayoutTests/ChangeLog	2022-01-05 18:21:25 UTC (rev 287633)
@@ -1,5 +1,52 @@
 2022-01-05  Russell Epstein  <[email protected]>
 
+        Cherry-pick r287353. rdar://problem/87125345
+
+    Use requester when calling updateRequestAndAddExtraFields
+    https://bugs.webkit.org/show_bug.cgi?id=234507
+    <rdar://problem/85049490>
+    
+    Reviewed by Brent Fulgham.
+    
+    Source/WebCore:
+    
+    In case of navigation loads, the requester is the fetch request client.
+    As such, it should be the one used to determine whether the request is cross-origin is not.
+    Pass the requester to updateRequestAndAddExtraFields to do the correct computation.
+    Validate that some request fields are now correctly observed in service workers.
+    
+    Test: http/wpt/service-workers/navigation-iframe-site.https.html
+    
+    * loader/FrameLoader.cpp:
+    * loader/FrameLoader.h:
+    * testing/ServiceWorkerInternals.cpp:
+    * testing/ServiceWorkerInternals.h:
+    * testing/ServiceWorkerInternals.idl:
+    
+    LayoutTests:
+    
+    * http/wpt/service-workers/navigation-iframe-site-worker.js: Added.
+    * http/wpt/service-workers/navigation-iframe-site.https-expected.txt: Added.
+    * http/wpt/service-workers/navigation-iframe-site.https.html: Added.
+    * http/wpt/service-workers/resources/navigation-iframe-site-frame.html: Added.
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@287353 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-12-22  Youenn Fablet  <[email protected]>
+
+            Use requester when calling updateRequestAndAddExtraFields
+            https://bugs.webkit.org/show_bug.cgi?id=234507
+            <rdar://problem/85049490>
+
+            Reviewed by Brent Fulgham.
+
+            * http/wpt/service-workers/navigation-iframe-site-worker.js: Added.
+            * http/wpt/service-workers/navigation-iframe-site.https-expected.txt: Added.
+            * http/wpt/service-workers/navigation-iframe-site.https.html: Added.
+            * http/wpt/service-workers/resources/navigation-iframe-site-frame.html: Added.
+
+2022-01-05  Russell Epstein  <[email protected]>
+
         Cherry-pick r285710. rdar://problem/87125070
 
     REGRESSION(r285624) Using revert keyword with a css variable hits assert

Added: branches/safari-612-branch/LayoutTests/http/wpt/service-workers/navigation-iframe-site-worker.js (0 => 287633)


--- branches/safari-612-branch/LayoutTests/http/wpt/service-workers/navigation-iframe-site-worker.js	                        (rev 0)
+++ branches/safari-612-branch/LayoutTests/http/wpt/service-workers/navigation-iframe-site-worker.js	2022-01-05 18:21:25 UTC (rev 287633)
@@ -0,0 +1,11 @@
+addEventListener("message", (e) => {
+    self.port = e.data.port;
+});
+
+addEventListener("fetch", (e) => {
+    if (self.internals) {
+        self.port.postMessage(self.internals.fetchEventIsSameSite(e) ? "FAIL" : "PASS");
+        return;
+    }
+    self.port.postMessage("PASS");
+});

Added: branches/safari-612-branch/LayoutTests/http/wpt/service-workers/navigation-iframe-site.https-expected.txt (0 => 287633)


--- branches/safari-612-branch/LayoutTests/http/wpt/service-workers/navigation-iframe-site.https-expected.txt	                        (rev 0)
+++ branches/safari-612-branch/LayoutTests/http/wpt/service-workers/navigation-iframe-site.https-expected.txt	2022-01-05 18:21:25 UTC (rev 287633)
@@ -0,0 +1,5 @@
+
+PASS Setup worker
+PASS Validate worker gets right request after navigation
+PASS Validate worker gets right request after post navigation
+

Added: branches/safari-612-branch/LayoutTests/http/wpt/service-workers/navigation-iframe-site.https.html (0 => 287633)


--- branches/safari-612-branch/LayoutTests/http/wpt/service-workers/navigation-iframe-site.https.html	                        (rev 0)
+++ branches/safari-612-branch/LayoutTests/http/wpt/service-workers/navigation-iframe-site.https.html	2022-01-05 18:21:25 UTC (rev 287633)
@@ -0,0 +1,68 @@
+<html>
+<head>
+<title>Service Worker Fetch Event</title>
+<script src=""
+<script src=""
+</head>
+<body>
+<script>
+var scope = "resources/";
+var registration;
+const channel = new MessageChannel;
+
+function withFrame(url)
+{
+    return new Promise((resolve) => {
+        let frame = document.createElement('iframe');
+        frame.src = ""
+        frame._onload_ = function() { resolve(frame); };
+        document.body.appendChild(frame);
+    });
+}
+
+async function registerServiceWorker(scope)
+{
+    var registration = await navigator.serviceWorker.register("navigation-iframe-site-worker.js", { scope : scope });
+    var activeWorker = registration.active;
+    if (activeWorker) {
+        activeWorker.postMessage({ port: channel.port1 }, [channel.port1]);
+        return;
+    }
+    activeWorker = registration.installing;
+    activeWorker.postMessage({ port: channel.port1 }, [channel.port1]);
+    return new Promise(resolve => {
+        activeWorker.addEventListener('statechange', () => {
+            if (activeWorker.state === "activated")
+                resolve(registration);
+        });
+    });
+}
+
+promise_test(async (test) => {
+    registration = await registerServiceWorker(scope);
+}, "Setup worker");
+
+promise_test(async (test) => {
+    const resultPromise = new Promise(resolve => channel.port2._onmessage_ = (event) => resolve(event.data));
+
+    // Cross-origin iframe that will redirect to iframe that will be controlled by registered service worker.
+    const framePromise = withFrame("https://127.0.0.1:9443/WebKit/service-workers/resources/navigation-iframe-site-frame.html");
+
+    assert_equals(await resultPromise, "PASS");
+    const frame = await framePromise;
+    frame.remove();
+}, "Validate worker gets right request after navigation");
+
+promise_test(async (test) => {
+    const resultPromise = new Promise(resolve => channel.port2._onmessage_ = (event) => resolve(event.data));
+
+    // Cross-origin iframe that will redirect to iframe that will be controlled by registered service worker through POST.
+    const framePromise = withFrame("https://127.0.0.1:9443/WebKit/service-workers/resources/navigation-iframe-site-frame.html?post");
+
+    assert_equals(await resultPromise, "PASS");
+    const frame = await framePromise;
+    frame.remove();
+}, "Validate worker gets right request after post navigation");
+</script>
+</body>
+</html>

Added: branches/safari-612-branch/LayoutTests/http/wpt/service-workers/resources/navigation-iframe-site-frame.html (0 => 287633)


--- branches/safari-612-branch/LayoutTests/http/wpt/service-workers/resources/navigation-iframe-site-frame.html	                        (rev 0)
+++ branches/safari-612-branch/LayoutTests/http/wpt/service-workers/resources/navigation-iframe-site-frame.html	2022-01-05 18:21:25 UTC (rev 287633)
@@ -0,0 +1,13 @@
+<form method="post" id="myForm" action=""
+<script>
+function doTest()
+{
+    if (window.location.search !== "?post") {
+        window.location = "https://localhost:9443/WebKit/service-workers/resources/";
+        return;
+    }
+    myForm.submit();
+}
+
+doTest();
+</script>

Modified: branches/safari-612-branch/Source/WebCore/ChangeLog (287632 => 287633)


--- branches/safari-612-branch/Source/WebCore/ChangeLog	2022-01-05 18:21:20 UTC (rev 287632)
+++ branches/safari-612-branch/Source/WebCore/ChangeLog	2022-01-05 18:21:25 UTC (rev 287633)
@@ -1,5 +1,60 @@
 2022-01-05  Russell Epstein  <[email protected]>
 
+        Cherry-pick r287353. rdar://problem/87125345
+
+    Use requester when calling updateRequestAndAddExtraFields
+    https://bugs.webkit.org/show_bug.cgi?id=234507
+    <rdar://problem/85049490>
+    
+    Reviewed by Brent Fulgham.
+    
+    Source/WebCore:
+    
+    In case of navigation loads, the requester is the fetch request client.
+    As such, it should be the one used to determine whether the request is cross-origin is not.
+    Pass the requester to updateRequestAndAddExtraFields to do the correct computation.
+    Validate that some request fields are now correctly observed in service workers.
+    
+    Test: http/wpt/service-workers/navigation-iframe-site.https.html
+    
+    * loader/FrameLoader.cpp:
+    * loader/FrameLoader.h:
+    * testing/ServiceWorkerInternals.cpp:
+    * testing/ServiceWorkerInternals.h:
+    * testing/ServiceWorkerInternals.idl:
+    
+    LayoutTests:
+    
+    * http/wpt/service-workers/navigation-iframe-site-worker.js: Added.
+    * http/wpt/service-workers/navigation-iframe-site.https-expected.txt: Added.
+    * http/wpt/service-workers/navigation-iframe-site.https.html: Added.
+    * http/wpt/service-workers/resources/navigation-iframe-site-frame.html: Added.
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@287353 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-12-22  Youenn Fablet  <[email protected]>
+
+            Use requester when calling updateRequestAndAddExtraFields
+            https://bugs.webkit.org/show_bug.cgi?id=234507
+            <rdar://problem/85049490>
+
+            Reviewed by Brent Fulgham.
+
+            In case of navigation loads, the requester is the fetch request client.
+            As such, it should be the one used to determine whether the request is cross-origin is not.
+            Pass the requester to updateRequestAndAddExtraFields to do the correct computation.
+            Validate that some request fields are now correctly observed in service workers.
+
+            Test: http/wpt/service-workers/navigation-iframe-site.https.html
+
+            * loader/FrameLoader.cpp:
+            * loader/FrameLoader.h:
+            * testing/ServiceWorkerInternals.cpp:
+            * testing/ServiceWorkerInternals.h:
+            * testing/ServiceWorkerInternals.idl:
+
+2022-01-05  Russell Epstein  <[email protected]>
+
         Cherry-pick r287286. rdar://problem/87124952
 
     Don't include SVGImageForContainers in allCachedSVGImages

Modified: branches/safari-612-branch/Source/WebCore/loader/FrameLoader.cpp (287632 => 287633)


--- branches/safari-612-branch/Source/WebCore/loader/FrameLoader.cpp	2022-01-05 18:21:20 UTC (rev 287632)
+++ branches/safari-612-branch/Source/WebCore/loader/FrameLoader.cpp	2022-01-05 18:21:25 UTC (rev 287633)
@@ -1356,7 +1356,7 @@
     if (!referrer.isEmpty())
         request.setHTTPReferrer(referrer);
 
-    updateRequestAndAddExtraFields(request, IsMainResource::Yes, newLoadType);
+    updateRequestAndAddExtraFields(request, IsMainResource::Yes, newLoadType, ShouldUpdateAppInitiatedValue::Yes, FrameLoader::IsServiceWorkerNavigationLoad::No, &frameLoadRequest.requester());
 
     ASSERT(newLoadType != FrameLoadType::Same);
 
@@ -2905,7 +2905,7 @@
     return ResourceRequestCachePolicy::UseProtocolCachePolicy;
 }
 
-void FrameLoader::updateRequestAndAddExtraFields(ResourceRequest& request, IsMainResource mainResource, FrameLoadType loadType, ShouldUpdateAppInitiatedValue shouldUpdate)
+void FrameLoader::updateRequestAndAddExtraFields(ResourceRequest& request, IsMainResource mainResource, FrameLoadType loadType, ShouldUpdateAppInitiatedValue shouldUpdate, Document* initiator)
 {
     // If the request came from a previous process due to process-swap-on-navigation then we should not modify the request.
     if (m_currentLoadContinuingState == LoadContinuingState::ContinuingWithRequest)
@@ -2923,14 +2923,16 @@
     }
 
     if (request.isSameSiteUnspecified()) {
-        auto* initiator = m_frame.document();
-        if (isMainResource) {
-            auto* ownerFrame = m_frame.tree().parent();
-            if (!ownerFrame && m_stateMachine.isDisplayingInitialEmptyDocument())
-                ownerFrame = m_opener.get();
-            if (ownerFrame)
-                initiator = ownerFrame->document();
-            ASSERT(ownerFrame || m_frame.isMainFrame());
+        if (!initiator) {
+            initiator = m_frame.document();
+            if (isMainResource) {
+                auto* ownerFrame = m_frame.tree().parent();
+                if (!ownerFrame && m_stateMachine.isDisplayingInitialEmptyDocument())
+                    ownerFrame = m_opener.get();
+                if (ownerFrame)
+                    initiator = ownerFrame->document();
+                ASSERT(ownerFrame || m_frame.isMainFrame());
+            }
         }
         addSameSiteInfoToRequestIfNeeded(request, initiator);
     }
@@ -3064,7 +3066,7 @@
     workingResourceRequest.setHTTPMethod("POST");
     workingResourceRequest.setHTTPBody(inRequest.httpBody());
     workingResourceRequest.setHTTPContentType(contentType);
-    updateRequestAndAddExtraFields(workingResourceRequest, IsMainResource::Yes, loadType);
+    updateRequestAndAddExtraFields(workingResourceRequest, IsMainResource::Yes, loadType, ShouldUpdateAppInitiatedValue::Yes, FrameLoader::IsServiceWorkerNavigationLoad::No, &request.requester());
 
     if (Document* document = m_frame.document())
         document->contentSecurityPolicy()->upgradeInsecureRequestIfNeeded(workingResourceRequest, ContentSecurityPolicy::InsecureRequestType::Load);

Modified: branches/safari-612-branch/Source/WebCore/loader/FrameLoader.h (287632 => 287633)


--- branches/safari-612-branch/Source/WebCore/loader/FrameLoader.h	2022-01-05 18:21:20 UTC (rev 287632)
+++ branches/safari-612-branch/Source/WebCore/loader/FrameLoader.h	2022-01-05 18:21:25 UTC (rev 287633)
@@ -318,7 +318,7 @@
     bool alwaysAllowLocalWebarchive() const { return m_alwaysAllowLocalWebarchive; }
 
     // For subresource requests the FrameLoadType parameter has no effect and can be skipped.
-    void updateRequestAndAddExtraFields(ResourceRequest&, IsMainResource, FrameLoadType = FrameLoadType::Standard, ShouldUpdateAppInitiatedValue = ShouldUpdateAppInitiatedValue::Yes);
+    void updateRequestAndAddExtraFields(ResourceRequest&, IsMainResource, FrameLoadType = FrameLoadType::Standard, ShouldUpdateAppInitiatedValue = ShouldUpdateAppInitiatedValue::Yes, Document* = nullptr);
 
     void scheduleRefreshIfNeeded(Document&, const String& content, IsMetaRefresh);
 

Modified: branches/safari-612-branch/Source/WebCore/testing/ServiceWorkerInternals.cpp (287632 => 287633)


--- branches/safari-612-branch/Source/WebCore/testing/ServiceWorkerInternals.cpp	2022-01-05 18:21:20 UTC (rev 287632)
+++ branches/safari-612-branch/Source/WebCore/testing/ServiceWorkerInternals.cpp	2022-01-05 18:21:25 UTC (rev 287633)
@@ -136,6 +136,11 @@
     });
 }
 
+bool ServiceWorkerInternals::fetchEventIsSameSite(FetchEvent& event)
+{
+    return event.request().internalRequest().isSameSite();
+}
+
 } // namespace WebCore
 
 #endif

Modified: branches/safari-612-branch/Source/WebCore/testing/ServiceWorkerInternals.h (287632 => 287633)


--- branches/safari-612-branch/Source/WebCore/testing/ServiceWorkerInternals.h	2022-01-05 18:21:20 UTC (rev 287632)
+++ branches/safari-612-branch/Source/WebCore/testing/ServiceWorkerInternals.h	2022-01-05 18:21:25 UTC (rev 287633)
@@ -62,6 +62,8 @@
 
     void lastNavigationWasAppInitiated(Ref<DeferredPromise>&&);
 
+    bool fetchEventIsSameSite(FetchEvent&);
+
 private:
     explicit ServiceWorkerInternals(ServiceWorkerIdentifier);
 

Modified: branches/safari-612-branch/Source/WebCore/testing/ServiceWorkerInternals.idl (287632 => 287633)


--- branches/safari-612-branch/Source/WebCore/testing/ServiceWorkerInternals.idl	2022-01-05 18:21:20 UTC (rev 287632)
+++ branches/safari-612-branch/Source/WebCore/testing/ServiceWorkerInternals.idl	2022-01-05 18:21:25 UTC (rev 287633)
@@ -44,4 +44,6 @@
     readonly attribute long processIdentifier;
 
     Promise<boolean> lastNavigationWasAppInitiated();
+
+    boolean fetchEventIsSameSite(FetchEvent event);
 };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to