Title: [290507] trunk
Revision
290507
Author
[email protected]
Date
2022-02-25 07:49:58 -0800 (Fri, 25 Feb 2022)

Log Message

Non-simple CORS preflight fails due to cache-control header
https://bugs.webkit.org/show_bug.cgi?id=236837
<rdar://problem/89382796>

Reviewed by Chris Dumez.

Source/WebCore:

We fixed cache-control in https://bugs.webkit.org/show_bug.cgi?id=233916.
The fix to make the website work is to ensure that Content-Type is not cleared when going to service worker.
Covered by updated tests.

* Modules/beacon/NavigatorBeacon.cpp:

LayoutTests:

* http/wpt/service-workers/cache-control-request-expected.txt:
* http/wpt/service-workers/cache-control-request.html:
* http/wpt/service-workers/resources/cross-origin-allow-for-beacon.py: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (290506 => 290507)


--- trunk/LayoutTests/ChangeLog	2022-02-25 13:28:38 UTC (rev 290506)
+++ trunk/LayoutTests/ChangeLog	2022-02-25 15:49:58 UTC (rev 290507)
@@ -1,3 +1,15 @@
+2022-02-25  Youenn Fablet  <[email protected]>
+
+        Non-simple CORS preflight fails due to cache-control header
+        https://bugs.webkit.org/show_bug.cgi?id=236837
+        <rdar://problem/89382796>
+
+        Reviewed by Chris Dumez.
+
+        * http/wpt/service-workers/cache-control-request-expected.txt:
+        * http/wpt/service-workers/cache-control-request.html:
+        * http/wpt/service-workers/resources/cross-origin-allow-for-beacon.py: Added.
+
 2022-02-25  Kimmo Kinnunen  <[email protected]>
 
         REGRESSION(r289580): [ iOS macOS ] TestWebKitAPI.IPCTestingAPI.CanReceiveSharedMemory is a constant timeout

Modified: trunk/LayoutTests/http/wpt/service-workers/cache-control-request-expected.txt (290506 => 290507)


--- trunk/LayoutTests/http/wpt/service-workers/cache-control-request-expected.txt	2022-02-25 13:28:38 UTC (rev 290506)
+++ trunk/LayoutTests/http/wpt/service-workers/cache-control-request-expected.txt	2022-02-25 15:49:58 UTC (rev 290507)
@@ -1,4 +1,5 @@
 
 PASS Setup worker
 PASS Ensure cache-control does not break service worker fetch handling
+PASS Ensure beacon headers are not broken by service worker fetch handling
 

Modified: trunk/LayoutTests/http/wpt/service-workers/cache-control-request.html (290506 => 290507)


--- trunk/LayoutTests/http/wpt/service-workers/cache-control-request.html	2022-02-25 13:28:38 UTC (rev 290506)
+++ trunk/LayoutTests/http/wpt/service-workers/cache-control-request.html	2022-02-25 15:49:58 UTC (rev 290507)
@@ -5,6 +5,7 @@
 <script src=""
 <script src=""
 <script src=""
+<script src=""
 </head>
 <body>
 <script>
@@ -33,6 +34,21 @@
     assert_not_equals(await response.text(), "no cache-control header");
     iframe.remove();
 }, "Ensure cache-control does not break service worker fetch handling");
+
+promise_test(async (test) => {
+    const iframe = await with_iframe("resources/empty.html");
+
+    const id = token();
+    const blob = new Blob(["test"], { type: "application/badabaoo" });
+
+    iframe.contentWindow.navigator.sendBeacon(get_host_info().HTTP_REMOTE_ORIGIN +  "/WebKit/service-workers/resources/cross-origin-allow-for-beacon.py?token=" + id, blob);
+    await new Promise(resolve => setTimeout(resolve, 50));
+
+    const response = await fetch("/WebKit/service-workers/resources/cross-origin-allow-for-beacon.py?token=" + id);
+    assert_equals(await response.text(), "preflight ok");
+
+    iframe.remove();
+}, "Ensure beacon headers are not broken by service worker fetch handling");
 </script>
 </body>
 </html>

