Title: [292650] branches/safari-613-branch
Revision
292650
Author
[email protected]
Date
2022-04-08 17:13:24 -0700 (Fri, 08 Apr 2022)

Log Message

Cherry-pick r291741. rdar://problem/88979099

    Computation of Document siteForCookies is buggy in case document is created by window.open
    https://bugs.webkit.org/show_bug.cgi?id=238202
    <rdar://88979099>

    Reviewed by John Wilander.

    Source/WebCore:

    For top level navigations, we need to use the security origin to compute siteForCookies as the document
    may have the opener security origin.
    Add a Document routine to handle this case.

    Tests: http/tests/cookies/same-site/popup-from-iframe-same-site-with-post-form.html
           http/tests/cookies/same-site/popup-same-site-with-post-form.html

    * dom/Document.cpp:
    * dom/Document.h:
    * loader/FrameLoader.cpp:

    LayoutTests:

    * http/tests/cookies/resources/testharness-helpers.js:
    * http/tests/cookies/same-site/popup-from-iframe-same-site-with-post-form-expected.txt: Added.
    * http/tests/cookies/same-site/popup-from-iframe-same-site-with-post-form.html: Added.
    * http/tests/cookies/same-site/popup-same-site-with-post-form-expected.txt: Added.
    * http/tests/cookies/same-site/popup-same-site-with-post-form.html: Added.
    * http/tests/cookies/same-site/resources/popup-iframe.html: Added.

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

Modified Paths

Added Paths

Diff

Modified: branches/safari-613-branch/LayoutTests/ChangeLog (292649 => 292650)


--- branches/safari-613-branch/LayoutTests/ChangeLog	2022-04-09 00:13:19 UTC (rev 292649)
+++ branches/safari-613-branch/LayoutTests/ChangeLog	2022-04-09 00:13:24 UTC (rev 292650)
@@ -1,5 +1,55 @@
 2022-04-07  Alan Coon  <[email protected]>
 
+        Cherry-pick r291741. rdar://problem/88979099
+
+    Computation of Document siteForCookies is buggy in case document is created by window.open
+    https://bugs.webkit.org/show_bug.cgi?id=238202
+    <rdar://88979099>
+    
+    Reviewed by John Wilander.
+    
+    Source/WebCore:
+    
+    For top level navigations, we need to use the security origin to compute siteForCookies as the document
+    may have the opener security origin.
+    Add a Document routine to handle this case.
+    
+    Tests: http/tests/cookies/same-site/popup-from-iframe-same-site-with-post-form.html
+           http/tests/cookies/same-site/popup-same-site-with-post-form.html
+    
+    * dom/Document.cpp:
+    * dom/Document.h:
+    * loader/FrameLoader.cpp:
+    
+    LayoutTests:
+    
+    * http/tests/cookies/resources/testharness-helpers.js:
+    * http/tests/cookies/same-site/popup-from-iframe-same-site-with-post-form-expected.txt: Added.
+    * http/tests/cookies/same-site/popup-from-iframe-same-site-with-post-form.html: Added.
+    * http/tests/cookies/same-site/popup-same-site-with-post-form-expected.txt: Added.
+    * http/tests/cookies/same-site/popup-same-site-with-post-form.html: Added.
+    * http/tests/cookies/same-site/resources/popup-iframe.html: Added.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@291741 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2022-03-23  Youenn Fablet  <[email protected]>
+
+            Computation of Document siteForCookies is buggy in case document is created by window.open
+            https://bugs.webkit.org/show_bug.cgi?id=238202
+            <rdar://88979099>
+
+            Reviewed by John Wilander.
+
+            * http/tests/cookies/resources/testharness-helpers.js:
+            * http/tests/cookies/same-site/popup-from-iframe-same-site-with-post-form-expected.txt: Added.
+            * http/tests/cookies/same-site/popup-from-iframe-same-site-with-post-form.html: Added.
+            * http/tests/cookies/same-site/popup-same-site-with-post-form-expected.txt: Added.
+            * http/tests/cookies/same-site/popup-same-site-with-post-form.html: Added.
+            * http/tests/cookies/same-site/resources/popup-iframe.html: Added.
+
+2022-04-07  Alan Coon  <[email protected]>
+
         Cherry-pick r291526. rdar://problem/90385586
 
     REGRESSION (r285529): Flash of missing text when content on https://ahumanfuture.co animates

Modified: branches/safari-613-branch/LayoutTests/http/tests/cookies/resources/testharness-helpers.js (292649 => 292650)


--- branches/safari-613-branch/LayoutTests/http/tests/cookies/resources/testharness-helpers.js	2022-04-09 00:13:19 UTC (rev 292649)
+++ branches/safari-613-branch/LayoutTests/http/tests/cookies/resources/testharness-helpers.js	2022-04-09 00:13:24 UTC (rev 292650)
@@ -20,3 +20,72 @@
     return cookie.split(/;\s*/).sort().join("; ");
 }
 
