mirror of
https://github.com/CyberSecurityUP/NeuroSploit.git
synced 2026-12-05 02:24:17 +01:00
Merge pull request #122 from JoasASantos/fix/dashboard-severity-fair
fix(web): severity counts, FAIR dedup/damping, PR modal markup
This commit is contained in:
1 file changed
+79
-34
+79
-34
@@ -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() {
|
||||
: '<span class="dash-badge dash-warn">File storage</span>';
|
||||
|
||||
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 => `<span class="dash-gap">${esc(typeof g === 'string' ? g : g.class || g.name || '')}</span>`).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 = `
|
||||
<div class="dash-row dash-row-main">
|
||||
@@ -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() {
|
||||
<div class="fair-point"><span class="k">maximum</span><span class="v">${money(ale[2])}</span></div>
|
||||
</div>
|
||||
<div class="fair-note">
|
||||
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.
|
||||
</div>
|
||||
</div>
|
||||
<div class="fair-contrib">
|
||||
@@ -6305,17 +6342,25 @@ $('#btnNewPrReview')?.addEventListener('click', () => {
|
||||
if (existing) { existing.hidden = false; return; }
|
||||
document.body.insertAdjacentHTML('beforeend', `
|
||||
<div class="modal-overlay" id="prReviewModal">
|
||||
<div class="modal" style="max-width:480px;">
|
||||
<div class="modal-head"><h3>New PR review</h3><button class="modal-close" id="btnClosePrReview">×</button></div>
|
||||
<div class="modal modal-sm">
|
||||
<div class="modal-head">
|
||||
<div class="title">New PR review<span class="modal-sub">Security review of a pull request</span></div>
|
||||
<button class="icon-btn" id="btnClosePrReview" aria-label="Close"><svg class="ico" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M6 6l12 12M18 6 6 18"/></svg></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<label class="field-label">Repository <small class="muted">(owner/repo)</small></label>
|
||||
<input class="input" id="prReviewRepo" placeholder="owner/repo" />
|
||||
<label class="field-label" style="margin-top:12px;">PR number</label>
|
||||
<input class="input" id="prReviewNumber" type="number" min="1" placeholder="123" />
|
||||
<div id="prReviewError" class="form-error" style="margin-top:8px;"></div>
|
||||
<div class="field-group">
|
||||
<label class="field-label" for="prReviewRepo">Repository</label>
|
||||
<input id="prReviewRepo" type="text" spellcheck="false" placeholder="owner/repo" />
|
||||
<div class="field-help">The GitHub repository, as <code>owner/repo</code>.</div>
|
||||
</div>
|
||||
<div class="field-group">
|
||||
<label class="field-label" for="prReviewNumber">Pull request number</label>
|
||||
<input id="prReviewNumber" type="number" min="1" placeholder="123" />
|
||||
</div>
|
||||
<div class="field-error" id="prReviewError" hidden></div>
|
||||
</div>
|
||||
<div class="modal-foot">
|
||||
<button class="btn" id="btnPrReviewCancel">Cancel</button>
|
||||
<button class="btn btn-ghost" id="btnPrReviewCancel">Cancel</button>
|
||||
<button class="btn btn-primary" id="btnPrReviewRun">Start review</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user