Added: trunk/LayoutTests/http/wpt/service-workers/resources/cross-origin-allow-for-beacon.py (0 => 290507)


--- trunk/LayoutTests/http/wpt/service-workers/resources/cross-origin-allow-for-beacon.py	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/service-workers/resources/cross-origin-allow-for-beacon.py	2022-02-25 15:49:58 UTC (rev 290507)
@@ -0,0 +1,15 @@
+def main(request, response):
+    token = request.GET.first(b"token", None)
+    if request.method == u'OPTIONS':
+        headers = request.headers.get("Access-Control-Request-Headers", "none")
+        if "cache-control" in str(headers):
+            request.server.stash.put(token, "preflight ko, got cache-control")
+            return 404, [(b"Cache-Control", b"no-store")], u"cache-control in preflight"
+        if "content-type" not in str(headers):
+            request.server.stash.put(token, "preflight ko got content-type")
+            return 404, [(b"Cache-Control", b"no-store")], u"content-type not in preflight"
+        request.server.stash.put(token, "preflight ok")
+        return 200, [(b"Cache-Control", b"no-store"), (b"Content-Type", b"text/ascii"), (b"Access-Control-Allow-Origin", b"http://localhost:8800"), (b"Access-Control-Allow-Credentials", b"true"), (b"Access-Control-Allow-Headers", b"content-type"), (b"Access-Control-Allow-Methods", b"*")], u"ok"
+    if request.method == u'GET':
+        return 200, [(b"Content-Type", b"text/ascii")], request.server.stash.take(token)
+    return 200, [(b"Content-Type", b"text/ascii"), (b"Access-Control-Allow-Origin", b"http://localhost:8800"), (b"Access-Control-Allow-Credentials", b"true")], u"post ok"

Modified: trunk/Source/WebCore/ChangeLog (290506 => 290507)


--- trunk/Source/WebCore/ChangeLog	2022-02-25 13:28:38 UTC (rev 290506)
+++ trunk/Source/WebCore/ChangeLog	2022-02-25 15:49:58 UTC (rev 290507)
@@ -1,3 +1,17 @@
+2022-02-25  Youenn Fablet  <[email protected]>
+
+        Non-simple CORS preflight fails due to cache-control header
+        https://bugs.webkit.org/show_bug.cgi?id=236837
+        <rdar://problem/89382796>
+
+        Reviewed by Chris Dumez.
+
+        We fixed cache-control in https://bugs.webkit.org/show_bug.cgi?id=233916.
+        The fix to make the website work is to ensure that Content-Type is not cleared when going to service worker.
+        Covered by updated tests.
+
+        * Modules/beacon/NavigatorBeacon.cpp:
+
 2022-02-25  Zan Dobersek  <[email protected]>
 
         [GTK][WPE] Uncouple libgbm, libdrm dependencies from ANGLE functionality

Modified: trunk/Source/WebCore/Modules/beacon/NavigatorBeacon.cpp (290506 => 290507)


--- trunk/Source/WebCore/Modules/beacon/NavigatorBeacon.cpp	2022-02-25 13:28:38 UTC (rev 290506)
+++ trunk/Source/WebCore/Modules/beacon/NavigatorBeacon.cpp	2022-02-25 15:49:58 UTC (rev 290507)
@@ -145,8 +145,10 @@
         request.setHTTPBody(fetchBody.bodyAsFormData());
         if (!mimeType.isEmpty()) {
             request.setHTTPContentType(mimeType);
-            if (!isCrossOriginSafeRequestHeader(HTTPHeaderName::ContentType, mimeType))
+            if (!isCrossOriginSafeRequestHeader(HTTPHeaderName::ContentType, mimeType)) {
                 options.mode = FetchOptions::Mode::Cors;
+                options.httpHeadersToKeep.add(HTTPHeadersToKeepFromCleaning::ContentType);
+            }
         }
     }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to