Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Clear pending Space login key on session cleanup

Anand Baburajan063e6028b362
diff --git a/web/apps/space/src/services/spaceSecureSessionStorage.ts b/web/apps/space/src/services/spaceSecureSessionStorage.ts
index 6f32d2499e..23a75fafb2 100644
--- a/web/apps/space/src/services/spaceSecureSessionStorage.ts
+++ b/web/apps/space/src/services/spaceSecureSessionStorage.ts
@@ -1,3 +1,4 @@
+import { clearStashedKeyEncryptionKeyFromSession } from "ente-accounts-rs/services/session-storage";
import { z } from "zod";
const windowNamePrefix = "ente-space-secure-session:";
@@ -43,6 +44,12 @@ const clearLegacyAccountsSessionKeys = () => {
for (const key of legacyAccountsSessionKeys) sessionStorage.removeItem(key);
};
+const clearSecureSessionState = () => {
+ if (window.name.startsWith(windowNamePrefix)) window.name = "";
+ sessionStorage.removeItem(sessionStorageKey);
+ clearLegacyAccountsSessionKeys();
+};
+
const readWindowShare = () => {
if (!window.name.startsWith(windowNamePrefix)) return undefined;
try {
@@ -107,7 +114,7 @@ const secureSessionState = (): SecureSessionState => {
try {
return SecureSessionState.parse(JSON.parse(secret));
} catch {
- clearSpaceSecureSessionStorage();
+ clearSecureSessionState();
return {};
}
};
@@ -115,7 +122,7 @@ const secureSessionState = (): SecureSessionState => {
const saveSecureSessionState = (state: SecureSessionState) => {
clearLegacyAccountsSessionKeys();
if (!hasSecret(state)) {
- clearSpaceSecureSessionStorage();
+ clearSecureSessionState();
return;
}
const [windowShare, sessionShare] = splitSecret(JSON.stringify(state));
@@ -124,9 +131,8 @@ const saveSecureSessionState = (state: SecureSessionState) => {
};
export const clearSpaceSecureSessionStorage = () => {
- if (window.name.startsWith(windowNamePrefix)) window.name = "";
- sessionStorage.removeItem(sessionStorageKey);
- clearLegacyAccountsSessionKeys();
+ clearSecureSessionState();
+ clearStashedKeyEncryptionKeyFromSession();
};
export const authMasterKeyFromSpaceSession = () =>
diff --git a/web/packages/accounts-rs/services/session-storage.ts b/web/packages/accounts-rs/services/session-storage.ts
index f1459b429f..1a65a52105 100644
--- a/web/packages/accounts-rs/services/session-storage.ts
+++ b/web/packages/accounts-rs/services/session-storage.ts
@@ -72,11 +72,14 @@ export const updateSessionFromElectronSafeStorageIfNeeded = async () => {
export const stashKeyEncryptionKeyInSessionStore = (kek: string) =>
saveKeyInSessionStore("keyEncryptionKey", kek);
+export const clearStashedKeyEncryptionKeyFromSession = () =>
+ sessionStorage.removeItem("keyEncryptionKey");
+
export const unstashKeyEncryptionKeyFromSession = async () => {
const value = sessionStorage.getItem("keyEncryptionKey");
if (!value) return undefined;
- sessionStorage.removeItem("keyEncryptionKey");
+ clearStashedKeyEncryptionKeyFromSession();
const { encryptedData, key, nonce } = SessionKeyData.parse(
JSON.parse(value),