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

Feature: Show exempted cookies in extension #522

Merged
merged 30 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
dbfc1b3
Adding exemptionReason to cookie.
amovar18 Feb 19, 2024
e082ae5
Organise cookies section.
amovar18 Feb 19, 2024
3c2c1f9
Organise cookie landing and add exemption reasons
amovar18 Feb 19, 2024
4c271bd
Merge branch 'develop' of github.com:GoogleChromeLabs/ps-analysis-too…
amovar18 Feb 19, 2024
484f082
Merge branch 'develop' of github.com:GoogleChromeLabs/ps-analysis-too…
amovar18 Feb 20, 2024
30dd31a
Add conditions for cookie calculation.
amovar18 Feb 20, 2024
43d17ae
Fix Nan for the cookie exempted key.
amovar18 Feb 20, 2024
2e14dca
Add reasons for cookie exemption reasons.
amovar18 Feb 23, 2024
5597f9d
Fix failing tests.
amovar18 Feb 23, 2024
a126e37
Merge branch 'develop' of github.com:GoogleChromeLabs/ps-analysis-too…
amovar18 Feb 26, 2024
eca31ab
Add exemption reason filter to the table.
amovar18 Feb 26, 2024
96b5aa9
Add exemption Reason to the cookie details page.
amovar18 Feb 26, 2024
38ff548
Merge branch 'develop' of github.com:GoogleChromeLabs/ps-analysis-too…
amovar18 Mar 1, 2024
bc069bf
Merge branch 'develop' of github.com:GoogleChromeLabs/ps-analysis-too…
amovar18 Mar 1, 2024
d15f1a7
Merge branch 'develop' of github.com:GoogleChromeLabs/ps-analysis-too…
amovar18 Mar 12, 2024
373dba2
Merge branch 'develop' of github.com:GoogleChromeLabs/ps-analysis-too…
amovar18 Mar 20, 2024
d3df5fc
Merge branch 'develop' of github.com:GoogleChromeLabs/ps-analysis-too…
amovar18 Apr 5, 2024
83ea2b4
Fix merge conflicts.
amovar18 Apr 5, 2024
e906413
Fix single value updater.
amovar18 Apr 5, 2024
d766d94
update devtools-protocol types package.
amovar18 Apr 5, 2024
851d99b
Fix types.
amovar18 Apr 5, 2024
10f4da6
Fix types and addition of the exempted cookies conditional.
amovar18 Apr 8, 2024
d4182b5
Merge branch 'develop' of github.com:GoogleChromeLabs/ps-analysis-too…
amovar18 Apr 9, 2024
e853ece
Rephrase messaging.
amovar18 Apr 9, 2024
2a4d296
Rephrase the messaging.
amovar18 Apr 9, 2024
04129f1
Merge branch 'develop' of github.com:GoogleChromeLabs/ps-analysis-too…
amovar18 Apr 9, 2024
0178bc2
Add tests and refactor code.
amovar18 Apr 9, 2024
6e7051a
Add section of exempted cookies to the report.
amovar18 Apr 9, 2024
e3f53b4
Fix failing tests.
amovar18 Apr 9, 2024
c025379
Merge branch 'develop' of github.com:GoogleChromeLabs/ps-analysis-too…
mohdsayed Apr 9, 2024
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
35 changes: 22 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
"tldts": "^6.0.14"
},
"devDependencies": {
"devtools-protocol": "^0.0.1236148"
"devtools-protocol": "^0.0.1282316"
}
}
10 changes: 10 additions & 0 deletions packages/common/src/cookies.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export type CookiesCount = {
total: number;
[key: string]: number;
};
exemptedCookies: {
total: number;
[key: string]: number;
};
};

export type CookieAnalytics = {
Expand Down Expand Up @@ -119,6 +123,7 @@ export type CookieData = {
inboundBlock: BLOCK_STATUS;
outboundBlock: BLOCK_STATUS;
};
exemptionReason?: Protocol.Network.CookieExemptionReason;
};

