@cclabsnz/sf-audit 1.21.1 → 1.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,240 +1,774 @@
1
- import { esc, STRICT_CSP_META } from '@cclabsnz/sf-core';
2
- import { fontFaceCss } from '@cclabsnz/sf-core';
3
- import { getCheckMeta } from '../findings/CheckMeta.js';
1
+ import { esc, STRICT_CSP_META, DEFAULT_BRANDING } from '@cclabsnz/sf-core';
4
2
  import { toolCreditHtml } from './toolCredit.js';
5
- import { selectPriorities } from '../report/ExecutivePriorities.js';
6
3
  import { buildRoadmap } from '../report/RemediationRoadmap.js';
7
4
  import { buildComplianceMatrix } from '../report/ComplianceMatrix.js';
8
- import { renderAttackChainDagSvg } from './AttackChainDagRenderer.js';
9
5
  import { coverageSummary, coverageAdvice } from '../findings/coverage.js';
6
+ import { techniqueLabel, ATTACK_TACTIC_ORDER } from '../threats/attack.js';
7
+ import { buildThreatView, threatRowStatusText } from '../threats/view.js';
8
+ import { buildActionPlan } from '../report/ActionPlan.js';
9
+ import { buildAttackJourney } from '../report/AttackJourney.js';
10
+ import { deckFontFaceCss } from './deckFonts.js';
11
+ // The executive report is a consulting-style deck: every slide's title states its conclusion, the
12
+ // exhibit below supports it, and a source note says where the numbers come from. Slides print one
13
+ // per landscape page; the appendix pages run as long as their content.
14
+ const CRIT = '#a3392b';
15
+ const AMBER = '#a8660f';
10
16
  const SEV_COLOR = {
11
- CRITICAL: '#7d3a3a', HIGH: '#a35a2a', MEDIUM: '#8a6d1f', LOW: '#3a5a82', INFO: '#636770',
17
+ CRITICAL: CRIT, HIGH: CRIT, MEDIUM: AMBER, LOW: 'var(--muted)', INFO: '#9aa1a8',
12
18
  };
13
19
  const SEV_RANK = { CRITICAL: 0, HIGH: 1, MEDIUM: 2, LOW: 3, INFO: 4 };
