mirror of https://github.com/gorhill/uBlock.git
Improve `[trusted-]set-cookie` scriptlets
Related issues: - https://github.com/uBlockOrigin/uBlock-issues/issues/3178 - https://github.com/uBlockOrigin/uBlock-issues/issues/2777
This commit is contained in:
parent
b78f0c4fa4
commit
11a48561e0
|
@ -969,6 +969,16 @@ function setCookieFn(
|
||||||
path = '',
|
path = '',
|
||||||
options = {},
|
options = {},
|
||||||
) {
|
) {
|
||||||
|
// https://datatracker.ietf.org/doc/html/rfc2616#section-2.2
|
||||||
|
// https://github.com/uBlockOrigin/uBlock-issues/issues/2777
|
||||||
|
if ( trusted === false && /[^!#$%&'*+\-.0-9A-Z[\]^_`a-z|~]/.test(name) ) {
|
||||||
|
name = encodeURIComponent(name);
|
||||||
|
}
|
||||||
|
// https://datatracker.ietf.org/doc/html/rfc6265#section-4.1.1
|
||||||
|
if ( /[^!#-+\--:<-[\]-~]/.test(value) ) {
|
||||||
|
value = encodeURIComponent(value);
|
||||||
|
}
|
||||||
|
|
||||||
const cookieBefore = getCookieFn(name);
|
const cookieBefore = getCookieFn(name);
|
||||||
if ( cookieBefore !== undefined && options.dontOverwrite ) { return; }
|
if ( cookieBefore !== undefined && options.dontOverwrite ) { return; }
|
||||||
if ( cookieBefore === value && options.reload ) { return; }
|
if ( cookieBefore === value && options.reload ) { return; }
|
||||||
|
@ -3713,7 +3723,6 @@ function setCookie(
|
||||||
if ( name === '' ) { return; }
|
if ( name === '' ) { return; }
|
||||||
const safe = safeSelf();
|
const safe = safeSelf();
|
||||||
const logPrefix = safe.makeLogPrefix('set-cookie', name, value, path);
|
const logPrefix = safe.makeLogPrefix('set-cookie', name, value, path);
|
||||||
name = encodeURIComponent(name);
|
|
||||||
|
|
||||||
const validValues = [
|
const validValues = [
|
||||||
'accept', 'reject',
|
'accept', 'reject',
|
||||||
|
|
Loading…
Reference in New Issue