+function with_iframe(url) {
+    return new Promise(function(resolve) {
+        var frame = document.createElement('iframe');
+        frame.src = ""
+        frame._onload_ = function() { setTimeout(() => resolve(frame), 0); };
+        document.body.appendChild(frame);
+    });
+}
+
+function loadPopupThenTriggerPost()
+{
+    let finish;
+    let promise = new Promise(resolve => finish = resolve);
+
+    clearKnownCookies();
+    document.cookie = LAX_DOM + "=1; SameSite=Lax; Max-Age=100; path=/";
+    document.cookie = NORMAL_DOM + "=1; Max-Age=100; path=/";
+    document.cookie = STRICT_DOM + "=1; SameSite=Strict; Max-Age=100; path=/";
+
+    const opener = window.open("http://127.0.0.1:8000/cookies/resources/post-cookies-to-opener.py")
+    window._onmessage_ = e => {
+        window._onmessage_ = e => {
+            opener.close();
+            finish(e.data);
+        };
+
+        const newDoc = opener.document;
+        var form = newDoc.createElement('form');
+        form.method = 'POST';
+        form.action = '';
+        var input = newDoc.createElement('input');
+        input.name = 'name';
+        input.value = 'value';
+        form.appendChild(input);
+        newDoc.body.appendChild(form);
+        form.submit();
+    };
+    return promise;
+}
+
+function openPopupAndTriggerPost(popupURL, callback)
+{
+    let finish;
+    let promise = new Promise(resolve => finish = resolve);
+
+    clearKnownCookies();
+    document.cookie = LAX_DOM + "=1; SameSite=Lax; Max-Age=100; path=/";
+    document.cookie = NORMAL_DOM + "=1; Max-Age=100; path=/";
+    document.cookie = STRICT_DOM + "=1; SameSite=Strict; Max-Age=100; path=/";
+
+    window.addEventListener("message", e => {
+        opener.close();
+        finish(e.data);
+    });
+
+    const opener = window.open(popupURL)
+    const newDoc = opener.document;
+    var form = newDoc.createElement('form');
+    form.method = 'POST';
+    form.action = '';
+    var input = newDoc.createElement('input');
+    input.name = 'name';
+    input.value = 'value';
+    form.appendChild(input);
+    newDoc.body.appendChild(form);
+    form.submit();
+
+    return promise;
+}

Added: branches/safari-613-branch/LayoutTests/http/tests/cookies/same-site/popup-from-iframe-same-site-with-post-form-expected.txt (0 => 292650)


--- branches/safari-613-branch/LayoutTests/http/tests/cookies/same-site/popup-from-iframe-same-site-with-post-form-expected.txt	                        (rev 0)
+++ branches/safari-613-branch/LayoutTests/http/tests/cookies/same-site/popup-from-iframe-same-site-with-post-form-expected.txt	2022-04-09 00:13:24 UTC (rev 292650)
@@ -0,0 +1,5 @@
+
+PASS popup opened as 'about:blank' from an iframe, then post navigation to 127.0.0.1, so samesite cookies are sent.
+PASS popup opened as '127.0.0.1' from an iframe, then post navigation to 127.0.0.1, so samesite cookies are sent.
+PASS popup loaded as '127.0.0.1' from an iframe, then post navigation to 127.0.0.1, so samesite cookies are sent.
+

Added: branches/safari-613-branch/LayoutTests/http/tests/cookies/same-site/popup-from-iframe-same-site-with-post-form.html (0 => 292650)


--- branches/safari-613-branch/LayoutTests/http/tests/cookies/same-site/popup-from-iframe-same-site-with-post-form.html	                        (rev 0)
+++ branches/safari-613-branch/LayoutTests/http/tests/cookies/same-site/popup-from-iframe-same-site-with-post-form.html	2022-04-09 00:13:24 UTC (rev 292650)
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<script src=""
+<script src=""
+<script src=""
+<body>
+<script>
+promise_test(async t => {
+    const frame = await with_iframe("resources/popup-iframe.html");
+    const data = "" frame.contentWindow.openPopupAndTriggerPost("about:blank");
+    frame.remove();
+    assert_equals(data.http[LAX_DOM], "1", "lax");
+    assert_equals(data.http[NORMAL_DOM], "1", "normal");
+    assert_equals(data.http[STRICT_DOM], "1", "strict");
+}, "popup opened as 'about:blank' from an iframe, then post navigation to 127.0.0.1, so samesite cookies are sent.");
+
+promise_test(async t => {
+    const frame = await with_iframe("resources/popup-iframe.html");
+    const data = "" frame.contentWindow.openPopupAndTriggerPost("http://127.0.0.1:8000");
+    frame.remove();
+    assert_equals(data.http[LAX_DOM], "1", "lax");
+    assert_equals(data.http[NORMAL_DOM], "1", "normal");
+    assert_equals(data.http[STRICT_DOM], "1", "strict");
+}, "popup opened as '127.0.0.1' from an iframe, then post navigation to 127.0.0.1, so samesite cookies are sent.");
+
+promise_test(async t => {
+    const frame = await with_iframe("resources/popup-iframe.html");
+    const data = "" frame.contentWindow.loadPopupThenTriggerPost();
+    frame.remove();
+    assert_equals(data.http[LAX_DOM], "1", "lax");
+    assert_equals(data.http[NORMAL_DOM], "1", "normal");
+    assert_equals(data.http[STRICT_DOM], "1", "strict");
+}, "popup loaded as '127.0.0.1' from an iframe, then post navigation to 127.0.0.1, so samesite cookies are sent.");
+</script>
+</body>

