diff --git a/web/public/app.js b/web/public/app.js index 7255c69..7bd6d28 100644 --- a/web/public/app.js +++ b/web/public/app.js @@ -1443,11 +1443,12 @@ function renderCoverageTab() { // ─── Dashboard stats (DB + cost + coverage) ──────────────────────────────── async function loadDashboardStats() { try { - const [dbStatus, stats, cost, coverage] = await Promise.all([ + const [dbStatus, stats, cost, coverage, issues] = await Promise.all([ api('/api/db/status').catch(() => ({ connected: false, engine: 'file' })), api('/api/db/stats').catch(() => null), api('/api/cost').catch(() => null), api('/api/coverage').catch(() => null), + api('/api/issues').catch(() => []), ]); const el = $('#dashboardStats'); @@ -1459,18 +1460,19 @@ async function loadDashboardStats() { : 'File storage'; const totalRuns = stats?.total_runs || state.runs.length || 0; - let totalFindings = stats?.total_findings || 0; - let critFindings = stats?.critical_findings || 0; - let highFindings = stats?.high_findings || 0; - if (!totalFindings && state.runs.length) { - for (const r of state.runs) { - const n = r.findings ?? r.validated ?? 0; - totalFindings += n; - const sev = r.severity || {}; - critFindings += sev.critical || 0; - highFindings += sev.high || 0; - } + + // Severity breakdown: /api/issues is the authoritative source — db/stats is + // empty without PostgreSQL and per-run `severities` is often unpopulated. + const sevCount = { critical: 0, high: 0, medium: 0, low: 0, info: 0 }; + for (const f of (Array.isArray(issues) ? issues : [])) { + const s = (f.severity || '').toLowerCase(); + if (sevCount[s] !== undefined) sevCount[s]++; } + const totalFindings = Array.isArray(issues) && issues.length + ? issues.length + : (stats?.total_findings || 0); + const critFindings = sevCount.critical || stats?.critical_findings || 0; + const highFindings = sevCount.high || stats?.high_findings || 0; const costUsd = cost?.total_usd ? `$${Number(cost.total_usd).toFixed(4)}` : '—'; const budgetUsd = cost?.budget_usd ? `$${Number(cost.budget_usd).toFixed(2)}` : '∞'; @@ -1481,9 +1483,8 @@ async function loadDashboardStats() { const gaps = coverage?.gaps || []; const topGaps = gaps.slice(0, 5).map(g => `${esc(typeof g === 'string' ? g : g.class || g.name || '')}`).join(''); - const medFindings = stats?.medium_findings || 0; - const lowFindings = stats?.low_findings || 0; - const infoFindings = stats?.info_findings || 0; + const medFindings = sevCount.medium || stats?.medium_findings || 0; + const lowFindings = sevCount.low || stats?.low_findings || 0; el.innerHTML = `
@@ -3359,6 +3360,43 @@ function fairForFinding(f, params) { return lm.map((m) => lef * m); } +/// Per-finding ALE, deduplicated and damped so the portfolio total stays +/// defensible. +/// +/// Summing every finding independently is wrong twice over. The same issue +/// reported by three agents is one issue, and thirty criticals on one host do +/// not mean thirty separate breaches — an attacker compromises that host once. +/// So: collapse duplicates on (title, target), then within each target rank the +/// survivors by exposure and apply harmonic decay (1, 1/2, 1/3 …), which keeps +/// the worst finding at full weight while additional findings on the same +/// target add progressively less. +function fairWeighted(findings, params) { + const norm = (s) => (s || '').toLowerCase().replace(/\s+/g, ' ').trim(); + const seen = new Map(); + for (const f of findings) { + const key = `${norm(f.title)}@@${norm(f.target)}`; + const prev = seen.get(key); + if (!prev || (f.confidence || 0) > (prev.confidence || 0)) seen.set(key, f); + } + + const byTarget = new Map(); + for (const f of seen.values()) { + const t = norm(f.target) || '(unknown)'; + if (!byTarget.has(t)) byTarget.set(t, []); + byTarget.get(t).push({ f, ale: fairForFinding(f, params) }); + } + + const out = []; + for (const group of byTarget.values()) { + group.sort((a, b) => b.ale[1] - a.ale[1]); + group.forEach((item, i) => { + const damp = 1 / (i + 1); + out.push({ f: item.f, ale: item.ale.map((v) => v * damp) }); + }); + } + return out; +} + /// Heuristic posture score, 0-100. Deliberately simple and fully stated in the /// UI: an opaque score invites arguing with the number instead of the findings. /// @@ -3433,15 +3471,13 @@ async function renderDashboard() { const score = exposureScore(findings); const band = scoreBand(score); - const ale = findings.reduce((acc, f) => { - const [lo, ml, hi] = fairForFinding(f, params); - return [acc[0] + lo, acc[1] + ml, acc[2] + hi]; - }, [0, 0, 0]); + const weighted = fairWeighted(findings, params); + const ale = weighted.reduce((acc, w) => [acc[0] + w.ale[0], acc[1] + w.ale[1], acc[2] + w.ale[2]], [0, 0, 0]); // Which findings actually drive the exposure — the reason to quantify at all // is to rank remediation, and the ranking is what gets acted on. - const contributors = findings - .map((f) => ({ f, ml: fairForFinding(f, params)[1] })) + const contributors = weighted + .map((w) => ({ f: w.f, ml: w.ale[1] })) .sort((a, b) => b.ml - a.ml) .slice(0, 6); @@ -3516,11 +3552,12 @@ async function renderDashboard() {
maximum${money(ale[2])}
- Loss Event Frequency × Loss Magnitude, summed over ${findings.length} finding(s). - Frequency comes from each finding's exploitability and validation confidence; - magnitude comes from the assumptions you set. A range, not a forecast. - Findings are summed independently, so shared root causes count twice — - read it as an upper bound on annual exposure, not a portfolio model. + Loss Event Frequency × Loss Magnitude over ${weighted.length} distinct finding(s), + from ${findings.length} reported. Frequency comes from each finding's exploitability + and validation confidence; magnitude comes from the assumptions you set. + Duplicates on the same target are collapsed, and additional findings on an + already-exposed target are damped (1, ½, ⅓ …) because compromising a target + once is the dominant loss event. A range, not a forecast.
@@ -6305,17 +6342,25 @@ $('#btnNewPrReview')?.addEventListener('click', () => { if (existing) { existing.hidden = false; return; } document.body.insertAdjacentHTML('beforeend', `