Fixed potential race condition in per-tab configuration cookie hack.
This commit is contained in:
parent
ae5704dcf9
commit
f9703b2bcb
|
@ -105,9 +105,10 @@
|
|||
|
||||
var ChildPolicies = {
|
||||
addTabInfoCookie(request, info) {
|
||||
let {tabId, frameId} = request;
|
||||
let h = {
|
||||
name: "Set-Cookie",
|
||||
value: `${marker}=${JSON.stringify(info)}`
|
||||
value: `${marker}_${tabId}_${frameId}=${JSON.stringify(info)}`
|
||||
};
|
||||
let {responseHeaders} = request;
|
||||
if (responseHeaders.some(({value, name}) => h.value === value && h.name === name)) {
|
||||
|
|
|
@ -52,13 +52,14 @@
|
|||
// (before any content can access it)
|
||||
|
||||
if (this.config.MARKER = MARKER) {
|
||||
let cookieRx = new RegExp(`(?:^|;\\s*)${MARKER}=([^;]*)`);
|
||||
let cookieRx = new RegExp(`(?:^|;\\s*)(${MARKER}(?:_\\d+){2})=([^;]*)`);
|
||||
let match = document.cookie.match(cookieRx);
|
||||
if (match) {
|
||||
let [cookie, cookieName, cookieValue] = match;
|
||||
// delete cookie NOW
|
||||
document.cookie = `${MARKER}=;expires=${new Date(Date.now() - 31536000000).toGMTString()}`;
|
||||
document.cookie = `${cookieName}=;expires=${new Date(Date.now() - 31536000000).toGMTString()}`;
|
||||
try {
|
||||
this.config.tabInfo = JSON.parse(decodeURIComponent(match[1]));
|
||||
this.config.tabInfo = JSON.parse(decodeURIComponent(cookieValue));
|
||||
} catch (e) {
|
||||
error(e);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue