Prevent persistent storage in incognito

This commit is contained in:
Mariusz Kaczmarczyk 2021-03-22 20:08:43 +01:00 committed by Oliver Blanthorn
parent ae9707c4cb
commit 480ec7a72e
No known key found for this signature in database
GPG key ID: 2BB8C36BB504BFF3
2 changed files with 11 additions and 9 deletions

View file

@ -2609,7 +2609,6 @@ export async function tabopenwait(...addressarr: string[]): Promise<browser.tabs
//#background_helper
export async function tabopen_helper({ addressarr = [], waitForDom = false }): Promise<browser.tabs.Tab> {
let active
let waitForDom
let container
const win = await browser.windows.getCurrent()

View file

@ -89,10 +89,11 @@ const state = new Proxy(overlay, {
set(target, property: keyof State, value) {
logger.debug("State changed!", property, value)
if (notBackground()) {
const inIncognitoContext = browser.extension.inIncognitoContext
browser.runtime.sendMessage({
type: "state",
command: "stateUpdate",
args: { property, value },
args: { property, value, inIncognitoContext },
})
return true
}
@ -101,13 +102,6 @@ const state = new Proxy(overlay, {
// Persist "sets" to storage in the background for some keys
if (PERSISTENT_KEYS.includes(property)) {
// Ensure we don't accidentally store anything sensitive
if (browser.extension.inIncognitoContext) {
console.error(
"Attempted to write to storage in private window.",
)
return false
}
browser.storage.local.set({
state: R.pick(PERSISTENT_KEYS, target),
} as any)
@ -136,6 +130,15 @@ notBackground &&
if (message.command == "stateUpdate") {
const property = message.args.property
const value = message.args.value
// Ensure we don't accidentally store anything sensitive
const inIncognitoContext = message.args.inIncognitoContext
if (inIncognitoContext && PERSISTENT_KEYS.includes(property)) {
overlay[property] = value
console.error(
"Attempted to write to storage in private window.",
)
return
}
logger.debug("State changed!", property, value)
state[property] = value
} else if (message.command == "stateGet") {