revert vault session to localStorage (per-origin, shared across tabs)
sessionStorage was per-tab which forced re-entering the password on every new tab to the same site. localStorage is scoped per-origin which is the right granularity. The lock button clears the session from localStorage when the user wants to end their session.
This commit is contained in:
parent
ec0897de2c
commit
01439ed29a
1 changed files with 7 additions and 7 deletions
|
|
@ -156,7 +156,7 @@ const UncloseVault = {
|
|||
/**
|
||||
* Create session for auto-unlock persistence
|
||||
* Stores the password encrypted with a random session key
|
||||
* Session is per-tab (sessionStorage): survives navigation, cleared on tab close
|
||||
* Session persists per-origin in localStorage until explicitly locked
|
||||
*/
|
||||
createSession(password) {
|
||||
if (!this.isAvailable()) return;
|
||||
|
|
@ -168,14 +168,14 @@ const UncloseVault = {
|
|||
// Encrypt password with session key
|
||||
const encryptedPassword = CryptoJS.AES.encrypt(password, sessionKey).toString();
|
||||
|
||||
// Store session data in sessionStorage (per-tab, survives navigation)
|
||||
// Store session data in localStorage (per-origin, persists until locked)
|
||||
const sessionData = {
|
||||
key: sessionKey,
|
||||
data: encryptedPassword,
|
||||
created: Date.now()
|
||||
};
|
||||
|
||||
sessionStorage.setItem(this.SESSION_KEY, JSON.stringify(sessionData));
|
||||
localStorage.setItem(this.SESSION_KEY, JSON.stringify(sessionData));
|
||||
} catch (e) {
|
||||
console.error('Failed to create session:', e);
|
||||
}
|
||||
|
|
@ -184,14 +184,14 @@ const UncloseVault = {
|
|||
/**
|
||||
* Try to restore session (auto-unlock)
|
||||
* Returns true if session was valid and vault unlocked
|
||||
* Session is per-tab: each new tab requires password, navigation within a tab does not
|
||||
* Session persists per-origin until explicitly locked
|
||||
*/
|
||||
tryRestoreSession() {
|
||||
if (!this.isAvailable()) return false;
|
||||
if (this.isUnlocked()) return true; // Already unlocked
|
||||
|
||||
try {
|
||||
const sessionJson = sessionStorage.getItem(this.SESSION_KEY);
|
||||
const sessionJson = localStorage.getItem(this.SESSION_KEY);
|
||||
if (!sessionJson) return false;
|
||||
|
||||
const session = JSON.parse(sessionJson);
|
||||
|
|
@ -225,7 +225,7 @@ const UncloseVault = {
|
|||
* Clear session data
|
||||
*/
|
||||
clearSession() {
|
||||
sessionStorage.removeItem(this.SESSION_KEY);
|
||||
localStorage.removeItem(this.SESSION_KEY);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -233,7 +233,7 @@ const UncloseVault = {
|
|||
*/
|
||||
getSessionInfo() {
|
||||
try {
|
||||
const sessionJson = sessionStorage.getItem(this.SESSION_KEY);
|
||||
const sessionJson = localStorage.getItem(this.SESSION_KEY);
|
||||
if (!sessionJson) return null;
|
||||
|
||||
const session = JSON.parse(sessionJson);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue