vigie-cli 0.0.0-stage → 1.0.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.
package/src/html.js ADDED
@@ -0,0 +1,424 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { CATEGORIES, SNIPPETS } from './catalog.js';
3
+ import { LANGS, LANG_CODES, message } from './i18n/index.js';
4
+ import { pkg } from './scan.js';
5
+
6
+ const LOGO = [
7
+ '███████╗██████╗ ███████╗███████╗██╗ ██╗██████╗ ███████╗██╗ ██╗',
8
+ '██╔════╝██╔══██╗██╔════╝██╔════╝██║ ██║██╔══██╗██╔════╝██║ ██║',
9
+ '█████╗ ██████╔╝█████╗ ███████╗███████║██║ ██║█████╗ ██║ ██║',
10
+ '██╔══╝ ██╔══██╗██╔══╝ ╚════██║██╔══██║██║ ██║██╔══╝ ╚██╗ ██╔╝',
11
+ '██║ ██║ ██║███████╗███████║██║ ██║██████╔╝███████╗ ╚████╔╝ ',
12
+ '╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝╚═════╝ ╚══════╝ ╚═══╝ ',
13
+ ].join('\n');
14
+
15
+ const STYLE = `
16
+ :root {
17
+ --desk: #ecebe6;
18
+ --paper: #fffefb;
19
+ --ink: #1d1d1b;
20
+ --ink-2: #4a4a46;
21
+ --mute: #7c7b74;
22
+ --hair: #d9d6cd;
23
+ --hair-2: #ebe8e0;
24
+ --brand: #0d6b5d;
25
+ --brand-soft: #e3f0ec;
26
+ --critical: #a8231b;
27
+ --high: #b9530b;
28
+ --medium: #9a7200;
29
+ --low: #2c62a8;
30
+ --info: #6b6b66;
31
+ --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Book Antiqua', 'URW Palladio L', Georgia, serif;
32
+ --sans: 'Segoe UI', 'Helvetica Neue', Arial, system-ui, sans-serif;
33
+ --mono: Consolas, 'Cascadia Mono', 'SF Mono', 'DejaVu Sans Mono', monospace;
34
+ color-scheme: light;
35
+ }
36
+ * { box-sizing: border-box; margin: 0; padding: 0; }
37
+ html { background: var(--desk); }
38
+ body { background: var(--desk); color: var(--ink); font: 15px/1.6 var(--sans); -webkit-font-smoothing: antialiased; }
39
+ body[data-lang="en"] .l[lang="fr"], body[data-lang="fr"] .l[lang="en"] { display: none; }
40
+ a { color: var(--brand); text-decoration: none; }
41
+ a:hover { text-decoration: underline; }
42
+ .controls { position: sticky; top: 0; z-index: 5; background: rgba(236, 235, 230, .94); backdrop-filter: blur(6px); border-bottom: 1px solid var(--hair); }
43
+ .controls__inner { max-width: 940px; margin: 0 auto; padding: 10px 32px; display: flex; justify-content: space-between; align-items: center; gap: 16px; font-size: 13px; color: var(--ink-2); }
44
+ .controls__doc { font-family: var(--serif); font-size: 14px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
45
+ .controls__tools { display: flex; align-items: center; gap: 22px; white-space: nowrap; }
46
+ .switch { display: inline-flex; gap: 2px; align-items: center; }
47
+ .switch button, .print { font: inherit; color: var(--ink-2); background: none; border: 0; cursor: pointer; padding: 2px 4px; }
48
+ .switch button[aria-pressed="true"] { color: var(--ink); font-weight: 600; text-decoration: underline; text-decoration-color: var(--brand); text-decoration-thickness: 2px; text-underline-offset: 5px; }
49
+ .switch span { color: var(--hair); }
50
+ .print:hover, .switch button:hover { color: var(--brand); }
51
+ .sheet { max-width: 940px; margin: 36px auto 64px; background: var(--paper); box-shadow: 0 1px 2px rgba(0,0,0,.06), 0 12px 40px rgba(40, 38, 30, .08); }
52
+ .page { padding: 72px 96px; }
53
+ .page + .page { border-top: 1px solid var(--hair); }
54
+ .cover { min-height: 760px; display: flex; flex-direction: column; }
55
+ .cover__brand { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; }
56
+ .logo { font: 4.2px/1.05 var(--mono); color: var(--brand); white-space: pre; user-select: none; letter-spacing: 0; }
57
+ .distribution { font-size: 12px; color: var(--mute); text-align: right; line-height: 1.5; }
58
+ .cover__title { margin-top: 140px; }
59
+ .eyebrow { font-size: 13px; color: var(--brand); font-weight: 600; letter-spacing: .02em; margin-bottom: 18px; }
60
+ .cover h1 { font: 400 46px/1.08 var(--serif); letter-spacing: -.01em; margin-bottom: 14px; }
61
+ .cover__target { font: italic 400 22px/1.3 var(--serif); color: var(--ink-2); word-break: break-word; }
62
+ .facts { margin-top: 72px; border-top: 1px solid var(--ink); }
63
+ .facts div { display: grid; grid-template-columns: 180px 1fr; gap: 24px; padding: 11px 0; border-bottom: 1px solid var(--hair); font-size: 14px; }
64
+ .facts dt { color: var(--mute); }
65
+ .facts dd { color: var(--ink); }
66
+ .risk { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
67
+ .risk__label { font-weight: 600; }
68
+ .scale { display: inline-grid; grid-template-columns: repeat(4, 34px); gap: 3px; }
69
+ .scale i { height: 8px; background: var(--hair-2); }
70
+ .scale i.on { background: var(--risk); }
71
+ .cover__foot { margin-top: auto; padding-top: 72px; font-size: 12px; color: var(--mute); display: flex; justify-content: space-between; gap: 16px; }
72
+ .r-A, .r-B { --risk: #3d7a4f; } .r-C { --risk: var(--medium); } .r-D { --risk: var(--high); } .r-F { --risk: var(--critical); }
73
+ h2 { font: 400 30px/1.2 var(--serif); margin-bottom: 26px; display: grid; grid-template-columns: 52px 1fr; align-items: baseline; }
74
+ h2 .num { font: 400 30px/1 var(--serif); color: var(--brand); }
75
+ h3 { font: 600 17px/1.35 var(--serif); margin: 38px 0 14px; display: flex; align-items: baseline; gap: 10px; }
76
+ h3 .count { font: 400 13px var(--sans); color: var(--mute); }
77
+ .prose { max-width: 640px; }
78
+ .prose p + p { margin-top: 12px; }
79
+ .lead { font: 400 19px/1.55 var(--serif); color: var(--ink); max-width: 680px; }
80
+ .statement { margin-top: 22px; padding-left: 18px; border-left: 3px solid var(--risk); max-width: 640px; color: var(--ink-2); }
81
+ .toc ol { list-style: none; counter-reset: toc; max-width: 640px; }
82
+ .toc li { display: flex; align-items: baseline; gap: 10px; padding: 7px 0; font-size: 15px; }
83
+ .toc li .n { color: var(--brand); font-family: var(--serif); min-width: 28px; }
84
+ .toc li .leader { flex: 1; border-bottom: 1px dotted var(--hair); transform: translateY(-4px); }
85
+ .toc li .meta { color: var(--mute); font-size: 13px; }
86
+ .toc a { color: var(--ink); }
87
+ .priorities { list-style: none; counter-reset: p; max-width: 680px; border-top: 1px solid var(--ink); }
88
+ .priorities li { counter-increment: p; display: grid; grid-template-columns: 36px 1fr auto; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--hair); align-items: baseline; }
89
+ .priorities li::before { content: counter(p); font-family: var(--serif); color: var(--brand); }
90
+ .priorities .what { font-weight: 500; }
91
+ .priorities .where { display: block; font-size: 13px; color: var(--mute); margin-top: 2px; font-family: var(--mono); word-break: break-all; }
92
+ .priorities .sev { font-size: 12px; white-space: nowrap; }
93
+ table { border-collapse: collapse; width: 100%; font-size: 14px; }
94
+ .matrix { border-top: 1.5px solid var(--ink); border-bottom: 1.5px solid var(--ink); }
95
+ .matrix th, .matrix td { padding: 9px 10px; text-align: right; border-bottom: 1px solid var(--hair-2); }
96
+ .matrix th:first-child, .matrix td:first-child { text-align: left; padding-left: 0; }
97
+ .matrix thead th { font-weight: 600; border-bottom: 1px solid var(--ink); font-size: 13px; }
98
+ .matrix tfoot td { font-weight: 600; border-top: 1px solid var(--ink); border-bottom: 0; }
99
+ .matrix td.zero { color: #c9c6bc; }
100
+ .matrix td.hot { font-weight: 600; color: var(--sev); }
101
+ .sev { color: var(--sev); }
102
+ .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--sev); margin-right: 7px; transform: translateY(-1px); }
103
+ .filters { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 13px; color: var(--ink-2); margin: -6px 0 8px; align-items: center; }
104
+ .filters label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
105
+ .filters input { accent-color: var(--brand); }
106
+ .group[hidden], .finding[hidden] { display: none; }
107
+ .finding { position: relative; padding: 26px 0 30px; border-top: 1px solid var(--hair); }
108
+ .finding:first-of-type { border-top: 1px solid var(--ink); }
109
+ .fid { position: absolute; left: -84px; top: 30px; width: 64px; text-align: right; font: 600 12px/1.3 var(--mono); color: var(--brand); }
110
+ .finding h4 { font: 600 19px/1.35 var(--serif); margin-bottom: 14px; padding-right: 110px; }
111
+ .finding .badge { position: absolute; right: 0; top: 30px; font-size: 12px; font-weight: 600; color: var(--sev); }
112
+ .meta { display: grid; grid-template-columns: repeat(4, auto); justify-content: start; gap: 4px 34px; font-size: 13px; margin-bottom: 18px; }
113
+ .meta dt { color: var(--mute); font-size: 12px; }
114
+ .meta dd { font-family: var(--mono); font-size: 12.5px; color: var(--ink); word-break: break-all; }
115
+ .block { display: grid; grid-template-columns: 132px 1fr; gap: 20px; margin-top: 12px; }
116
+ .block > span { font-size: 12px; color: var(--mute); padding-top: 3px; }
117
+ .block p { max-width: 600px; }
118
+ .evidence { font: 12.5px/1.7 var(--mono); background: #f7f6f1; border: 1px solid var(--hair-2); overflow-x: auto; padding: 8px 0; }
119
+ .evidence div { display: grid; grid-template-columns: 52px 1fr; white-space: pre; }
120
+ .evidence .n { text-align: right; padding-right: 16px; color: #aaa79d; user-select: none; }
121
+ .evidence .hit { background: #fbeee9; }
122
+ .evidence .hit .n { color: var(--sev); font-weight: 600; }
123
+ .evidence .hit .n::before { content: '▸ '; }
124
+ .fix { color: var(--ink); }
125
+ .nothing { color: var(--mute); font-style: italic; }
126
+ .scope td, .scope th { padding: 9px 10px; border-bottom: 1px solid var(--hair-2); text-align: left; vertical-align: baseline; }
127
+ .scope th { font-weight: 600; font-size: 13px; border-bottom: 1px solid var(--ink); }
128
+ .scope { border-top: 1.5px solid var(--ink); border-bottom: 1.5px solid var(--ink); margin-bottom: 34px; }
129
+ .scope td:first-child, .scope th:first-child { padding-left: 0; }
130
+ .scope td.num, .scope th.num { text-align: right; }
131
+ .scope .ok { color: #3d7a4f; }
132
+ .colophon { margin-top: 56px; padding-top: 18px; border-top: 1px solid var(--hair); font-size: 12px; color: var(--mute); display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
133
+ .snippets { display: grid; gap: 8px; margin-top: 10px; max-width: 640px; }
134
+ .snippet { border: 1px solid var(--hair-2); background: #f7f6f1; }
135
+ .snippet b { display: block; font: 600 10.5px/1 var(--sans); letter-spacing: .06em; text-transform: uppercase; color: var(--mute); padding: 7px 10px 0; }
136
+ .snippet pre { font: 12px/1.6 var(--mono); padding: 6px 10px 8px; white-space: pre-wrap; word-break: break-all; color: var(--ink); }
137
+ .evidence.lines div { grid-template-columns: 1fr; padding: 0 14px; white-space: pre-wrap; word-break: break-all; }
138
+ .grade-big { font: 400 64px/1 var(--serif); color: var(--risk); margin-right: 6px; }
139
+ .target { margin-top: 30px; }
140
+ .target h4 { font: 600 16px/1.3 var(--serif); margin-bottom: 10px; word-break: break-all; }
141
+ .kv { border-top: 1px solid var(--ink); font-size: 13px; margin-bottom: 18px; }
142
+ .kv div { display: grid; grid-template-columns: 220px 1fr; gap: 16px; padding: 6px 0; border-bottom: 1px solid var(--hair-2); }
143
+ .kv dt { color: var(--mute); font-family: var(--mono); font-size: 12px; }
144
+ .kv dd { font-family: var(--mono); font-size: 12px; word-break: break-all; }
145
+ .r-Ap { --risk: #3d7a4f; }
146
+ @media (max-width: 760px) { .kv div { grid-template-columns: 1fr; gap: 2px; } .grade-big { font-size: 48px; } }
147
+ .sev-critical { --sev: var(--critical); } .sev-high { --sev: var(--high); } .sev-medium { --sev: var(--medium); } .sev-low { --sev: var(--low); } .sev-info { --sev: var(--info); }
148
+ @media (max-width: 1100px) {
149
+ .fid { position: static; width: auto; text-align: left; display: block; margin-bottom: 6px; }
150
+ }
151
+ @media (max-width: 760px) {
152
+ .controls__inner { padding: 10px 16px; }
153
+ .controls__doc { display: none; }
154
+ .sheet { margin: 0; box-shadow: none; }
155
+ .page { padding: 40px 20px; }
156
+ .cover { min-height: 0; }
157
+ .cover__title { margin-top: 64px; }
158
+ .cover h1 { font-size: 34px; }
159
+ .logo { font-size: 3.2px; }
160
+ .facts div { grid-template-columns: 1fr; gap: 2px; }
161
+ h2 { grid-template-columns: 40px 1fr; font-size: 25px; }
162
+ .meta { grid-template-columns: repeat(2, auto); }
163
+ .block { grid-template-columns: 1fr; gap: 4px; }
164
+ .finding h4 { padding-right: 0; }
165
+ .finding .badge { position: static; display: block; margin-bottom: 6px; }
166
+ .matrix { font-size: 12.5px; }
167
+ .matrix th, .matrix td { padding: 8px 5px; }
168
+ .priorities li { grid-template-columns: 28px 1fr; }
169
+ .priorities .sev { grid-column: 2; }
170
+ }
171
+ @media print {
172
+ @page { size: A4; margin: 15mm 14mm 16mm; }
173
+ :root { --paper: #fff; }
174
+ html, body { background: #fff; font-size: 9.5pt; line-height: 1.45; }
175
+ .controls, .filters { display: none; }
176
+ .sheet { margin: 0; box-shadow: none; max-width: none; background: #fff; }
177
+ .page { padding: 0; border: 0 !important; }
178
+ .page + .page { break-before: page; }
179
+ #matrix { break-before: avoid; margin-top: 14mm; }
180
+ .cover { min-height: 255mm; }
181
+ .cover__title { margin-top: 60mm; }
182
+ .cover h1 { font-size: 30pt; }
183
+ .logo { font-size: 3.6px; }
184
+ h2 { font-size: 20pt; margin-bottom: 14px; }
185
+ h2 .num { font-size: 20pt; }
186
+ h3 { font-size: 12pt; margin: 18px 0 8px; }
187
+ .lead { font-size: 12pt; }
188
+ .finding { break-inside: avoid; padding: 12px 0 14px; }
189
+ .finding h4 { font-size: 12pt; margin-bottom: 8px; }
190
+ .finding .badge { top: 14px; font-size: 8.5pt; }
191
+ .meta { margin-bottom: 8px; gap: 2px 26px; }
192
+ .meta dt { font-size: 7.5pt; }
193
+ .meta dd { font-size: 8pt; }
194
+ .block { grid-template-columns: 26mm 1fr; gap: 10px; margin-top: 5px; }
195
+ .block > span { font-size: 8pt; padding-top: 1px; }
196
+ .evidence { font-size: 7.6pt; line-height: 1.5; padding: 4px 0; overflow: hidden; }
197
+ .evidence div { white-space: pre-wrap; word-break: break-all; }
198
+ .finding[hidden], .group[hidden] { display: block; }
199
+ .fid { position: static; display: block; text-align: left; width: auto; margin-bottom: 2px; font-size: 8pt; }
200
+ .priorities li { padding: 7px 0; }
201
+ .matrix th, .matrix td, .scope th, .scope td { padding: 5px 8px; }
202
+ a { color: var(--ink); }
203
+ }
204
+ `;
205
+
206
+ const SCRIPT = `
207
+ (() => {
208
+ const body = document.body;
209
+ const buttons = [...document.querySelectorAll('[data-set-lang]')];
210
+ const titles = JSON.parse(document.getElementById('titles').textContent);
211
+ const setLang = (lang) => {
212
+ body.dataset.lang = lang;
213
+ document.documentElement.lang = lang;
214
+ document.title = titles[lang];
215
+ buttons.forEach((b) => b.setAttribute('aria-pressed', String(b.dataset.setLang === lang)));
216
+ try { localStorage.setItem('fxguard-lang', lang); } catch (e) {}
217
+ };
218
+ let saved = null;
219
+ try { saved = localStorage.getItem('fxguard-lang'); } catch (e) {}
220
+ if (saved && titles[saved]) setLang(saved);
221
+ buttons.forEach((b) => b.addEventListener('click', () => setLang(b.dataset.setLang)));
222
+ document.querySelector('.print').addEventListener('click', () => window.print());
223
+ const boxes = [...document.querySelectorAll('.filters input')];
224
+ const apply = () => {
225
+ const on = new Set(boxes.filter((b) => b.checked).map((b) => b.value));
226
+ document.querySelectorAll('.group').forEach((g) => { g.hidden = !on.has(g.dataset.sev); });
227
+ };
228
+ boxes.forEach((b) => b.addEventListener('change', apply));
229
+ })();
230
+ `;
231
+
232
+ const ORDER = ['critical', 'high', 'medium', 'low', 'info'];
233
+ const GRADES = ['A+', 'A', 'B', 'C', 'D', 'F'];
234
+
235
+ const esc = (value) => String(value ?? '').replace(/[&<>"']/g, (ch) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[ch]);
236
+
237
+ const both = (pick) => LANG_CODES.map((code) => `<span class="l" lang="${code}">${pick(LANGS[code], code)}</span>`).join('');
238
+
239
+ const plain = (pick) => Object.fromEntries(LANG_CODES.map((code) => [code, pick(LANGS[code], code)]));
240
+
241
+ const riskClass = (grade) => (grade === 'A+' ? 'Ap' : grade);
242
+
243
+ function reference(results, when) {
244
+ const hash = createHash('sha256').update(`${results.map((result) => result.url).join(',')}|${when.toISOString()}`).digest('hex');
245
+ return `VG-${when.toISOString().slice(0, 10).replace(/-/g, '')}-${hash.slice(0, 4).toUpperCase()}`;
246
+ }
247
+
248
+ function snippetBlock(rule) {
249
+ const snippet = SNIPPETS[rule];
250
+ if (!snippet) return '';
251
+ const parts = Object.entries(snippet).map(([name, code]) => `<div class="snippet"><b>${name === 'file' ? '/.well-known/security.txt' : name}</b><pre>${esc(code)}</pre></div>`);
252
+ return `<div class="snippets">${parts.join('')}</div>`;
253
+ }
254
+
255
+ function renderFinding(finding, id, result) {
256
+ const cwe = finding.cwe ? `<a href="https://cwe.mitre.org/data/definitions/${finding.cwe}.html" target="_blank" rel="noopener">CWE-${finding.cwe}</a>` : '—';
257
+ const block = (label, content) => `<div class="block"><span>${both((d) => d.report[label])}</span>${content}</div>`;
258
+ const evidence = finding.evidence.length ? `<div class="evidence lines">${finding.evidence.map((line) => `<div>${esc(line)}</div>`).join('')}</div>` : '';
259
+ return `<article class="finding sev-${finding.severity}" id="${id}">
260
+ <span class="fid">${id}</span>
261
+ <span class="badge"><span class="dot"></span>${both((d) => d.severityTitles[finding.severity])}</span>
262
+ <h4>${both((d) => esc(d.rules[finding.rule].title))}</h4>
263
+ <dl class="meta">
264
+ <div><dt>${both((d) => d.report.rule)}</dt><dd>${esc(finding.rule)}</dd></div>
265
+ <div><dt>${both((d) => d.report.location)}</dt><dd>${esc(new URL(result.finalUrl ?? result.url).host)}</dd></div>
266
+ <div><dt>${both((d) => d.report.category)}</dt><dd>${both((d) => esc(d.categories[finding.category]))}</dd></div>
267
+ <div><dt>${both((d) => d.report.weakness)}</dt><dd>${cwe}</dd></div>
268
+ </dl>
269
+ ${block('description', `<p>${both((d) => esc(d.rules[finding.rule].description))}</p>`)}
270
+ ${block('observation', `<p>${both((d, code) => esc(message(code, finding)))}</p>`)}
271
+ ${evidence ? block('evidence', evidence) : ''}
272
+ ${block('recommendation', `<div><p class="fix">${both((d) => esc(d.rules[finding.rule].fix))}</p>${snippetBlock(finding.rule)}</div>`)}
273
+ </article>`;
274
+ }
275
+
276
+ function targetDetails(result) {
277
+ const rows = [];
278
+ if (result.tls) {
279
+ rows.push(['TLS', `${result.tls.protocol ?? '?'} · ${result.tls.cipher ?? '?'}`]);
280
+ rows.push([both((d) => d.report.certificate), `${result.tls.subject ?? '?'} · ${result.tls.issuer ?? '?'} · ${result.tls.validTo ? result.tls.validTo.slice(0, 10) : '?'}`]);
281
+ }
282
+ const redirects = result.redirects.map((hop) => `${hop.status ?? hop.error} ${hop.url}`).join('\n');
283
+ const headers = Object.entries(result.headers).map(([name, value]) => `<div><dt>${esc(name)}</dt><dd>${esc(value)}</dd></div>`).join('');
284
+ return `<section class="target"><h4>${esc(result.url)}</h4>
285
+ <dl class="kv">${rows.map(([k, v]) => `<div><dt>${k}</dt><dd>${esc(v)}</dd></div>`).join('')}<div><dt>${both((d) => d.report.redirects)}</dt><dd style="white-space:pre-wrap">${esc(redirects || '—')}</dd></div></dl>
286
+ ${headers ? `<p class="eyebrow" style="margin:0 0 8px">${both((d) => d.report.headersTitle)}</p><dl class="kv">${headers}</dl>` : ''}
287
+ </section>`;
288
+ }
289
+
290
+ export function toHtml(results, lang = 'en') {
291
+ const when = new Date();
292
+ const ref = reference(results, when);
293
+ const all = results.flatMap((result) => result.findings.map((finding) => ({ finding, result })));
294
+ const counts = Object.fromEntries(ORDER.map((severity) => [severity, all.filter(({ finding }) => finding.severity === severity).length]));
295
+ const total = all.length;
296
+ const worst = results.reduce((acc, result) => (GRADES.indexOf(result.grade) > GRADES.indexOf(acc) ? result.grade : acc), 'A+');
297
+ const lowest = Math.min(...results.map((result) => result.score));
298
+ const name = results.length > 1 ? results.map((result) => result.host).join(', ') : results[0].host;
299
+ const requests = results.reduce((sum, result) => sum + result.requests, 0);
300
+
301
+ const ordered = ORDER.flatMap((severity) => all.filter(({ finding }) => finding.severity === severity));
302
+ const width = Math.max(2, String(total).length);
303
+ const ids = new Map(ordered.map((item, index) => [item, `VG-${String(index + 1).padStart(width, '0')}`]));
304
+
305
+ const titles = plain((d) => `${d.report.documentTitle} · ${name} · ${ref}`);
306
+ const dates = plain((d, code) => new Intl.DateTimeFormat(code === 'fr' ? 'fr-FR' : 'en-GB', { day: 'numeric', month: 'long', year: 'numeric' }).format(when));
307
+ const breakdown = (d) => ORDER.filter((severity) => counts[severity]).map((severity) => [d.severities[severity], counts[severity]]);
308
+ const summary = both((d) => esc(d.report.summary({ targets: results.length, requests, total, breakdown: breakdown(d) })));
309
+
310
+ const seen = new Set();
311
+ const priorities = ordered.filter(({ finding }) => finding.severity !== 'info' && !seen.has(finding.rule) && seen.add(finding.rule)).slice(0, 5);
312
+ const prioritiesHtml = priorities.length
313
+ ? `<ol class="priorities">${priorities.map((item) => `<li class="sev-${item.finding.severity}"><div><a class="what" href="#${ids.get(item)}">${both((d) => esc(d.rules[item.finding.rule].title))}</a><span class="where">${esc(item.result.host)} · ${both((d) => esc(d.rules[item.finding.rule].fix))}</span></div><span class="sev"><span class="dot"></span>${both((d) => d.severityTitles[item.finding.severity])}</span></li>`).join('')}</ol>`
314
+ : `<p class="nothing">${both((d) => d.report.noPriorities)}</p>`;
315
+
316
+ const matrixHead = `<tr><th>${both((d) => d.report.category)}</th>${ORDER.map((severity) => `<th class="sev-${severity}"><span class="dot"></span>${both((d) => d.severityTitles[severity])}</th>`).join('')}<th>${both((d) => d.report.total)}</th></tr>`;
317
+ const matrixRows = CATEGORIES.map((category) => {
318
+ const cells = ORDER.map((severity) => {
319
+ const n = all.filter(({ finding }) => finding.category === category && finding.severity === severity).length;
320
+ return `<td class="sev-${severity} ${n ? 'hot' : 'zero'}">${n}</td>`;
321
+ }).join('');
322
+ return `<tr><td>${both((d) => esc(d.categories[category]))}</td>${cells}<td>${all.filter(({ finding }) => finding.category === category).length}</td></tr>`;
323
+ }).join('');
324
+ const matrixFoot = `<tr><td>${both((d) => d.report.total)}</td>${ORDER.map((severity) => `<td>${counts[severity]}</td>`).join('')}<td>${total}</td></tr>`;
325
+
326
+ const groups = ORDER.filter((severity) => counts[severity]).map((severity, index) => {
327
+ const items = ordered.filter(({ finding }) => finding.severity === severity);
328
+ return `<section class="group sev-${severity}" data-sev="${severity}"><h3><span>3.${index + 1}</span> ${both((d) => d.severityTitles[severity])} <span class="count">${both((d) => d.ui.findings(items.length))}</span></h3>${items.map((item) => renderFinding(item.finding, ids.get(item), item.result)).join('')}</section>`;
329
+ }).join('');
330
+ const filters = total
331
+ ? `<div class="filters"><span>${both((d) => d.report.filter)}</span>${ORDER.filter((severity) => counts[severity]).map((severity) => `<label class="sev-${severity}"><input type="checkbox" value="${severity}" checked><span class="dot"></span>${both((d) => d.severityTitles[severity])} (${counts[severity]})</label>`).join('')}</div>`
332
+ : '';
333
+
334
+ const scopeRows = results.map((result) => `<tr><td>${esc(result.url)}</td><td class="r-${riskClass(result.grade)}"><b style="color:var(--risk)">${esc(result.grade)}</b></td><td class="num">${result.reachable ? result.score : '—'}</td><td class="num">${result.findings.length}</td><td>${result.reachable ? esc(result.finalUrl) : `<span style="color:var(--critical)">${both((d) => d.report.unreachable)} (${esc(result.error)})</span>`}</td></tr>`).join('');
335
+
336
+ const toc = [
337
+ ['1', 'summary', '#summary', ''],
338
+ ['2', 'matrix', '#matrix', ''],
339
+ ['3', 'findings', '#findings', both((d) => d.ui.findings(total))],
340
+ ['4', 'scope', '#scope', ''],
341
+ ].map(([n, key, href, extra]) => `<li><span class="n">${n}</span><a href="${href}">${both((d) => d.report.sections[key])}</a><span class="leader"></span><span class="meta">${extra}</span></li>`).join('');
342
+
343
+
344
+ return `<!doctype html>
345
+ <html lang="${lang}">
346
+ <head>
347
+ <meta charset="utf-8">
348
+ <meta name="viewport" content="width=device-width, initial-scale=1">
349
+ <meta name="generator" content="vigie ${pkg.version}">
350
+ <title>${esc(titles[lang])}</title>
351
+ <style>${STYLE}</style>
352
+ </head>
353
+ <body data-lang="${lang}" class="r-${riskClass(worst)}">
354
+ <div class="controls"><div class="controls__inner">
355
+ <span class="controls__doc">${both((d) => d.report.documentTitle)} — ${esc(name)}</span>
356
+ <span class="controls__tools">
357
+ <span class="switch" role="group" aria-label="Language / Langue">${LANG_CODES.map((code, i) => `${i ? '<span>|</span>' : ''}<button type="button" data-set-lang="${code}" aria-pressed="${code === lang}" lang="${code}">${code.toUpperCase()}</button>`).join('')}</span>
358
+ <button type="button" class="print">${both((d) => d.report.print)}</button>
359
+ </span>
360
+ </div></div>
361
+
362
+ <main class="sheet">
363
+ <section class="page cover">
364
+ <div class="cover__brand">
365
+ <pre class="logo" aria-label="FreshDev">${LOGO}</pre>
366
+ <div class="distribution">${esc(ref)}<br>${both((d, code) => esc(dates[code]))}</div>
367
+ </div>
368
+ <div class="cover__title">
369
+ <p class="eyebrow">vigie ${pkg.version}</p>
370
+ <h1>${both((d) => d.report.documentTitle)}</h1>
371
+ <p class="cover__target">${esc(name)}</p>
372
+ </div>
373
+ <dl class="facts">
374
+ <div><dt>${both((d) => d.report.reference)}</dt><dd>${esc(ref)}</dd></div>
375
+ <div><dt>${both((d) => d.report.date)}</dt><dd>${both((d, code) => esc(dates[code]))}</dd></div>
376
+ <div><dt>${both((d) => d.report.scope)}</dt><dd>${results.map((result) => esc(result.url)).join('<br>')}</dd></div>
377
+ <div><dt>${both((d) => d.report.tool)}</dt><dd>vigie ${pkg.version} · ${requests} HTTP</dd></div>
378
+ <div><dt>${both((d) => d.report.overallRisk)}</dt><dd class="risk"><span class="grade-big">${esc(worst)}</span><span>${both((d) => d.report.scoreOf(lowest))}<br><span style="color:var(--mute)">${both((d) => esc(d.verdicts[worst]))}</span></span></dd></div>
379
+ </dl>
380
+ <div class="cover__foot"><span>${both((d) => d.report.preparedWith)}</span><span>${esc(ref)}</span></div>
381
+ </section>
382
+
383
+ <section class="page toc">
384
+ <h2><span class="num">—</span>${both((d) => d.report.contents)}</h2>
385
+ <ol>${toc}</ol>
386
+ </section>
387
+
388
+ <section class="page" id="summary">
389
+ <h2><span class="num">1</span>${both((d) => d.report.sections.summary)}</h2>
390
+ <p class="lead">${summary}</p>
391
+ <p class="statement">${both((d) => esc(d.report.statement[worst]))}</p>
392
+ <h3>${both((d) => d.report.priorities)}</h3>
393
+ ${prioritiesHtml}
394
+ </section>
395
+
396
+ <section class="page" id="matrix">
397
+ <h2><span class="num">2</span>${both((d) => d.report.sections.matrix)}</h2>
398
+ <table class="matrix"><thead>${matrixHead}</thead><tbody>${matrixRows}</tbody><tfoot>${matrixFoot}</tfoot></table>
399
+ </section>
400
+
401
+ <section class="page" id="findings">
402
+ <h2><span class="num">3</span>${both((d) => d.report.sections.findings)}</h2>
403
+ ${filters}
404
+ ${groups || `<p class="nothing">${both((d) => d.report.noFindings)}</p>`}
405
+ </section>
406
+
407
+ <section class="page" id="scope">
408
+ <h2><span class="num">4</span>${both((d) => d.report.sections.scope)}</h2>
409
+ <div class="prose"><p>${both((d) => d.report.scopeIntro)}</p></div>
410
+ <table class="scope" style="margin-top:20px"><thead><tr><th>${both((d) => d.report.website)}</th><th>${both((d) => d.report.grade)}</th><th class="num">${both((d) => d.report.score)}</th><th class="num">${both((d) => d.report.findingsCol)}</th><th>${both((d) => d.report.landed)}</th></tr></thead><tbody>${scopeRows}</tbody></table>
411
+ ${results.filter((result) => result.reachable).map(targetDetails).join('')}
412
+ <h3>${both((d) => d.report.method)}</h3>
413
+ <div class="prose"><p>${both((d) => esc(d.report.methodText))}</p></div>
414
+ <h3>${both((d) => d.report.limits)}</h3>
415
+ <div class="prose"><p>${both((d) => esc(d.report.limitsText))}</p></div>
416
+ <div class="colophon"><span>${both((d) => d.report.preparedWith)} · vigie ${pkg.version}</span><span>${esc(ref)}</span></div>
417
+ </section>
418
+ </main>
419
+ <script type="application/json" id="titles">${JSON.stringify(titles).replace(/</g, '\\u003c')}</script>
420
+ <script>${SCRIPT}</script>
421
+ </body>
422
+ </html>
423
+ `;
424
+ }