Skip to content

armgit / AiSOC

Public Imported from GitHub
0

Open-source AI Security Operations Center: alert fusion, LLM-agent triage, MITRE ATT&CK investigation, and a replayable decision ledger for every agent step. Self-hostable, runs with no API keys, MIT licensed. Ships an MCP server for Claude, Cursor and Continue.

fix(web): investigation tab survives refresh; responder cards render; overview timeline populated

Alexandru Mateescud95e27dcf154
diff --git a/apps/web/src/components/alerts/AlertDetailView.tsx b/apps/web/src/components/alerts/AlertDetailView.tsx
index 039fb7930..c49d5c76f 100644
--- a/apps/web/src/components/alerts/AlertDetailView.tsx
+++ b/apps/web/src/components/alerts/AlertDetailView.tsx
@@ -9,7 +9,7 @@ import {
alertsApi,
casesApi,
ledgerApi,
- feedbackApi,
+ feedbackApi, computeRedispositionToken,
type Alert,
type ConfidenceFactor,
type ConfidenceLabel,
@@ -549,9 +549,12 @@ function AnalystOverridePanel({
if (!verdict || selectedIds.size === 0) return;
setApplying(true);
try {
+ const ids = Array.from(selectedIds);
+ const token = await computeRedispositionToken(ids, verdict);
const resp = await feedbackApi.applyRedisposition({
- alert_ids: Array.from(selectedIds),
+ alert_ids: ids,
new_disposition: verdict,
+ confirmation_token: token,
});
toast.success(
`Re-dispositioned ${resp.updated} past alert${resp.updated === 1 ? '' : 's'}`,
diff --git a/apps/web/src/components/cases/CaseWorkspace.tsx b/apps/web/src/components/cases/CaseWorkspace.tsx
index 46692db62..b893b358b 100644
--- a/apps/web/src/components/cases/CaseWorkspace.tsx
+++ b/apps/web/src/components/cases/CaseWorkspace.tsx
@@ -175,7 +175,12 @@ const STATUS_DOT: Record<CaseStatus, string> = {
contained: 'bg-amber-400',
resolved: 'bg-emerald-400',
closed: 'bg-slate-600',
-};
+ new: 'bg-slate-400',
+ triaged: 'bg-amber-400',
+ investigating: 'bg-blue-400 animate-pulse',
+ contained: 'bg-teal-400',
+ pending_closure: 'bg-violet-400',
+ cancelled: 'bg-slate-500'};
const TASK_STATUS_BADGE: Record<CaseTask['status'], string> = {
todo: 'bg-slate-500/15 text-slate-300 ring-slate-500/30',
@@ -334,6 +339,8 @@ export function CaseWorkspace({ caseId }: { caseId: string }) {
}, [data, useFallback, caseId]);
// ─── Investigation state ───────────────────────────────────────────────────
+ const [fetchedTimeline, setFetchedTimeline] = useState<CaseTimelineEvent[]>([]);
+
const [investigating, setInvestigating] = useState(false);
const [investigationRunId, setInvestigationRunId] = useState<string | null>(null);
const [investigationStatus, setInvestigationStatus] = useState<string>('idle');
@@ -359,6 +366,57 @@ export function CaseWorkspace({ caseId }: { caseId: string }) {
useEffect(() => () => { stopPolling(); closeWs(); }, [stopPolling, closeWs]);
+ // The case detail payload carries no timeline; the dedicated
+ // /cases/{id}/timeline endpoint synthesises opened/status/investigation
+ // events. Fetch it so the Overview timeline is never blank by silence.
+ useEffect(() => {
+ let cancelled = false;
+ casesApi.getTimeline(caseId).then((res) => {
+ if (!cancelled && Array.isArray(res?.events)) setFetchedTimeline(res.events);
+ }).catch(() => { /* overview falls back to inline timeline */ });
+ return () => { cancelled = true; };
+ }, [caseId]);
+
+ // Restore the latest terminal run on mount — run state lives only in
+ // memory, so a refresh left the Investigation tab on its idle prompt even
+ // though completed runs exist server-side (the ledger fetched its own list
+ // and therefore looked fine).
+ useEffect(() => {
+ let cancelled = false;
+ (async () => {
+ try {
+ const resp = await apiFetch(`/api/v1/cases/${caseId}/investigations`);
+ if (!resp.ok || cancelled) return;
+ const body = (await resp.json()) as { runs?: Array<Record<string, unknown>> };
+ const runs = body.runs ?? [];
+ const latest = runs.find(
+ (r) => typeof r?.run_id === "string" && (r.status === "completed" || r.status === "failed"),
+ );
+ if (!latest || cancelled) return;
+ const runId = String(latest.run_id);
+ let skip = false;
+ setInvestigationRunId((prev) => {
+ if (prev) skip = true;
+ return prev ?? runId;
+ });
+ if (skip) return;
+ setInvestigationStatus(String(latest.status ?? "completed"));
+ const inv = (await casesApi.getInvestigation(caseId, runId)) as Record<string, unknown>;
+ if (cancelled) return;
+ setInvestigationData(inv);
+ setInvestigationStatus(String(inv.status ?? latest.status ?? "completed"));
+ if (inv.status === "completed") {
+ const rep = await apiFetch(`/api/v1/cases/${caseId}/investigations/${runId}/report.md`);
+ if (!cancelled && rep.ok) setReportMd(await rep.text());
+ }
+ } catch {
+ /* best-effort restore; tab falls back to its idle prompt */
+ }
+ })();
+ return () => { cancelled = true; };
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [caseId]);
+
/** Connect to the realtime service WebSocket for this run_id */
const connectWs = useCallback((runId: string) => {
closeWs();
@@ -624,7 +682,8 @@ export function CaseWorkspace({ caseId }: { caseId: string }) {
);
}
- const sortedTimeline = [...(caseRecord.timeline ?? [])].sort(
+ const sortedTimeline = [...new Map([...fetchedTimeline, ...(caseRecord.timeline ?? [])]
+ .map((e) => [e.id, e])).values()].sort(
(a, b) =>
new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime(),
);
@@ -1193,13 +1252,28 @@ function InvestigationPanel({
<h4 className="text-xs font-semibold uppercase tracking-wide text-amber-300">Response</h4>
{responder?.summary != null && <p className="text-xs text-slate-400">{String(responder.summary)}</p>}
{Array.isArray(responder?.recommended_actions) && (
- <ul className="space-y-1">
- {(responder.recommended_actions as string[]).slice(0, 4).map((action, i) => (
- <li key={i} className="flex items-start gap-1.5 text-xs text-slate-300">
- <span className="mt-0.5 h-1.5 w-1.5 flex-none rounded-full bg-amber-400" />
- {action}
- </li>
- ))}
+ <ul className="space-y-1.5">
+ {(responder.recommended_actions as Array<unknown>).slice(0, 4).map((raw, i) => {
+ const a = (raw ?? {}) as Record<string, unknown>;
+ const text = typeof raw === "string" ? raw : String(a.action ?? "");
+ const prio = typeof a.priority === "number" ? a.priority : null;
+ const risk = a.risk != null ? String(a.risk) : null;
+ return (
+ <li key={i} className="flex items-start gap-1.5 text-xs text-slate-300">
+ <span className="mt-0.5 h-1.5 w-1.5 flex-none rounded-full bg-amber-400" />
+ <span>
+ {prio != null && <span className="mr-1 text-[10px] font-semibold text-amber-300">P{prio}</span>}
+ {text}
+ {risk != null && risk.toLowerCase() !== "low" && (
+ <span className="ml-1 rounded bg-red-500/10 px-1 py-0.5 text-[9px] uppercase text-red-300 ring-1 ring-red-500/20">{risk}</span>
+ )}
+ {a.rationale != null && String(a.rationale).length > 0 && (
+ <span className="block text-[10px] text-slate-500">{String(a.rationale)}</span>
+ )}
+ </span>
+ </li>
+ );
+ })}
</ul>
)}
{responder?.risk_level != null && (
diff --git a/apps/web/src/lib/api.ts b/apps/web/src/lib/api.ts
index f1968c561..8be1af928 100644
--- a/apps/web/src/lib/api.ts
+++ b/apps/web/src/lib/api.ts
@@ -5613,6 +5613,77 @@ export interface AlertOverrideResponse {
export interface RedispositionApplyRequest {
alert_ids: string[];
new_disposition: AnalystVerdict;
+ /**
+ * Blast-radius control: sha256 over the exact alert set + disposition,
+ * mirroring the server's compute_confirmation_token. Required — apply
+ * fails validation without it.
+ */
+ confirmation_token: string;
+}
+
+/** Mirror of the server's canonical token (sorted ids joined, hashed).
+ * Uses WebCrypto when available (secure context) and a pure-JS SHA-256
+ * fallback otherwise — the console is often served over plain HTTP on a
+ * LAN address, where crypto.subtle is undefined. */
+export async function computeRedispositionToken(
+ alertIds: string[],
+ newDisposition: string,
+): Promise<string> {
+ const canonical = [...alertIds].sort().join('|') + '=>' + newDisposition;
+ if (globalThis.crypto?.subtle) {
+ const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(canonical));
+ return Array.from(new Uint8Array(digest))
+ .map((b) => b.toString(16).padStart(2, '0'))
+ .join('');
+ }
+ return sha256Hex(canonical);
+}
+
+/* Compact SHA-256 (public-domain style), fallback for insecure contexts. */
+function sha256Hex(ascii: string): string {
+ const K = [
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
+ ];
+ const rotr = (x: number, n: number) => (x >>> n) | (x << (32 - n));
+ const bytes = Array.from(new TextEncoder().encode(ascii));
+ const bitLen = bytes.length * 8;
+ bytes.push(0x80);
+ while (bytes.length % 64 !== 56) bytes.push(0);
+ const hi = Math.floor(bitLen / 0x100000000);
+ const lo = bitLen >>> 0;
+ bytes.push((hi >>> 24) & 0xff, (hi >>> 16) & 0xff, (hi >>> 8) & 0xff, hi & 0xff);
+ bytes.push((lo >>> 24) & 0xff, (lo >>> 16) & 0xff, (lo >>> 8) & 0xff, lo & 0xff);
+ let h = [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19];
+ const w = new Array<number>(64);
+ for (let i = 0; i < bytes.length; i += 64) {
+ for (let j = 0; j < 16; j++) {
+ w[j] = (bytes[i + j * 4] << 24) | (bytes[i + j * 4 + 1] << 16) | (bytes[i + j * 4 + 2] << 8) | bytes[i + j * 4 + 3];
+ }
+ for (let j = 16; j < 64; j++) {
+ const s0 = rotr(w[j - 15], 7) ^ rotr(w[j - 15], 18) ^ (w[j - 15] >>> 3);
+ const s1 = rotr(w[j - 2], 17) ^ rotr(w[j - 2], 19) ^ (w[j - 2] >>> 10);
+ w[j] = (w[j - 16] + s0 + w[j - 7] + s1) >>> 0;
+ }
+ let [a, b, c, d, e, f, g, hh] = h;
+ for (let j = 0; j < 64; j++) {
+ const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
+ const ch = (e & f) ^ (~e & g);
+ const t1 = (hh + S1 + ch + K[j] + w[j]) >>> 0;
+ const S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
+ const maj = (a & b) ^ (a & c) ^ (b & c);
+ const t2 = (S0 + maj) >>> 0;
+ hh = g; g = f; f = e; e = (d + t1) >>> 0; d = c; c = b; b = a; a = (t1 + t2) >>> 0;
+ }
+ h = h.map((x, k) => (x + [a, b, c, d, e, f, g, hh][k]) >>> 0);
+ }
+ return h.map((x) => x.toString(16).padStart(8, '0')).join('');
}
export interface RedispositionApplyResponse {