Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): use sessionStorage for API key to reduce XSS persistence risk

rmyndharisba3dc7cc37af
diff --git a/dashboard/src/App.tsx b/dashboard/src/App.tsx
index ada45d27e..f7b8ab3b7 100644
--- a/dashboard/src/App.tsx
+++ b/dashboard/src/App.tsx
@@ -16,15 +16,15 @@ import { ErrorBoundary } from './components/ErrorBoundary';
import './App.css';
function AppContent() {
- // Initialize from localStorage to avoid setState in effect
- const savedKey = localStorage.getItem('openwa_api_key');
+ // Initialize from sessionStorage to avoid setState in effect
+ const savedKey = sessionStorage.getItem('openwa_api_key');
const [isAuthenticated, setIsAuthenticated] = useState(!!savedKey);
const [, setApiKey] = useState(savedKey || '');
const { setRole, role } = useRole();
const handleLogin = async (key: string) => {
setApiKey(key);
- localStorage.setItem('openwa_api_key', key);
+ sessionStorage.setItem('openwa_api_key', key);
// Fetch the role from API
try {
@@ -48,7 +48,7 @@ function AppContent() {
setApiKey('');
setIsAuthenticated(false);
setRole(null);
- localStorage.removeItem('openwa_api_key');
+ sessionStorage.removeItem('openwa_api_key');
};
// Re-validate and get role on mount if already authenticated
diff --git a/dashboard/src/hooks/useWebSocket.ts b/dashboard/src/hooks/useWebSocket.ts
index e6ca3346e..592f7c8a6 100644
--- a/dashboard/src/hooks/useWebSocket.ts
+++ b/dashboard/src/hooks/useWebSocket.ts
@@ -36,8 +36,8 @@ export function useWebSocket(events: WebSocketEvents = {}) {
const connect = useCallback(() => {
if (socketRef.current?.connected) return;
- // Get API key from localStorage (same as api.ts)
- const apiKey = localStorage.getItem('openwa_api_key');
+ // Get API key from sessionStorage (same as api.ts)
+ const apiKey = sessionStorage.getItem('openwa_api_key');
if (!apiKey) {
console.warn('[WebSocket] No API key found, skipping connection');
diff --git a/dashboard/src/services/api.ts b/dashboard/src/services/api.ts
index 75e433993..80972ae31 100644
--- a/dashboard/src/services/api.ts
+++ b/dashboard/src/services/api.ts
@@ -148,8 +148,8 @@ export interface Settings {
async function request<T>(endpoint: string, options: RequestInit = {}): Promise<T> {
const url = `${API_BASE_URL}${endpoint}`;
- // Get API key from localStorage for authentication
- const apiKey = localStorage.getItem('openwa_api_key');
+ // Get API key from sessionStorage for authentication
+ const apiKey = sessionStorage.getItem('openwa_api_key');
const headers: HeadersInit = {
'Content-Type': 'application/json',