Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
SameSite=Lax cookie attribute not correctly handled in Safari 14.0.2 …
…< version <= current https://bugs.webkit.org/show_bug.cgi?id=230568 <rdar://83360821> Reviewed by Darin Adler. The `isTopLevelNavigation` flag on the request needs to be properly set for top-level navigations in order for SameSite=Lax cookies to be sent. In the case of this bug, the navigation is initiated by a cross-origin iframe but it is still a top-level navigation since the navigation occurs in a new window, not in the iframe itself. However, the isTopLevelNavigation flag would be unset and SameSite=Lax cookies wouldn't get sent. The issue was that FrameLoader::updateRequestAndAddExtraFields() was checking if the FrameLoader's m_frame was the main frame to determine if the main frame is being navigated. This generally works because targeted (e.g. via `target="foo"`) are usually resolved before calling this function so we're supposed to be on the target frame's FrameLoader already. However, this is not the case when the navigation is to happen in a new window since there isn't a target frame yet (it will get created later on). To address the issue, call sites of updateRequestAndAddExtraFields() now pass in a new willOpenInNewWindow flag whenever the navigation will happen in a new window. As a result, updateRequestAndAddExtraFields() can properly set the `isTopLevelNavigation` flag in this case. Test: http/tests/cookies/same-site/popup-cross-site-from-cross-origin-iframe.html * LayoutTests/http/tests/cookies/same-site/popup-cross-site-from-cross-origin-iframe-expected.txt: Added. * LayoutTests/http/tests/cookies/same-site/popup-cross-site-from-cross-origin-iframe.html: Added. * LayoutTests/http/tests/cookies/same-site/resources/navigate-to-post-cookies-to-opener-iframe.html: Added. * Source/WebCore/loader/FrameLoader.cpp: (WebCore::FrameLoader::loadURL): (WebCore::FrameLoader::updateRequestAndAddExtraFields): (WebCore::FrameLoader::loadPostRequest): * Source/WebCore/loader/FrameLoader.h: Canonical link: https://commits.webkit.org/252341@main
- Loading branch information
Showing
7 changed files
with
70 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
|
||
PASS '127.0.0.1' is not same-site with 'localhost', so strict samesite cookies are not sent, but lax ones are. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script src="/js-test-resources/testharness.js"></script> | ||
<script src="/js-test-resources/testharnessreport.js"></script> | ||
<script src="../resources/testharness-helpers.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
if (window.location.hostname == "127.0.0.1") { | ||
document.cookie = STRICT_DOM + "=1; SameSite=Strict; Max-Age=100; path=/"; | ||
document.cookie = IMPLICIT_STRICT_DOM + "=1; SameSite; Max-Age=100; path=/"; | ||
document.cookie = STRICT_BECAUSE_INVALID_SAMESITE_VALUE + "=1; SameSite=invalid; Max-Age=100; path=/"; | ||
document.cookie = LAX_DOM + "=1; SameSite=Lax; Max-Age=100; path=/"; | ||
document.cookie = NORMAL_DOM + "=1; Max-Age=100; path=/"; | ||
window.location.hostname = "localhost"; | ||
} else { | ||
async_test(t => { | ||
let iframe = document.createElement("iframe"); | ||
iframe.src = "http://127.0.0.1:8000/cookies/same-site/resources/navigate-to-post-cookies-to-opener-iframe.html"; | ||
document.body.appendChild(iframe); | ||
window.addEventListener("message", t.step_func_done(e => { | ||
assert_equals(e.data.http[STRICT_DOM], undefined, "strict"); | ||
assert_equals(e.data.http[IMPLICIT_STRICT_DOM], "1", "implicit-strict"); | ||
assert_equals(e.data.http[STRICT_BECAUSE_INVALID_SAMESITE_VALUE], "1", "strict-because-invalid-SameSite-value"); | ||
assert_equals(e.data.http[LAX_DOM], "1", "lax"); | ||
assert_equals(e.data.http[NORMAL_DOM], "1", "normal"); | ||
assert_equals(normalizeCookie(e.data.document), normalizeCookie(IMPLICIT_STRICT_DOM + "=1; " + LAX_DOM + "=1; " + NORMAL_DOM + "=1; " + STRICT_BECAUSE_INVALID_SAMESITE_VALUE + "=1; " + STRICT_DOM + "=1")); | ||
})); | ||
}, "'127.0.0.1' is not same-site with 'localhost', so strict samesite cookies are not sent, but lax ones are."); | ||
} | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<a id="testLink" href="../../resources/post-cookies-to-opener.py" target="foo">Click me</a> | ||
<script> | ||
|
||
window.addEventListener("message", (e) => { | ||
top.postMessage(e.data, "*"); | ||
}); | ||
|
||
onload = () => { | ||
setTimeout(() => { | ||
document.getElementById("testLink").click(); | ||
}, 0); | ||
}; | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters