Skip to content

Commit 3a2bb62

Browse files
committed
Improve trusted-set-cookie scriptlet
Ability to use regex value for `, domain, value` vararg. Related discussion: uBlockOrigin/uAssets@afc6ff5#commitcomment-160035082
1 parent 28d2326 commit 3a2bb62

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/js/resources/cookie.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,15 @@ export function setCookieFn(
135135

136136
if ( trusted ) {
137137
if ( options.domain ) {
138-
cookieParts.push(`; domain=${options.domain}`);
138+
let domain = options.domain;
139+
if ( /^\/.+\//.test(domain) ) {
140+
const reDomain = new RegExp(domain.slice(1, -1));
141+
const match = reDomain.exec(document.location.hostname);
142+
domain = match ? match[0] : undefined;
143+
}
144+
if ( domain ) {
145+
cookieParts.push(`; domain=${domain}`);
146+
}
139147
}
140148
cookieParts.push('; Secure');
141149
} else if ( /^__(Host|Secure)-/.test(name) ) {

0 commit comments

Comments
 (0)