@secureport/core 2.1.0 → 2.3.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/dist/index.d.ts +9 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/issue.d.ts +1 -1
- package/dist/issue.d.ts.map +1 -1
- package/dist/reconcile.d.ts +46 -1
- package/dist/reconcile.d.ts.map +1 -1
- package/dist/reconcile.js +34 -1
- package/dist/reconcile.js.map +1 -1
- package/dist/report/anchors.d.ts +39 -0
- package/dist/report/anchors.d.ts.map +1 -0
- package/dist/report/anchors.js +73 -0
- package/dist/report/anchors.js.map +1 -0
- package/dist/report/csv.d.ts +41 -0
- package/dist/report/csv.d.ts.map +1 -0
- package/dist/report/csv.js +152 -0
- package/dist/report/csv.js.map +1 -0
- package/dist/report/html.d.ts.map +1 -1
- package/dist/report/html.js +126 -22
- package/dist/report/html.js.map +1 -1
- package/dist/report/json.d.ts +15 -0
- package/dist/report/json.d.ts.map +1 -1
- package/dist/report/json.js +1 -0
- package/dist/report/json.js.map +1 -1
- package/dist/report/markdown.d.ts +24 -2
- package/dist/report/markdown.d.ts.map +1 -1
- package/dist/report/markdown.js +133 -31
- package/dist/report/markdown.js.map +1 -1
- package/dist/report/model.d.ts +288 -2
- package/dist/report/model.d.ts.map +1 -1
- package/dist/report/model.js +153 -21
- package/dist/report/model.js.map +1 -1
- package/dist/report/sarif.d.ts +60 -0
- package/dist/report/sarif.d.ts.map +1 -0
- package/dist/report/sarif.js +125 -0
- package/dist/report/sarif.js.map +1 -0
- package/dist/report/stream.d.ts +108 -0
- package/dist/report/stream.d.ts.map +1 -0
- package/dist/report/stream.js +534 -0
- package/dist/report/stream.js.map +1 -0
- package/package.json +4 -2
- package/src/index.ts +11 -2
- package/src/issue.ts +1 -0
- package/src/reconcile.ts +86 -2
- package/src/report/anchors.ts +96 -0
- package/src/report/csv.ts +180 -0
- package/src/report/html.ts +146 -26
- package/src/report/json.ts +17 -0
- package/src/report/markdown.ts +146 -30
- package/src/report/model.ts +433 -21
- package/src/report/sarif.ts +166 -0
- package/src/report/stream.ts +702 -0
package/dist/report/model.js
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
import { SEVERITY_ORDER } from '../severity.js';
|
|
2
|
+
/**
|
|
3
|
+
* How each verdict is printed.
|
|
4
|
+
*
|
|
5
|
+
* Exported because it is printed, and a printed vocabulary is a contract —
|
|
6
|
+
* `00-DOMAIN.md` §7 says so of the verdicts themselves. It was defined
|
|
7
|
+
* identically in both renderers, which PDF and DOCX would have made four
|
|
8
|
+
* copies of, each one a chance for `not_retested` to be worded differently in
|
|
9
|
+
* the format somebody actually reads. The underscores are an implementation
|
|
10
|
+
* detail of the union and should never reach a page.
|
|
11
|
+
*/
|
|
12
|
+
export const VERDICT_LABELS = Object.freeze({
|
|
13
|
+
fixed: 'fixed',
|
|
14
|
+
still_present: 'still present',
|
|
15
|
+
returned: 'returned',
|
|
16
|
+
not_retested: 'not retested',
|
|
17
|
+
new: 'new since',
|
|
18
|
+
});
|
|
2
19
|
/** Works out what a run established about the issues carried into it. */
|
|
3
20
|
function describeRetest(snapshot) {
|
|
4
21
|
const { baseline } = snapshot;
|
|
@@ -43,8 +60,11 @@ function describeRetest(snapshot) {
|
|
|
43
60
|
* an issue left open because the run never covered it looks identical to one
|
|
44
61
|
* left open because the run found it again, and telling a reader those are the
|
|
45
62
|
* same thing is the failure this report exists to avoid.
|
|
63
|
+
*
|
|
64
|
+
* Exported: it is per-issue and needs nothing but the one entry, which is
|
|
65
|
+
* exactly what the streaming machine renderers can offer it a row at a time.
|
|
46
66
|
*/
|
|
47
|
-
function verdictFor(entry) {
|
|
67
|
+
export function verdictFor(entry) {
|
|
48
68
|
if (entry.change === 'resolved')
|
|
49
69
|
return 'fixed';
|
|
50
70
|
if (entry.change === 'regressed')
|
|
@@ -53,8 +73,16 @@ function verdictFor(entry) {
|
|
|
53
73
|
return 'new';
|
|
54
74
|
return entry.findings.length > 0 ? 'still_present' : 'not_retested';
|
|
55
75
|
}
|
|
56
|
-
/**
|
|
57
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Works out what a report cannot establish, from the run rather than a
|
|
78
|
+
* template.
|
|
79
|
+
*
|
|
80
|
+
* Takes primitives rather than a {@link Snapshot} so the streaming machine
|
|
81
|
+
* renderers can produce the same wording from a fold over a cursor, without
|
|
82
|
+
* needing the eagerly-materialised issue array this package's PDF/HTML path
|
|
83
|
+
* builds.
|
|
84
|
+
*/
|
|
85
|
+
export function describeLimitations(coveragePaths, runCreatedAt, basis, suppressedCount, omitted) {
|
|
58
86
|
const limitations = [];
|
|
59
87
|
if (!basis.includesManual) {
|
|
60
88
|
limitations.push('This is evidence of automated security testing. It is not a human-led penetration ' +
|
|
@@ -62,32 +90,100 @@ function describeLimitations(snapshot, basis) {
|
|
|
62
90
|
}
|
|
63
91
|
limitations.push('Findings should be verified by a qualified technician before this document is relied ' +
|
|
64
92
|
'upon as audit evidence.');
|
|
65
|
-
limitations.push(`Testing covered only ${
|
|
93
|
+
limitations.push(`Testing covered only ${coveragePaths.join(', ')}. Anything outside that ` +
|
|
66
94
|
'was not examined, and its absence from this document is not evidence that it is sound.');
|
|
67
|
-
limitations.push(`This reflects the state of the target as of ${
|
|
95
|
+
limitations.push(`This reflects the state of the target as of ${runCreatedAt
|
|
68
96
|
.toISOString()
|
|
69
97
|
.slice(0, 10)}. It says nothing about the target before or after that date.`);
|
|
70
98
|
limitations.push('Automated testing cannot establish the absence of a vulnerability. A clean result means ' +
|
|
71
99
|
'nothing was detected, not that nothing is there.');
|
|
72
|
-
if (
|
|
73
|
-
limitations.push(`${
|
|
100
|
+
if (suppressedCount > 0) {
|
|
101
|
+
limitations.push(`${suppressedCount} finding${suppressedCount === 1 ? ' has' : 's have'} been ` +
|
|
74
102
|
'suppressed and excluded from the counts above. They are listed in full in the appendix.');
|
|
75
103
|
}
|
|
104
|
+
// Immediately after the suppression sentence and before the compliance one,
|
|
105
|
+
// because it answers the same question a reader is entitled to ask: what am
|
|
106
|
+
// I not being shown? A floor that removed pages silently would be the
|
|
107
|
+
// over-claim §7 exists to stop, in a quieter form than the appendix one.
|
|
108
|
+
if (omitted !== undefined)
|
|
109
|
+
limitations.push(omitted.statement);
|
|
76
110
|
limitations.push('This document does not certify compliance with any standard, framework or regulation.');
|
|
77
111
|
return limitations;
|
|
78
112
|
}
|
|
79
|
-
|
|
113
|
+
/**
|
|
114
|
+
* Hex triplets only. See {@link Branding.primaryColour} for why this is a
|
|
115
|
+
* refusal rather than a sanitisation.
|
|
116
|
+
*/
|
|
117
|
+
const HEX_COLOUR = /^#(?:[0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/iu;
|
|
118
|
+
/**
|
|
119
|
+
* Why this branding cannot be rendered, or `undefined` if it can.
|
|
120
|
+
*
|
|
121
|
+
* **Exported so the rules have one home rather than two.** {@link buildReportModel}
|
|
122
|
+
* enforces these at render time, which is the last possible moment — by then the
|
|
123
|
+
* value has been stored, and the caller who set it is long gone. A hosted
|
|
124
|
+
* service wants to refuse it at the boundary instead, with a `400` naming the
|
|
125
|
+
* field. That needs the same two rules in two places, and a colour pattern
|
|
126
|
+
* copied into an API schema is a copy free to drift from the one that actually
|
|
127
|
+
* protects the stylesheet.
|
|
128
|
+
*
|
|
129
|
+
* So both callers ask this. The messages are identical wherever the value is
|
|
130
|
+
* rejected, because there is only one place that composes them.
|
|
131
|
+
*
|
|
132
|
+
* The white-label rule is deliberately **not** here: it depends on the report
|
|
133
|
+
* kind and on `preparedBy`, so it is a property of the options rather than of
|
|
134
|
+
* the branding, and only the renderer can decide it.
|
|
135
|
+
*/
|
|
136
|
+
export function brandingProblem(branding) {
|
|
137
|
+
const colour = branding?.primaryColour;
|
|
138
|
+
if (colour !== undefined && !HEX_COLOUR.test(colour)) {
|
|
139
|
+
return (`primaryColour must be a hex triplet such as #0a7 or #00aa77, not ${JSON.stringify(colour)}: ` +
|
|
140
|
+
'it is interpolated into the document stylesheet, where anything else could end the element');
|
|
141
|
+
}
|
|
142
|
+
const logo = branding?.logo;
|
|
143
|
+
if (logo !== undefined && !logo.startsWith('data:image/')) {
|
|
144
|
+
return (`logo must be a data: URI, not ${JSON.stringify(logo.slice(0, 40))}: ` +
|
|
145
|
+
'a linked image would make the report depend on a network at render time, ' +
|
|
146
|
+
'which is the guarantee that lets it be rendered to PDF reproducibly');
|
|
147
|
+
}
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Who the document says carried out the testing, resolved once so the PDF/HTML
|
|
152
|
+
* path and the streaming machine path cannot word it two different ways.
|
|
153
|
+
*
|
|
154
|
+
* @throws TypeError A white-labelled attestation naming nobody: a formal
|
|
155
|
+
* statement that testing was carried out has to say who carried it out.
|
|
156
|
+
*/
|
|
157
|
+
export function resolveAttestor(options) {
|
|
158
|
+
const attestor = options.preparedBy ?? options.branding?.companyName;
|
|
159
|
+
// An attestation is a statement that a named party carried out testing. With
|
|
160
|
+
// Secureport's name removed and nothing put in its place there is no such
|
|
161
|
+
// party, and the document would assert something on nobody's behalf.
|
|
162
|
+
if (attestor === undefined &&
|
|
163
|
+
options.branding?.whiteLabel === true &&
|
|
164
|
+
options.kind === 'attest') {
|
|
165
|
+
throw new TypeError('a white-labelled attestation must name who carried out the testing: ' +
|
|
166
|
+
'set branding.companyName or preparedBy');
|
|
167
|
+
}
|
|
168
|
+
return attestor ?? 'Secureport';
|
|
169
|
+
}
|
|
170
|
+
/** The title printed when {@link ReportOptions.title} is not given. */
|
|
171
|
+
export const DEFAULT_TITLES = Object.freeze({
|
|
80
172
|
pen: 'Penetration Test Report',
|
|
81
173
|
vap: 'Vulnerability Assessment Report',
|
|
82
174
|
exec: 'Executive Summary',
|
|
83
175
|
attest: 'Attestation of Security Testing',
|
|
84
176
|
retest: 'Retest Report',
|
|
85
177
|
});
|
|
86
|
-
/**
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
178
|
+
/**
|
|
179
|
+
* Works out how the findings were produced, from the run rather than a claim.
|
|
180
|
+
*
|
|
181
|
+
* Takes `kind`/`engines`/`includesManual` as primitives, the same reason
|
|
182
|
+
* {@link describeLimitations} does: the streaming machine renderers know
|
|
183
|
+
* `includesManual` only once a fold over the issue cursor finishes, and have
|
|
184
|
+
* no `Snapshot` to read `run.kind`/`run.engines` from.
|
|
185
|
+
*/
|
|
186
|
+
export function describeBasis(kind, engines, includesManual) {
|
|
91
187
|
const automated = kind === 'scan';
|
|
92
188
|
const uploaded = kind === 'upload';
|
|
93
189
|
const parts = [];
|
|
@@ -138,22 +234,36 @@ export function buildReportModel(snapshot, options) {
|
|
|
138
234
|
const bySeverity = new Map();
|
|
139
235
|
const resolved = [];
|
|
140
236
|
let breached = 0;
|
|
237
|
+
let omittedBelowFloor = 0;
|
|
238
|
+
// `SEVERITY_ORDER` is most-severe-first, so "at or above the floor" is a
|
|
239
|
+
// *lower* index. Same trap `describeRetest` records above, from the other
|
|
240
|
+
// direction: `severityRank` counts the opposite way and using it here would
|
|
241
|
+
// floor out everything except the advisories.
|
|
242
|
+
const floorAt = options.severityFloor === undefined
|
|
243
|
+
? SEVERITY_ORDER.length
|
|
244
|
+
: SEVERITY_ORDER.indexOf(options.severityFloor);
|
|
141
245
|
for (const entry of snapshot.issues) {
|
|
142
246
|
if (entry.issue.status === 'resolved') {
|
|
143
247
|
resolved.push(entry);
|
|
144
248
|
continue;
|
|
145
249
|
}
|
|
146
250
|
const severity = entry.issue.effectiveSeverity;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
group.push(entry);
|
|
150
|
-
else
|
|
151
|
-
bySeverity.set(severity, [entry]);
|
|
251
|
+
// Counted before the floor is consulted, deliberately: the floor decides
|
|
252
|
+
// what is *listed*, never what is *counted*.
|
|
152
253
|
if (entry.issue.status === 'open' || entry.issue.status === 'regressed') {
|
|
153
254
|
outstanding[severity]++;
|
|
154
255
|
if (entry.slaStatus === 'breached')
|
|
155
256
|
breached++;
|
|
156
257
|
}
|
|
258
|
+
if (SEVERITY_ORDER.indexOf(severity) > floorAt) {
|
|
259
|
+
omittedBelowFloor++;
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
const group = bySeverity.get(severity);
|
|
263
|
+
if (group)
|
|
264
|
+
group.push(entry);
|
|
265
|
+
else
|
|
266
|
+
bySeverity.set(severity, [entry]);
|
|
157
267
|
}
|
|
158
268
|
resolved.sort((a, b) => b.issue.lastSeen.getTime() - a.issue.lastSeen.getTime());
|
|
159
269
|
const sections = [];
|
|
@@ -168,14 +278,30 @@ export function buildReportModel(snapshot, options) {
|
|
|
168
278
|
issues: [...issues].sort((a, b) => b.issue.lastSeen.getTime() - a.issue.lastSeen.getTime()),
|
|
169
279
|
});
|
|
170
280
|
}
|
|
281
|
+
const floor = options.severityFloor;
|
|
282
|
+
const omitted = omittedBelowFloor === 0 || floor === undefined
|
|
283
|
+
? undefined
|
|
284
|
+
: {
|
|
285
|
+
count: omittedBelowFloor,
|
|
286
|
+
floor,
|
|
287
|
+
statement: `${omittedBelowFloor} issue${omittedBelowFloor === 1 ? '' : 's'} below ${floor} severity ` +
|
|
288
|
+
`${omittedBelowFloor === 1 ? 'is' : 'are'} not listed individually in this document. ` +
|
|
289
|
+
`${omittedBelowFloor === 1 ? 'It remains' : 'They remain'} open and ` +
|
|
290
|
+
`${omittedBelowFloor === 1 ? 'is' : 'are'} included in every count above.`,
|
|
291
|
+
};
|
|
171
292
|
const outstandingTotal = SEVERITY_ORDER.reduce((sum, s) => sum + outstanding[s], 0);
|
|
172
|
-
const basis = describeBasis(snapshot);
|
|
293
|
+
const basis = describeBasis(snapshot.run.kind, snapshot.run.engines, snapshot.issues.some((i) => i.issue.origin === 'manual'));
|
|
173
294
|
const retest = describeRetest(snapshot);
|
|
174
295
|
// Rendering a retest of nothing is the over-claim §7 warns about: the
|
|
175
296
|
// document's whole content is a comparison, and one run does not have one.
|
|
176
297
|
if (options.kind === 'retest' && retest === undefined) {
|
|
177
298
|
throw new TypeError('a retest report needs a baseline: build the snapshot with `previous` set to the run being retested');
|
|
178
299
|
}
|
|
300
|
+
const branding = options.branding;
|
|
301
|
+
const problem = brandingProblem(branding);
|
|
302
|
+
if (problem !== undefined)
|
|
303
|
+
throw new TypeError(problem);
|
|
304
|
+
const attestor = resolveAttestor(options);
|
|
179
305
|
return {
|
|
180
306
|
kind: options.kind,
|
|
181
307
|
title: options.title ?? DEFAULT_TITLES[options.kind],
|
|
@@ -183,10 +309,16 @@ export function buildReportModel(snapshot, options) {
|
|
|
183
309
|
generatedAt: options.now,
|
|
184
310
|
...(options.preparedBy === undefined ? {} : { preparedBy: options.preparedBy }),
|
|
185
311
|
...(options.preparedFor === undefined ? {} : { preparedFor: options.preparedFor }),
|
|
312
|
+
attestor,
|
|
313
|
+
coverPage: options.coverPage === true,
|
|
314
|
+
tableOfContents: options.tableOfContents === true,
|
|
315
|
+
...(branding === undefined ? {} : { branding }),
|
|
186
316
|
basis,
|
|
187
|
-
|
|
317
|
+
evidenceVerbosity: options.evidenceVerbosity ?? 'summary',
|
|
318
|
+
limitations: describeLimitations(snapshot.run.coverage.paths, snapshot.run.createdAt, basis, snapshot.suppressed.length, omitted),
|
|
188
319
|
sections,
|
|
189
|
-
resolved,
|
|
320
|
+
resolved: options.includeResolved === false ? [] : resolved,
|
|
321
|
+
...(omitted === undefined ? {} : { omitted }),
|
|
190
322
|
outstanding,
|
|
191
323
|
outstandingTotal,
|
|
192
324
|
exposureScore: snapshot.run.exposureScore,
|
package/dist/report/model.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../src/report/model.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../src/report/model.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE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IAAI,SAAS;QACzD,WAAW,EAAE,mBAAmB,CAC9B,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,EAC3B,QAAQ,CAAC,GAAG,CAAC,SAAS,EACtB,KAAK,EACL,QAAQ,CAAC,UAAU,CAAC,MAAM,EAC1B,OAAO,CACR;QACD,QAAQ;QACR,QAAQ,EAAE,OAAO,CAAC,eAAe,KAAK,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ;QAC3D,GAAG,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC;QAC7C,WAAW;QACX,gBAAgB;QAChB,aAAa,EAAE,QAAQ,CAAC,GAAG,CAAC,aAAa;QACzC,QAAQ;QACR,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC;KAC5C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Severity } from '../severity.js';
|
|
2
|
+
import type { SnapshotIssue } from '../snapshot.js';
|
|
3
|
+
import type { ReportHeader } from './stream.js';
|
|
4
|
+
/**
|
|
5
|
+
* What a SARIF export can be asked for.
|
|
6
|
+
*
|
|
7
|
+
* Deliberately its own type rather than {@link ReportOptions}: SARIF has no
|
|
8
|
+
* `kind` — it is always "the issues open right now", never a retest or an
|
|
9
|
+
* attestation — and no branding, cover page or evidence verbosity. Accepting
|
|
10
|
+
* `ReportOptions` and silently ignoring most of its fields would be a worse
|
|
11
|
+
* API than a type that only offers what SARIF actually uses.
|
|
12
|
+
*/
|
|
13
|
+
export interface SarifOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Keep issues below this severity out of `results`.
|
|
16
|
+
*
|
|
17
|
+
* Unlike the other formats, there is no `omitted` count to report: SARIF
|
|
18
|
+
* has no prose to carry a disclosure sentence in, and a consumer asking
|
|
19
|
+
* for `critical` only is asking to scope a code-scanning feed, not
|
|
20
|
+
* reading a document that owes it an explanation of what it left out.
|
|
21
|
+
*/
|
|
22
|
+
readonly severityFloor?: Severity;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Renders a snapshot's open issues as SARIF 2.1.0, from a header and a
|
|
26
|
+
* cursor — the machine path's format for GitHub code scanning (P8), and the
|
|
27
|
+
* streaming sibling of {@link renderJsonStream} and
|
|
28
|
+
* {@link renderMarkdownStream}. See {@link renderJsonStream} for the memory
|
|
29
|
+
* argument.
|
|
30
|
+
*
|
|
31
|
+
* **Resolved issues never appear, unconditionally — there is no
|
|
32
|
+
* `includeResolved` option.** SARIF is not a document a person reads; it is
|
|
33
|
+
* the input to GitHub's own diffing, which closes an alert when a new
|
|
34
|
+
* upload no longer contains it. Including a resolved issue would tell
|
|
35
|
+
* GitHub the finding is still open, which is the opposite of what resolving
|
|
36
|
+
* it meant.
|
|
37
|
+
*
|
|
38
|
+
* **Suppressed issues never appear either, and take no `suppressed`
|
|
39
|
+
* parameter at all.** An accepted risk is not a code-scanning alert; SARIF
|
|
40
|
+
* has no accepted-risk register to carry it in the way the appendix does
|
|
41
|
+
* for the human and other machine formats.
|
|
42
|
+
*
|
|
43
|
+
* **`ruleId` is `Issue.vulnKey`, not `Finding.sourceRuleId` or
|
|
44
|
+
* `sourceEngine`.** `vulnKey` is engine-independent by construction
|
|
45
|
+
* (`fingerprint.ts`), and naming a scanner in a customer-facing artefact is
|
|
46
|
+
* the thing this package's report options have twice had to stop doing
|
|
47
|
+
* (`ReportOptions.evidenceVerbosity`'s own TSDoc records it). `rules[]` is
|
|
48
|
+
* built from the same stream, deduplicated on `vulnKey` — bounded by the
|
|
49
|
+
* number of distinct weakness classes, not by issue count, so buffering it
|
|
50
|
+
* (unlike `results`) costs nothing worth avoiding.
|
|
51
|
+
*
|
|
52
|
+
* @param header - The run and the target. Never scales with issue count.
|
|
53
|
+
* @param issues - Every open issue, in any order — SARIF results are an
|
|
54
|
+
* unordered set, so this format is the one place in the streaming
|
|
55
|
+
* contract with no ordering requirement on its input.
|
|
56
|
+
* @param options - A severity floor, and nothing else.
|
|
57
|
+
* @returns Chunks of JSON text; concatenated, they are one SARIF document.
|
|
58
|
+
*/
|
|
59
|
+
export declare function renderSarifStream(header: ReportHeader, issues: AsyncIterable<SnapshotIssue>, options?: SarifOptions): AsyncGenerator<string>;
|
|
60
|
+
//# sourceMappingURL=sarif.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sarif.d.ts","sourceRoot":"","sources":["../../src/report/sarif.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD;;;;;;;;GAQG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;;;OAOG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,QAAQ,CAAC;CACnC;AAyCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAuB,iBAAiB,CACtC,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,aAAa,CAAC,aAAa,CAAC,EACpC,OAAO,GAAE,YAAiB,GACzB,cAAc,CAAC,MAAM,CAAC,CA8DxB"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
const SARIF_LEVEL = Object.freeze({
|
|
2
|
+
critical: 'error',
|
|
3
|
+
high: 'error',
|
|
4
|
+
medium: 'warning',
|
|
5
|
+
low: 'note',
|
|
6
|
+
advisory: 'note',
|
|
7
|
+
});
|
|
8
|
+
/**
|
|
9
|
+
* The `security-severity` GitHub code scanning reads to rank an alert, as a
|
|
10
|
+
* string 0.0–10.0 — GitHub's convention, not part of the SARIF spec itself.
|
|
11
|
+
* Fixed bands rather than a CVSS score, because not every finding has one
|
|
12
|
+
* and two issues at the same {@link Severity} should rank the same.
|
|
13
|
+
*/
|
|
14
|
+
const SECURITY_SEVERITY = Object.freeze({
|
|
15
|
+
critical: '9.0',
|
|
16
|
+
high: '7.5',
|
|
17
|
+
medium: '5.0',
|
|
18
|
+
low: '3.0',
|
|
19
|
+
advisory: '1.0',
|
|
20
|
+
});
|
|
21
|
+
/** `SEVERITY_ORDER`, duplicated as an index rather than imported, to keep this file's only dependency on `severity.ts` the type. */
|
|
22
|
+
const FLOOR_RANK = Object.freeze({
|
|
23
|
+
critical: 0,
|
|
24
|
+
high: 1,
|
|
25
|
+
medium: 2,
|
|
26
|
+
low: 3,
|
|
27
|
+
advisory: 4,
|
|
28
|
+
});
|
|
29
|
+
/** `"key":value`, run through `JSON.stringify` so nothing is hand-escaped. */
|
|
30
|
+
function field(key, value) {
|
|
31
|
+
return `${JSON.stringify(key)}:${JSON.stringify(value)}`;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Renders a snapshot's open issues as SARIF 2.1.0, from a header and a
|
|
35
|
+
* cursor — the machine path's format for GitHub code scanning (P8), and the
|
|
36
|
+
* streaming sibling of {@link renderJsonStream} and
|
|
37
|
+
* {@link renderMarkdownStream}. See {@link renderJsonStream} for the memory
|
|
38
|
+
* argument.
|
|
39
|
+
*
|
|
40
|
+
* **Resolved issues never appear, unconditionally — there is no
|
|
41
|
+
* `includeResolved` option.** SARIF is not a document a person reads; it is
|
|
42
|
+
* the input to GitHub's own diffing, which closes an alert when a new
|
|
43
|
+
* upload no longer contains it. Including a resolved issue would tell
|
|
44
|
+
* GitHub the finding is still open, which is the opposite of what resolving
|
|
45
|
+
* it meant.
|
|
46
|
+
*
|
|
47
|
+
* **Suppressed issues never appear either, and take no `suppressed`
|
|
48
|
+
* parameter at all.** An accepted risk is not a code-scanning alert; SARIF
|
|
49
|
+
* has no accepted-risk register to carry it in the way the appendix does
|
|
50
|
+
* for the human and other machine formats.
|
|
51
|
+
*
|
|
52
|
+
* **`ruleId` is `Issue.vulnKey`, not `Finding.sourceRuleId` or
|
|
53
|
+
* `sourceEngine`.** `vulnKey` is engine-independent by construction
|
|
54
|
+
* (`fingerprint.ts`), and naming a scanner in a customer-facing artefact is
|
|
55
|
+
* the thing this package's report options have twice had to stop doing
|
|
56
|
+
* (`ReportOptions.evidenceVerbosity`'s own TSDoc records it). `rules[]` is
|
|
57
|
+
* built from the same stream, deduplicated on `vulnKey` — bounded by the
|
|
58
|
+
* number of distinct weakness classes, not by issue count, so buffering it
|
|
59
|
+
* (unlike `results`) costs nothing worth avoiding.
|
|
60
|
+
*
|
|
61
|
+
* @param header - The run and the target. Never scales with issue count.
|
|
62
|
+
* @param issues - Every open issue, in any order — SARIF results are an
|
|
63
|
+
* unordered set, so this format is the one place in the streaming
|
|
64
|
+
* contract with no ordering requirement on its input.
|
|
65
|
+
* @param options - A severity floor, and nothing else.
|
|
66
|
+
* @returns Chunks of JSON text; concatenated, they are one SARIF document.
|
|
67
|
+
*/
|
|
68
|
+
export async function* renderSarifStream(header, issues, options = {}) {
|
|
69
|
+
const floor = options.severityFloor;
|
|
70
|
+
const floorAt = floor === undefined ? 4 : FLOOR_RANK[floor];
|
|
71
|
+
// Small — bounded by distinct weakness classes, not by issue count — and
|
|
72
|
+
// known only once the stream is exhausted. So `results` (the one array
|
|
73
|
+
// that must never be buffered) is written first and `tool.driver.rules`
|
|
74
|
+
// last, the one key order that lets both be true without a second pass
|
|
75
|
+
// over `issues`: JSON does not care which key comes first.
|
|
76
|
+
const rules = new Map();
|
|
77
|
+
yield '{';
|
|
78
|
+
// The schema's own `id`, not a GitHub raw link — checked by hand, because
|
|
79
|
+
// an unreachable $schema is a broken document a validator would still call
|
|
80
|
+
// valid, and getting it wrong once cost the trip to the OASIS repo to
|
|
81
|
+
// learn its real path (`tests/fixtures/README.md` records that trip).
|
|
82
|
+
yield field('$schema', 'https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json');
|
|
83
|
+
yield ',' + field('version', '2.1.0');
|
|
84
|
+
yield ',"runs":[{"results":[';
|
|
85
|
+
let firstResult = true;
|
|
86
|
+
for await (const entry of issues) {
|
|
87
|
+
const { issue } = entry;
|
|
88
|
+
if (issue.status === 'resolved')
|
|
89
|
+
continue;
|
|
90
|
+
if (FLOOR_RANK[issue.effectiveSeverity] > floorAt)
|
|
91
|
+
continue;
|
|
92
|
+
if (!rules.has(issue.vulnKey)) {
|
|
93
|
+
rules.set(issue.vulnKey, { title: issue.title, cwe: issue.cwe });
|
|
94
|
+
}
|
|
95
|
+
const message = entry.findings[0]?.description ?? issue.title;
|
|
96
|
+
const result = {
|
|
97
|
+
ruleId: issue.vulnKey,
|
|
98
|
+
level: SARIF_LEVEL[issue.effectiveSeverity],
|
|
99
|
+
message: { text: message },
|
|
100
|
+
locations: [
|
|
101
|
+
{
|
|
102
|
+
physicalLocation: {
|
|
103
|
+
artifactLocation: { uri: issue.location },
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
partialFingerprints: { secureportFingerprint: issue.fingerprint },
|
|
108
|
+
properties: { 'security-severity': SECURITY_SEVERITY[issue.effectiveSeverity] },
|
|
109
|
+
};
|
|
110
|
+
yield (firstResult ? '' : ',') + JSON.stringify(result);
|
|
111
|
+
firstResult = false;
|
|
112
|
+
}
|
|
113
|
+
yield ']';
|
|
114
|
+
const ruleDefs = [...rules.entries()].map(([vulnKey, rule]) => ({
|
|
115
|
+
id: vulnKey,
|
|
116
|
+
shortDescription: { text: rule.title },
|
|
117
|
+
...(rule.cwe === undefined ? {} : { properties: { tags: [rule.cwe] } }),
|
|
118
|
+
}));
|
|
119
|
+
yield ',"tool":{"driver":{';
|
|
120
|
+
yield field('name', 'Secureport');
|
|
121
|
+
yield ',' + field('informationUri', 'https://secureport.io/');
|
|
122
|
+
yield ',"rules":' + JSON.stringify(ruleDefs);
|
|
123
|
+
yield '}}}]}';
|
|
124
|
+
}
|
|
125
|
+
//# source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F;YACD,mBAAmB,EAAE,EAAE,qBAAqB,EAAE,KAAK,CAAC,WAAW,EAAE;YACjE,UAAU,EAAE,EAAE,mBAAmB,EAAE,iBAAiB,CAAC,KAAK,CAAC,iBAAiB,CAAC,EAAE;SAChF,CAAC;QACF,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACxD,WAAW,GAAG,KAAK,CAAC;IACtB,CAAC;IACD,MAAM,GAAG,CAAC;IAEV,MAAM,QAAQ,GAAG,CAAC,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;QAC9D,EAAE,EAAE,OAAO;QACX,gBAAgB,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE;QACtC,GAAG,CAAC,IAAI,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;KACxE,CAAC,CAAC,CAAC;IACJ,MAAM,qBAAqB,CAAC;IAC5B,MAAM,KAAK,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAClC,MAAM,GAAG,GAAG,KAAK,CAAC,gBAAgB,EAAE,wBAAwB,CAAC,CAAC;IAC9D,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC7C,MAAM,OAAO,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { RunSummary } from '../run.js';
|
|
2
|
+
import type { SnapshotIssue, SuppressedIssue, Target } from '../snapshot.js';
|
|
3
|
+
import { type ReportOptions } from './model.js';
|
|
4
|
+
/**
|
|
5
|
+
* Everything a streaming machine-readable report needs that is not per-issue.
|
|
6
|
+
*
|
|
7
|
+
* **Deliberately not a {@link Snapshot}.** A `Snapshot`'s `issues` and
|
|
8
|
+
* `suppressed` are eagerly-materialised arrays — the right shape for PDF and
|
|
9
|
+
* HTML, which are queued, capped at 500 issues, and fully in memory before
|
|
10
|
+
* Chromium ever runs. The machine formats have no such cap, so their
|
|
11
|
+
* assembler must never hold every issue at once; a `ReportHeader` carries
|
|
12
|
+
* only the handful of fields that do not scale with issue count, and the
|
|
13
|
+
* issues themselves arrive as an `AsyncIterable`.
|
|
14
|
+
*/
|
|
15
|
+
export interface ReportHeader {
|
|
16
|
+
/** The run this report describes. */
|
|
17
|
+
readonly run: RunSummary;
|
|
18
|
+
/** What to compare against, for a retest. Absent for a first run. */
|
|
19
|
+
readonly baseline?: RunSummary;
|
|
20
|
+
/** The system under test. */
|
|
21
|
+
readonly target: Target;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Renders a report as JSON, from a header and a cursor over its issues,
|
|
25
|
+
* rather than from a fully-assembled {@link Snapshot}.
|
|
26
|
+
*
|
|
27
|
+
* **This is the machine path's whole reason to exist (B124).** `renderJson`
|
|
28
|
+
* holds every issue in one array before `JSON.stringify` walks it — measured
|
|
29
|
+
* at 239 MiB for 25,000 issues — so memory scales with the result and three
|
|
30
|
+
* concurrent exports exhaust a 512 MiB instance. This function instead
|
|
31
|
+
* yields the document a fragment at a time: everything that does not depend
|
|
32
|
+
* on having seen every issue is emitted immediately, the `issues` and
|
|
33
|
+
* `suppressed` arrays are written one element per row as the cursors
|
|
34
|
+
* produce them, and the handful of fields that need a full pass —
|
|
35
|
+
* `basis.includesManual`, `breached`, `omitted`, the retest counts — are
|
|
36
|
+
* accumulated in a fold whose state is a few counters, never the issues
|
|
37
|
+
* themselves, and written once both cursors are exhausted. Concatenating
|
|
38
|
+
* every yielded chunk produces one JSON document; nothing here buffers it
|
|
39
|
+
* as a string first.
|
|
40
|
+
*
|
|
41
|
+
* **`sections` grouped by severity and the sorted `resolved` list do not
|
|
42
|
+
* exist here.** Both require holding the whole array to sort; this function
|
|
43
|
+
* instead trusts that `issues` and `suppressed` already arrive in the order
|
|
44
|
+
* the document should show them; a cursor-based caller supplies that with a
|
|
45
|
+
* SQL `ORDER BY`, not with an in-memory sort. `includeResolved` and
|
|
46
|
+
* `severityFloor` still apply, filtering rows out of the stream rather than
|
|
47
|
+
* out of an array.
|
|
48
|
+
*
|
|
49
|
+
* @param header - The run, its baseline, and the target. Never scales with
|
|
50
|
+
* issue count.
|
|
51
|
+
* @param issues - Every issue in scope, most urgent first, in the order the
|
|
52
|
+
* document should list them.
|
|
53
|
+
* @param suppressed - The accepted-risk register, in the order the appendix
|
|
54
|
+
* should list it.
|
|
55
|
+
* @param options - Which report, attribution, and the render time.
|
|
56
|
+
* @returns Chunks of JSON text; concatenated, they are one document.
|
|
57
|
+
*/
|
|
58
|
+
export declare function renderJsonStream(header: ReportHeader, issues: AsyncIterable<SnapshotIssue>, suppressed: AsyncIterable<SuppressedIssue>, options: ReportOptions): AsyncGenerator<string>;
|
|
59
|
+
/**
|
|
60
|
+
* Renders a report as Markdown, from a header and a cursor over its issues,
|
|
61
|
+
* rather than from a fully-assembled {@link Snapshot}. The streaming sibling
|
|
62
|
+
* of {@link renderJsonStream} — see it for the memory argument, which applies
|
|
63
|
+
* here identically: `renderMarkdown` holds every issue in one array before
|
|
64
|
+
* formatting any of it.
|
|
65
|
+
*
|
|
66
|
+
* **The document is reordered relative to `renderMarkdown`, and that is
|
|
67
|
+
* forced rather than stylistic.** The array-based renderer opens with "Basis
|
|
68
|
+
* of testing" and a "What changed" line naming how many issues are past
|
|
69
|
+
* their remediation deadline — both need to know something about *every*
|
|
70
|
+
* issue (`basis.includesManual`, `breached`) before the first line can be
|
|
71
|
+
* printed, which a forward-only stream cannot offer without buffering
|
|
72
|
+
* everything first. So this function prints what it already knows up front
|
|
73
|
+
* (title, scope, the New/Still open/Regressed/Resolved/Suppressed table,
|
|
74
|
+
* which all read straight off `RunSummary`) and moves everything that needs
|
|
75
|
+
* a full pass — the basis statement, the remediation-deadline count, what a
|
|
76
|
+
* severity floor omitted, the retest verdict counts — into a closing
|
|
77
|
+
* `## Summary` section, written once both cursors are exhausted.
|
|
78
|
+
*
|
|
79
|
+
* **`sections` grouped by severity do not exist here**, for the reason given
|
|
80
|
+
* in {@link renderJsonStream}: `issues` and `suppressed` are trusted to
|
|
81
|
+
* already arrive in the order the document should show them. For a `pen`
|
|
82
|
+
* report that means a severity sub-heading appears whenever the incoming
|
|
83
|
+
* severity changes, without the issue count that heading carries in
|
|
84
|
+
* `renderMarkdown` — the count is not known until the section ends. A
|
|
85
|
+
* `retest` report's per-issue table has no severity floor applied to it,
|
|
86
|
+
* matching `renderMarkdown`: the whole point of that table is showing what
|
|
87
|
+
* happened to every issue carried into the retest, not a curated subset.
|
|
88
|
+
*
|
|
89
|
+
* **`attest` buffers its suppressed list; nothing else buffers issues.** An
|
|
90
|
+
* Attestation Letter states counts and names nobody's individual issue, so
|
|
91
|
+
* it folds the whole `issues` cursor for those counts without printing a
|
|
92
|
+
* row — but it also prints the suppressed appendix *after* that letter body,
|
|
93
|
+
* by which point the `suppressed` cursor would already be exhausted. Holding
|
|
94
|
+
* that one list (the accepted-risk register, ordinarily a minority of the
|
|
95
|
+
* total) is the one deliberate exception to "never hold more than a row".
|
|
96
|
+
*
|
|
97
|
+
* @param header - The run, its baseline, and the target. Never scales with
|
|
98
|
+
* issue count.
|
|
99
|
+
* @param issues - Every issue in scope, most urgent first: open/regressed
|
|
100
|
+
* before resolved, each group by severity then most-recently-seen first —
|
|
101
|
+
* the order the document lists them in.
|
|
102
|
+
* @param suppressed - The accepted-risk register, in the order the appendix
|
|
103
|
+
* should list it.
|
|
104
|
+
* @param options - Which report, attribution, and the render time.
|
|
105
|
+
* @returns Chunks of Markdown text; concatenated, they are one document.
|
|
106
|
+
*/
|
|
107
|
+
export declare function renderMarkdownStream(header: ReportHeader, issues: AsyncIterable<SnapshotIssue>, suppressed: AsyncIterable<SuppressedIssue>, options: ReportOptions): AsyncGenerator<string>;
|
|
108
|
+
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/report/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAG5C,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE7E,OAAO,EASL,KAAK,aAAa,EAEnB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;GAUG;AACH,MAAM,WAAW,YAAY;IAC3B,qCAAqC;IACrC,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC;IAEzB,qEAAqE;IACrE,QAAQ,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAC;IAE/B,6BAA6B;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAoED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAuB,gBAAgB,CACrC,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,aAAa,CAAC,aAAa,CAAC,EACpC,UAAU,EAAE,aAAa,CAAC,eAAe,CAAC,EAC1C,OAAO,EAAE,aAAa,GACrB,cAAc,CAAC,MAAM,CAAC,CAoGxB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,wBAAuB,oBAAoB,CACzC,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,aAAa,CAAC,aAAa,CAAC,EACpC,UAAU,EAAE,aAAa,CAAC,eAAe,CAAC,EAC1C,OAAO,EAAE,aAAa,GACrB,cAAc,CAAC,MAAM,CAAC,CA6TxB"}
|