export type CookieTableData = CookieData & {
Expand Down Expand Up @@ -167,6 +172,7 @@ export interface Legend {
export interface CookieStatsComponents {
legend: Legend[];
blockedCookiesLegend: Legend[];
exemptedCookiesLegend: Legend[];
firstParty: {
count: number;
color: string;
Expand All @@ -179,6 +185,10 @@ export interface CookieStatsComponents {
count: number;
color: string;
}[];
exempted: {
count: number;
color: string;
}[];
}

export interface FramesWithCookies {
Expand Down
32 changes: 32 additions & 0 deletions packages/common/src/data/cookieExemptionReason/exemptionReasons.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//For source see https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/core/sdk/NetworkRequest.ts
const CookieExemptionReason = {
UserSetting: 'This cookie is allowed by user preference.',
TPCDMetadata:
'This cookie is allowed by a third-party cookie deprecation trial grace period.',
TPCDDeprecationTrial:
'This cookie is allowed by third-party cookie phaseout deprecation trial.',
TPCDHeuristics:
'This cookie is allowed by third-party cookie phaseout heuristics.',
EnterprisePolicy: 'This cookie is allowed by Chrome Enterprise policy.',
StorageAccessAPI: 'This cookie is allowed by the Storage Access API.',
TopLevelStorageAccessAPI:
'This cookie is allowed by the top-level Storage Access API.',
CorsOptIn: 'This cookie is allowed by CORS opt-in',
};

export default CookieExemptionReason;
16 changes: 16 additions & 0 deletions packages/common/src/data/cookieExemptionReason/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export { default as cookieExemptionReason } from './exemptionReasons';
17 changes: 17 additions & 0 deletions packages/common/src/data/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export { default as cookieIssueDetails } from './cookieExclusionAndWarningReasons';
export { cookieExemptionReason } from './cookieExemptionReason';
2 changes: 1 addition & 1 deletion packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export { default as calculateEffectiveExpiryDate } from './utils/calculateEffect
export { default as sanitizeCsvRecord } from './utils/sanitizeCsvRecord';
export { parseUrl } from './utils/parseUrl';
export { default as fetchLocalData } from './utils/fetchLocalData';
export { default as cookieIssueDetails } from './data/cookieExclusionAndWarningReasons';
export * from './data';
export { default as parseResponseReceivedExtraInfo } from './utils/parseResponseReceivedExtraInfo';
export { default as parseRequestWillBeSentExtraInfo } from './utils/parseRequestWillBeSentExtraInfo';
export { default as getDomainFromUrl } from './utils/getDomainFromUrl';
Expand Down
11 changes: 3 additions & 8 deletions packages/common/src/utils/filterCookiesByFrame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,17 @@
/**
* Internal dependencies.
*/
import { CookieTableData } from '../cookies.types';

interface Cookies {
[key: string]: CookieTableData;
}

import { TabCookies } from '../cookies.types';
interface TabFrames {
[key: string]: { frameIds: number[] };
}

const filterCookiesByFrame = (
cookies: Cookies | null,
cookies: TabCookies | null,
tabFrames: TabFrames | null,
frameUrl: string | null
) => {
const frameFilteredCookies: { [key: string]: CookieTableData } = {};
const frameFilteredCookies: TabCookies = {};
if (!cookies || !frameUrl || !tabFrames || !tabFrames[frameUrl]) {
return Object.values(frameFilteredCookies);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/common/src/utils/parseRequestWillBeSentExtraInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function parseRequestWillBeSentExtraInfo(
) {
const cookies: CookieData[] = [];

associatedCookies.forEach(({ blockedReasons, cookie }) => {
associatedCookies.forEach(({ blockedReasons, cookie, exemptionReason }) => {
const effectiveExpirationDate = calculateEffectiveExpiryDate(
cookie.expires
);
Expand Down Expand Up @@ -91,6 +91,7 @@ export default function parseRequestWillBeSentExtraInfo(
headerType: 'request' as CookieData['headerType'],
isFirstParty: isFirstParty(domain, tabUrl),
frameIdList: [],
exemptionReason: exemptionReason ? exemptionReason : undefined,
};

cookies.push(singleCookie);
Expand Down
10 changes: 10 additions & 0 deletions packages/common/src/utils/parseResponseReceivedExtraInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import isFirstParty from './isFirstParty';
* Parse Network.responseReceivedExtraInfo for extra information about a cookie.
* @param {object} headers Headers of resonse to be parsed to get extra information about a cookie.
* @param {object} blockedCookies Blocked Cookies associated with the response being parsed.
* @param {object} exemptedCookies Blocked Cookies associated with the response being parsed.
* @param {string|undefined} cookiePartitionKey Partittion key for the response.
* @param {object} requestMap An object for requestId to url.
* @param {string} tabUrl - The top-level URL (URL in the tab's address bar).
Expand All @@ -45,6 +46,7 @@ import isFirstParty from './isFirstParty';
export default function parseResponseReceivedExtraInfo(
headers: Protocol.Network.ResponseReceivedExtraInfoEvent['headers'],
blockedCookies: Protocol.Network.ResponseReceivedExtraInfoEvent['blockedCookies'],
exemptedCookies: Protocol.Network.ResponseReceivedExtraInfoEvent['exemptedCookies'],
cookiePartitionKey: Protocol.Network.ResponseReceivedExtraInfoEvent['cookiePartitionKey'],
requestMap: { [requestId: string]: string },
tabUrl: string,
Expand All @@ -66,6 +68,13 @@ export default function parseResponseReceivedExtraInfo(
}
});

const exemptedCookie = exemptedCookies?.find((c) => {
if (c.cookie) {
return c.cookie?.name === parsedCookie.name;
}
return false;
});

const effectiveExpirationDate = calculateEffectiveExpiryDate(
parsedCookie.expires
);
Expand Down Expand Up @@ -118,6 +127,7 @@ export default function parseResponseReceivedExtraInfo(
isFirstParty: isFirstParty(domain, tabUrl),
headerType: 'response' as CookieData['headerType'],
frameIdList: [],
exemptionReason: exemptedCookie?.exemptionReason,
};

cookies.push(singleCookie);
Expand Down
16 changes: 16 additions & 0 deletions packages/design-system/src/components/cookieDetails/details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import React, { useState } from 'react';
import classNames from 'classnames';
import {
BLOCK_STATUS,
CookieData,
cookieExemptionReason,
cookieIssueDetails,
type CookieTableData,
} from '@ps-analysis-tool/common';
Expand Down Expand Up @@ -87,6 +89,20 @@ const Details = ({ selectedCookie, isUsingCDP }: DetailsProps) => {

return (
<div className="text-xs py-1 px-1.5">
{selectedCookie.exemptionReason && (
<div className="mb-4">
<p className="font-bold text-raising-black dark:text-bright-gray mb-1">
Exemption Reason
</p>
<p className="text-outer-space-crayola dark:text-bright-gray">
{
cookieExemptionReason[
selectedCookie.exemptionReason as CookieData['exemptionReason']
]
}
</p>
</div>
)}
{selectedCookie.isDomainInAllowList && (
<div className="mb-4">
<p className="font-bold text-raising-black dark:text-bright-gray mb-1">
Expand Down
Loading
Loading