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

Add CHIPS cookie state to firefox (cloudflare) #1465

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Changes from all 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
54 changes: 28 additions & 26 deletions plugin/js/HttpClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,33 +207,35 @@ class HttpClient {
}

static async setPartitionCookies(url) {
if (!util.isFirefox()) {
// get partitionKey in the form of https://<site name>.<tld>
let parsedUrl = new URL(url);
// get partitionKey in the form of https://<site name>.<tld>
let parsedUrl = new URL(url);
//keep old code for reference in case it changes again
//let topLevelSite = parsedUrl.protocol + "//" + parsedUrl.hostname;

try {
// get all cookie from the site which use the partitionKey (e.g. cloudflare)
//keep old code for reference in case it changes again
//let topLevelSite = parsedUrl.protocol + "//" + parsedUrl.hostname;

try {
// get all cookie from the site which use the partitionKey (e.g. cloudflare)
//keep old code for reference in case it changes again
//let cookies = await chrome.cookies.getAll({partitionKey: {topLevelSite: topLevelSite}});

//set domain to the highest level from the website as all subdomains are included #1447 #1445
let urlparts = parsedUrl.hostname.split(".");
let cookies = await chrome.cookies.getAll({domain: urlparts[urlparts.length-2]+"."+urlparts[urlparts.length-1],partitionKey: {}});

//create new cookies for the site without the partitionKey
//cookies without the partitionKey get sent with fetch
cookies.forEach(element => chrome.cookies.set({
domain: element.domain,
url: "https://"+element.domain.substring(1),
name: element.name,
value: element.value
}));
} catch {
// Probably running browser that doesn't support partitionKey, e.g. Kiwi
}
}
//let cookies = await chrome.cookies.getAll({partitionKey: {topLevelSite: topLevelSite}});

//set domain to the highest level from the website as all subdomains are included #1447 #1445
let urlparts = parsedUrl.hostname.split(".");
let cookies = "";
if (!util.isFirefox()) {
cookies = await chrome.cookies.getAll({domain: urlparts[urlparts.length-2]+"."+urlparts[urlparts.length-1],partitionKey: {}});
}else{
cookies = await browser.cookies.getAll({domain: urlparts[urlparts.length-2]+"."+urlparts[urlparts.length-1],partitionKey: {}});
}
//create new cookies for the site without the partitionKey
//cookies without the partitionKey get sent with fetch
cookies.forEach(element => chrome.cookies.set({
domain: element.domain,
url: "https://"+element.domain.substring(1),
name: element.name,
value: element.value
}));
} catch {
// Probably running browser that doesn't support partitionKey, e.g. Kiwi
}
}
}

Expand Down
Loading