Skip to content

armgit / ARES

Public Imported from GitHub
0

ARES - authorized red-team engagement automation with dashboard, campaign scope, module orchestration, OPSEC controls, encrypted vault, and reporting.

fix(web): scope dashboard notification state per operator, purge on logout (#75)

kraii_850ace045ced
diff --git a/frontend/src/features/dashboard/DashboardPages.tsx b/frontend/src/features/dashboard/DashboardPages.tsx
index 7d3ccf2..fe4d926 100644
--- a/frontend/src/features/dashboard/DashboardPages.tsx
+++ b/frontend/src/features/dashboard/DashboardPages.tsx
@@ -198,10 +198,15 @@ function formatRole(role?: string): string {
const NOTIFICATIONS_DELETED_KEY = "ares.dashboard.notifications.deleted";
const NOTIFICATIONS_READ_KEY = "ares.dashboard.notifications.read";
-function getStoredNotificationIds(key: string, username?: string): string[] {
+export function getStoredNotificationIds(key: string, username?: string): string[] {
+ // AUDIT run-1 H20: notification state must be scoped to the current operator.
+ // The previous unscoped fallback (reading `key` when the per-user key was
+ // absent) let one operator's dismissals/read-state leak to the next operator
+ // who signed in on the same browser. Without a username there is no scope, so
+ // we read nothing rather than a shared blob.
+ if (!username) return [];
try {
- const userKey = username ? `${key}.${username}` : key;
- const raw = window.localStorage.getItem(userKey) || window.localStorage.getItem(key);
+ const raw = window.localStorage.getItem(`${key}.${username}`);
if (!raw) return [];
const parsed = JSON.parse(raw);
return Array.isArray(parsed) ? parsed.filter((x): x is string => typeof x === "string") : [];
@@ -210,13 +215,12 @@ function getStoredNotificationIds(key: string, username?: string): string[] {
}
}
-function setStoredNotificationIds(key: string, username: string | undefined, ids: string[]): void {
+export function setStoredNotificationIds(key: string, username: string | undefined, ids: string[]): void {
+ // Only ever persist under the per-operator key; never write the unscoped key
+ // that leaks across operators. (AUDIT run-1 H20)
+ if (!username) return;
try {
- const serialized = JSON.stringify(ids);
- if (username) {
- window.localStorage.setItem(`${key}.${username}`, serialized);
- }
- window.localStorage.setItem(key, serialized);
+ window.localStorage.setItem(`${key}.${username}`, JSON.stringify(ids));
} catch {
// Storage sandbox fallback
}
diff --git a/frontend/src/features/dashboard/NotificationScoping.test.tsx b/frontend/src/features/dashboard/NotificationScoping.test.tsx
new file mode 100644
index 0000000..5b2e77c
--- /dev/null
+++ b/frontend/src/features/dashboard/NotificationScoping.test.tsx
@@ -0,0 +1,51 @@
+import { beforeEach, describe, expect, it } from "vitest";
+
+import { getStoredNotificationIds, setStoredNotificationIds } from "./DashboardPages";
+import { clearDashboardSession } from "./dashboardUiState";
+
+// AUDIT run-1 H20: notification read/deleted state must be scoped to the current
+// operator, never written to an unscoped key, never read via an unscoped
+// fallback, and purged from localStorage on logout.
+describe("Dashboard notification state is per-operator (H20)", () => {
+ const KEY = "ares.dashboard.notifications.deleted";
+
+ beforeEach(() => {
+ localStorage.clear();
+ sessionStorage.clear();
+ });
+
+ it("writes only the per-operator key and isolates operators", () => {
+ setStoredNotificationIds(KEY, "alice", ["telemetry:a"]);
+
+ expect(localStorage.getItem(`${KEY}.alice`)).not.toBeNull();
+ // The unscoped key must never be written (that is what leaked across operators).
+ expect(localStorage.getItem(KEY)).toBeNull();
+
+ // Another operator on the same browser sees nothing.
+ expect(getStoredNotificationIds(KEY, "bob")).toEqual([]);
+ // The owning operator still sees their own state.
+ expect(getStoredNotificationIds(KEY, "alice")).toEqual(["telemetry:a"]);
+ });
+
+ it("does not fall back to a legacy unscoped blob", () => {
+ localStorage.setItem(KEY, JSON.stringify(["leaked-from-previous-operator"]));
+ expect(getStoredNotificationIds(KEY, "alice")).toEqual([]);
+ });
+
+ it("returns nothing when there is no operator scope", () => {
+ localStorage.setItem(KEY, JSON.stringify(["x"]));
+ expect(getStoredNotificationIds(KEY, undefined)).toEqual([]);
+ setStoredNotificationIds(KEY, undefined, ["y"]);
+ expect(localStorage.getItem(KEY)).toBe(JSON.stringify(["x"])); // unchanged, not overwritten
+ });
+
+ it("purges notification localStorage on logout", () => {
+ setStoredNotificationIds(KEY, "alice", ["telemetry:a"]);
+ localStorage.setItem("ares.dashboard.notifications.read.alice", "[]");
+
+ clearDashboardSession();
+
+ expect(localStorage.getItem(`${KEY}.alice`)).toBeNull();
+ expect(localStorage.getItem("ares.dashboard.notifications.read.alice")).toBeNull();
+ });
+});
diff --git a/frontend/src/features/dashboard/dashboardUiState.ts b/frontend/src/features/dashboard/dashboardUiState.ts
index 662b7cf..ddf5001 100644
--- a/frontend/src/features/dashboard/dashboardUiState.ts
+++ b/frontend/src/features/dashboard/dashboardUiState.ts
@@ -105,6 +105,24 @@ export function clearDashboardSession(): void {
removeDashboardSessionKey(key);
}
}
+ // AUDIT run-1 H20: notification read/deleted state is persisted in
+ // localStorage (per-operator keys under this prefix). Logout previously only
+ // cleared sessionStorage, leaving the next operator on this browser able to
+ // read the prior operator's notification state. Purge it here too.
+ try {
+ const prefix = "ares.dashboard.notifications";
+ const localKeys = Array.from(
+ { length: window.localStorage.length },
+ (_, index) => window.localStorage.key(index),
+ );
+ for (const key of localKeys) {
+ if (key && key.startsWith(prefix)) {
+ window.localStorage.removeItem(key);
+ }
+ }
+ } catch {
+ // Storage sandbox / private-mode fallback
+ }
}
function purgeDisallowedDashboardSession(): void {