Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run cookie header tests in frames. #109

Merged
merged 3 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion privacy-protections/storage-blocking/helpers/commonTests.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
/* exported commonTests */
/* global cookieStore */
/* global cookieStore, THIRD_PARTY_TRACKER_ORIGIN, THIRD_PARTY_ORIGIN */

function generateCookieHeaderTest (namePrefix, origin) {
return {
id: `${namePrefix} header cookie`,
store: (data) => {
return fetch(`${origin}/set-cookie?value=${data}`, { credentials: 'include' }).then(r => {
if (!r.ok) {
throw new Error('Request failed.');
}
});
},
retrive: () => {
return fetch(`${origin}/reflect-headers`, { credentials: 'include' })
.then(r => r.json())
.then(data => data.headers.cookie.match(/headerdata=([0-9]+)/)[1]);
kdzwinel marked this conversation as resolved.
Show resolved Hide resolved
}
};
}

const cookieHeaderTests = [generateCookieHeaderTest('first party', '')];
if (document.location.origin !== THIRD_PARTY_ORIGIN) {
cookieHeaderTests.push(generateCookieHeaderTest('safe third party', THIRD_PARTY_ORIGIN));
}
if (document.location.origin !== THIRD_PARTY_TRACKER_ORIGIN) {
cookieHeaderTests.push(generateCookieHeaderTest('tracking third party', THIRD_PARTY_TRACKER_ORIGIN));
}

// tests that are common for both main frame and an iframe
const commonTests = [
...cookieHeaderTests,
{
id: 'JS cookie',
store: (data) => {
Expand Down
3 changes: 3 additions & 0 deletions privacy-protections/storage-blocking/helpers/globals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* exported THIRD_PARTY_ORIGIN,THIRD_PARTY_TRACKER_ORIGIN */
const THIRD_PARTY_ORIGIN = 'https://good.third-party.site';
const THIRD_PARTY_TRACKER_ORIGIN = 'https://broken.third-party.site';
1 change: 1 addition & 0 deletions privacy-protections/storage-blocking/iframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Storage blocking test page - iframe</title>
<script src='/helpers/idb-wrapper.js'></script>
<script src="./helpers/globals.js"></script>
<script src='./helpers/commonTests.js'></script>
<script src='./iframe.js'></script>
</head>
Expand Down
1 change: 1 addition & 0 deletions privacy-protections/storage-blocking/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<title>Storage blocking test page</title>

<script src='/helpers/idb-wrapper.js' defer></script>
<script src="./helpers/globals.js"></script>
<script src='./helpers/commonTests.js'></script>
<script src='https://broken.third-party.site/privacy-protections/storage-blocking/3rdparty.js' defer></script>
<script src='https://good.third-party.site/privacy-protections/storage-blocking/3rdparty.js' defer></script>
Expand Down
51 changes: 2 additions & 49 deletions privacy-protections/storage-blocking/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* globals commonTests */
const THIRD_PARTY_ORIGIN = 'https://good.third-party.site';
const THIRD_PARTY_TRACKER_ORIGIN = 'https://broken.third-party.site';
/* globals commonTests,THIRD_PARTY_ORIGIN,THIRD_PARTY_TRACKER_ORIGIN */

const storeButton = document.querySelector('#store');
const retriveButton = document.querySelector('#retrive');
Expand Down Expand Up @@ -82,51 +80,6 @@ function create3pIframeTest (name, origin) {
}

const tests = [
{
id: 'first party header cookie',
store: (data) => {
return fetch(`/set-cookie?value=${data}`).then(r => {
if (!r.ok) {
throw new Error('Request failed.');
}
});
},
retrive: () => {
return fetch('/reflect-headers')
.then(r => r.json())
.then(data => data.headers.cookie.match(/headerdata=([0-9]+)/)[1]);
}
},
{
id: 'safe third party header cookie',
store: (data) => {
return fetch(`${THIRD_PARTY_ORIGIN}/set-cookie?value=${data}`, { credentials: 'include' }).then(r => {
if (!r.ok) {
throw new Error('Request failed.');
}
});
},
retrive: () => {
return fetch(`${THIRD_PARTY_ORIGIN}/reflect-headers`, { credentials: 'include' })
.then(r => r.json())
.then(data => data.headers.cookie.match(/headerdata=([0-9]+)/)[1]);
}
},
{
id: 'tracking third party header cookie',
store: (data) => {
return fetch(`${THIRD_PARTY_TRACKER_ORIGIN}/set-cookie?value=${data}`, { credentials: 'include' }).then(r => {
if (!r.ok) {
throw new Error('Request failed.');
}
});
},
retrive: () => {
return fetch(`${THIRD_PARTY_TRACKER_ORIGIN}/reflect-headers`, { credentials: 'include' })
.then(r => r.json())
.then(data => data.headers.cookie.match(/headerdata=([0-9]+)/)[1]);
}
},
create3pIframeTest('safe', THIRD_PARTY_ORIGIN),
create3pIframeTest('tracking', THIRD_PARTY_TRACKER_ORIGIN),
{
Expand Down Expand Up @@ -278,7 +231,7 @@ function retrieveData () {
});
}

tests.concat(commonTests).forEach(test => {
sammacbeth marked this conversation as resolved.
Show resolved Hide resolved
[...commonTests, ...tests].forEach(test => {
all++;

const li = document.createElement('li');
Expand Down