Skip to content

Commit f9703b2

Browse files
committed
Fixed potential race condition in per-tab configuration cookie hack.
1 parent ae5704d commit f9703b2

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/bg/ChildPolicies.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,10 @@
105105

106106
var ChildPolicies = {
107107
addTabInfoCookie(request, info) {
108+
let {tabId, frameId} = request;
108109
let h = {
109110
name: "Set-Cookie",
110-
value: `${marker}=${JSON.stringify(info)}`
111+
value: `${marker}_${tabId}_${frameId}=${JSON.stringify(info)}`
111112
};
112113
let {responseHeaders} = request;
113114
if (responseHeaders.some(({value, name}) => h.value === value && h.name === name)) {

src/content/staticNS.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,14 @@
5252
// (before any content can access it)
5353

5454
if (this.config.MARKER = MARKER) {
55-
let cookieRx = new RegExp(`(?:^|;\\s*)${MARKER}=([^;]*)`);
55+
let cookieRx = new RegExp(`(?:^|;\\s*)(${MARKER}(?:_\\d+){2})=([^;]*)`);
5656
let match = document.cookie.match(cookieRx);
5757
if (match) {
58+
let [cookie, cookieName, cookieValue] = match;
5859
// delete cookie NOW
59-
document.cookie = `${MARKER}=;expires=${new Date(Date.now() - 31536000000).toGMTString()}`;
60+
document.cookie = `${cookieName}=;expires=${new Date(Date.now() - 31536000000).toGMTString()}`;
6061
try {
61-
this.config.tabInfo = JSON.parse(decodeURIComponent(match[1]));
62+
this.config.tabInfo = JSON.parse(decodeURIComponent(cookieValue));
6263
} catch (e) {
6364
error(e);
6465
}

0 commit comments

Comments
 (0)