Skip to content

OpenReel Video - Professional browser-based video editor. Open source CapCut alternative. 100% browser-based, no installation, no cloud uploads, no watermarks.

TypeScript

fix(security): clear API caches on session lock

lvalics566b78a518b9
diff --git a/apps/web/src/components/editor/inspector/TextToSpeechPanel.tsx b/apps/web/src/components/editor/inspector/TextToSpeechPanel.tsx
index 89f74329..4f264382 100644
--- a/apps/web/src/components/editor/inspector/TextToSpeechPanel.tsx
+++ b/apps/web/src/components/editor/inspector/TextToSpeechPanel.tsx
@@ -73,10 +73,6 @@ const PIPER_VOICES: Voice[] = [
{ id: "ryan", name: "Ryan", gender: "male", language: "en-US" },
];
-// Session caches to avoid re-fetching within the same page session
-let cachedElevenLabsVoices: ElevenLabsVoice[] | null = null;
-let cachedElevenLabsModels: ElevenLabsModel[] | null = null;
-
export const TextToSpeechPanel: React.FC = () => {
const importMedia = useProjectStore((state) => state.importMedia);
const project = useProjectStore((state) => state.project);
@@ -94,6 +90,10 @@ export const TextToSpeechPanel: React.FC = () => {
favoriteModels,
addFavoriteModel,
removeFavoriteModel,
+ cachedElevenLabsVoices,
+ cachedElevenLabsModels,
+ setCachedElevenLabsVoices,
+ setCachedElevenLabsModels,
} = useSettingsStore();
const defaultProvider: TtsProvider =
@@ -164,14 +164,14 @@ export const TextToSpeechPanel: React.FC = () => {
const models = (Array.isArray(data) ? data : []) as ElevenLabsModel[];
// Only keep TTS-capable models
const ttsModels = models.filter((m) => m.can_do_text_to_speech !== false);
- cachedElevenLabsModels = ttsModels;
+ setCachedElevenLabsModels(ttsModels);
setAllModels(ttsModels);
} catch {
setAllModels(FALLBACK_MODELS);
} finally {
setIsLoadingModels(false);
}
- }, []);
+ }, [cachedElevenLabsModels, setCachedElevenLabsModels]);
// Fetch ElevenLabs voices
const fetchVoices = useCallback(async () => {
@@ -193,14 +193,14 @@ export const TextToSpeechPanel: React.FC = () => {
const data = await response.json();
const voices = (data.voices ?? []) as ElevenLabsVoice[];
- cachedElevenLabsVoices = voices;
+ setCachedElevenLabsVoices(voices);
setAllVoices(voices);
} catch {
// Silently fail — user can still use favorites
} finally {
setIsLoadingVoices(false);
}
- }, []);
+ }, [cachedElevenLabsVoices, setCachedElevenLabsVoices]);
useEffect(() => {
if (provider === "elevenlabs" && hasElevenLabsKey) {
diff --git a/apps/web/src/services/secure-storage.ts b/apps/web/src/services/secure-storage.ts
index 173dcb43..8974fbda 100644
--- a/apps/web/src/services/secure-storage.ts
+++ b/apps/web/src/services/secure-storage.ts
@@ -36,6 +36,21 @@ interface MetaRecord {
let derivedKey: CryptoKey | null = null;
let inactivityTimer: ReturnType<typeof setTimeout> | null = null;
+// Listeners notified when the session locks (for cache cleanup, etc.)
+const lockListeners: Array<() => void> = [];
+
+/**
+ * Register a callback invoked whenever the session locks.
+ * Returns an unsubscribe function.
+ */
+export function onSessionLock(listener: () => void): () => void {
+ lockListeners.push(listener);
+ return () => {
+ const idx = lockListeners.indexOf(listener);
+ if (idx >= 0) lockListeners.splice(idx, 1);
+ };
+}
+
const SESSION_TIMEOUT_MS = 30 * 60 * 1000; // 30 minutes
function resetInactivityTimer(): void {
@@ -272,6 +287,10 @@ export function lockSession(): void {
clearTimeout(inactivityTimer);
inactivityTimer = null;
}
+
+ for (const listener of lockListeners) {
+ listener();
+ }
}
/**
diff --git a/apps/web/src/stores/settings-store.ts b/apps/web/src/stores/settings-store.ts
index 75e230bd..2c0f92d0 100644
--- a/apps/web/src/stores/settings-store.ts
+++ b/apps/web/src/stores/settings-store.ts
@@ -1,5 +1,6 @@
import { create } from "zustand";
import { subscribeWithSelector, persist } from "zustand/middleware";
+import { onSessionLock } from "../services/secure-storage";
export interface ServiceConfig {
readonly id: string;
@@ -60,6 +61,10 @@ export interface SettingsState {
favoriteModels: Array<{ modelId: string; name: string }>;
configuredServices: string[]; // IDs of services with stored API keys
+ // Session-scoped API caches (cleared on session lock, not persisted)
+ cachedElevenLabsVoices: Array<{ voice_id: string; name: string; category: string; labels: Record<string, string>; preview_url?: string }> | null;
+ cachedElevenLabsModels: Array<{ model_id: string; name: string; description?: string; can_do_text_to_speech?: boolean; languages?: Array<{ language_id: string; name: string }> }> | null;
+
// Settings dialog state
settingsOpen: boolean;
settingsTab: string;
@@ -78,6 +83,9 @@ export interface SettingsState {
removeFavoriteModel: (modelId: string) => void;
addConfiguredService: (serviceId: string) => void;
removeConfiguredService: (serviceId: string) => void;
+ setCachedElevenLabsVoices: (voices: SettingsState["cachedElevenLabsVoices"]) => void;
+ setCachedElevenLabsModels: (models: SettingsState["cachedElevenLabsModels"]) => void;
+ clearApiCaches: () => void;
openSettings: (tab?: string) => void;
closeSettings: () => void;
}
@@ -98,6 +106,9 @@ export const useSettingsStore = create<SettingsState>()(
favoriteModels: [],
configuredServices: [],
+ cachedElevenLabsVoices: null,
+ cachedElevenLabsModels: null,
+
settingsOpen: false,
settingsTab: "general",
@@ -158,6 +169,15 @@ export const useSettingsStore = create<SettingsState>()(
});
},
+ setCachedElevenLabsVoices: (voices) =>
+ set({ cachedElevenLabsVoices: voices }),
+
+ setCachedElevenLabsModels: (models) =>
+ set({ cachedElevenLabsModels: models }),
+
+ clearApiCaches: () =>
+ set({ cachedElevenLabsVoices: null, cachedElevenLabsModels: null }),
+
openSettings: (tab?: string) =>
set({
settingsOpen: true,
@@ -185,3 +205,8 @@ export const useSettingsStore = create<SettingsState>()(
),
),
);
+
+// Clear API caches when the secure session locks
+onSessionLock(() => {
+ useSettingsStore.getState().clearApiCaches();
+});