14
- const GRADE_COLOR = {
15
- A: '#4a7d5e', B: '#4a7d5e', C: '#8a6d1f', D: '#a35a2a', F: '#7d3a3a',
20
+ const SEVERITIES = ['CRITICAL', 'HIGH', 'MEDIUM', 'LOW', 'INFO'];
21
+ const EFFORT_LABEL = { quick: 'Under a day', moderate: 'Days', project: 'Weeks' };
22
+ const WAVE_LABEL = { 1: 'Start now', 2: 'Next 30 days', 3: 'This quarter' };
23
+ const WAVE_WHY = {
24
+ 1: 'breaks a critical chain or closes a critical finding, whatever the effort',
25
+ 2: 'high severity, days of work or less',
26
+ 3: 'high severity, weeks of work',
27
+ };
28
+ const PLAN_ROWS_PER_SLIDE = 6;
29
+ const MATRIX_MAX = 10;
30
+ const TACTIC_SHORT = {
31
+ 'reconnaissance': 'Recon', 'resource-development': 'Resource dev.', 'initial-access': 'Initial access',
32
+ 'execution': 'Execution', 'persistence': 'Persistence', 'privilege-escalation': 'Privilege esc.',
33
+ 'stealth': 'Stealth', 'defense-impairment': 'Defense impair.', 'credential-access': 'Credential access',
34
+ 'discovery': 'Discovery', 'lateral-movement': 'Lateral move.', 'collection': 'Collection',
35
+ 'command-and-control': 'Command & control', 'exfiltration': 'Exfiltration', 'impact': 'Impact',
16
36
  };
17
- const SEV_ORDER = ['CRITICAL', 'HIGH', 'MEDIUM', 'LOW'];
18
37
  const FRAMEWORK_LABEL = {
19
38
  OWASP: 'OWASP Top 10', OWASP_LLM: 'OWASP LLM Top 10', SOC2: 'SOC 2', ISO27001: 'ISO/IEC 27001',
20
39
  SBS: 'Security Benchmark for Salesforce', PRIVACY_ACT: 'NZ Privacy Act',
21
40
  HISO10029: 'HISO 10029', NZISM: 'NZISM', HIPAA: 'HIPAA', GDPR: 'GDPR',
22
41
  };
42
+ /** The grade's reason in words: "F: 7 CRITICAL (4 findings, 3 attack chains) (D allows none)" reads as a sentence. */
43
+ function gradeInWords(grade, reason) {
44
+ if (!reason)
45
+ return `Graded ${grade} from the health score.`;
46
+ const m = /^[A-F]: (\d+) (CRITICAL|HIGH|MEDIUM)(?: \((.+?)\))? \(([A-F]) allows (none|at most \d+)\)$/.exec(reason);
47
+ if (!m)
48
+ return `Graded ${grade}: ${reason.replace(/^[A-F]: /, '')}.`;
49
+ const [, n, level, parts, better, allows] = m;
50
+ return `Graded ${grade} because ${n} ${level.toLowerCase()} issue${n === '1' ? ' is' : 's are'} open${parts ? ` (${parts})` : ''}, and a ${better} allows ${allows}, whatever the health score.`;
51
+ }
52
+ // A check that gathered no evidence (inconclusive, or failed outright) is unassessed, not open.
53
+ const unassessed = (f) => !f.passed && (!!f.inconclusive || !!f.notAssessed);
54
+ const isOpen = (f) => !f.passed && !unassessed(f) && !f.waived;
55
+ const isWaived = (f) => !f.passed && !unassessed(f) && !!f.waived;
56
+ const plural = (n, word, many = `${word}s`) => `${n} ${n === 1 ? word : many}`;
57
+ const cap = (s) => s.charAt(0).toUpperCase() + s.slice(1);
58
+ const NUMBER_WORDS = ['No', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten'];
59
+ const countWord = (n) => NUMBER_WORDS[n] ?? String(n);
60
+ const actions = (n) => `${countWord(n)} action${n === 1 ? '' : 's'}`;
61
+ /** The verb agreeing with a count: verb(1, 'closes', 'close'). */
62
+ const verb = (n, one, many) => (n === 1 ? one : many);
63
+ /** The findings schedule's order, which also numbers every reference: open by severity, waived, unassessed, passed. */
64
+ function scheduleOrder(findings) {
65
+ const bySev = (a, b) => SEV_RANK[a.riskLevel] - SEV_RANK[b.riskLevel];
66
+ return [
67
+ ...findings.filter(isOpen).sort(bySev), ...findings.filter(isWaived).sort(bySev),
68
+ ...findings.filter(unassessed), ...findings.filter((f) => f.passed),
69
+ ];
70
+ }
71
+ /**
72
+ * A CSS string literal for text that reaches a stylesheet (print page footers). Every character that
73
+ * could end the string, the declaration or the style element is hex-escaped.
74
+ */
75
+ function cssStr(text) {
76
+ return `"${text.replace(/[^\w .·:/()-]/gu, (ch) => `\\${ch.codePointAt(0).toString(16)} `)}"`;
77
+ }
78
+ /** An escaped title that may break after a slash, so long annotation lists wrap at the slash, not mid-word. */
79
+ function title(text) {
80
+ return esc(text).replace(/\//g, '/<wbr>');
81
+ }
82
+ /** Escaped text with `code` spans set apart. */
83
+ function prose(text) {
84
+ return esc(text).replace(/`([^`\s][^`]*)`/g, '<code>$1</code>');
85
+ }
86
+ /**
87
+ * Tool-authored advice only: also turns "NAME (https://…)" into a link on NAME. Never used for finding
88
+ * text, where a URL can be a lapsed or attacker-held domain the finding is warning about.
89
+ */
90
+ function advice(text) {
91
+ return esc(text)
92
+ .replace(/(\S+) \((https:\/\/[^\s)`]+)\)/g, '<a href="$2">$1</a>')
93
+ .replace(/`([^`\s][^`]*)`/g, '<code>$1</code>');
94
+ }
23
95
  export class ClientReportRenderer {
24
96
  opts;
25
97
  format = 'executive';
26
98
  fileExtension = '.html';
27
99
  filenamePrefix = 'SF_Audit_Executive';
100
+ // Finding id to its schedule ref (F-001), and each chain's label (named C1…, potential P1…), for one render.
101
+ refs = new Map();
102
+ labels = [];
28
103
  constructor(opts) {
29
104
  this.opts = opts;
30
105
  }
31
106
  render(result) {
32
107
  const b = this.opts.branding;
33
108
  const chains = result.attackChains ?? [];
34
- const chainIds = new Set();
35
- for (const c of chains)
36
- for (const s of c.steps)
37
- chainIds.add(s.findingId);
38
- const priorities = selectPriorities(result.findings, chainIds, this.opts.topN);
109
+ this.refs = new Map();
110
+ scheduleOrder(result.findings).forEach((f, i) => { if (!this.refs.has(f.id))
111
+ this.refs.set(f.id, `F-${String(i + 1).padStart(3, '0')}`); });
112
+ let nc = 0, np = 0;
113
+ this.labels = chains.map((c) => (c.abuseCase ? `C${++nc}` : `P${++np}`));
114
+ const plan = buildActionPlan(result.findings, chains);
39
115
  const roadmap = buildRoadmap(result.findings);
40
116
  const matrix = buildComplianceMatrix(result, this.opts.frameworks);
41
- let n = 0;
42
- const num = () => String(++n).padStart(2, '0');
43
- const sections = [
44
- this.summary(result, num()),
45
- this.prioritiesSection(priorities, chainIds, num()),
46
- chains.length ? this.scenarios(chains, num()) : '',
47
- result.waivedFindings?.length ? this.waiversSection(result.waivedFindings, num()) : '',
48
- this.roadmapSection(roadmap, num()),
49
- matrix.length ? this.matrixSection(matrix, num()) : '',
50
- this.findingsAppendix(result, num()),
51
- ].join('\n');
117
+ const named = chains.map((c, i) => ({ c, i })).filter((x) => x.c.abuseCase);
118
+ const potential = chains.map((c, i) => ({ c, i })).filter((x) => !x.c.abuseCase);
119
+ const slides = [
120
+ this.coverSlide(result, b),
121
+ this.summarySlide(result, plan, chains),
122
+ ...(plan.length ? [this.matrixSlide(plan)] : []),
123
+ ...this.planSlides(plan, chains, result),
124
+ ...this.threatSlides(result, chains),
125
+ ...named.map(({ c, i }) => this.chainSlide(c, i, result.findings)),
126
+ ...(potential.length ? [this.potentialSlide(potential)] : []),
127
+ this.roadmapPage(roadmap),
128
+ ...(matrix.length ? [this.matrixPage(matrix)] : []),
129
+ ...(result.waivedFindings?.length ? [this.waiversPage(result.waivedFindings)] : []),
130
+ this.findingsPage(result),
131
+ this.signOffPage(result, b),
132
+ ];
133
+ const total = slides.length;
134
+ const date = result.generatedAt.toISOString().slice(0, 10);
135
+ const body = slides.map((s, i) => this.slide(s, i + 1, total, result, date)).join('\n');
136
+ // Every printed page names its client, date and page, so a page pulled from the pack is still identified.
137
+ const pages = slides.map((s, i) => `@page s${i + 1}{@bottom-left{content:${cssStr(`${result.orgName} · ${result.orgId} · ${date}`)}}@bottom-right{content:${cssStr(`${s.kicker.toUpperCase()} · page `)} counter(page)}}`).join('\n');
52
138
  return `<!DOCTYPE html>
53
- <html lang="en"><head><meta charset="utf-8">${STRICT_CSP_META}<title>Security Audit: ${esc(result.orgName)}</title>
54
- <style>${fontFaceCss()}
55
- :root{--ink:${b.ink};--bg:${b.bg};--bgalt:${b.bgAlt};--muted:${b.muted};--border:${b.border};--primary:${b.primary};
56
- --display:'${b.fontDisplay}',Georgia,serif;--body:'${b.fontBody}',system-ui,sans-serif;--mono:ui-monospace,'SF Mono',Menlo,monospace;}
139
+ <html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">${STRICT_CSP_META}<title>Security Assessment: ${esc(result.orgName)}</title>
140
+ <style>${deckFontFaceCss()}
141
+ ${this.css(b)}
142
+ ${pages}
143
+ </style></head><body><main class="deck">
144
+ ${body}
145
+ </main></body></html>`;
146
+ }
147
+ css(b) {
148
+ // A firm's own fonts and surfaces replace the deck's only when the firm changed them from the default.
149
+ const display = b.fontDisplay && b.fontDisplay !== DEFAULT_BRANDING.fontDisplay ? `'${b.fontDisplay}',` : '';
150
+ const text = b.fontBody && b.fontBody !== DEFAULT_BRANDING.fontBody ? `'${b.fontBody}',` : '';
151
+ const own = (k, concept) => (b[k] && b[k] !== DEFAULT_BRANDING[k] ? b[k] : concept);
152
+ return `:root{--ink:${b.ink};--accent:${b.primary};--muted:${b.muted};--paper:${own('bgAlt', '#ffffff')};--desk:${own('bg', '#eef0f1')};
153
+ --hair:${own('border', '#e3e6e9')};--crit:${CRIT};--amber:${AMBER};
154
+ --serif:${display}'Source Serif 4',Georgia,serif;--sans:${text}'Source Sans 3',system-ui,sans-serif;--ease:cubic-bezier(0.16,1,0.3,1)}
57
155
  *{box-sizing:border-box}
58
156
  html{-webkit-print-color-adjust:exact;print-color-adjust:exact}
59
- body{font-family:var(--body);color:var(--ink);background:var(--bg);margin:0;line-height:1.6;font-variant-numeric:tabular-nums}
60
- .wrap{max-width:780px;margin:0 auto;padding:64px 44px}
61
- h1{font-family:var(--display);font-size:clamp(38px,6vw,52px);line-height:1.02;letter-spacing:-0.02em;margin:6px 0 0}
62
- h2{font-family:var(--display);font-size:25px;letter-spacing:-0.01em;line-height:1.1;margin:0}
63
- h3{font-family:var(--display);font-size:18px;letter-spacing:-0.01em;margin:0 0 6px}
64
- p{margin:0 0 10px;max-width:68ch}
65
- .label{font-family:var(--mono);text-transform:uppercase;letter-spacing:0.16em;font-size:11px;color:var(--muted)}
157
+ body{margin:0;background:var(--desk);color:var(--ink);font-family:var(--sans);font-size:15px;line-height:1.5;font-variant-numeric:tabular-nums}
158
+ p{margin:0 0 10px}
159
+ strong{font-weight:650}
160
+ code{font-family:ui-monospace,Menlo,monospace;font-size:0.88em;background:color-mix(in srgb,var(--accent) 7%,var(--paper));padding:0 3px}
161
+ a{color:var(--accent);text-underline-offset:2px;transition:color 150ms var(--ease)}
162
+ a:hover{color:var(--crit)}
66
163
  .muted{color:var(--muted)}
67
- /* cover */
68
- .cover{padding-bottom:8px}
69
- .meta{font-family:var(--mono);font-size:11px;letter-spacing:0.12em;color:var(--muted);text-transform:uppercase;margin-top:6px}
70
- .prepared{font-family:var(--mono);font-size:11px;letter-spacing:0.08em;color:var(--muted);text-transform:uppercase;margin-top:14px}
71
- /* scorecard */
72
- .scorecard{display:flex;align-items:center;gap:28px;margin:30px 0 8px;padding:24px 28px;background:var(--bgalt);border:1px solid var(--border);border-radius:12px;break-inside:avoid}
73
- .grade{font-family:var(--display);font-size:104px;line-height:0.86;font-weight:400}
74
- .score-num{font-family:var(--display);font-size:34px;line-height:1}
75
- .score-num span{font-size:18px;color:var(--muted)}
76
- .chips{display:flex;flex-wrap:wrap;gap:6px;margin-top:10px}
77
- .chip{font-family:var(--mono);font-size:11px;letter-spacing:0.04em;font-weight:600;color:var(--c);border:1px solid var(--c);border-radius:999px;padding:2px 9px;white-space:nowrap}
78
- .chip.solid{background:var(--c);color:#fff;border-color:var(--c)}
79
- .pnum{font-family:var(--mono);color:var(--primary);font-size:13px;letter-spacing:0.05em;margin-right:10px}
80
- /* section markers */
81
- .sec{display:flex;align-items:baseline;gap:14px;margin:56px 0 18px;border-bottom:1px solid var(--border);padding-bottom:10px}
82
- .sec-num{font-family:var(--mono);font-size:13px;letter-spacing:0.1em;color:var(--primary)}
83
- /* cards */
84
- .card{background:var(--bgalt);border:1px solid var(--border);border-left:3px solid var(--c,var(--border));border-radius:8px;padding:16px 18px;margin:12px 0;break-inside:avoid}
85
- .card .row{display:flex;align-items:baseline;justify-content:space-between;gap:12px}
86
- .scenario{border-left-width:3px}
87
- /* roadmap */
88
- .tier{display:flex;align-items:baseline;gap:10px;margin:22px 0 6px}
89
- .tier h3{margin:0}
90
- .count{font-family:var(--mono);font-size:11px;color:var(--muted);border:1px solid var(--border);border-radius:999px;padding:1px 8px}
91
- .tier-list{list-style:none;margin:0;padding:0}
92
- .tier-list li{display:flex;align-items:baseline;justify-content:space-between;gap:12px;padding:6px 0;border-bottom:1px solid var(--border)}
93
- /* findings appendix — denser, quieter */
94
- .find{padding:12px 0;border-bottom:1px solid var(--border)}
95
- .find h3{font-family:var(--body);font-size:15px;font-weight:600;margin:0 0 3px}
96
- .find p{font-size:13px;color:var(--muted);margin:0}
97
- .matrix{width:100%;border-collapse:collapse;margin:8px 0 22px;font-size:13px}
98
- .matrix th{text-align:left;font-family:var(--mono);text-transform:uppercase;letter-spacing:0.08em;font-size:10px;color:var(--muted);border-bottom:1px solid var(--border);padding:6px 8px}
99
- .matrix td{border-bottom:1px solid var(--border);padding:7px 8px;vertical-align:top}
100
- .matrix .cid{font-family:var(--mono);font-size:12px;color:var(--primary);white-space:nowrap}
101
- .matrix .st{text-align:right;white-space:nowrap}
102
- footer{margin-top:56px;border-top:1px solid var(--border);padding-top:18px;color:var(--muted);font-size:12px;line-height:1.55}
103
- footer .label{display:block;margin-bottom:6px;color:var(--ink)}
104
- @page{margin:18mm}
105
- @media print{.wrap{padding:0 0 24px}.sec{break-after:avoid}.card,.scorecard{break-inside:avoid}}
106
- </style></head><body><div class="wrap">
107
- ${this.cover(result, b)}
108
- ${sections}
109
- ${this.footer(b)}
110
- </div></body></html>`;
111
- }
112
- chip(sev, text) {
164
+ .deck{max-width:1280px;margin:0 auto;padding:36px 28px 56px;display:grid;grid-template-columns:minmax(0,1fr);gap:28px}
165
+ .slide{background:var(--paper);min-width:0;min-height:calc(min(1224px, 100vw - 56px) * 9 / 16);padding:52px 64px 26px;display:flex;flex-direction:column;box-shadow:0 1px 2px rgba(20,30,40,0.06),0 14px 34px -24px rgba(20,30,40,0.35)}
166
+ .slide.page{min-height:0}
167
+ .kicker{font-size:13px;font-weight:650;color:var(--accent);letter-spacing:0.01em}
168
+ h2.title{font-family:var(--serif);font-size:30px;font-weight:600;line-height:1.22;letter-spacing:-0.005em;margin:8px 0 0;max-width:34em}
169
+ .rule{width:72px;height:2px;background:var(--accent);margin:20px 0 24px}
170
+ .content{flex:1 0 auto;display:flex;flex-direction:column}
171
+ .content>*{flex:none}
172
+ .foot{display:flex;justify-content:space-between;gap:24px;margin-top:22px;padding-top:11px;border-top:1px solid var(--hair);font-size:11.5px;color:var(--muted);line-height:1.45}
173
+ .foot .src{max-width:110ch}
174
+ .foot .pg{white-space:nowrap}
175
+ h3{font-size:19px;font-weight:650;line-height:1.3;margin:0}
176
+ .lbl{font-size:12px;font-weight:700;letter-spacing:0.06em;text-transform:uppercase;color:var(--muted)}
177
+ .tag{display:inline-block;font-size:11px;font-weight:700;letter-spacing:0.04em;text-transform:uppercase;color:var(--c);border:1.25px solid var(--c);padding:0 6px;white-space:nowrap;line-height:1.6}
178
+ .tag.solid{background:var(--c);color:#fff}
179
+ .num{flex:none;width:26px;height:26px;border-radius:50%;display:inline-grid;place-items:center;font-size:13px;font-weight:700;border:1.5px solid var(--accent);color:var(--accent);background:var(--paper)}
180
+ .num.w1{background:var(--accent);color:#fff}
181
+ .num.w3{border-color:#9aa1a8;color:var(--muted)}
182
+ .cover{padding:64px 64px 30px}
183
+ .cover .content .kicker{color:var(--muted)}
184
+ .cover h1{font-family:var(--serif);font-size:50px;font-weight:600;line-height:1.08;letter-spacing:-0.015em;margin:16px 0 0;max-width:15em}
185
+ .cover .org{font-size:26px;font-weight:600;margin-top:14px}
186
+ .cover .sub{font-size:16px;color:var(--muted);margin-top:6px}
187
+ .cover .spacer{flex:1 1 auto;min-height:48px}
188
+ .cover .bottom{display:flex;align-items:flex-end;justify-content:space-between;gap:40px}
189
+ .grade{display:flex;align-items:center;gap:18px}
190
+ .grade .mark{flex:none;width:72px;height:72px;border-radius:12px;border:1px solid var(--hair);display:grid;place-items:center;font-family:var(--serif);font-size:42px;font-weight:600;color:var(--g)}
191
+ .grade .what{font-size:14px;color:var(--muted);max-width:52ch}
192
+ .grade .what strong{color:var(--ink)}
193
+ .prepared{font-size:13px;color:var(--muted);text-align:right}
194
+ .scr{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:0}
195
+ .scr>div{padding:0 32px;border-left:1px solid var(--hair)}
196
+ .scr>div:first-child{padding-left:0;border-left:0}
197
+ .scr .head{font-size:19px;font-weight:650;line-height:1.3;margin:8px 0 12px}
198
+ .scr ul{margin:0;padding-left:18px;color:#3a434d;font-size:14.5px;line-height:1.55}
199
+ .scr li{margin-bottom:6px}
200
+ .scr .res .lbl{color:var(--accent)}
201
+ .waves{display:flex;flex-direction:column;gap:12px}
202
+ .wave{display:grid;grid-template-columns:28px minmax(0,1fr);gap:10px;font-size:14.5px;line-height:1.45}
203
+ .wave ol.w1{margin:4px 0 0;padding-left:18px}
204
+ .wave ol.w1 li{margin-bottom:3px}
205
+ .mx-wrap{flex:1 1 auto !important;display:grid;grid-template-columns:minmax(0,1.05fr) minmax(0,1fr);gap:44px}
206
+ .plot{position:relative;min-height:360px}
207
+ .plot .area{position:absolute;left:34px;top:0;right:0;bottom:30px;display:grid;grid-template-columns:1fr 1fr;grid-template-rows:1fr 1fr;border-left:1.5px solid var(--ink);border-bottom:1.5px solid var(--ink)}
208
+ .plot .q{padding:10px 12px;font-size:12.5px;font-weight:700;color:var(--muted);background:#f6f7f8}
209
+ .plot .q.hot{background:color-mix(in srgb,var(--accent) 9%,var(--paper));color:var(--accent)}
210
+ .plot .q.r{text-align:right;border-left:1px dashed #c9ced3}
211
+ .plot .q.b{display:flex;align-items:flex-end;border-top:1px dashed #c9ced3}
212
+ .plot .q.r.b{justify-content:flex-end}
213
+ .plot .pt{position:absolute;transform:translate(-50%,50%)}
214
+ .plot .pt .num{width:30px;height:30px;box-shadow:0 0 0 3px var(--paper)}
215
+ .plot .yl{position:absolute;left:0;top:0;bottom:30px;width:24px;display:flex;align-items:center;justify-content:center}
216
+ .plot .yl span{transform:rotate(-90deg);white-space:nowrap;font-size:12.5px;font-weight:650;color:#3a434d}
217
+ .plot .xl{position:absolute;left:34px;right:0;bottom:0;height:24px;display:flex;justify-content:space-between;align-items:flex-end;font-size:12.5px;color:#3a434d}
218
+ .keylist{list-style:none;margin:0;padding:0}
219
+ .keylist li{display:grid;grid-template-columns:30px minmax(0,1fr) 92px;gap:10px;align-items:baseline;padding:5px 0;border-bottom:1px solid var(--hair);font-size:14px;line-height:1.35}
220
+ .keylist .e{font-size:12.5px;color:var(--muted);text-align:right}
221
+ .plan{width:100%;border-collapse:collapse;table-layout:fixed;font-size:14px}
222
+ .plan th{text-align:left;font-size:11.5px;font-weight:700;letter-spacing:0.05em;text-transform:uppercase;color:var(--muted);padding:0 10px 8px 0;border-bottom:1.5px solid var(--ink)}
223
+ .plan td{padding:9px 10px 9px 0;border-bottom:1px solid var(--hair);vertical-align:top;line-height:1.4}
224
+ .plan tr.wave-h td{border-bottom:0;padding:12px 0 2px;font-size:12.5px;font-weight:700;color:var(--accent)}
225
+ .plan tr.wave-h.w3 td{color:var(--muted)}
226
+ .plan tr.wave-h .why{font-weight:400;color:var(--muted)}
227
+ .plan .at{font-weight:600}
228
+ .plan .ad{display:block;font-size:12.5px;color:var(--muted);margin-top:2px}
229
+ .plan .ar{display:block;font-size:11.5px;color:#8a929b;margin-top:2px}
230
+ .plan .s{font-size:13px;color:#3a434d}
231
+ .balls{display:flex;gap:4px;padding-top:4px}
232
+ .balls i{width:11px;height:11px;border-radius:50%;border:1.5px solid #c9ced3}
233
+ .balls i.on{background:var(--accent);border-color:var(--accent)}
234
+ .jr{display:grid;grid-template-columns:240px repeat(15,minmax(0,1fr));align-content:start}
235
+ .jr .bar{display:flex;flex-direction:column;justify-content:flex-end;align-items:center;height:96px;padding:0 3px;font-size:12.5px;font-weight:700}
236
+ .jr .bar i{display:block;width:100%;max-width:42px;margin-top:3px;background:var(--accent)}
237
+ .jr .bar i.z{background:var(--hair)}
238
+ .jr .tl{min-height:52px;padding:7px 2px 6px;border-top:1.5px solid var(--ink);font-size:11px;line-height:1.2;text-align:center}
239
+ .jr .tl.z{color:#b3b9bf}
240
+ .jr .cn{display:flex;align-items:center;gap:8px;min-height:34px;padding:4px 10px 4px 0;border-top:1px solid #eef0f2;font-size:12.5px;line-height:1.25;min-width:0}
241
+ .jr .cn b{width:26px;flex:none}
242
+ .jr .cc{position:relative;min-height:34px;border-top:1px solid #eef0f2;display:grid;place-items:center}
243
+ .jr .cc .ln{position:absolute;top:calc(50% - 1px);height:0;border-top:2px solid var(--c)}
244
+ .jr .cc.pot .ln{border-top-style:dashed}
245
+ .jr .cc .dt{position:relative;width:13px;height:13px;border-radius:50%;background:var(--c)}
246
+ .tm{display:grid;grid-template-columns:minmax(0,1.4fr) minmax(0,1fr);gap:52px}
247
+ .hm{display:grid;grid-template-columns:200px repeat(5,minmax(0,1fr)) 52px;gap:4px;align-items:center}
248
+ .hm .h{font-size:11.5px;font-weight:700;color:var(--muted);text-align:center;padding-bottom:4px}
249
+ .hm .h.t{text-align:right}
250
+ .hm .n{font-size:14px;line-height:1.25}
251
+ .hm .n b{display:inline-block;width:20px}
252
+ .hm .c{height:46px;display:grid;place-items:center;font-size:14.5px;font-weight:700;background:#f6f7f8}
253
+ .hm .none{grid-column:span 5;height:46px;display:flex;align-items:center;padding:0 12px;font-size:13px;color:var(--muted);background:#f6f7f8}
254
+ .hm .tt{text-align:right;font-weight:700}
255
+ .lb{display:grid;grid-template-columns:190px minmax(0,1fr) 30px;gap:12px;align-items:center;min-height:38px;border-bottom:1px solid #eef0f2;font-size:14px}
256
+ .lb .segs{display:flex;gap:2px;height:12px}
257
+ .lb .segs i{display:block;height:12px}
258
+ .lb .st{font-size:12.5px;color:var(--muted)}
259
+ .legend{display:flex;flex-wrap:wrap;gap:6px 16px;margin-top:12px;font-size:12px;color:var(--muted)}
260
+ .legend span{display:inline-flex;align-items:center;gap:6px}
261
+ .legend i{width:11px;height:11px;display:inline-block}
262
+ .sc{display:grid;grid-template-columns:minmax(0,1.1fr) minmax(0,1fr);gap:44px}
263
+ .steps{list-style:none;margin:0;padding:0}
264
+ .step{position:relative;display:grid;grid-template-columns:30px minmax(0,1fr);column-gap:14px;padding:0 0 13px;break-inside:avoid}
265
+ .step::before{content:"";position:absolute;left:14px;top:28px;bottom:0;border-left:1.5px solid #c9ced3}
266
+ .step:last-child::before{display:none}
267
+ .step .num{width:28px;height:28px;font-size:12px;border-color:#9aa1a8;color:#3a434d}
268
+ .step.cut .num{background:var(--crit);border-color:var(--crit);color:#fff}
269
+ .step .t{font-weight:600;line-height:1.35;padding-top:3px;font-size:14.5px}
270
+ .step .m{font-size:12px;color:var(--muted);margin-top:2px}
271
+ .cutmark{color:var(--crit);font-weight:700;white-space:nowrap;margin-left:6px}
272
+ .abuse{font-size:15px;margin-bottom:10px}
273
+ .narr{font-size:14px;color:#3a434d;line-height:1.6}
274
+ .breaks{border-left:3px solid var(--crit);background:color-mix(in srgb,var(--crit) 5%,var(--paper));padding:12px 16px;margin-top:14px;font-size:15px}
275
+ .breaks p,.full p{margin:0}
276
+ .breaks strong{color:var(--crit)}
277
+ .breaks.potential{border-left-color:var(--accent);background:color-mix(in srgb,var(--accent) 6%,var(--paper))}
278
+ .breaks.potential strong{color:var(--accent)}
279
+ .full{margin-top:10px;font-size:13px;color:var(--muted)}
280
+ .pot{width:100%;border-collapse:collapse;font-size:14px}
281
+ .pot td,.pot th{padding:10px 12px 10px 0;border-bottom:1px solid var(--hair);vertical-align:top;text-align:left}
282
+ .pot th{font-size:11.5px;font-weight:700;letter-spacing:0.05em;text-transform:uppercase;color:var(--muted);border-bottom:1.5px solid var(--ink)}
283
+ .sched{width:100%;border-collapse:collapse;font-size:13.5px;margin:0 0 30px;table-layout:fixed}
284
+ .sched caption{text-align:left;font-size:17px;font-weight:650;padding:0 0 8px;caption-side:top}
285
+ .sched caption .muted{font-size:13px;font-weight:400;margin-left:8px}
286
+ .sched th{text-align:left;font-size:11.5px;font-weight:700;letter-spacing:0.05em;text-transform:uppercase;color:var(--muted);border-bottom:1.5px solid var(--ink);padding:6px 10px 8px 0}
287
+ .sched td{border-bottom:1px solid var(--hair);padding:9px 10px 9px 0;vertical-align:top}
288
+ .c-ref{width:64px}.c-sv{width:104px}.c-fx{width:36%}.c-ctl{width:120px}.c-st{width:150px}.c-role{width:200px}.c-rev{width:56px}.c-date{width:120px}.c-by{width:220px}
289
+ .sched .ref{color:var(--accent);font-size:12.5px;white-space:nowrap}
290
+ .sched .sv{white-space:nowrap}
291
+ .mx .sv{text-align:right}
292
+ .sched .ft{font-weight:650;display:block;margin-bottom:2px}
293
+ .sched .fd{color:var(--muted);font-size:12.5px;display:block}
294
+ .sched .fx{font-size:12.5px}
295
+ .sched .fx .k{display:none}
296
+ .sched tbody tr{transition:background-color 150ms var(--ease)}
297
+ .sched tbody tr:hover{background:color-mix(in srgb,var(--accent) 4%,var(--paper))}
298
+ h3.cap{font-size:17px;margin:0 0 8px}
299
+ h3.cap .muted{font-size:13px;font-weight:400;margin-left:8px}
300
+ .passed{list-style:none;margin:0;padding:0;display:grid;grid-template-columns:1fr 1fr;column-gap:24px;font-size:13px;border-top:1.5px solid var(--ink)}
301
+ .passed li{display:grid;grid-template-columns:60px minmax(0,1fr);gap:8px;padding:6px 0;border-bottom:1px solid var(--hair);break-inside:avoid;line-height:1.4}
302
+ .passed .ref{color:var(--accent);font-size:12px}
303
+ .phase{margin-bottom:26px}
304
+ .phase .ph{display:flex;align-items:baseline;gap:12px;padding-bottom:8px;border-bottom:1.5px solid var(--ink)}
305
+ .phase ul{list-style:none;margin:0;padding:0}
306
+ .phase li{display:grid;grid-template-columns:64px minmax(0,1fr) 96px;gap:12px;align-items:baseline;padding:8px 0;border-bottom:1px solid var(--hair);font-size:14px;line-height:1.4}
307
+ .phase .rref{color:var(--accent);font-size:12.5px}
308
+ .phase .rs{text-align:right}
309
+ .phase .empty{padding:10px 0;color:var(--muted);font-size:13.5px}
310
+ .aside{border-left:2px solid var(--accent);padding-left:14px;font-size:13.5px;color:var(--muted);margin:0 0 22px;max-width:110ch}
311
+ .approve td{height:46px}
312
+ .approve td.lbl{vertical-align:middle;color:var(--ink);text-transform:none;letter-spacing:0;font-weight:600;font-size:14px}
313
+ footer{margin-top:28px;color:var(--muted);font-size:13px;line-height:1.6;max-width:80ch}
314
+ footer .lbl{display:block;margin-bottom:6px;color:var(--ink)}
315
+ h3,.t,.ft,.at,.phase li>span:nth-child(2),.keylist li>span:nth-child(2){overflow-wrap:anywhere;min-width:0}
316
+ @media screen and (prefers-reduced-motion:no-preference){
317
+ .slide{animation:rise 520ms var(--ease) both}
318
+ .slide:nth-child(2){animation-delay:80ms}.slide:nth-child(n+3){animation-delay:140ms}
319
+ @supports (animation-timeline:view()){
320
+ .plot .pt{animation:pop linear both;animation-timeline:view();animation-range:entry 20% cover 35%}
321
+ .jr .bar i{transform-origin:bottom;animation:grow linear both;animation-timeline:view();animation-range:entry 10% cover 35%}
322
+ }}
323
+ @keyframes rise{from{opacity:0;transform:translateY(12px)}to{opacity:1;transform:none}}
324
+ @keyframes pop{from{opacity:0;transform:translate(-50%,50%) scale(0.6)}to{opacity:1;transform:translate(-50%,50%) scale(1)}}
325
+ @keyframes grow{from{transform:scaleY(0)}to{transform:scaleY(1)}}
326
+ @media screen and (max-width:760px){
327
+ .deck{padding:14px 10px 28px;gap:16px}
328
+ .slide,.cover{min-height:0;padding:26px 20px 18px}
329
+ h2.title{font-size:22px}
330
+ .cover h1{font-size:32px}
331
+ .cover .bottom,.grade{flex-direction:column;align-items:flex-start}
332
+ .prepared{text-align:left}
333
+ .scr{grid-template-columns:minmax(0,1fr);gap:22px}
334
+ .scr>div{padding:0;border-left:0}
335
+ .mx-wrap,.tm,.sc{grid-template-columns:minmax(0,1fr);gap:24px}
336
+ .plot{min-height:300px}
337
+ .plan thead{display:none}
338
+ .plan,.plan tbody,.plan tr,.plan td{display:block;width:100%}
339
+ .plan tr{border-bottom:1px solid var(--hair);padding:8px 0}
340
+ .plan td{border:0;padding:2px 0}
341
+ .plan td[data-l]{display:flex;gap:8px;align-items:baseline}
342
+ .plan td[data-l]::before{content:attr(data-l);flex:none;width:58px;font-size:11px;font-weight:700;letter-spacing:0.04em;text-transform:uppercase;color:var(--muted)}
343
+ .content{min-width:0}
344
+ .jr{overflow-x:auto;grid-template-columns:150px repeat(15,48px)}
345
+ .hm{grid-template-columns:120px repeat(5,minmax(0,1fr)) 34px}
346
+ .lb{grid-template-columns:120px minmax(0,1fr) 24px}
347
+ .passed{grid-template-columns:minmax(0,1fr)}
348
+ .sched:not(.approve),.sched:not(.approve) tbody,.sched:not(.approve) tr,.sched:not(.approve) td{display:block;width:100%}
349
+ .sched:not(.approve) thead{display:none}
350
+ .sched caption{display:block}
351
+ .sched tr{border-bottom:1px solid var(--hair);padding:8px 0}
352
+ .sched td{border:0;padding:2px 0}
353
+ .sched td.ref,.sched td.sv{display:inline-block;width:auto;padding-right:6px}
354
+ .sched .fx .k{display:block;margin-top:6px}
355
+ .sched{table-layout:auto}
356
+ .foot{flex-direction:column;gap:6px}
357
+ }
358
+ @page{size:A4 landscape;margin:10mm 10mm 14mm;@bottom-left{font-family:'Source Sans 3',sans-serif;font-size:7.5pt;color:#5b646e}@bottom-right{font-family:'Source Sans 3',sans-serif;font-size:7.5pt;color:#5b646e}}
359
+ @media print{
360
+ body{background:#fff;font-size:12.5px}
361
+ .deck{max-width:none;padding:0;display:block}
362
+ .slide{box-shadow:none;break-before:page;min-height:182mm;padding:8mm 10mm 4mm}
363
+ /* A slide is one page: scale it to the sheet, keeping its frame (182mm / 0.8). */
364
+ .slide:not(.page){zoom:0.8;min-height:227mm;break-inside:avoid}
365
+ .slide.page{min-height:0}
366
+ .slide:first-child{break-before:auto}
367
+ .step,.plan tr,.sched tr,.keylist li,.phase li,.passed li,.breaks{break-inside:avoid}
368
+ h2.title,.rule{break-after:avoid}
369
+ }`;
370
+ }
371
+ slide(s, n, total, r, date) {
372
+ const head = s.kind === 'cover' ? '' : `<div class="kicker">${esc(s.kicker)}</div><h2 class="title">${s.title}</h2><div class="rule"></div>`;
373
+ return `<section class="slide${s.kind && s.kind !== 'slide' ? ` ${s.kind}` : ''}" style="page:s${n}" aria-label="${esc(s.kicker)}">
374
+ ${head}<div class="content">${s.body}</div>
375
+ <div class="foot"><span class="src">${s.source ?? ''}</span><span class="pg">${esc(r.orgName)} · ${esc(date)} · ${n} / ${total}</span></div>
376
+ </section>`;
377
+ }
378
+ tag(sev, text) {
113
379
  const solid = sev === 'CRITICAL' ? ' solid' : '';
114
- return `<span class="chip${solid}" style="--c:${SEV_COLOR[sev]}">${esc(text)}</span>`;
115
- }
116
- sectionHead(numStr, title) {
117
- return `<div class="sec"><span class="sec-num">${numStr} /</span><h2>${esc(title)}</h2></div>`;
118
- }
119
- cover(r, b) {
120
- const meta = [r.orgName, r.orgType, r.orgId, r.generatedAt.toISOString().slice(0, 10)]
121
- .map((s) => esc(String(s))).join(' · ');
122
- const counts = SEV_ORDER
123
- .map((l) => ({ l, n: r.findings.filter((f) => f.riskLevel === l && !f.passed && !f.inconclusive && !f.waived).length }))
124
- .filter((c) => c.n > 0)
125
- .map((c) => this.chip(c.l, `${c.n} ${c.l}`)).join('');
126
- const prepared = b.preparedFor ? ` for ${esc(b.preparedFor)}` : '';
127
- return `<header class="cover">
128
- <div class="label">${esc(b.firmName)}</div>
129
- <h1>Salesforce Security Audit</h1>
130
- <div class="meta">${meta}</div>
131
- <div class="scorecard" style="border-left:4px solid ${GRADE_COLOR[r.grade] ?? b.primary}">
132
- <div class="grade" style="color:${GRADE_COLOR[r.grade] ?? b.primary}">${esc(r.grade)}</div>
133
- <div>
134
- <div class="label">Security grade · health score</div>
135
- <div class="score-num">${r.healthScore}<span>/100</span></div>
136
- <div class="chips">${counts || this.chip('LOW', 'No active findings')}</div>
137
- </div>
138
- </div>
139
- <div class="prepared">Prepared by ${esc(b.firmName)}${prepared}</div></header>`;
140
- }
141
- summary(r, numStr) {
142
- const incon = r.findings.filter((f) => f.inconclusive).length;
143
- const active = r.findings.filter((f) => !f.passed && !f.inconclusive && !f.waived).length;
144
- const waived = r.findings.filter((f) => f.waived).length;
145
- const waivedNote = waived ? `, with ${waived} waived as accepted risk` : '';
146
- return `${this.sectionHead(numStr, 'Executive Summary')}
147
- <p>This audit assessed the org’s security configuration and scored it <strong>${r.healthScore}/100 (Grade ${esc(r.grade)})</strong>${r.gradeReason ? `, a grade set by ${esc(r.gradeReason.replace(/^[A-F]: /, ''))},` : ''} across ${active} active finding${active === 1 ? '' : 's'}${incon ? `, with ${incon} inconclusive (no evidence gathered)` : ''}${waivedNote}. The priorities below are the highest-impact items to address first; the remediation roadmap groups every fix by effort. See Scope &amp; Liability for the basis and limits of this assessment.</p>${this.coverageNote(r)}`;
148
- }
149
- prioritiesSection(priorities, chainIds, numStr) {
150
- const head = this.sectionHead(numStr, 'Executive Priorities');
151
- if (priorities.length === 0)
152
- return `${head}<p class="muted">No active findings to prioritise.</p>`;
153
- const items = priorities.map((f, i) => {
154
- const meta = f.checkId ? getCheckMeta(f.checkId) : undefined;
155
- const chained = chainIds.has(f.id) ? '<p class="muted">Part of an attack chain. See Attack Scenarios.</p>' : '';
156
- const impact = meta ? `<p><strong>Impact:</strong> ${esc(meta.impact)}</p>` : '';
157
- return `<div class="card" style="--c:${SEV_COLOR[f.riskLevel]}">
158
- <div class="row"><h3><span class="pnum">${String(i + 1).padStart(2, '0')}</span>${esc(f.title)}</h3>${this.chip(f.riskLevel, f.riskLevel)}</div>
159
- ${impact}${chained}<p><strong>Fix:</strong> ${esc(f.remediation)}</p></div>`;
160
- }).join('');
161
- return `${head}<p class="muted">Focus areas, highest impact first.</p>${items}`;
380
+ return `<span class="tag${solid}" style="--c:${SEV_COLOR[sev]}">${esc(text)}</span>`;
162
381
  }
163
- coverageNote(r) {
382
+ gradeColor(g) {
383
+ return g === 'D' || g === 'F' ? 'var(--crit)' : g === 'C' ? 'var(--amber)' : 'var(--accent)';
384
+ }
385
+ coverSlide(r, b) {
386
+ const prepared = `Prepared by ${esc(b.firmName)}${b.preparedFor ? ` for ${esc(b.preparedFor)}` : ''}`;
387
+ return {
388
+ kicker: 'Cover', title: '', kind: 'cover',
389
+ body: `<div class="kicker">Salesforce security assessment</div>
390
+ <h1>Findings and action plan</h1>
391
+ <div class="org">${esc(r.orgName)}</div>
392
+ <div class="sub">${esc(r.orgType)} · ${esc(r.orgId)} · ${esc(r.generatedAt.toISOString().slice(0, 10))}</div>
393
+ <div class="spacer"></div>
394
+ <div class="bottom"><div class="grade"><div class="mark" style="--g:${this.gradeColor(r.grade)}">${esc(r.grade)}</div>
395
+ <div class="what">Grade <strong>${esc(r.grade)}</strong> · health score <strong>${r.healthScore}/100</strong><br>${esc(gradeInWords(r.grade, r.gradeReason))}</div></div>
396
+ <div class="prepared">${prepared}</div></div>`,
397
+ };
398
+ }
399
+ summarySlide(r, plan, chains) {
400
+ const open = r.findings.filter(isOpen);
401
+ const count = (l) => open.filter((f) => f.riskLevel === l).length;
402
+ const crit = count('CRITICAL'), high = count('HIGH');
403
+ const passed = r.findings.filter((f) => f.passed).length;
404
+ const named = chains.filter((c) => c.abuseCase);
405
+ const critChains = chains.map((c, i) => ({ c, i })).filter((x) => x.c.severity === 'CRITICAL' && x.c.abuseCase);
406
+ // Every critical chain, potential ones too: a path is only "closed" when an action breaks it.
407
+ const allCrit = chains.map((c, i) => ({ c, i })).filter((x) => x.c.severity === 'CRITICAL');
408
+ const wave1 = plan.filter((a) => a.wave === 1);
409
+ const brokenByWave1 = new Set(wave1.flatMap((a) => a.breaks));
410
+ const allCritBroken = allCrit.length > 0 && allCrit.every((x) => brokenByWave1.has(x.i));
411
+ const rest = plan.length - wave1.length;
412
+ const restText = rest ? `; ${rest} more action${verb(rest, ' completes', 's complete')} the plan` : '';
413
+ const n1 = wave1.length;
414
+ let headline;
415
+ if (plan.length === 0)
416
+ headline = 'No critical or high-severity issues are open; the remaining fixes are routine hardening';
417
+ else if (allCritBroken)
418
+ headline = `${actions(n1)} to start now ${verb(n1, 'closes', 'close')} every critical attack path${restText}`;
419
+ else if (n1)
420
+ headline = `${actions(n1)} to start now ${verb(n1, 'addresses', 'address')} the critical exposure${restText}`;
421
+ else if (high)
422
+ headline = `${actions(plan.length)} ${verb(plan.length, 'addresses', 'address')} every open high-severity issue; none is critical`;
423
+ else
424
+ headline = `${actions(plan.length)} ${verb(plan.length, 'addresses', 'address')} the remaining exposure; none is critical or high`;
164
425
  const c = r.coverage;
165
- if (!c || c.notAssessed.length === 0)
166
- return '';
167
- return `<p class="muted">${esc(coverageSummary(c))}. The checks that gathered no evidence are listed as inconclusive in the findings appendix; their areas are unassessed, not clean. ${esc(coverageAdvice(c))}</p>`;
426
+ const incon = r.findings.filter(unassessed).length;
427
+ const waivedN = r.findings.filter(isWaived).length;
428
+ const parts = [`${open.length} open`, `${passed} passed`, ...(incon ? [`${incon} inconclusive`] : []), ...(waivedN ? [`${waivedN} waived as accepted risk`] : [])];
429
+ const situation = [
430
+ c ? `${plural(c.checksRun, 'check')} ran (${c.checksAssessed} gathered evidence) and produced ${plural(r.findings.length, 'result')}: ${parts.join(', ')}` : `${plural(r.findings.length, 'result')}: ${parts.join(', ')}`,
431
+ esc(gradeInWords(r.grade, r.gradeReason)),
432
+ ];
433
+ const compHead = crit ? `${plural(crit, 'critical finding')} and ${high} high are open`
434
+ : high ? `${plural(high, 'high-severity finding')} ${high === 1 ? 'is' : 'are'} open` : `${plural(open.length, 'finding')} open, none critical or high`;
435
+ const complication = [
436
+ named.length ? `${plural(named.length, 'proven attack chain')} link findings into a path to data or control${critChains.length ? `, ${critChains.length} of them critical` : ''}${chains.length > named.length ? `; ${plural(chains.length - named.length, 'more path')} ${verb(chains.length - named.length, 'is', 'are')} possible but unproven` : ''}` : '',
437
+ ...critChains.slice(0, 2).map((x) => `${esc(cap(x.c.abuseCase.actor))} could ${esc(x.c.abuseCase.goal)}`),
438
+ ].filter(Boolean);
439
+ const waves = [1, 2, 3].map((w) => ({ w, items: plan.filter((a) => a.wave === w) })).filter((x) => x.items.length);
440
+ const resolution = waves.length
441
+ ? `<div class="waves">${waves.map(({ w, items }) => {
442
+ const named1 = w === 1 ? items.slice(0, 4) : items.slice(0, 1);
443
+ const more = items.length - named1.length;
444
+ const what = w === 1 && named1.length > 1
445
+ ? `<ol class="w1">${named1.map((a) => `<li>${esc(a.title)}${a.breaks.length ? ` <span class="muted">(breaks ${a.breaks.map((i) => this.labels[i]).join(', ')})</span>` : ''}</li>`).join('')}</ol>${more ? `<span class="muted">and ${plural(more, 'more action')}</span>` : ''}`
446
+ : `${esc(named1[0].title)}${more ? `, and ${plural(more, 'more action')}` : ''}`;
447
+ return `<div class="wave"><span class="num w${w}">${w}</span><span><strong>${WAVE_LABEL[w]}:</strong> ${what}</span></div>`;
448
+ }).join('')}</div>`
449
+ : '<p>Keep the configuration where it is and re-run the audit after changes.</p>';
450
+ const list = (xs) => (xs.length ? `<ul>${xs.map((x) => `<li>${x}</li>`).join('')}</ul>` : '');
451
+ return {
452
+ kicker: 'Executive summary', title: esc(headline),
453
+ body: `<div class="scr">
454
+ <div><div class="lbl">Situation</div><div class="head">The org scores ${r.healthScore}/100 on configuration health, graded ${esc(r.grade)}</div>${list(situation)}</div>
455
+ <div><div class="lbl">Complication</div><div class="head">${esc(compHead)}</div>${list(complication)}</div>
456
+ <div class="res"><div class="lbl">Resolution</div><div class="head">${waves.length ? `Act in ${countWord(waves.length).toLowerCase()} wave${waves.length === 1 ? '' : 's'}${n1 ? ', starting now' : ''}` : 'Hold the line'}</div>${resolution}</div>
457
+ </div>`,
458
+ source: `${c ? `${esc(coverageSummary(c))}. ` : ''}Source: read-only configuration audit of ${esc(r.orgName)}. See Scope &amp; Liability on the last page.`,
459
+ };
168
460
  }
169
- waiversSection(waived, numStr) {
170
- const items = waived
171
- .map((f) => {
172
- // The approval (reason, approver, expiry) is on each item's note, or on the detail when the finding has no items.
173
- const scope = f.affectedItems?.length ? f.affectedItems.map((i) => (i.note ? `${i.label} ${i.note}` : i.label)).join('; ') : f.id;
174
- return `<div class="card" style="--c:#16a34a">
175
- <div class="row"><h3>${esc(f.title)}</h3>${this.chip('INFO', 'WAIVED')}</div>
176
- <p><strong>Scope:</strong> ${esc(scope)}</p><p>${esc(f.detail)}</p></div>`;
177
- })
178
- .join('');
179
- return `${this.sectionHead(numStr, 'Accepted Risks')}<p class="muted">Findings covered by an approved, unexpired waiver. They are excluded from the score and from the priorities above, and still count toward the attack scenarios.</p>${items}`;
180
- }
181
- scenarios(chains, numStr) {
182
- const items = chains.map((c) => {
183
- const dagSvg = renderAttackChainDagSvg(c, { theme: 'light' });
184
- return `<div class="card scenario" style="--c:${SEV_COLOR[c.severity]}">
185
- <div class="row"><h3>${esc(c.title)}</h3>${this.chip(c.severity, c.severity)}</div>
186
- ${c.abuseCase ? `<p><strong>Abuse case:</strong> ${esc(c.abuseCase.actor)} wants to ${esc(c.abuseCase.goal)}.</p>` : ''}
187
- <p>${esc(c.narrative)}</p>
188
- ${dagSvg}
189
- ${c.abuseCase
190
- ? `<p><strong>Breaks the chain:</strong> ${esc(c.abuseCase.breakPoint)}</p><p class="muted"><strong>Full remediation:</strong> ${esc(c.remediation)}</p>`
191
- : `<p><strong>Recommended fixes:</strong> ${esc(c.remediation)}</p>`}</div>`;
461
+ matrixSlide(plan) {
462
+ const shown = plan.slice(0, Math.max(1, Math.min(this.opts.topN, MATRIX_MAX)));
463
+ const realMax = Math.max(...shown.map((a) => a.risk), 0);
464
+ const maxRisk = realMax || 1;
465
+ // Days of work counts as "do now": quick and moderate sit left of the midline, projects right.
466
+ const X = { quick: 0.14, moderate: 0.37, project: 0.78 };
467
+ const placed = [];
468
+ const pts = shown.map((a, i) => {
469
+ // Points sit on their effort column; only a collision nudges one sideways.
470
+ const y = 0.08 + (a.risk / maxRisk) * 0.84;
471
+ let x = X[a.effort];
472
+ for (let k = 1; placed.some((p) => Math.abs(p.x - x) < 0.045 && Math.abs(p.y - y) < 0.07); k++)
473
+ x = X[a.effort] + (k % 2 ? 1 : -1) * Math.ceil(k / 2) * 0.05;
474
+ placed.push({ x, y });
475
+ return `<div class="pt" style="left:calc(34px + (100% - 34px) * ${x.toFixed(3)});bottom:calc(30px + (100% - 30px) * ${y.toFixed(3)})"><span class="num w${a.wave}">${i + 1}</span></div>`;
192
476
  }).join('');
193
- return `${this.sectionHead(numStr, 'Attack Scenarios')}<p class="muted">How findings combine into real attack paths.</p>${items}`;
194
- }
195
- roadmapSection(roadmap, numStr) {
196
- const tier = (label, sub, arr) => {
197
- if (arr.length === 0)
198
- return '';
199
- const rows = arr.map((f) => `<li><span>${esc(f.title)}</span>${this.chip(f.riskLevel, f.riskLevel)}</li>`).join('');
200
- return `<div class="tier"><h3>${esc(label)}</h3><span class="count">${arr.length} · ${esc(sub)}</span></div><ul class="tier-list">${rows}</ul>`;
477
+ const nums = (xs) => (xs.length > 1 ? `${xs.slice(0, -1).join(', ')} and ${xs[xs.length - 1]}` : String(xs[0]));
478
+ const big = shown.map((a, i) => ({ a, n: i + 1 })).filter((x) => x.a.risk >= maxRisk / 2);
479
+ const cheap = big.filter((x) => x.a.effort !== 'project').map((x) => x.n);
480
+ const costly = big.filter((x) => x.a.effort === 'project').map((x) => x.n);
481
+ const headline = realMax === 0 ? 'None of these actions removes critical or high-severity risk'
482
+ : cheap.length && costly.length ? `Action${cheap.length === 1 ? '' : 's'} ${nums(cheap)} ${verb(cheap.length, 'is', 'are')} the cheapest large risk reduction${cheap.length === 1 ? '' : 's'}; ${nums(costly)} also ${verb(costly.length, 'removes', 'remove')} large risk but ${verb(costly.length, 'needs', 'need')} project funding`
483
+ : cheap.length ? `Action${cheap.length === 1 ? '' : 's'} ${nums(cheap)} remove${cheap.length === 1 ? 's' : ''} the most risk for days of work or less`
484
+ : `The largest risk reductions (${nums(costly)}) need project funding`;
485
+ const key = shown.map((a, i) => `<li><span class="num w${a.wave}">${i + 1}</span><span>${esc(a.title)}</span><span class="e">${EFFORT_LABEL[a.effort]}</span></li>`).join('');
486
+ return {
487
+ kicker: 'Where to act', title: esc(headline),
488
+ body: `<div class="mx-wrap"><div class="plot">
489
+ <div class="area"><div class="q hot">Do now</div><div class="q r">Plan and fund</div><div class="q b">Quick hygiene</div><div class="q r b">Schedule</div></div>
490
+ ${pts}<div class="yl"><span>Risk removed →</span></div><div class="xl"><span>Under a day</span><span><strong>Effort →</strong></span><span>Weeks</span></div>
491
+ </div><ol class="keylist">${key}</ol></div>`,
492
+ source: `Risk removed weighs the severity of each finding an action closes, and counts twice the severity of each attack chain it breaks. Effort is each check's remediation estimate.${plan.length > shown.length ? ` The top ${shown.length} of ${plan.length} actions are shown; all are in the action plan.` : ''}`,
493
+ };
494
+ }
495
+ planSlides(plan, chains, r) {
496
+ if (plan.length === 0)
497
+ return [];
498
+ const maxRisk = Math.max(...plan.map((a) => a.risk), 1);
499
+ const named = chains.filter((c) => c.abuseCase).length;
500
+ const broken = new Set(plan.flatMap((a) => a.breaks)).size;
501
+ const closed = new Set(plan.flatMap((a) => a.fixes)).size;
502
+ const open = r.findings.filter(isOpen).length;
503
+ const n = plan.length;
504
+ const headline = `${actions(n)}${named ? ` ${verb(n, 'breaks', 'break')} ${broken} of ${plural(named, 'named attack chain')} and` : ''} ${verb(n, 'closes', 'close')} ${closed} of ${plural(open, 'open finding')}`;
505
+ const label = (i) => this.labels[i];
506
+ const rows = plan.map((a, i) => {
507
+ const refs = a.fixes.map((f) => this.refs.get(f.id)).filter(Boolean).join(' ');
508
+ const breaks = a.breaks.length ? a.breaks.map(label).join(', ') : '—';
509
+ const weakens = a.weakens.length ? `<span class="ad">weakens ${a.weakens.map(label).join(', ')}: part of its break point is waived or passed</span>` : '';
510
+ const inChains = a.inChains.length ? `<span class="ad">part of ${a.inChains.map(label).join(', ')}</span>` : '';
511
+ const balls = [1, 2, 3, 4].map((k) => `<i${k <= Math.ceil((a.risk / maxRisk) * 4) ? ' class="on"' : ''}></i>`).join('');
512
+ return { wave: a.wave, html: `<tr><td><span class="num w${a.wave}">${i + 1}</span></td><td><span class="at">${title(a.title)}</span><span class="ad">${esc(a.detail ?? a.why)}</span><span class="ar">${esc(refs)}</span></td><td class="s" data-l="Breaks">${breaks}${weakens}${inChains}</td><td data-l="Risk"><span class="balls">${balls}</span></td><td class="s" data-l="Effort">${EFFORT_LABEL[a.effort]}</td><td class="s muted" data-l="Owner">[To agree]</td></tr>` };
513
+ });
514
+ const pages = [];
515
+ for (let start = 0; start < rows.length; start += PLAN_ROWS_PER_SLIDE) {
516
+ const chunk = rows.slice(start, start + PLAN_ROWS_PER_SLIDE);
517
+ let last = 0;
518
+ const body = chunk.map((row) => {
519
+ const h = row.wave !== last ? `<tr class="wave-h w${row.wave}"><td></td><td colspan="5">${WAVE_LABEL[row.wave]} <span class="why">· ${WAVE_WHY[row.wave]}</span></td></tr>` : '';
520
+ last = row.wave;
521
+ return h + row.html;
522
+ }).join('');
523
+ const cont = start > 0;
524
+ pages.push({
525
+ kicker: cont ? 'Action plan (continued)' : 'Action plan',
526
+ title: cont ? `Actions ${start + 1}–${Math.min(start + PLAN_ROWS_PER_SLIDE, rows.length)} of ${rows.length}` : esc(headline),
527
+ body: `<table class="plan"><colgroup><col style="width:44px"><col><col style="width:150px"><col style="width:84px"><col style="width:104px"><col style="width:104px"></colgroup>
528
+ <thead><tr><th></th><th>Action</th><th>Breaks</th><th>Risk</th><th>Effort</th><th>Owner</th></tr></thead><tbody>${body}</tbody></table>`,
529
+ source: 'Each named attack chain becomes the action that breaks it; every other open critical or high finding becomes an action per check. Risk marks: share of the largest action’s risk removed. References point to the findings appendix; medium and low fixes are in the roadmap.',
530
+ });
531
+ }
532
+ return pages;
533
+ }
534
+ threatSlides(r, chains) {
535
+ const out = [];
536
+ const journey = buildAttackJourney(r.findings, chains);
537
+ if (journey.tactics.some((t) => t.findings.length)) {
538
+ const max = Math.max(...journey.tactics.map((t) => t.findings.length), 1);
539
+ const top = journey.tactics.map((t, i) => ({ ...t, i })).filter((t) => t.findings.length)
540
+ .sort((a, b) => b.findings.length - a.findings.length || a.i - b.i);
541
+ const crit = chains.map((c, i) => ({ c, i })).filter((x) => x.c.severity === 'CRITICAL');
542
+ const initial = ATTACK_TACTIC_ORDER.indexOf('initial-access');
543
+ const fromOutside = crit.filter((x) => journey.chains[x.i][0] === initial).length;
544
+ const cutoff = top[Math.min(1, top.length - 1)].findings.length;
545
+ const lead = top.filter((t) => t.findings.length >= cutoff).slice(0, 3);
546
+ const names = lead.map((t) => TACTIC_SHORT[t.tactic].toLowerCase().replace(' esc.', ' escalation'));
547
+ const critClause = crit.length
548
+ ? `; ${fromOutside === 0 ? 'none' : countWord(fromOutside).toLowerCase()} of the ${countWord(crit.length).toLowerCase()} critical chain${crit.length === 1 ? '' : 's'} ${fromOutside === 1 ? 'starts' : 'start'} with initial access`
549
+ : '';
550
+ const joined = names.length > 2 ? `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]}` : names.join(' and ');
551
+ const headline = `Findings cluster in ${joined}${critClause}`;
552
+ const bars = journey.tactics.map((t) => `<div class="bar">${t.findings.length || ''}<i${t.findings.length ? '' : ' class="z"'} style="height:${t.findings.length ? Math.round((t.findings.length / max) * 64) : 2}px"></i></div>`).join('');
553
+ const labels = journey.tactics.map((t) => `<div class="tl${t.findings.length ? '' : ' z'}">${esc(TACTIC_SHORT[t.tactic])}</div>`).join('');
554
+ const rows = chains.map((c, ci) => {
555
+ const hits = journey.chains[ci];
556
+ const col = !c.abuseCase ? '#9aa1a8' : c.severity === 'CRITICAL' ? 'var(--crit)' : '#5b646e';
557
+ const lo = hits[0] ?? -1, hi = hits[hits.length - 1] ?? -1;
558
+ const cells = journey.tactics.map((_, ti) => {
559
+ const span = hits.length > 1 && ti >= lo && ti <= hi;
560
+ const line = span ? `<i class="ln" style="left:${ti > lo ? '0' : '50%'};right:${ti < hi ? '0' : '50%'}"></i>` : '';
561
+ return `<div class="cc${c.abuseCase ? '' : ' pot'}" style="--c:${col}">${line}${hits.includes(ti) ? '<i class="dt"></i>' : ''}</div>`;
562
+ }).join('');
563
+ return `<div class="cn"><b style="color:${col}">${this.labels[ci]}</b><span>${esc(c.title)}${c.abuseCase ? '' : ' <em class="muted">(potential)</em>'}</span></div>${cells}`;
564
+ }).join('');
565
+ const none = chains.map((_, i) => (journey.chains[i].length ? '' : this.labels[i])).filter(Boolean);
566
+ out.push({
567
+ kicker: 'Threat model · MITRE ATT&CK', title: esc(headline),
568
+ body: `<div class="jr"><div></div>${bars}<div></div>${labels}${rows}</div>`,
569
+ source: `Bars: open findings whose granted access maps to a technique in each tactic (Enterprise ATT&amp;CK v20.0, verified techniques only). Rows: the tactics each attack chain reaches, in attack order.${none.length ? ` ${none.join(', ')} map${none.length === 1 ? 's' : ''} to no technique.` : ''}`,
570
+ });
571
+ }
572
+ const view = buildThreatView(r.findings);
573
+ const sevCount = (row) => SEVERITIES.map((l) => row.findings.filter((f) => f.riskLevel === l).length);
574
+ const shade = (n, crit) => (!n ? '' : crit ? 'background:var(--crit);color:#fff'
575
+ : `background:color-mix(in srgb,var(--accent) ${Math.round(16 + Math.min(n, 10) * 7)}%,var(--paper));${n >= 6 ? 'color:#fff' : ''}`);
576
+ const stride = view.stride.map((row) => {
577
+ const v = sevCount(row);
578
+ const cells = row.findings.length
579
+ ? v.map((n, i) => `<div class="c" style="${shade(n, i === 0)}">${n || ''}</div>`).join('')
580
+ : `<div class="none">${esc(threatRowStatusText(row))}</div>`;
581
+ return `<div class="n"><b>${esc(row.category)}</b>${esc(row.name)}</div>${cells}<div class="tt">${row.findings.length || ''}</div>`;
582
+ }).join('');
583
+ const critRows = view.stride.filter((row) => row.findings.some((f) => f.riskLevel === 'CRITICAL'));
584
+ const busiest = [...view.stride].sort((a, b) => b.findings.length - a.findings.length)[0];
585
+ // "All critical risk" holds only when every open critical finding sits in those categories.
586
+ const unmappedCritical = r.findings.filter((f) => isOpen(f) && f.riskLevel === 'CRITICAL' && !f.threats?.stride?.length).length;
587
+ let headline = critRows.length && critRows.length <= 2 && unmappedCritical === 0
588
+ ? `All critical risk is ${critRows.map((x) => x.name.toLowerCase()).join(' or ')}`
589
+ : busiest.findings.length ? `${busiest.name} carries the most open findings` : 'No open finding maps to a STRIDE category';
590
+ const segColors = [CRIT, '#d98a7f', '#d9b071', '#cdd3d8'];
591
+ let privacy = '';
592
+ if (view.linddun) {
593
+ const bars = view.linddun.map((row) => {
594
+ const v = sevCount(row).slice(0, 4);
595
+ const segs = row.findings.length
596
+ ? `<span class="segs">${v.map((n, i) => (n ? `<i style="width:${n * 22}px;background:${segColors[i]}"></i>` : '')).join('')}</span>`
597
+ : `<span class="st">${esc(threatRowStatusText(row))}</span>`;
598
+ return `<div class="lb"><span>${esc(row.name)}</span>${segs}<b style="text-align:right">${row.findings.length || ''}</b></div>`;
599
+ }).join('');
600
+ const topPrivacy = [...view.linddun].sort((a, b) => b.findings.length - a.findings.length)[0];
601
+ if (topPrivacy.findings.length)
602
+ headline += `; on privacy, ${topPrivacy.name.toLowerCase()} leads`;
603
+ privacy = `<div><h3 style="font-size:15px;margin-bottom:10px">Privacy threats (LINDDUN) · open findings</h3>${bars}
604
+ <div class="legend"><span><i style="background:${segColors[0]}"></i>Critical</span><span><i style="background:${segColors[1]}"></i>High</span><span><i style="background:${segColors[2]}"></i>Medium</span><span><i style="background:${segColors[3]}"></i>Low</span></div></div>`;
605
+ }
606
+ out.push({
607
+ kicker: 'Threat model · STRIDE and LINDDUN', title: esc(headline),
608
+ body: `<div class="tm"><div><h3 style="font-size:15px;margin-bottom:10px">Security threats (STRIDE) · open findings by severity <span class="muted" style="font-weight:400">(a finding counts in each category it touches)</span></h3>
609
+ <div class="hm"><div class="h"></div>${SEVERITIES.map((l) => `<div class="h">${cap(l.toLowerCase())}</div>`).join('')}<div class="h t">Total</div>${stride}</div></div>${privacy}</div>`,
610
+ source: `Each check is mapped to the STRIDE categories it guards and, where personal data is involved, to LINDDUN.${[...view.stride, ...(view.linddun ?? [])].some((row) => !row.findings.length) ? ' A row without findings is not assurance: it says how many checks covered it.' : ''}`,
611
+ });
612
+ return out;
613
+ }
614
+ stepMeta(s) {
615
+ const parts = [];
616
+ const ref = this.refs.get(s.findingId);
617
+ if (ref)
618
+ parts.push(ref);
619
+ if (s.severity)
620
+ parts.push(cap(s.severity.toLowerCase()));
621
+ for (const t of s.techniques ?? [])
622
+ parts.push(techniqueLabel(t));
623
+ return parts.map(esc).join(' · ');
624
+ }
625
+ steps(c) {
626
+ return `<ol class="steps" aria-label="Steps, in attack order">${c.steps.map((s, i) => {
627
+ const cut = s.breaksChain ? ' cut' : '';
628
+ const mark = s.breaksChain ? '<span class="cutmark">✂ BREAK POINT</span>' : '';
629
+ return `<li class="step${cut}"><span class="num">${i + 1}</span><div><div class="t">${title(s.title || s.findingId)}</div><div class="m">${this.stepMeta(s)}${mark}</div></div></li>`;
630
+ }).join('')}</ol>`;
631
+ }
632
+ chainSlide(c, i, findings) {
633
+ const openIds = new Set(findings.filter(isOpen).map((f) => f.id));
634
+ const cutIds = [...new Set(c.steps.filter((s) => s.breaksChain).map((s) => s.findingId))];
635
+ const fixable = cutIds.filter((id) => openIds.has(id)).length;
636
+ const headline = cutIds.length === 0 ? esc(c.title)
637
+ : fixable < cutIds.length ? `${esc(c.title)}: part of its break point is waived or passed, so it stays open`
638
+ : `${esc(c.title)}: fixing ${plural(cutIds.length, 'finding')} breaks it`;
639
+ return {
640
+ kicker: `Attack scenario ${this.labels[i]} · ${cap(c.severity.toLowerCase())}`,
641
+ title: headline,
642
+ body: `<div class="sc"><div>${this.steps(c)}</div><div>
643
+ <p class="abuse"><strong>Abuse case:</strong> ${esc(c.abuseCase.actor)} wants to ${esc(c.abuseCase.goal)}.</p>
644
+ <div class="narr"><p>${esc(c.narrative)}</p></div>
645
+ <div class="breaks"><p><strong>Breaks the chain:</strong> ${esc(c.abuseCase.breakPoint)}</p></div>
646
+ <div class="full"><p><strong>Full remediation:</strong> ${esc(c.remediation)}</p></div></div></div>`,
647
+ source: `${this.ratingNote(c)}Steps run in attack order. Steps marked ✂ are the break point: fixing all of them stops the chain. References point to the findings appendix.`,
648
+ };
649
+ }
650
+ /** Why a chain is rated above or below its steps, so the rating never looks like an error. */
651
+ ratingNote(c) {
652
+ const steps = c.steps.map((s) => s.severity).filter((x) => !!x);
653
+ if (!steps.length)
654
+ return '';
655
+ const worst = steps.reduce((a, b) => (SEV_RANK[b] < SEV_RANK[a] ? b : a));
656
+ const chain = cap(c.severity.toLowerCase());
657
+ if (SEV_RANK[c.severity] < SEV_RANK[worst]) {
658
+ return `Rated ${chain} as a path; its steps are rated up to ${worst.toLowerCase()}. `;
659
+ }
660
+ if (SEV_RANK[c.severity] > SEV_RANK[worst]) {
661
+ return `Rated ${chain} as a path; its ${worst.toLowerCase()} step is also counted on its own in the findings and the grade. `;
662
+ }
663
+ return '';
664
+ }
665
+ potentialSlide(list) {
666
+ const rows = list.map(({ c, i }) => `<tr><td style="width:56px;color:var(--accent);font-weight:700">${this.labels[i]}</td><td><strong>${esc(c.title)}</strong><div style="font-size:13.5px;margin-top:4px;color:#3a434d">${esc(c.narrative)}</div><div class="muted" style="font-size:13px;margin-top:4px">${c.steps.map((s) => title(s.title || s.findingId)).join(' → ')}</div></td><td style="width:42%"><div class="breaks potential" style="margin-top:0"><p><strong>Recommended fixes:</strong> ${esc(c.remediation)}</p></div></td></tr>`).join('');
667
+ return {
668
+ kicker: 'Attack scenarios · potential',
669
+ title: `${countWord(list.length)} further path${list.length === 1 ? ' is' : 's are'} possible but unproven`,
670
+ body: `<table class="pot"><thead><tr><th></th><th>Path</th><th>What would close it</th></tr></thead><tbody>${rows}</tbody></table>`,
671
+ source: 'Potential chains link findings whose access could combine; no single break point is proven for them, so their fixes are recommendations.',
672
+ };
673
+ }
674
+ roadmapPage(roadmap) {
675
+ const phase = (label, sub, arr) => {
676
+ const rows = arr.length
677
+ ? `<ul>${arr.map((f) => `<li><span class="rref">${esc(this.refs.get(f.id) ?? '')}</span><span>${title(f.title)}</span><span class="rs">${this.tag(f.riskLevel, f.riskLevel)}</span></li>`).join('')}</ul>`
678
+ : '<div class="empty">Nothing at this effort.</div>';
679
+ return `<div class="phase"><div class="ph"><h3>${esc(label)}</h3><span class="muted">${arr.length} · ${esc(sub)}</span></div>${rows}</div>`;
680
+ };
681
+ return {
682
+ kicker: 'Appendix · Remediation roadmap', kind: 'page',
683
+ title: 'Every open fix above informational, grouped by the effort it takes',
684
+ body: `${phase('Quick wins', 'a day or less each', roadmap.quick)}${phase('Moderate', 'days each', roadmap.moderate)}${phase('Projects', 'weeks each', roadmap.project)}`,
201
685
  };
202
- return `${this.sectionHead(numStr, 'Remediation Roadmap')}
203
- ${tier('Quick wins', '≤1 day', roadmap.quick)}
204
- ${tier('Moderate', 'days', roadmap.moderate)}
205
- ${tier('Projects', 'weeks', roadmap.project)}`;
206
686
  }
207
687
  worst(findings) {
208
688
  return findings.slice().sort((a, b) => SEV_RANK[a.riskLevel] - SEV_RANK[b.riskLevel])[0]?.riskLevel;
209
689
  }
210
- matrixSection(matrix, numStr) {
690
+ matrixPage(matrix) {
211
691
  const blocks = matrix.map((fm) => {
212
692
  const rows = fm.rows.map((row) => {
213
693
  const w = this.worst(row.findings);
214
694
  const status = w
215
- ? this.chip(w, `${row.findings.length} finding${row.findings.length === 1 ? '' : 's'}`)
695
+ ? this.tag(w, `${row.findings.length} finding${row.findings.length === 1 ? '' : 's'}`)
216
696
  : '<span class="muted">No findings detected</span>';
217
- return `<tr><td class="cid">${esc(row.control.id)}</td><td>${esc(row.control.title)}</td><td class="st">${status}</td></tr>`;
697
+ return `<tr><td class="ref">${esc(row.control.id)}</td><td>${esc(row.control.title)}</td><td class="sv">${status}</td></tr>`;
218
698
  }).join('');
219
- return `<h3>${esc(FRAMEWORK_LABEL[fm.framework])} <span class="muted">· ${esc(fm.version)}</span></h3>
220
- <table class="matrix"><thead><tr><th>Control</th><th>Requirement area</th><th>Status</th></tr></thead><tbody>${rows}</tbody></table>`;
699
+ return `<table class="sched mx"><colgroup><col class="c-ctl"><col><col class="c-st"></colgroup><caption>${esc(FRAMEWORK_LABEL[fm.framework])} <span class="muted">${esc(fm.version)}</span></caption>
700
+ <thead><tr><th>Control</th><th>Requirement area</th><th>Status</th></tr></thead><tbody>${rows}</tbody></table>`;
221
701
  }).join('');
222
- return `${this.sectionHead(numStr, 'Compliance Coverage')}<p class="muted">Findings mapped to framework controls. “No findings detected” is not an attestation of compliance. See Scope &amp; Liability.</p>${blocks}`;
702
+ return {
703
+ kicker: 'Appendix · Compliance coverage', kind: 'page',
704
+ title: 'Findings mapped to framework controls',
705
+ body: blocks,
706
+ source: '“No findings detected” is not an attestation of compliance. Status shows the findings mapped to a control, coloured by the most severe. See Scope &amp; Liability on the last page.',
707
+ };
223
708
  }
224
- findingsAppendix(r, numStr) {
225
- const rows = r.findings.map((f) => {
226
- const tag = f.inconclusive ? this.chip('INFO', 'inconclusive') : f.passed ? this.chip('INFO', 'passed') : this.chip(f.riskLevel, f.riskLevel);
227
- return `<div class="find"><div class="row"><h3>${esc(f.title)}</h3>${tag}</div>
228
- <p>${esc(f.detail)}</p><p><strong>Remediation:</strong> ${esc(f.remediation)}</p></div>`;
709
+ waiversPage(waived) {
710
+ const rows = waived.map((f, i) => {
711
+ // The approval (reason, approver, expiry) is on each item's note, or on the detail when the finding has no items.
712
+ const scope = f.affectedItems?.length ? f.affectedItems.map((it) => (it.note ? `${it.label} ${it.note}` : it.label)).join('; ') : f.id;
713
+ return `<tr><td class="ref">W-${String(i + 1).padStart(2, '0')}</td><td class="sv">${this.tag('INFO', 'WAIVED')}</td><td><span class="ft">${title(f.title)}</span><span class="fd">${esc(f.detail)}</span></td><td class="fx"><strong>Scope:</strong> ${esc(scope)}</td></tr>`;
229
714
  }).join('');
230
- return `${this.sectionHead(numStr, 'All Findings')}${rows}`;
715
+ return {
716
+ kicker: 'Appendix · Accepted risks', kind: 'page',
717
+ title: `${plural(waived.length, 'finding')} accepted under an approved waiver`,
718
+ body: `<table class="sched"><colgroup><col class="c-ref"><col class="c-sv"><col><col class="c-fx"></colgroup><thead><tr><th>Ref</th><th>Status</th><th>Finding</th><th>Scope</th></tr></thead><tbody>${rows}</tbody></table>`,
719
+ source: 'Waived findings are excluded from the score and the action plan, and still count toward the attack scenarios.',
720
+ };
721
+ }
722
+ coverageNote(r) {
723
+ const c = r.coverage;
724
+ if (!c || c.notAssessed.length === 0)
725
+ return '';
726
+ return `<p class="aside">${prose(coverageSummary(c))}. The checks that gathered no evidence are listed as inconclusive below; their areas are unassessed, not clean. ${advice(coverageAdvice(c))}</p>`;
727
+ }
728
+ findingsPage(r) {
729
+ const order = scheduleOrder(r.findings);
730
+ const open = order.filter(isOpen);
731
+ const waived = order.filter(isWaived);
732
+ const incon = order.filter(unassessed);
733
+ const passed = order.filter((f) => f.passed);
734
+ const refOf = new Map(order.map((f, i) => [f, `F-${String(i + 1).padStart(3, '0')}`]));
735
+ const ref = (f) => refOf.get(f) ?? '';
736
+ const row = (f, tag) => `<tr><td class="ref">${ref(f)}</td><td class="sv">${tag}</td><td><span class="ft">${title(f.title)}</span><span class="fd">${prose(f.detail)}</span></td><td class="fx"><span class="k lbl">Fix</span>${prose(f.remediation)}</td></tr>`;
737
+ const cols = '<colgroup><col class="c-ref"><col class="c-sv"><col><col class="c-fx"></colgroup>';
738
+ const table = (caption, note, head, rows) => rows
739
+ ? `<table class="sched">${cols}<caption>${caption} <span class="muted">${note}</span></caption><thead><tr>${head}</tr></thead><tbody>${rows}</tbody></table>`
740
+ : '';
741
+ const passedList = passed.length
742
+ ? `<h3 class="cap">Passed <span class="muted">${passed.length}</span></h3><ol class="passed">${passed.map((f) => `<li><span class="ref">${ref(f)}</span><span>${title(f.title)}</span></li>`).join('')}</ol>`
743
+ : '';
744
+ const body = order.length === 0 ? '<p class="muted">No check results in this run.</p>' : `${this.coverageNote(r)}
745
+ ${table('Open findings', `${open.length}`, '<th>Ref</th><th>Severity</th><th>Finding</th><th>Remediation</th>', open.map((f) => row(f, this.tag(f.riskLevel, f.riskLevel))).join(''))}
746
+ ${table('Waived', `${waived.length} · accepted risk, excluded from the score`, '<th>Ref</th><th>Severity</th><th>Finding</th><th>Remediation</th>', waived.map((f) => row(f, `${this.tag(f.riskLevel, f.riskLevel)} ${this.tag('INFO', 'WAIVED')}`)).join(''))}
747
+ ${table('Inconclusive', `${incon.length} · no evidence gathered`, '<th>Ref</th><th>Status</th><th>Check</th><th>Next step</th>', incon.map((f) => row(f, this.tag('INFO', 'inconclusive'))).join(''))}
748
+ ${passedList}`;
749
+ return {
750
+ kicker: 'Appendix · All findings', kind: 'page',
751
+ title: 'Every check result, open findings first by severity',
752
+ body,
753
+ };
754
+ }
755
+ signOffPage(r, b) {
756
+ return {
757
+ kicker: 'Issue and approval', kind: 'page',
758
+ title: 'Sign-off',
759
+ body: `<table class="sched rev"><colgroup><col class="c-rev"><col class="c-date"><col><col class="c-by"></colgroup><thead><tr><th>Rev</th><th>Date</th><th>Description</th><th>By</th></tr></thead>
760
+ <tbody><tr><td class="ref">A</td><td>${esc(r.generatedAt.toISOString().slice(0, 10))}</td><td>Issued for review: grade ${esc(r.grade)}, health score ${r.healthScore}/100</td><td>${esc(b.firmName)}</td></tr></tbody></table>
761
+ <table class="sched approve"><colgroup><col class="c-role"><col><col><col class="c-date"></colgroup><thead><tr><th>Role</th><th>Name</th><th>Signature</th><th>Date</th></tr></thead>
762
+ <tbody>${['Prepared by', 'Reviewed by', 'Accepted by client'].map((role) => `<tr><td class="lbl">${role}</td><td></td><td></td><td></td></tr>`).join('')}</tbody></table>
763
+ ${this.footer(b)}`,
764
+ };
231
765
  }
232
766
  footer(b) {
233
767
  const site = b.website
234
768
  ? ` · <a href="https://${esc(b.website.replace(/^https?:\/\//, ''))}">${esc(b.website.replace(/^https?:\/\//, ''))}</a>`
235
769
  : '';
236
- return `<footer><span class="label">Scope &amp; Liability</span>
237
- Read-only, point-in-time configuration review: not a penetration test, not a code audit. The grade is a prioritisation aid, not a certification. Validate findings before remediation. © ${new Date().getFullYear()} ${esc(b.firmName)} · ${esc(b.contact)}${site}<br>${toolCreditHtml('executive-report')}</footer>`;
770
+ return `<footer><span class="lbl">Scope &amp; Liability</span>
771
+ Read-only, point-in-time review of configuration, metadata, selected records and event logs, including pattern-based static checks of Apex and Flow: not a penetration test and not a code review. The grade is a prioritisation aid, not a certification. Confirm each finding in the org before changing production. © ${new Date().getFullYear()} ${esc(b.firmName)} · ${esc(b.contact)}${site}<br>${toolCreditHtml('executive-report')}</footer>`;
238
772
  }
239
773
  }
240
774
  //# sourceMappingURL=ClientReportRenderer.js.map