mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-04 08:37:11 +02:00
Fix cookie removal on subdomains of base domain
Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/1126
This commit is contained in:
parent
d95bab1e43
commit
c4d39d3763
@ -1197,14 +1197,14 @@
|
||||
// https://github.com/NanoAdblocker/NanoFilters/issues/149
|
||||
/// cookie-remover.js
|
||||
(function() {
|
||||
let needle = '{{1}}',
|
||||
reName = /./;
|
||||
const needle = '{{1}}';
|
||||
let reName = /./;
|
||||
if ( /^\/.+\/$/.test(needle) ) {
|
||||
reName = new RegExp(needle.slice(1,-1));
|
||||
} else if ( needle !== '' && needle !== '{{1}}' ) {
|
||||
reName = new RegExp(needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
|
||||
}
|
||||
let removeCookie = function() {
|
||||
const removeCookie = function() {
|
||||
document.cookie.split(';').forEach(cookieStr => {
|
||||
let pos = cookieStr.indexOf('=');
|
||||
if ( pos === -1 ) { return; }
|
||||
@ -1213,8 +1213,16 @@
|
||||
let part1 = cookieName + '=';
|
||||
let part2a = '; domain=' + document.location.hostname;
|
||||
let part2b = '; domain=.' + document.location.hostname;
|
||||
let part2c, part2d;
|
||||
let domain = document.domain;
|
||||
let part2c = domain && domain !== document.location.hostname ? '; domain=.' + domain : undefined;
|
||||
if ( domain ) {
|
||||
if ( domain !== document.location.hostname ) {
|
||||
part2c = '; domain=.' + domain;
|
||||
}
|
||||
if ( domain.startsWith('www.') ) {
|
||||
part2d = '; domain=' + domain.replace('www', '');
|
||||
}
|
||||
}
|
||||
let part3 = '; path=/';
|
||||
let part4 = '; Max-Age=-1000; expires=Thu, 01 Jan 1970 00:00:00 GMT';
|
||||
document.cookie = part1 + part4;
|
||||
@ -1226,6 +1234,9 @@
|
||||
if ( part2c !== undefined ) {
|
||||
document.cookie = part1 + part2c + part3 + part4;
|
||||
}
|
||||
if ( part2d !== undefined ) {
|
||||
document.cookie = part1 + part2d + part3 + part4;
|
||||
}
|
||||
});
|
||||
};
|
||||
removeCookie();
|
||||
|
Loading…
Reference in New Issue
Block a user