Added: branches/safari-613-branch/LayoutTests/http/tests/cookies/same-site/popup-same-site-with-post-form-expected.txt (0 => 292650)


--- branches/safari-613-branch/LayoutTests/http/tests/cookies/same-site/popup-same-site-with-post-form-expected.txt	                        (rev 0)
+++ branches/safari-613-branch/LayoutTests/http/tests/cookies/same-site/popup-same-site-with-post-form-expected.txt	2022-04-09 00:13:24 UTC (rev 292650)
@@ -0,0 +1,5 @@
+
+PASS popup opened as 'about:blank', then post navigation to 127.0.0.1, so samesite cookies are sent.
+PASS popup opened as '127.0.0.1', then post navigation to 127.0.0.1, so samesite cookies are sent.
+PASS popup loaded as '127.0.0.1', then post navigation to 127.0.0.1, so samesite cookies are sent.
+

Added: branches/safari-613-branch/LayoutTests/http/tests/cookies/same-site/popup-same-site-with-post-form.html (0 => 292650)


--- branches/safari-613-branch/LayoutTests/http/tests/cookies/same-site/popup-same-site-with-post-form.html	                        (rev 0)
+++ branches/safari-613-branch/LayoutTests/http/tests/cookies/same-site/popup-same-site-with-post-form.html	2022-04-09 00:13:24 UTC (rev 292650)
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<script src=""
+<script src=""
+<script src=""
+<script>
+promise_test(async t => {
+    const data = "" openPopupAndTriggerPost("about:blank");
+    assert_equals(data.http[LAX_DOM], "1", "lax");
+    assert_equals(data.http[NORMAL_DOM], "1", "normal");
+    assert_equals(data.http[STRICT_DOM], "1", "strict");
+}, "popup opened as 'about:blank', then post navigation to 127.0.0.1, so samesite cookies are sent.");
+
+promise_test(async t => {
+    const data = "" openPopupAndTriggerPost("http://127.0.0.1:8000");
+    assert_equals(data.http[LAX_DOM], "1", "lax");
+    assert_equals(data.http[NORMAL_DOM], "1", "normal");
+    assert_equals(data.http[STRICT_DOM], "1", "strict");
+}, "popup opened as '127.0.0.1', then post navigation to 127.0.0.1, so samesite cookies are sent.");
+
+promise_test(async t => {
+    const data = "" loadPopupThenTriggerPost();
+    assert_equals(data.http[LAX_DOM], "1", "lax");
+    assert_equals(data.http[NORMAL_DOM], "1", "normal");
+    assert_equals(data.http[STRICT_DOM], "1", "strict");
+}, "popup loaded as '127.0.0.1', then post navigation to 127.0.0.1, so samesite cookies are sent.");
+</script>

Added: branches/safari-613-branch/LayoutTests/http/tests/cookies/same-site/resources/popup-iframe.html (0 => 292650)


--- branches/safari-613-branch/LayoutTests/http/tests/cookies/same-site/resources/popup-iframe.html	                        (rev 0)
+++ branches/safari-613-branch/LayoutTests/http/tests/cookies/same-site/resources/popup-iframe.html	2022-04-09 00:13:24 UTC (rev 292650)
@@ -0,0 +1,4 @@
+<!DOCTYPE html>
+<script src=""
+<body>
+</body>

Modified: branches/safari-613-branch/Source/WebCore/ChangeLog (292649 => 292650)


--- branches/safari-613-branch/Source/WebCore/ChangeLog	2022-04-09 00:13:19 UTC (rev 292649)
+++ branches/safari-613-branch/Source/WebCore/ChangeLog	2022-04-09 00:13:24 UTC (rev 292650)
@@ -1,5 +1,59 @@
 2022-04-07  Alan Coon  <[email protected]>
 
