Fix passing IP Addresses into browsingData removal functions (#1451)
* First commit to see if passing IP address work again. Signed-off-by: Kenneth T <6724477+kennethtran93@users.noreply.github.com>
This commit is contained in:
parent
cb8d6e2fa0
commit
8d00e6e068
|
@ -1324,6 +1324,30 @@ describe('Library Functions', () => {
|
|||
'https://.www.example.com',
|
||||
]);
|
||||
});
|
||||
|
||||
it('should return proper IPv4 address', () => {
|
||||
expect(prepareCleanupDomains('127.0.0.1', browserName.Firefox)).toEqual([
|
||||
'127.0.0.1',
|
||||
]);
|
||||
});
|
||||
|
||||
it('should return proper IPv4 address for Chrome', () => {
|
||||
expect(prepareCleanupDomains('127.0.0.1', browserName.Chrome)).toEqual([
|
||||
'http://127.0.0.1',
|
||||
'https://127.0.0.1',
|
||||
]);
|
||||
});
|
||||
it('should return proper IPv6 address', () => {
|
||||
expect(prepareCleanupDomains('::1', browserName.Firefox)).toEqual([
|
||||
'[::1]',
|
||||
]);
|
||||
});
|
||||
it('should return proper IPv6 address for Chrome', () => {
|
||||
expect(prepareCleanupDomains('::1', browserName.Chrome)).toEqual([
|
||||
'http://[::1]',
|
||||
'https://[::1]',
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('prepareCookieDomain()', () => {
|
||||
|
@ -1338,6 +1362,17 @@ describe('Library Functions', () => {
|
|||
).toEqual('https://google.com/');
|
||||
});
|
||||
|
||||
it('should return an IPv4 Address if domain was an IPv4 address', () => {
|
||||
expect(
|
||||
prepareCookieDomain({
|
||||
...mockCookie,
|
||||
domain: '127.0.0.1',
|
||||
path: '/',
|
||||
secure: true,
|
||||
}),
|
||||
).toEqual('https://127.0.0.1/');
|
||||
});
|
||||
|
||||
it('should return a wrapped ivp6 ip cookie domain in brackets', () => {
|
||||
expect(
|
||||
prepareCookieDomain({
|
||||
|
|
|
@ -519,7 +519,10 @@ export const isAnIP = (url: string | undefined): boolean => {
|
|||
return false;
|
||||
}
|
||||
const hostname = getHostname(url);
|
||||
return ipaddr.isValid(hostname);
|
||||
return (
|
||||
ipaddr.IPv4.isValidFourPartDecimal(hostname) ||
|
||||
ipaddr.IPv6.isValid(hostname)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -680,21 +683,28 @@ export const prepareCleanupDomains = (
|
|||
bName: browserName = browserDetect() as browserName,
|
||||
): string[] => {
|
||||
if (domain.trim() === '') return [];
|
||||
const www = new RegExp(/^www[0-9a-z]?\./i);
|
||||
const sDot = new RegExp(/^\./);
|
||||
let d: string = domain.trim();
|
||||
const domains = new Set<string>();
|
||||
if (sDot.test(d)) {
|
||||
// dot at beginning. .sub.doma.in(.)
|
||||
d = d.slice(1);
|
||||
}
|
||||
// at this point it should be all unison - sub.doma.in(.)
|
||||
domains.add(d); // sub.doma.in
|
||||
domains.add(`.${d}`); // .sub.doma.in
|
||||
if (ipaddr.IPv4.isValidFourPartDecimal(d)) {
|
||||
domains.add(d);
|
||||
} else if (ipaddr.IPv6.isValid(d)) {
|
||||
domains.add(`[${d}]`);
|
||||
} else {
|
||||
const www = new RegExp(/^www[0-9a-z]?\./i);
|
||||
const sDot = new RegExp(/^\./);
|
||||
// Most likely not an IPv4 or IPv6 address. Presuming domain.
|
||||
if (sDot.test(d)) {
|
||||
// dot at beginning. .sub.doma.in(.)
|
||||
d = d.slice(1);
|
||||
}
|
||||
// at this point it should be all unison - sub.doma.in(.)
|
||||
domains.add(d); // sub.doma.in
|
||||
domains.add(`.${d}`); // .sub.doma.in
|
||||
|
||||
if (!www.test(d)) {
|
||||
domains.add(`www.${d}`); // www.sub.doma.in
|
||||
domains.add(`.www.${d}`); // .www.sub.doma.in
|
||||
if (!www.test(d)) {
|
||||
domains.add(`www.${d}`); // www.sub.doma.in
|
||||
domains.add(`.www.${d}`); // .www.sub.doma.in
|
||||
}
|
||||
}
|
||||
|
||||
if (bName === browserName.Chrome || bName === browserName.Opera) {
|
||||
|
@ -718,8 +728,8 @@ export const prepareCookieDomain = (cookie: browser.cookies.Cookie): string => {
|
|||
// No Domain - presuming local file (file:// protocol)
|
||||
return `file://${cookie.path}`;
|
||||
}
|
||||
// Looks like a v6 IP
|
||||
if (/^[0-9a-f]*:[0-9a-f:]+$/i.test(cookieDomain)) {
|
||||
|
||||
if (ipaddr.IPv6.isValid(cookieDomain)) {
|
||||
cookieDomain = `[${cookieDomain}]`;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
{
|
||||
"version": "3.8.2",
|
||||
"notes": [
|
||||
"Fixed: Passing IP Addresses to browsingData / site data cleanups. Fixes #983 via PR#1451, with thanks to Rob W.",
|
||||
"Fixed: Removing expired cookies now respect configured domain cleanup rules. Fixes #1427 via PR#1450.",
|
||||
"Updated: Translations from Crowdin."
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue