From 9c505550a98546dde67f8349b146d55c0db45b4d Mon Sep 17 00:00:00 2001 From: Brendan Early Date: Fri, 12 Jul 2019 22:26:13 -0500 Subject: [PATCH 1/8] no more cookie Can't manipulate cookie from background script --- manifest-chrome.json | 3 +-- src/components/Popup/MainHeader.vue | 1 - src/import.ts | 10 ---------- src/store/Accounts.ts | 17 ----------------- 4 files changed, 1 insertion(+), 30 deletions(-) diff --git a/manifest-chrome.json b/manifest-chrome.json index 49271dd7a..26b5d2b6c 100644 --- a/manifest-chrome.json +++ b/manifest-chrome.json @@ -33,8 +33,7 @@ "background": { "scripts": [ "dist/background.js" - ], - "persistent": false + ] }, "permissions": [ "activeTab", diff --git a/src/components/Popup/MainHeader.vue b/src/components/Popup/MainHeader.vue index 1e37dbc27..4884c7272 100644 --- a/src/components/Popup/MainHeader.vue +++ b/src/components/Popup/MainHeader.vue @@ -100,7 +100,6 @@ export default Vue.extend({ this.$store.commit("accounts/stopFilter"); }, lock() { - document.cookie = 'passphrase=";expires=Thu, 01 Jan 1970 00:00:00 GMT"'; chrome.runtime.sendMessage({ action: "lock" }, window.close); return; }, diff --git a/src/import.ts b/src/import.ts index 2fd827d72..874abee3c 100644 --- a/src/import.ts +++ b/src/import.ts @@ -32,16 +32,6 @@ init(); function getCachedPassphrase() { return new Promise( (resolve: (value: string) => void, reject: (reason: Error) => void) => { - const cookie = document.cookie; - const cookieMatch = cookie - ? document.cookie.match(/passphrase=([^;]*)/) - : null; - const cachedPassphrase = - cookieMatch && cookieMatch.length > 1 ? cookieMatch[1] : null; - if (cachedPassphrase) { - return resolve(cachedPassphrase); - } - chrome.runtime.sendMessage( { action: "passphrase" }, (passphrase: string) => { diff --git a/src/store/Accounts.ts b/src/store/Accounts.ts index dfff8d064..6a33463cb 100644 --- a/src/store/Accounts.ts +++ b/src/store/Accounts.ts @@ -163,7 +163,6 @@ export class Accounts implements IModule { state.commit("style/hideInfo", null, { root: true }); if (!state.getters.currentlyEncrypted) { - document.cookie = "passphrase=" + password; chrome.runtime.sendMessage({ action: "cachePassphrase", value: password @@ -181,7 +180,6 @@ export class Accounts implements IModule { ); state.state.encryption.updateEncryptionPassword(password); - document.cookie = "passphrase=" + password; chrome.runtime.sendMessage({ action: "cachePassphrase", value: password @@ -354,21 +352,6 @@ export class Accounts implements IModule { private getCachedPassphrase() { return new Promise( (resolve: (value: string) => void, reject: (reason: Error) => void) => { - const cookie = document.cookie; - const cookieMatch = cookie - ? document.cookie.match(/passphrase=([^;]*)/) - : null; - const cachedPassphrase = - cookieMatch && cookieMatch.length > 1 ? cookieMatch[1] : null; - const cachedPassphraseLocalStorage = localStorage.encodedPhrase - ? CryptoJS.AES.decrypt(localStorage.encodedPhrase, "").toString( - CryptoJS.enc.Utf8 - ) - : ""; - if (cachedPassphrase || cachedPassphraseLocalStorage) { - return resolve(cachedPassphrase || cachedPassphraseLocalStorage); - } - chrome.runtime.sendMessage( { action: "passphrase" }, (passphrase: string) => { From 3a02fdc2f0ca86c83316794407206c481e31c1f5 Mon Sep 17 00:00:00 2001 From: Brendan Early Date: Fri, 12 Jul 2019 22:49:54 -0500 Subject: [PATCH 2/8] autolock (#219) --- _locales/en/messages.json | 6 ++++++ src/background.ts | 15 +++++++++++++++ src/components/Popup/PrefrencesPage.vue | 23 +++++++++++++++++++++++ src/definitions/module-interface.d.ts | 1 + src/store/Menu.ts | 5 +++++ 5 files changed, 50 insertions(+) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index bb9353304..ad51c0710 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -303,5 +303,11 @@ }, "loading": { "message": "Loading..." + }, + "autolock": { + "message": "Lock after" + }, + "seconds": { + "message": "seconds" } } diff --git a/src/background.ts b/src/background.ts index f52c2269f..5a5d3afde 100644 --- a/src/background.ts +++ b/src/background.ts @@ -9,6 +9,8 @@ import { EntryStorage, ManagedStorage } from "./models/storage"; import { Dropbox, Drive } from "./models/backup"; let cachedPassphrase = ""; +let autolockTimeout: number; + chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { if (message.action === "position") { if (!sender.tab) { @@ -24,12 +26,17 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { ); } else if (message.action === "cachePassphrase") { cachedPassphrase = message.value; + clearTimeout(autolockTimeout); + setAutolock(); } else if (message.action === "passphrase") { sendResponse(cachedPassphrase); } else if (["dropbox", "drive"].indexOf(message.action) > -1) { getBackupToken(message.action); } else if (message.action === "lock") { cachedPassphrase = ""; + } else if (message.action === "resetAutolock") { + clearTimeout(autolockTimeout); + setAutolock(); } }); @@ -395,3 +402,11 @@ chrome.commands.onCommand.addListener(async (command: string) => { break; } }); + +function setAutolock() { + if (Number(localStorage.autolock) > 0) { + autolockTimeout = setTimeout(() => { + cachedPassphrase = ""; + }, Number(localStorage.autolock) * 1000); + } +} diff --git a/src/components/Popup/PrefrencesPage.vue b/src/components/Popup/PrefrencesPage.vue index 6396c83dd..f6d0dc940 100644 --- a/src/components/Popup/PrefrencesPage.vue +++ b/src/components/Popup/PrefrencesPage.vue @@ -24,6 +24,17 @@ +
+ + + {{ i18n.seconds }} +
{{ i18n.popout }}
@@ -55,6 +66,18 @@ export default Vue.extend({ set(useHighContrast: boolean) { this.$store.commit("menu/setHighContrast", useHighContrast); } + }, + encryption(): IEncryption { + return this.$store.state.accounts.encryption; + }, + autolock: { + get(): number { + return this.$store.state.menu.autolock; + }, + set(autolock: number) { + this.$store.commit("menu/setAutolock", autolock); + chrome.runtime.sendMessage({ action: "resetAutolock" }); + } } }, methods: { diff --git a/src/definitions/module-interface.d.ts b/src/definitions/module-interface.d.ts index 75b1dffeb..094e6d053 100644 --- a/src/definitions/module-interface.d.ts +++ b/src/definitions/module-interface.d.ts @@ -29,6 +29,7 @@ interface VuexConstructor { interface MenuState { version: String; zoom: Number; + autolock: Number; useAutofill: Boolean; useHighContrast: Boolean; backupDisabled: Boolean; diff --git a/src/store/Menu.ts b/src/store/Menu.ts index e459d3166..d76ab68de 100644 --- a/src/store/Menu.ts +++ b/src/store/Menu.ts @@ -8,6 +8,7 @@ export class Menu implements IModule { zoom: Number(localStorage.zoom) || 100, useAutofill: localStorage.autofill === "true", useHighContrast: localStorage.highContrast === "true", + autolock: Number(localStorage.autolock) || 0, backupDisabled: await ManagedStorage.get("disableBackup"), storageArea: await ManagedStorage.get("storageArea"), feedbackURL: await ManagedStorage.get("feedbackURL") @@ -25,6 +26,10 @@ export class Menu implements IModule { setHighContrast(state: MenuState, useHighContrast: boolean) { state.useHighContrast = useHighContrast; localStorage.highContrast = useHighContrast; + }, + setAutolock(state: MenuState, autolock: number) { + state.autolock = autolock; + localStorage.autolock = autolock; } }, namespaced: true From da351b0e9889d6a6cbdd87b90d007d16e081448e Mon Sep 17 00:00:00 2001 From: Brendan Early Date: Sat, 13 Jul 2019 13:50:41 -0500 Subject: [PATCH 3/8] seconds => minutes --- _locales/en/messages.json | 4 ++-- src/background.ts | 2 +- src/components/Popup/PrefrencesPage.vue | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index ad51c0710..723ca1066 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -307,7 +307,7 @@ "autolock": { "message": "Lock after" }, - "seconds": { - "message": "seconds" + "minutes": { + "message": "minutes" } } diff --git a/src/background.ts b/src/background.ts index 5a5d3afde..0ecaed00f 100644 --- a/src/background.ts +++ b/src/background.ts @@ -407,6 +407,6 @@ function setAutolock() { if (Number(localStorage.autolock) > 0) { autolockTimeout = setTimeout(() => { cachedPassphrase = ""; - }, Number(localStorage.autolock) * 1000); + }, Number(localStorage.autolock) * 60000); } } diff --git a/src/components/Popup/PrefrencesPage.vue b/src/components/Popup/PrefrencesPage.vue index f6d0dc940..250c34814 100644 --- a/src/components/Popup/PrefrencesPage.vue +++ b/src/components/Popup/PrefrencesPage.vue @@ -33,7 +33,7 @@ style="width: 70px;" v-model="autolock" /> - {{ i18n.seconds }} + {{ i18n.minutes }}
{{ i18n.popout }}
From 43be56c99210aa2b5c00be3834486403c30f3672 Mon Sep 17 00:00:00 2001 From: Brendan Early Date: Sat, 13 Jul 2019 14:00:55 -0500 Subject: [PATCH 4/8] fix build --- .travis.yml | 2 +- package-lock.json | 43 ++++++++++--------------------------------- 2 files changed, 11 insertions(+), 34 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7cc685e5d..a661374cf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ jobs: env: CACHE_NAME=LINTSPACES - stage: test name: Build Firefox and run addons-linter - script: npm install --only=production addons-linter && npm run firefox && addons-linter + script: npm install --only=production -g addons-linter && npm run firefox && addons-linter firefox env: CACHE_NAME=FIREFOXLINTER - stage: test diff --git a/package-lock.json b/package-lock.json index aee9f5d30..b3fa42e07 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3120,9 +3120,9 @@ } }, "mixin-deep": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/mixin-deep/-/mixin-deep-1.3.1.tgz", - "integrity": "sha512-8ZItLHeEgaqEvd5lYBXfm4EZSFCX29Jb9K+lAHhDKzReKBQKj3R+7NOF6tjqYi9t4oI8VUfaWITJQm86wnXGNQ==", + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/mixin-deep/-/mixin-deep-1.3.2.tgz", + "integrity": "sha512-WRoDn//mXBiJ1H40rqa3vH0toePwSsGb45iInWlTySa+Uu4k3tYUSxa2v1KqAiLtvlrSzaExqS1gtk96A9zvEA==", "dev": true, "requires": { "for-in": "^1.0.2", @@ -4074,9 +4074,9 @@ "dev": true }, "set-value": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/set-value/-/set-value-2.0.0.tgz", - "integrity": "sha512-hw0yxk9GT/Hr5yJEYnHNKYXkIA8mVJgd9ditYZCe16ZczcaELYYcfvaXesNACk2O8O0nTiPQcQhGUQj8JLzeeg==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/set-value/-/set-value-2.0.1.tgz", + "integrity": "sha512-JxHc1weCN68wRY0fhCoXpyK55m/XPHafOmK4UWD7m2CI14GMcFypt4w/0+NV5f/ZMby2F6S2wwA7fgynh9gWSw==", "dev": true, "requires": { "extend-shallow": "^2.0.1", @@ -4665,38 +4665,15 @@ "dev": true }, "union-value": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.0.tgz", - "integrity": "sha1-XHHDTLW61dzr4+oM0IIHulqhrqQ=", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.1.tgz", + "integrity": "sha512-tJfXmxMeWYnczCVs7XAEvIV7ieppALdyepWMkHkwciRpZraG/xwT+s2JN8+pr1+8jCRf80FFzvr+MpQeeoF4Xg==", "dev": true, "requires": { "arr-union": "^3.1.0", "get-value": "^2.0.6", "is-extendable": "^0.1.1", - "set-value": "^0.4.3" - }, - "dependencies": { - "extend-shallow": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz", - "integrity": "sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8=", - "dev": true, - "requires": { - "is-extendable": "^0.1.0" - } - }, - "set-value": { - "version": "0.4.3", - "resolved": "https://registry.npmjs.org/set-value/-/set-value-0.4.3.tgz", - "integrity": "sha1-fbCPnT0i3H945Trzw79GZuzfzPE=", - "dev": true, - "requires": { - "extend-shallow": "^2.0.1", - "is-extendable": "^0.1.1", - "is-plain-object": "^2.0.1", - "to-object-path": "^0.3.0" - } - } + "set-value": "^2.0.1" } }, "uniq": { From 6406b620e2235894fc43f1f87a156b6d1b286de5 Mon Sep 17 00:00:00 2001 From: Brendan Early Date: Wed, 7 Aug 2019 12:38:48 -0500 Subject: [PATCH 5/8] Revert "no more cookie" This reverts commit 9c505550a98546dde67f8349b146d55c0db45b4d. --- manifest-chrome.json | 3 ++- src/components/Popup/MainHeader.vue | 1 + src/import.ts | 10 ++++++++++ src/store/Accounts.ts | 17 +++++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/manifest-chrome.json b/manifest-chrome.json index 26b5d2b6c..49271dd7a 100644 --- a/manifest-chrome.json +++ b/manifest-chrome.json @@ -33,7 +33,8 @@ "background": { "scripts": [ "dist/background.js" - ] + ], + "persistent": false }, "permissions": [ "activeTab", diff --git a/src/components/Popup/MainHeader.vue b/src/components/Popup/MainHeader.vue index 4884c7272..1e37dbc27 100644 --- a/src/components/Popup/MainHeader.vue +++ b/src/components/Popup/MainHeader.vue @@ -100,6 +100,7 @@ export default Vue.extend({ this.$store.commit("accounts/stopFilter"); }, lock() { + document.cookie = 'passphrase=";expires=Thu, 01 Jan 1970 00:00:00 GMT"'; chrome.runtime.sendMessage({ action: "lock" }, window.close); return; }, diff --git a/src/import.ts b/src/import.ts index 874abee3c..2fd827d72 100644 --- a/src/import.ts +++ b/src/import.ts @@ -32,6 +32,16 @@ init(); function getCachedPassphrase() { return new Promise( (resolve: (value: string) => void, reject: (reason: Error) => void) => { + const cookie = document.cookie; + const cookieMatch = cookie + ? document.cookie.match(/passphrase=([^;]*)/) + : null; + const cachedPassphrase = + cookieMatch && cookieMatch.length > 1 ? cookieMatch[1] : null; + if (cachedPassphrase) { + return resolve(cachedPassphrase); + } + chrome.runtime.sendMessage( { action: "passphrase" }, (passphrase: string) => { diff --git a/src/store/Accounts.ts b/src/store/Accounts.ts index 6a33463cb..dfff8d064 100644 --- a/src/store/Accounts.ts +++ b/src/store/Accounts.ts @@ -163,6 +163,7 @@ export class Accounts implements IModule { state.commit("style/hideInfo", null, { root: true }); if (!state.getters.currentlyEncrypted) { + document.cookie = "passphrase=" + password; chrome.runtime.sendMessage({ action: "cachePassphrase", value: password @@ -180,6 +181,7 @@ export class Accounts implements IModule { ); state.state.encryption.updateEncryptionPassword(password); + document.cookie = "passphrase=" + password; chrome.runtime.sendMessage({ action: "cachePassphrase", value: password @@ -352,6 +354,21 @@ export class Accounts implements IModule { private getCachedPassphrase() { return new Promise( (resolve: (value: string) => void, reject: (reason: Error) => void) => { + const cookie = document.cookie; + const cookieMatch = cookie + ? document.cookie.match(/passphrase=([^;]*)/) + : null; + const cachedPassphrase = + cookieMatch && cookieMatch.length > 1 ? cookieMatch[1] : null; + const cachedPassphraseLocalStorage = localStorage.encodedPhrase + ? CryptoJS.AES.decrypt(localStorage.encodedPhrase, "").toString( + CryptoJS.enc.Utf8 + ) + : ""; + if (cachedPassphrase || cachedPassphraseLocalStorage) { + return resolve(cachedPassphrase || cachedPassphraseLocalStorage); + } + chrome.runtime.sendMessage( { action: "passphrase" }, (passphrase: string) => { From 67bcea6787b36a169bb73a6043ed04c729858d30 Mon Sep 17 00:00:00 2001 From: Brendan Early Date: Wed, 7 Aug 2019 12:50:48 -0500 Subject: [PATCH 6/8] cookie to the background --- src/background.ts | 35 +++++++++++++++++++++++------ src/components/Popup/MainHeader.vue | 1 - src/import.ts | 10 --------- src/store/Accounts.ts | 17 -------------- 4 files changed, 28 insertions(+), 35 deletions(-) diff --git a/src/background.ts b/src/background.ts index 0ecaed00f..16c1d9be9 100644 --- a/src/background.ts +++ b/src/background.ts @@ -25,15 +25,17 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { message.info.windowWidth ); } else if (message.action === "cachePassphrase") { + document.cookie = "passphrase=" + message.value; cachedPassphrase = message.value; clearTimeout(autolockTimeout); setAutolock(); } else if (message.action === "passphrase") { - sendResponse(cachedPassphrase); + sendResponse(getCachedPassphrase()); } else if (["dropbox", "drive"].indexOf(message.action) > -1) { getBackupToken(message.action); } else if (message.action === "lock") { cachedPassphrase = ""; + document.cookie = 'passphrase=";expires=Thu, 01 Jan 1970 00:00:00 GMT"'; } else if (message.action === "resetAutolock") { clearTimeout(autolockTimeout); setAutolock(); @@ -283,12 +285,12 @@ function getBackupToken(service: string) { xhr.open( "POST", "https://www.googleapis.com/oauth2/v4/token?client_id=" + - getCredentials().drive.client_id + - "&client_secret=" + - getCredentials().drive.client_secret + - "&code=" + - value + - "&redirect_uri=https://authenticator.cc/oauth&grant_type=authorization_code" + getCredentials().drive.client_id + + "&client_secret=" + + getCredentials().drive.client_secret + + "&code=" + + value + + "&redirect_uri=https://authenticator.cc/oauth&grant_type=authorization_code" ); xhr.setRequestHeader("Accept", "application/json"); xhr.setRequestHeader( @@ -406,7 +408,26 @@ chrome.commands.onCommand.addListener(async (command: string) => { function setAutolock() { if (Number(localStorage.autolock) > 0) { autolockTimeout = setTimeout(() => { + document.cookie = 'passphrase=";expires=Thu, 01 Jan 1970 00:00:00 GMT"'; cachedPassphrase = ""; }, Number(localStorage.autolock) * 60000); } } + +function getCachedPassphrase() { + if (cachedPassphrase) { + return cachedPassphrase; + } + + const cookie = document.cookie; + const cookieMatch = cookie + ? document.cookie.match(/passphrase=([^;]*)/) + : null; + const cookiePassphrase = + cookieMatch && cookieMatch.length > 1 ? cookieMatch[1] : null; + if (cookiePassphrase) { + return cookiePassphrase; + } + + return ""; +} diff --git a/src/components/Popup/MainHeader.vue b/src/components/Popup/MainHeader.vue index 1e37dbc27..4884c7272 100644 --- a/src/components/Popup/MainHeader.vue +++ b/src/components/Popup/MainHeader.vue @@ -100,7 +100,6 @@ export default Vue.extend({ this.$store.commit("accounts/stopFilter"); }, lock() { - document.cookie = 'passphrase=";expires=Thu, 01 Jan 1970 00:00:00 GMT"'; chrome.runtime.sendMessage({ action: "lock" }, window.close); return; }, diff --git a/src/import.ts b/src/import.ts index 2fd827d72..874abee3c 100644 --- a/src/import.ts +++ b/src/import.ts @@ -32,16 +32,6 @@ init(); function getCachedPassphrase() { return new Promise( (resolve: (value: string) => void, reject: (reason: Error) => void) => { - const cookie = document.cookie; - const cookieMatch = cookie - ? document.cookie.match(/passphrase=([^;]*)/) - : null; - const cachedPassphrase = - cookieMatch && cookieMatch.length > 1 ? cookieMatch[1] : null; - if (cachedPassphrase) { - return resolve(cachedPassphrase); - } - chrome.runtime.sendMessage( { action: "passphrase" }, (passphrase: string) => { diff --git a/src/store/Accounts.ts b/src/store/Accounts.ts index dfff8d064..6a33463cb 100644 --- a/src/store/Accounts.ts +++ b/src/store/Accounts.ts @@ -163,7 +163,6 @@ export class Accounts implements IModule { state.commit("style/hideInfo", null, { root: true }); if (!state.getters.currentlyEncrypted) { - document.cookie = "passphrase=" + password; chrome.runtime.sendMessage({ action: "cachePassphrase", value: password @@ -181,7 +180,6 @@ export class Accounts implements IModule { ); state.state.encryption.updateEncryptionPassword(password); - document.cookie = "passphrase=" + password; chrome.runtime.sendMessage({ action: "cachePassphrase", value: password @@ -354,21 +352,6 @@ export class Accounts implements IModule { private getCachedPassphrase() { return new Promise( (resolve: (value: string) => void, reject: (reason: Error) => void) => { - const cookie = document.cookie; - const cookieMatch = cookie - ? document.cookie.match(/passphrase=([^;]*)/) - : null; - const cachedPassphrase = - cookieMatch && cookieMatch.length > 1 ? cookieMatch[1] : null; - const cachedPassphraseLocalStorage = localStorage.encodedPhrase - ? CryptoJS.AES.decrypt(localStorage.encodedPhrase, "").toString( - CryptoJS.enc.Utf8 - ) - : ""; - if (cachedPassphrase || cachedPassphraseLocalStorage) { - return resolve(cachedPassphrase || cachedPassphraseLocalStorage); - } - chrome.runtime.sendMessage( { action: "passphrase" }, (passphrase: string) => { From 5b4de3bd06ea210ef3c1cd81ed9b3c3c9658154e Mon Sep 17 00:00:00 2001 From: Brendan Early Date: Wed, 7 Aug 2019 12:51:15 -0500 Subject: [PATCH 7/8] style --- src/background.ts | 12 ++++++------ src/models/encryption.ts | 4 +++- src/qrdebug.ts | 4 +++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/background.ts b/src/background.ts index 16c1d9be9..28b953ed8 100644 --- a/src/background.ts +++ b/src/background.ts @@ -285,12 +285,12 @@ function getBackupToken(service: string) { xhr.open( "POST", "https://www.googleapis.com/oauth2/v4/token?client_id=" + - getCredentials().drive.client_id + - "&client_secret=" + - getCredentials().drive.client_secret + - "&code=" + - value + - "&redirect_uri=https://authenticator.cc/oauth&grant_type=authorization_code" + getCredentials().drive.client_id + + "&client_secret=" + + getCredentials().drive.client_secret + + "&code=" + + value + + "&redirect_uri=https://authenticator.cc/oauth&grant_type=authorization_code" ); xhr.setRequestHeader("Accept", "application/json"); xhr.setRequestHeader( diff --git a/src/models/encryption.ts b/src/models/encryption.ts index 1ccc79472..422bb6cfd 100644 --- a/src/models/encryption.ts +++ b/src/models/encryption.ts @@ -68,7 +68,9 @@ export class Encryption implements IEncryption { } console.warn( - `Account ${entry.hash} may have secret ${decryptedSecret}, but hash did not match.` + `Account ${ + entry.hash + } may have secret ${decryptedSecret}, but hash did not match.` ); return null; } catch (error) { diff --git a/src/qrdebug.ts b/src/qrdebug.ts index c2e90826a..0db7cb1c9 100644 --- a/src/qrdebug.ts +++ b/src/qrdebug.ts @@ -60,7 +60,9 @@ function getQrDebug( `Screen Height: ${window.screen.height}
` + `Capture Width: ${qr.width}
` + `Capture Height: ${qr.height}
` + - `Device Pixel Ratio: ${devicePixelRatio} / ${window.devicePixelRatio}
` + + `Device Pixel Ratio: ${devicePixelRatio} / ${ + window.devicePixelRatio + }
` + `Tab ID: ${tab.id}
` + "
" + "Captured Screenshot:"; From 915403301fb94c308f04500c8047f2bed5fab087 Mon Sep 17 00:00:00 2001 From: Brendan Early Date: Thu, 8 Aug 2019 16:45:37 -0500 Subject: [PATCH 8/8] fix --- src/background.ts | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/background.ts b/src/background.ts index 28b953ed8..3795ff784 100644 --- a/src/background.ts +++ b/src/background.ts @@ -25,7 +25,7 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { message.info.windowWidth ); } else if (message.action === "cachePassphrase") { - document.cookie = "passphrase=" + message.value; + document.cookie = `passphrase="${message.value}${getCookieExpiry()}"`; cachedPassphrase = message.value; clearTimeout(autolockTimeout); setAutolock(); @@ -285,12 +285,12 @@ function getBackupToken(service: string) { xhr.open( "POST", "https://www.googleapis.com/oauth2/v4/token?client_id=" + - getCredentials().drive.client_id + - "&client_secret=" + - getCredentials().drive.client_secret + - "&code=" + - value + - "&redirect_uri=https://authenticator.cc/oauth&grant_type=authorization_code" + getCredentials().drive.client_id + + "&client_secret=" + + getCredentials().drive.client_secret + + "&code=" + + value + + "&redirect_uri=https://authenticator.cc/oauth&grant_type=authorization_code" ); xhr.setRequestHeader("Accept", "application/json"); xhr.setRequestHeader( @@ -407,13 +407,25 @@ chrome.commands.onCommand.addListener(async (command: string) => { function setAutolock() { if (Number(localStorage.autolock) > 0) { + document.cookie = `passphrase="${getCachedPassphrase()}${getCookieExpiry()}"`; autolockTimeout = setTimeout(() => { - document.cookie = 'passphrase=";expires=Thu, 01 Jan 1970 00:00:00 GMT"'; cachedPassphrase = ""; }, Number(localStorage.autolock) * 60000); } } +function getCookieExpiry() { + if (localStorage.autolock && Number(localStorage.autolock) > 0) { + const offset = Number(localStorage.autolock) * 60000; + const now = new Date().getTime(); + const autolockExpiry = new Date(now + offset).toUTCString(); + + return `;expires=${autolockExpiry}`; + } else { + return ""; + } +} + function getCachedPassphrase() { if (cachedPassphrase) { return cachedPassphrase;