Add `domain` vararg to `trusted-set-cookie`

Related issue:
https://github.com/uBlockOrigin/uBlock-issues/issues/2893
This commit is contained in:
Raymond Hill 2023-10-22 18:19:18 -04:00
parent 1e745c2f4d
commit 82c59b4b6e
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 22 additions and 8 deletions

View File

@ -738,10 +738,11 @@ function objectPruneFn(
/******************************************************************************/
builtinScriptlets.push({
name: 'set-cookie-helper.fn',
fn: setCookieHelper,
name: 'set-cookie.fn',
fn: setCookieFn,
});
function setCookieHelper(
function setCookieFn(
trusted = false,
name = '',
value = '',
expires = '',
@ -772,7 +773,18 @@ function setCookieHelper(
if ( path === '/' ) {
cookieParts.push('; path=/');
}
document.cookie = cookieParts.join('');
if ( trusted ) {
if ( options.domain ) {
cookieParts.push(`; domain=${options.domain}`);
}
cookieParts.push('; Secure');
}
try {
document.cookie = cookieParts.join('');
} catch(_) {
}
if ( options.reload && getCookieValue(name) === value ) {
window.location.reload();
@ -3336,7 +3348,7 @@ builtinScriptlets.push({
world: 'ISOLATED',
dependencies: [
'safe-self.fn',
'set-cookie-helper.fn',
'set-cookie.fn',
],
});
function setCookie(
@ -3362,7 +3374,8 @@ function setCookie(
}
value = encodeURIComponent(value);
setCookieHelper(
setCookieFn(
false,
name,
value,
'',
@ -3721,7 +3734,7 @@ builtinScriptlets.push({
world: 'ISOLATED',
dependencies: [
'safe-self.fn',
'set-cookie-helper.fn',
'set-cookie.fn',
],
});
function trustedSetCookie(
@ -3753,7 +3766,8 @@ function trustedSetCookie(
expires = time.toUTCString();
}
setCookieHelper(
setCookieFn(
true,
name,
value,
expires,