+        Cherry-pick r291741. rdar://problem/88979099
+
+    Computation of Document siteForCookies is buggy in case document is created by window.open
+    https://bugs.webkit.org/show_bug.cgi?id=238202
+    <rdar://88979099>
+    
+    Reviewed by John Wilander.
+    
+    Source/WebCore:
+    
+    For top level navigations, we need to use the security origin to compute siteForCookies as the document
+    may have the opener security origin.
+    Add a Document routine to handle this case.
+    
+    Tests: http/tests/cookies/same-site/popup-from-iframe-same-site-with-post-form.html
+           http/tests/cookies/same-site/popup-same-site-with-post-form.html
+    
+    * dom/Document.cpp:
+    * dom/Document.h:
+    * loader/FrameLoader.cpp:
+    
+    LayoutTests:
+    
+    * http/tests/cookies/resources/testharness-helpers.js:
+    * http/tests/cookies/same-site/popup-from-iframe-same-site-with-post-form-expected.txt: Added.
+    * http/tests/cookies/same-site/popup-from-iframe-same-site-with-post-form.html: Added.
+    * http/tests/cookies/same-site/popup-same-site-with-post-form-expected.txt: Added.
+    * http/tests/cookies/same-site/popup-same-site-with-post-form.html: Added.
+    * http/tests/cookies/same-site/resources/popup-iframe.html: Added.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@291741 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2022-03-23  Youenn Fablet  <[email protected]>
+
+            Computation of Document siteForCookies is buggy in case document is created by window.open
+            https://bugs.webkit.org/show_bug.cgi?id=238202
+            <rdar://88979099>
+
+            Reviewed by John Wilander.
+
+            For top level navigations, we need to use the security origin to compute siteForCookies as the document
+            may have the opener security origin.
+            Add a Document routine to handle this case.
+
+            Tests: http/tests/cookies/same-site/popup-from-iframe-same-site-with-post-form.html
+                   http/tests/cookies/same-site/popup-same-site-with-post-form.html
+
+            * dom/Document.cpp:
+            * dom/Document.h:
+            * loader/FrameLoader.cpp:
+
+2022-04-07  Alan Coon  <[email protected]>
+
         Cherry-pick r291526. rdar://problem/90385586
 
     REGRESSION (r285529): Flash of missing text when content on https://ahumanfuture.co animates

Modified: branches/safari-613-branch/Source/WebCore/dom/Document.cpp (292649 => 292650)


--- branches/safari-613-branch/Source/WebCore/dom/Document.cpp	2022-04-09 00:13:19 UTC (rev 292649)
+++ branches/safari-613-branch/Source/WebCore/dom/Document.cpp	2022-04-09 00:13:24 UTC (rev 292650)
@@ -9082,6 +9082,12 @@
     return m_elementsWithPendingUserAgentShadowTreeUpdates.contains(element);
 }
 
+bool Document::isSameSiteForCookies(const URL& url) const
+{
+    auto domain = isTopDocument() ? RegistrableDomain(securityOrigin().data()) : RegistrableDomain(siteForCookies());
+    return domain.matches(url);
+}
+
 } // namespace WebCore
 
 #undef DOCUMENT_RELEASE_LOG

Modified: branches/safari-613-branch/Source/WebCore/dom/Document.h (292649 => 292650)


--- branches/safari-613-branch/Source/WebCore/dom/Document.h	2022-04-09 00:13:19 UTC (rev 292649)
+++ branches/safari-613-branch/Source/WebCore/dom/Document.h	2022-04-09 00:13:24 UTC (rev 292650)
@@ -1018,7 +1018,8 @@
     // URL. For the top-level document, it is set to the document's URL.
     const URL& siteForCookies() const { return m_siteForCookies; }
     void setSiteForCookies(const URL& url) { m_siteForCookies = url; }
-    
+    bool isSameSiteForCookies(const URL&) const;
+
     // The following implements the rule from HTML 4 for what valid names are.
     // To get this right for all the XML cases, we probably have to improve this or move it
     // and make it sensitive to the type of document.

Modified: branches/safari-613-branch/Source/WebCore/loader/FrameLoader.cpp (292649 => 292650)


--- branches/safari-613-branch/Source/WebCore/loader/FrameLoader.cpp	2022-04-09 00:13:19 UTC (rev 292649)
+++ branches/safari-613-branch/Source/WebCore/loader/FrameLoader.cpp	2022-04-09 00:13:24 UTC (rev 292650)
@@ -3048,7 +3048,8 @@
         request.setIsSameSite(true);
         return;
     }
-    request.setIsSameSite(areRegistrableDomainsEqual(initiator->siteForCookies(), request.url()));
+
+    request.setIsSameSite(initiator->isSameSiteForCookies(request.url()));
 }
 
 void FrameLoader::loadPostRequest(FrameLoadRequest&& request, const String& referrer, FrameLoadType loadType, Event* event, RefPtr<FormState>&& formState, CompletionHandler<void()>&& completionHandler)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to