-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SameSite cookies: Consider redirect chain for same-site requests
The cookie spec is being amended in httpwg/http-extensions#1348 to consider the redirect chain when computing whether a request is considered same-site. This aligns with the new specification by considering a request cross- site if any URL in the redirect chain was cross-site from the current request URL. Bug: 830101 Change-Id: I060026647ccea2a97267e865c8292ac64915e87b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2605504 Commit-Queue: Lily Chen <[email protected]> Reviewed-by: Maksim Orlovich <[email protected]> Reviewed-by: Min Qin <[email protected]> Reviewed-by: Andrey Kosyakov <[email protected]> Cr-Commit-Position: refs/heads/master@{#860890} GitOrigin-RevId: 306b8fba167a809c5389a58d65bee438ca3bd15d
- Loading branch information
1 parent
6f5b1cf
commit 7663a61
Showing
7 changed files
with
200 additions
and
10 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
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
59 changes: 59 additions & 0 deletions
59
blink/web_tests/http/tests/inspector-protocol/fetch/fetch-samesite-cookies-expected.txt
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,59 @@ | ||
Tests that fetch exposes cookies according to SameSite rules. | ||
Request to https://setcookies.a.test/, type: Document | ||
Request to https://subdomain.a.test/, type: Document | ||
Request to https://a.test/, type: Document | ||
Cookies after same-site navigation: | ||
StrictCookie=1; LaxCookie=1; NoneCookie=1; UnspecifiedCookie=1 | ||
Request to https://b.test/, type: Document | ||
Request to https://a.test/, type: Document | ||
Cookies after cross-site navigation: | ||
LaxCookie=1; NoneCookie=1; UnspecifiedCookie=1 | ||
Request to https://subdomain.a.test/, type: Document | ||
Request to https://a.test/, type: Document | ||
Cookies for same-site iframe: | ||
StrictCookie=1; LaxCookie=1; NoneCookie=1; UnspecifiedCookie=1 | ||
Request to https://b.test/, type: Document | ||
Request to https://a.test/, type: Document | ||
Cookies for cross-site iframe: | ||
NoneCookie=1 | ||
Request to https://subdomain.a.test/, type: Document | ||
Request to https://redirect.a.test/, type: Document | ||
Request to https://a.test/, type: Document | ||
Cookies for same-site initiated same-site redirect: | ||
StrictCookie=1; LaxCookie=1; NoneCookie=1; UnspecifiedCookie=1 | ||
Request to https://subdomain.a.test/, type: Document | ||
Request to https://redirect.b.test/, type: Document | ||
Request to https://a.test/, type: Document | ||
Cookies for same-site initiated cross-site redirect: | ||
LaxCookie=1; NoneCookie=1; UnspecifiedCookie=1 | ||
Request to https://b.test/, type: Document | ||
Request to https://redirect.a.test/, type: Document | ||
Request to https://a.test/, type: Document | ||
Cookies for cross-site initiated same-site redirect: | ||
LaxCookie=1; NoneCookie=1; UnspecifiedCookie=1 | ||
Request to https://b.test/, type: Document | ||
Request to https://redirect.b.test/, type: Document | ||
Request to https://a.test/, type: Document | ||
Cookies for cross-site initiated cross-site redirect: | ||
LaxCookie=1; NoneCookie=1; UnspecifiedCookie=1 | ||
Request to https://subdomain.a.test/, type: Document | ||
Request to https://redirect.a.test/, type: Document | ||
Request to https://a.test/, type: Document | ||
Cookies for same-site embedded same-site redirect: | ||
StrictCookie=1; LaxCookie=1; NoneCookie=1; UnspecifiedCookie=1 | ||
Request to https://subdomain.a.test/, type: Document | ||
Request to https://redirect.b.test/, type: Document | ||
Request to https://a.test/, type: Document | ||
Cookies for same-site embedded cross-site redirect: | ||
NoneCookie=1 | ||
Request to https://b.test/, type: Document | ||
Request to https://redirect.a.test/, type: Document | ||
Request to https://a.test/, type: Document | ||
Cookies for cross-site embedded same-site redirect: | ||
NoneCookie=1 | ||
Request to https://b.test/, type: Document | ||
Request to https://redirect.b.test/, type: Document | ||
Request to https://a.test/, type: Document | ||
Cookies for cross-site embedded cross-site redirect: | ||
NoneCookie=1 | ||
|
131 changes: 131 additions & 0 deletions
131
blink/web_tests/http/tests/inspector-protocol/fetch/fetch-samesite-cookies.js
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,131 @@ | ||
(async function(testRunner) { | ||
const {page, session, dp} = await testRunner.startBlank( | ||
`Tests that fetch exposes cookies according to SameSite rules.`); | ||
|
||
const FetchHelper = await testRunner.loadScript('resources/fetch-test.js'); | ||
const helper = new FetchHelper(testRunner, testRunner.browserP()); | ||
await helper.enable(); | ||
|
||
helper.onceRequest(/setcookies.a.test/).fulfill({ | ||
responseCode: 200, | ||
responseHeaders: [ | ||
{name: 'Set-Cookie', value: 'StrictCookie=1; Secure; SameSite=Strict; Domain=a.test'}, | ||
{name: 'Set-Cookie', value: 'LaxCookie=1; Secure; SameSite=Lax; Domain=a.test'}, | ||
{name: 'Set-Cookie', value: 'NoneCookie=1; Secure; SameSite=None; Domain=a.test'}, | ||
{name: 'Set-Cookie', value: 'UnspecifiedCookie=1; Secure; Domain=a.test'} | ||
], | ||
body: btoa("<html></html>") | ||
}); | ||
|
||
await dp.Page.enable(); | ||
await session.navigate('https://setcookies.a.test/'); | ||
|
||
// URL whose cookies are dumped in the following tests. | ||
const cookieUrl = 'https://a.test/'; | ||
|
||
// Set up redirect to a.test from any URL containing 'redirect'. | ||
helper.onRequest(/redirect/).fulfill({ | ||
responseCode: 302, | ||
responseHeaders: [{name: 'Location', value: cookieUrl}] | ||
}); | ||
|
||
// Returns a string containing a script to append an iframe to the DOM. | ||
function appendIframeScript(url) { | ||
// This may run before or after the page is fully loaded, so account for | ||
// both cases to avoid flakiness. | ||
return ` | ||
function appendIframe() { | ||
var frame = document.createElement('iframe'); | ||
frame.src = '${url}'; | ||
document.body.appendChild(frame); | ||
} | ||
window.onload = appendIframe; | ||
if (document.readyState === 'complete') | ||
appendIframe();` | ||
} | ||
|
||
// Navigates to `fromUrl`, then navigates to a.test and dumps cookies that | ||
// were sent. | ||
async function navigateAndDumpCookies(fromUrl, description) { | ||
// Navigate to the starting location. | ||
helper.onceRequest(new RegExp(fromUrl)).fulfill({ | ||
responseCode: 200, | ||
body: btoa("<html></html>") | ||
}); | ||
await dp.Page.navigate({url: fromUrl}); | ||
// Navigate to a.test. | ||
session.evaluate(`location.href = '${cookieUrl}'`); | ||
const request = await helper.onceRequest(cookieUrl).matched(); | ||
testRunner.log(`Cookies after ${description}:`); | ||
testRunner.log(request.request.headers['Cookie']); | ||
dp.Fetch.fulfillRequest({requestId: request.requestId, responseCode: 200}); | ||
} | ||
|
||
// Navigates to `mainUrl`, then loads a.test in an iframe and dumps cookies | ||
// that were sent. | ||
async function loadIframeAndDumpCookies(mainUrl, description) { | ||
// Navigate to the main page URL. | ||
helper.onceRequest(new RegExp(mainUrl)).fulfill({ | ||
responseCode: 200, | ||
body: btoa("<html></html>") | ||
}); | ||
await dp.Page.navigate({url: mainUrl}); | ||
// Load iframe with a.test. | ||
session.evaluate(appendIframeScript(cookieUrl)); | ||
const request = await helper.onceRequest(cookieUrl).matched(); | ||
testRunner.log(`Cookies for ${description}:`); | ||
testRunner.log(request.request.headers['Cookie']); | ||
dp.Fetch.fulfillRequest({requestId: request.requestId, responseCode: 200}); | ||
} | ||
|
||
// Navigates to `fromUrl`, then navigates to `redirectUrl`, which then | ||
// redirects to a.test and dumps cookies that were sent. | ||
// `redirectUrl` must match the pattern /redirect/. | ||
async function redirectAndDumpCookies(fromUrl, redirectUrl, description) { | ||
helper.onceRequest(new RegExp(fromUrl)).fulfill({ | ||
responseCode: 200, | ||
body: btoa("<html></html>") | ||
}); | ||
// Navigate to the starting location. | ||
await dp.Page.navigate({url: fromUrl}); | ||
// Navigate to `redirectUrl` which then redirects to a.test. | ||
session.evaluate(`location.href = '${redirectUrl}'`); | ||
const request = await helper.onceRequest(cookieUrl).matched(); | ||
testRunner.log(`Cookies for ${description}:`); | ||
testRunner.log(request.request.headers['Cookie']); | ||
dp.Fetch.fulfillRequest({requestId: request.requestId, responseCode: 200}); | ||
} | ||
|
||
// Navigates to `mainUrl`, then loads `redirectUrl` in an iframe. The iframe | ||
// then redirects to a.test and dumps cookies that were sent. | ||
// `redirectUrl` must match the pattern /redirect/. | ||
async function redirectInIframeAndDumpCookies(mainUrl, redirectUrl, description) { | ||
helper.onceRequest(new RegExp(mainUrl)).fulfill({ | ||
responseCode: 200, | ||
body: btoa("<html></html>") | ||
}); | ||
// Navigate to the main page URL. | ||
await dp.Page.navigate({url: mainUrl}); | ||
// Load an iframe with `redirectUrl` which then redirects to a.test. | ||
session.evaluate(appendIframeScript(redirectUrl)); | ||
const request = await helper.onceRequest(cookieUrl).matched(); | ||
testRunner.log(`Cookies for ${description}:`); | ||
testRunner.log(request.request.headers['Cookie']); | ||
dp.Fetch.fulfillRequest({requestId: request.requestId, responseCode: 200}); | ||
} | ||
|
||
await navigateAndDumpCookies('https://subdomain.a.test/', 'same-site navigation'); | ||
await navigateAndDumpCookies('https://b.test/', 'cross-site navigation'); | ||
await loadIframeAndDumpCookies('https://subdomain.a.test/', 'same-site iframe'); | ||
await loadIframeAndDumpCookies('https://b.test/', 'cross-site iframe'); | ||
await redirectAndDumpCookies('https://subdomain.a.test/', 'https://redirect.a.test/', 'same-site initiated same-site redirect'); | ||
await redirectAndDumpCookies('https://subdomain.a.test/', 'https://redirect.b.test/', 'same-site initiated cross-site redirect'); | ||
await redirectAndDumpCookies('https://b.test/', 'https://redirect.a.test/', 'cross-site initiated same-site redirect'); | ||
await redirectAndDumpCookies('https://b.test/', 'https://redirect.b.test/', 'cross-site initiated cross-site redirect'); | ||
await redirectInIframeAndDumpCookies('https://subdomain.a.test/', 'https://redirect.a.test/', 'same-site embedded same-site redirect'); | ||
await redirectInIframeAndDumpCookies('https://subdomain.a.test/', 'https://redirect.b.test/', 'same-site embedded cross-site redirect'); | ||
await redirectInIframeAndDumpCookies('https://b.test/', 'https://redirect.a.test/', 'cross-site embedded same-site redirect'); | ||
await redirectInIframeAndDumpCookies('https://b.test/', 'https://redirect.b.test/', 'cross-site embedded cross-site redirect'); | ||
|
||
testRunner.completeTest(); | ||
}) |