@secureport/core 0.2.1 → 0.4.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/README.md +146 -33
- package/dist/coverage.d.ts +21 -0
- package/dist/coverage.d.ts.map +1 -0
- package/dist/coverage.js +65 -0
- package/dist/coverage.js.map +1 -0
- package/dist/finding.d.ts +89 -0
- package/dist/finding.d.ts.map +1 -0
- package/dist/finding.js +2 -0
- package/dist/finding.js.map +1 -0
- package/dist/fingerprint.d.ts +185 -0
- package/dist/fingerprint.d.ts.map +1 -0
- package/dist/fingerprint.js +247 -0
- package/dist/fingerprint.js.map +1 -0
- package/dist/import/burp.d.ts +19 -0
- package/dist/import/burp.d.ts.map +1 -0
- package/dist/import/burp.js +114 -0
- package/dist/import/burp.js.map +1 -0
- package/dist/import/generic.d.ts +90 -0
- package/dist/import/generic.d.ts.map +1 -0
- package/dist/import/generic.js +159 -0
- package/dist/import/generic.js.map +1 -0
- package/dist/import/nessus.d.ts +32 -0
- package/dist/import/nessus.d.ts.map +1 -0
- package/dist/import/nessus.js +125 -0
- package/dist/import/nessus.js.map +1 -0
- package/dist/import/nuclei.d.ts +39 -0
- package/dist/import/nuclei.d.ts.map +1 -0
- package/dist/import/nuclei.js +115 -0
- package/dist/import/nuclei.js.map +1 -0
- package/dist/import/xml.d.ts +47 -0
- package/dist/import/xml.d.ts.map +1 -0
- package/dist/import/xml.js +157 -0
- package/dist/import/xml.js.map +1 -0
- package/dist/import/zap.d.ts +26 -0
- package/dist/import/zap.d.ts.map +1 -0
- package/dist/import/zap.js +119 -0
- package/dist/import/zap.js.map +1 -0
- package/dist/index.d.ts +41 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +29 -2
- package/dist/index.js.map +1 -1
- package/dist/issue.d.ts +190 -11
- package/dist/issue.d.ts.map +1 -1
- package/dist/reconcile.d.ts +115 -10
- package/dist/reconcile.d.ts.map +1 -1
- package/dist/reconcile.js +306 -12
- package/dist/reconcile.js.map +1 -1
- package/dist/report/html.d.ts +21 -0
- package/dist/report/html.d.ts.map +1 -0
- package/dist/report/html.js +324 -0
- package/dist/report/html.js.map +1 -0
- package/dist/report/json.d.ts +81 -0
- package/dist/report/json.d.ts.map +1 -0
- package/dist/report/json.js +47 -0
- package/dist/report/json.js.map +1 -0
- package/dist/report/markdown.d.ts +24 -0
- package/dist/report/markdown.d.ts.map +1 -0
- package/dist/report/markdown.js +304 -0
- package/dist/report/markdown.js.map +1 -0
- package/dist/report/model.d.ts +215 -0
- package/dist/report/model.d.ts.map +1 -0
- package/dist/report/model.js +197 -0
- package/dist/report/model.js.map +1 -0
- package/dist/run.d.ts +134 -0
- package/dist/run.d.ts.map +1 -0
- package/dist/run.js +2 -0
- package/dist/run.js.map +1 -0
- package/dist/severity.d.ts +191 -0
- package/dist/severity.d.ts.map +1 -0
- package/dist/severity.js +171 -0
- package/dist/severity.js.map +1 -0
- package/dist/snapshot-builder.d.ts +78 -0
- package/dist/snapshot-builder.d.ts.map +1 -0
- package/dist/snapshot-builder.js +172 -0
- package/dist/snapshot-builder.js.map +1 -0
- package/dist/snapshot.d.ts +125 -0
- package/dist/snapshot.d.ts.map +1 -0
- package/dist/snapshot.js +2 -0
- package/dist/snapshot.js.map +1 -0
- package/package.json +5 -4
- package/src/coverage.ts +65 -0
- package/src/finding.ts +112 -0
- package/src/fingerprint.ts +315 -0
- package/src/import/burp.ts +126 -0
- package/src/import/generic.ts +258 -0
- package/src/import/nessus.ts +136 -0
- package/src/import/nuclei.ts +173 -0
- package/src/import/xml.ts +187 -0
- package/src/import/zap.ts +161 -0
- package/src/index.ts +75 -2
- package/src/issue.ts +244 -11
- package/src/reconcile.ts +421 -17
- package/src/report/html.ts +449 -0
- package/src/report/json.ts +134 -0
- package/src/report/markdown.ts +435 -0
- package/src/report/model.ts +462 -0
- package/src/run.ts +163 -0
- package/src/severity.ts +250 -0
- package/src/snapshot-builder.ts +225 -0
- package/src/snapshot.ts +146 -0
package/src/coverage.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { Coverage } from './run.js';
|
|
2
|
+
|
|
3
|
+
/** Escapes a literal so it can sit inside a regular expression. */
|
|
4
|
+
function escapeLiteral(text: string): string {
|
|
5
|
+
return text.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Compiles a coverage glob into a regular expression.
|
|
10
|
+
*
|
|
11
|
+
* `**` matches anything including `/`; `*` matches anything except `/`, so
|
|
12
|
+
* `https://a.example/*` covers `/orders` but not `/orders/123`; `?` matches one
|
|
13
|
+
* character. Everything else is literal.
|
|
14
|
+
*/
|
|
15
|
+
function globToRegExp(glob: string): RegExp {
|
|
16
|
+
let out = '';
|
|
17
|
+
for (let i = 0; i < glob.length; i++) {
|
|
18
|
+
const char = glob[i];
|
|
19
|
+
if (char === '*') {
|
|
20
|
+
if (glob[i + 1] === '*') {
|
|
21
|
+
out += '.*';
|
|
22
|
+
i++;
|
|
23
|
+
} else {
|
|
24
|
+
out += '[^/]*';
|
|
25
|
+
}
|
|
26
|
+
} else if (char === '?') {
|
|
27
|
+
out += '[^/]';
|
|
28
|
+
} else {
|
|
29
|
+
out += escapeLiteral(char);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return new RegExp(`^${out}$`, 'u');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The port in a location, where it states one. */
|
|
36
|
+
function portOf(location: string): number | undefined {
|
|
37
|
+
const match = /^[a-z][a-z0-9+.-]*:\/\/[^/]*?:(\d+)(?:[/?#]|$)/iu.exec(location);
|
|
38
|
+
return match ? Number(match[1]) : undefined;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Whether a run could have found something at this location.
|
|
43
|
+
*
|
|
44
|
+
* **This is what makes auto-resolution safe.** A run only resolves what it
|
|
45
|
+
* could have found (invariant 5): a quick profile that skipped `/admin` must
|
|
46
|
+
* not close an `/admin` issue, because not looking is not the same as not
|
|
47
|
+
* finding. Anything outside coverage is left entirely alone — not resolved, and
|
|
48
|
+
* not counted as a miss either.
|
|
49
|
+
*
|
|
50
|
+
* A location matches when it matches at least one covered path glob, **and**,
|
|
51
|
+
* where both the location and the coverage state a port, that port was
|
|
52
|
+
* exercised. The port rule errs towards leaving issues open: a scan of `:443`
|
|
53
|
+
* says nothing about `:8443`.
|
|
54
|
+
*
|
|
55
|
+
* @param location - The issue's location.
|
|
56
|
+
* @param coverage - What the run exercised.
|
|
57
|
+
* @returns `true` if the run could have found it.
|
|
58
|
+
*/
|
|
59
|
+
export function coversLocation(location: string, coverage: Coverage): boolean {
|
|
60
|
+
const port = portOf(location);
|
|
61
|
+
if (port !== undefined && coverage.ports !== undefined && coverage.ports.length > 0) {
|
|
62
|
+
if (!coverage.ports.includes(port)) return false;
|
|
63
|
+
}
|
|
64
|
+
return coverage.paths.some((glob) => globToRegExp(glob).test(location));
|
|
65
|
+
}
|
package/src/finding.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { Severity, SeveritySource } from './severity.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* One detection, in one run.
|
|
5
|
+
*
|
|
6
|
+
* **Findings are immutable evidence.** A finding is never updated after it is
|
|
7
|
+
* recorded (invariant 1) and it carries no status: whether something is open,
|
|
8
|
+
* fixed or accepted is a property of the {@link Issue} it reconciles into, not
|
|
9
|
+
* of the evidence for it. If a field here would need to change as a human works
|
|
10
|
+
* on the problem, it belongs on the issue instead.
|
|
11
|
+
*
|
|
12
|
+
* Many findings, from many runs and many engines, fold into one issue by
|
|
13
|
+
* {@link Finding.fingerprint}.
|
|
14
|
+
*/
|
|
15
|
+
export interface Finding {
|
|
16
|
+
/** Unique id for this detection. */
|
|
17
|
+
readonly id: string;
|
|
18
|
+
|
|
19
|
+
/** Organisation this finding belongs to. Every query carries it. */
|
|
20
|
+
readonly orgId: string;
|
|
21
|
+
|
|
22
|
+
/** The run that produced it. */
|
|
23
|
+
readonly runId: string;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Content address of the underlying weakness, used to reconcile findings
|
|
27
|
+
* into a single issue across runs and engines.
|
|
28
|
+
*
|
|
29
|
+
* Derived from the target, the {@link Finding.vulnKey}, the normalised
|
|
30
|
+
* location and the parameter — never from volatile evidence such as tokens,
|
|
31
|
+
* timestamps or response bodies, which would make every run look new.
|
|
32
|
+
*/
|
|
33
|
+
readonly fingerprint: string;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Which fingerprint algorithm produced {@link Finding.fingerprint}.
|
|
37
|
+
*
|
|
38
|
+
* **A public contract.** It travels with every fingerprint everywhere
|
|
39
|
+
* (invariant 8) so a stored fingerprint can always be interpreted, and
|
|
40
|
+
* changing the algorithm means a re-fingerprint migration that preserves
|
|
41
|
+
* history rather than a silent recomputation.
|
|
42
|
+
*/
|
|
43
|
+
readonly fingerprintVersion: string;
|
|
44
|
+
|
|
45
|
+
/** Short human-readable name for the weakness. */
|
|
46
|
+
readonly title: string;
|
|
47
|
+
|
|
48
|
+
/** Fuller explanation of what was detected. */
|
|
49
|
+
readonly description?: string;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Severity as detected for this finding.
|
|
53
|
+
*
|
|
54
|
+
* What the evidence says. The issue's `effectiveSeverity` may differ, because
|
|
55
|
+
* a human may have overridden it.
|
|
56
|
+
*/
|
|
57
|
+
readonly detectedSeverity: Severity;
|
|
58
|
+
|
|
59
|
+
/** Why {@link Finding.detectedSeverity} is what it is. */
|
|
60
|
+
readonly severitySource: SeveritySource;
|
|
61
|
+
|
|
62
|
+
/** CVSS base score, where the engine or advisory supplied one. */
|
|
63
|
+
readonly cvssScore?: number;
|
|
64
|
+
|
|
65
|
+
/** CVSS vector string, where one was supplied. */
|
|
66
|
+
readonly cvssVector?: string;
|
|
67
|
+
|
|
68
|
+
/** CWE identifier, e.g. `CWE-79`. */
|
|
69
|
+
readonly cwe?: string;
|
|
70
|
+
|
|
71
|
+
/** CVE identifier, e.g. `CVE-2026-1234`. */
|
|
72
|
+
readonly cve?: string;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Engine-independent key for the weakness class.
|
|
76
|
+
*
|
|
77
|
+
* This is what makes a Nuclei detection and a ZAP detection of the same
|
|
78
|
+
* weakness collide into one issue. Without it there is no cross-engine
|
|
79
|
+
* deduplication, only per-engine.
|
|
80
|
+
*/
|
|
81
|
+
readonly vulnKey: string;
|
|
82
|
+
|
|
83
|
+
/** Broad grouping for reports, e.g. `injection`, `tls`, `access-control`. */
|
|
84
|
+
readonly category?: string;
|
|
85
|
+
|
|
86
|
+
/** Where it was found — a URL, host, port or file path. */
|
|
87
|
+
readonly location: string;
|
|
88
|
+
|
|
89
|
+
/** The specific parameter implicated, where the weakness has one. */
|
|
90
|
+
readonly parameter?: string;
|
|
91
|
+
|
|
92
|
+
/** Pointers to stored evidence: request/response captures, screenshots. */
|
|
93
|
+
readonly evidenceUri?: readonly string[];
|
|
94
|
+
|
|
95
|
+
/** What to do about it. */
|
|
96
|
+
readonly recommendation?: string;
|
|
97
|
+
|
|
98
|
+
/** External reading: advisories, vendor bulletins, standards. */
|
|
99
|
+
readonly references?: readonly string[];
|
|
100
|
+
|
|
101
|
+
/** Which engine detected it, e.g. `nuclei`, `zap`, `burp`, `nessus`. */
|
|
102
|
+
readonly sourceEngine: string;
|
|
103
|
+
|
|
104
|
+
/** The engine's own identifier for the rule that fired. */
|
|
105
|
+
readonly sourceRuleId?: string;
|
|
106
|
+
|
|
107
|
+
/** The engine's confidence, where it reports one, from 0 to 1. */
|
|
108
|
+
readonly confidence?: number;
|
|
109
|
+
|
|
110
|
+
/** When the finding was recorded. */
|
|
111
|
+
readonly createdAt: Date;
|
|
112
|
+
}
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Which fingerprint algorithm this build of the package implements.
|
|
5
|
+
*
|
|
6
|
+
* **A public contract, and the most consequential string in the package.** It
|
|
7
|
+
* is stored on every finding and every issue, everywhere, so that a fingerprint
|
|
8
|
+
* recorded a year ago can still be interpreted. Changing the algorithm means
|
|
9
|
+
* bumping this *and* running a per-organisation re-fingerprint migration that
|
|
10
|
+
* preserves history — never a silent recomputation, which would orphan every
|
|
11
|
+
* issue whose evidence no longer hashes to the same value.
|
|
12
|
+
*
|
|
13
|
+
* If you are tempted to "just tweak" the normaliser, that is this constant's
|
|
14
|
+
* job to prevent.
|
|
15
|
+
*/
|
|
16
|
+
export const FINGERPRINT_VERSION = 'fp_v1';
|
|
17
|
+
|
|
18
|
+
/** A path segment that is entirely digits, e.g. the `123` in `/orders/123`. */
|
|
19
|
+
const NUMERIC_SEGMENT = /^\d+$/u;
|
|
20
|
+
|
|
21
|
+
/** A path segment that is a UUID in the canonical 8-4-4-4-12 form. */
|
|
22
|
+
const UUID_SEGMENT = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The placeholder that a variable path segment collapses to.
|
|
26
|
+
*
|
|
27
|
+
* Exported because it appears in normalised locations, which appear in reports
|
|
28
|
+
* and in support conversations: someone reading `/orders/{id}` should be able
|
|
29
|
+
* to find out what produced it.
|
|
30
|
+
*/
|
|
31
|
+
export const PATH_PLACEHOLDER = '{id}';
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Decodes percent-encoding exactly once, and never throws.
|
|
35
|
+
*
|
|
36
|
+
* Once, not repeatedly: decoding until stable would make `%2541` and `%41`
|
|
37
|
+
* collapse to the same thing, so a target that double-encodes could be made to
|
|
38
|
+
* collide with one that does not.
|
|
39
|
+
*
|
|
40
|
+
* Malformed encoding is left alone rather than rejected. A fingerprint that
|
|
41
|
+
* throws on strange input is a fingerprint that loses a finding.
|
|
42
|
+
*/
|
|
43
|
+
function decodeOnce(value: string): string {
|
|
44
|
+
try {
|
|
45
|
+
return decodeURIComponent(value);
|
|
46
|
+
} catch {
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Collapses one path segment to {@link PATH_PLACEHOLDER} if it identifies a
|
|
53
|
+
* record rather than a route.
|
|
54
|
+
*/
|
|
55
|
+
function collapseSegment(segment: string): string {
|
|
56
|
+
if (NUMERIC_SEGMENT.test(segment) || UUID_SEGMENT.test(segment)) return PATH_PLACEHOLDER;
|
|
57
|
+
return segment;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Normalises a location so that the same weakness in the same place produces
|
|
62
|
+
* the same string, however the engine happened to write it down.
|
|
63
|
+
*
|
|
64
|
+
* This is the part of the fingerprint that decides whether `/orders/1` and
|
|
65
|
+
* `/orders/2` are one issue or two thousand. Applies, in order:
|
|
66
|
+
*
|
|
67
|
+
* - **Lowercases the host**, and converts an internationalised domain to
|
|
68
|
+
* punycode, so `HTTPS://例え.テスト/x` and `https://xn--r8jz45g.xn--zckzah/x`
|
|
69
|
+
* are one location.
|
|
70
|
+
* - **Drops a default port** (`:443` on https, `:80` on http) and keeps any
|
|
71
|
+
* other, because `:8443` is a different service and `:443` is not.
|
|
72
|
+
* - **Decodes percent-encoding once.**
|
|
73
|
+
* - **Collapses numeric and UUID path segments** to `{id}`, so a per-record URL
|
|
74
|
+
* does not open a per-record issue.
|
|
75
|
+
* - **Drops a trailing slash**, except on the root path where it is the path.
|
|
76
|
+
* - **Strips query values but keeps parameter names, sorted.** `?b=2&a=secret`
|
|
77
|
+
* becomes `?a&b`. The names are structure and belong in identity; the values
|
|
78
|
+
* are usually the payload that proved the weakness, which is evidence and
|
|
79
|
+
* must never reach a fingerprint. Sorting means parameter order cannot split
|
|
80
|
+
* one issue into two.
|
|
81
|
+
* - **Drops the fragment**, which the server never sees.
|
|
82
|
+
*
|
|
83
|
+
* Anything that is not a parseable absolute URL — a bare host, a file path, a
|
|
84
|
+
* `host:port` pair from a network scan — is normalised as a path alone. That is
|
|
85
|
+
* deliberate: refusing to fingerprint a non-HTTP finding would exclude whole
|
|
86
|
+
* classes of scanner from the model.
|
|
87
|
+
*
|
|
88
|
+
* @param location - Where the weakness was found.
|
|
89
|
+
* @returns The normalised location.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* normaliseLocation('HTTPS://API.Example.com:443/Orders/123/items/?b=2&a=secret#f');
|
|
94
|
+
* // 'https://api.example.com/Orders/{id}/items?a&b'
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export function normaliseLocation(location: string): string {
|
|
98
|
+
const trimmed = location.trim();
|
|
99
|
+
|
|
100
|
+
let url: URL | undefined;
|
|
101
|
+
try {
|
|
102
|
+
url = new URL(trimmed);
|
|
103
|
+
} catch {
|
|
104
|
+
url = undefined;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Not an absolute URL: normalise it as a bare path and stop. `new URL` would
|
|
108
|
+
// otherwise turn `example.com/x` into the `example.com:` protocol.
|
|
109
|
+
if (!url || url.protocol === '' || !url.host) {
|
|
110
|
+
return normalisePathOnly(trimmed);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Not `decodeOnce` here: normalisePathOnly decodes, and decoding on the way
|
|
114
|
+
// in as well would decode twice — which would fold `%252F` into `%2F` into
|
|
115
|
+
// `/` and let a double-encoding target collide with a single-encoding one.
|
|
116
|
+
const path = normalisePathOnly(url.pathname);
|
|
117
|
+
|
|
118
|
+
// `url.host` already carries punycode and lower case, and omits a default
|
|
119
|
+
// port for the scheme.
|
|
120
|
+
const names = [...new Set([...url.searchParams.keys()].map(decodeOnce))].sort();
|
|
121
|
+
const query = names.length > 0 ? `?${names.join('&')}` : '';
|
|
122
|
+
|
|
123
|
+
return `${url.protocol}//${url.host}${path}${query}`;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Normalises a path with no scheme or host.
|
|
128
|
+
*/
|
|
129
|
+
function normalisePathOnly(path: string): string {
|
|
130
|
+
const decoded = decodeOnce(path.trim());
|
|
131
|
+
if (decoded === '' || decoded === '/') return decoded === '' ? '' : '/';
|
|
132
|
+
|
|
133
|
+
const collapsed = decoded
|
|
134
|
+
.split('/')
|
|
135
|
+
.map((segment) => collapseSegment(segment))
|
|
136
|
+
.join('/');
|
|
137
|
+
|
|
138
|
+
return collapsed.length > 1 && collapsed.endsWith('/') ? collapsed.slice(0, -1) : collapsed;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* What a scanner said it found, in the terms needed to name the weakness.
|
|
143
|
+
*/
|
|
144
|
+
export interface VulnKeyInput {
|
|
145
|
+
/** Which engine detected it, e.g. `nuclei`, `zap`. */
|
|
146
|
+
readonly sourceEngine: string;
|
|
147
|
+
|
|
148
|
+
/** The engine's own identifier for the rule that fired. */
|
|
149
|
+
readonly sourceRuleId?: string;
|
|
150
|
+
|
|
151
|
+
/** CWE identifier, e.g. `CWE-79`. */
|
|
152
|
+
readonly cwe?: string;
|
|
153
|
+
|
|
154
|
+
/** Broad grouping, e.g. `injection`. */
|
|
155
|
+
readonly category?: string;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Maps `engine:ruleId` to a shared, engine-independent weakness key.
|
|
160
|
+
*
|
|
161
|
+
* **This table is the entire mechanism of cross-engine deduplication.** Without
|
|
162
|
+
* it a ZAP detection and a Nuclei detection of the same weakness fall back to
|
|
163
|
+
* CWE, and where either engine omits the CWE they never collide at all — you
|
|
164
|
+
* get per-engine tracking wearing the clothes of an issue tracker.
|
|
165
|
+
*
|
|
166
|
+
* **It is deliberately small, and that is not laziness.** A mapping asserts
|
|
167
|
+
* that a specific rule id means a specific weakness, and a wrong assertion
|
|
168
|
+
* silently merges two unrelated issues — worse than not mapping at all, because
|
|
169
|
+
* the merge is invisible. Rule ids cannot be known honestly until real scanner
|
|
170
|
+
* output has been parsed, which is what 4.4a and 4.4b do with committed
|
|
171
|
+
* fixtures. The table grows there, from evidence.
|
|
172
|
+
*
|
|
173
|
+
* **Entries must be added in pairs, per weakness, across engines — a half-filled
|
|
174
|
+
* table is worse than an empty one.** The mapping beats the CWE fallback, so
|
|
175
|
+
* mapping ZAP's HSTS rule while leaving Nuclei's unmapped gives them *different*
|
|
176
|
+
* keys, when falling back to `CWE-319` on both sides would have collided them
|
|
177
|
+
* correctly. Adding one engine's rule silently un-deduplicates the weakness.
|
|
178
|
+
* Found by importing a fixture from each engine and watching them stop
|
|
179
|
+
* agreeing.
|
|
180
|
+
*
|
|
181
|
+
* `00-DOMAIN.md` §10 leaves the eventual size open, leaning towards the top
|
|
182
|
+
* ~200 Nuclei templates plus ZAP's plugin list, with CWE fallback beyond.
|
|
183
|
+
*
|
|
184
|
+
* Keys are `${sourceEngine}:${sourceRuleId}`, both lowercased.
|
|
185
|
+
*/
|
|
186
|
+
export const VULN_KEY_MAP: Readonly<Record<string, string>> = Object.freeze({
|
|
187
|
+
// ZAP plugin ids are stable and documented, which is why the seed is ZAP's.
|
|
188
|
+
'zap:40012': 'xss-reflected',
|
|
189
|
+
'zap:40014': 'xss-persistent',
|
|
190
|
+
'zap:40018': 'sql-injection',
|
|
191
|
+
'zap:10038': 'csp-missing',
|
|
192
|
+
'zap:10035': 'hsts-missing',
|
|
193
|
+
'zap:10021': 'x-content-type-options-missing',
|
|
194
|
+
'zap:10020': 'x-frame-options-missing',
|
|
195
|
+
|
|
196
|
+
// Nuclei's side of the pairs above. Anything mapped for one engine and not
|
|
197
|
+
// the other stops the two agreeing, so these travel together.
|
|
198
|
+
'nuclei:xss-reflected': 'xss-reflected',
|
|
199
|
+
'nuclei:missing-hsts': 'hsts-missing',
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* The engine-independent key for a weakness class.
|
|
204
|
+
*
|
|
205
|
+
* Resolution order, per `00-DOMAIN.md` §4:
|
|
206
|
+
*
|
|
207
|
+
* 1. {@link VULN_KEY_MAP}, looked up by `engine:ruleId`.
|
|
208
|
+
* 2. `cwe` alone.
|
|
209
|
+
* 3. `category` alone.
|
|
210
|
+
* 4. `engine:ruleId` itself.
|
|
211
|
+
*
|
|
212
|
+
* **The spec says `cwe + '/' + category`, and that was tried and abandoned.**
|
|
213
|
+
* Engines do not share a category vocabulary: ZAP supplies no category at all,
|
|
214
|
+
* so reflected XSS there keys as `CWE-79`, while Nuclei tags the same finding
|
|
215
|
+
* `xss` and keys as `CWE-79/xss`. The two never collide — so the fallback
|
|
216
|
+
* actively prevented the cross-engine deduplication it exists to provide, which
|
|
217
|
+
* a fixture from each engine demonstrated immediately.
|
|
218
|
+
*
|
|
219
|
+
* CWE alone is coarser, and the coarseness is bounded: the fingerprint also
|
|
220
|
+
* carries the normalised location and the parameter, so two findings only merge
|
|
221
|
+
* when they share a weakness class *and* a place. Two genuinely different
|
|
222
|
+
* weaknesses under one CWE, at the same URL and parameter, is the case this
|
|
223
|
+
* gets wrong — and `POST /issues/{a}/merge/{b}` exists because something will.
|
|
224
|
+
*
|
|
225
|
+
* Steps 3 and 4 keep a finding trackable when there is no CWE at all. **Step 4
|
|
226
|
+
* never deduplicates across engines**, which is the honest outcome for a rule
|
|
227
|
+
* nobody has mapped: it tracks correctly and merges nothing it should not.
|
|
228
|
+
*
|
|
229
|
+
* @param input - What the engine reported.
|
|
230
|
+
* @returns The weakness key.
|
|
231
|
+
* @throws TypeError If nothing identifying is present at all.
|
|
232
|
+
*/
|
|
233
|
+
export function vulnKey(input: VulnKeyInput): string {
|
|
234
|
+
const engine = input.sourceEngine.trim().toLowerCase();
|
|
235
|
+
const ruleId = input.sourceRuleId?.trim().toLowerCase();
|
|
236
|
+
|
|
237
|
+
if (engine !== '' && ruleId !== undefined && ruleId !== '') {
|
|
238
|
+
const mapped = VULN_KEY_MAP[`${engine}:${ruleId}`];
|
|
239
|
+
if (mapped !== undefined) return mapped;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const cwe = input.cwe?.trim().toUpperCase();
|
|
243
|
+
const category = input.category?.trim().toLowerCase();
|
|
244
|
+
|
|
245
|
+
if (cwe !== undefined && cwe !== '') return cwe;
|
|
246
|
+
if (category !== undefined && category !== '') return category;
|
|
247
|
+
if (engine !== '' && ruleId !== undefined && ruleId !== '') return `${engine}:${ruleId}`;
|
|
248
|
+
|
|
249
|
+
throw new TypeError(
|
|
250
|
+
'cannot derive a vuln_key: a finding needs a mapped rule, a CWE, a category, or an engine rule id',
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Everything the fingerprint is computed from.
|
|
256
|
+
*
|
|
257
|
+
* Note what is absent: no title, no description, no evidence, no timestamp, no
|
|
258
|
+
* severity. **Volatile evidence never enters a fingerprint** — a nonce or a
|
|
259
|
+
* response body in here would make every run look like a fresh discovery, and
|
|
260
|
+
* the product's whole claim is that it can tell you what changed.
|
|
261
|
+
*/
|
|
262
|
+
export interface FingerprintInput {
|
|
263
|
+
/**
|
|
264
|
+
* The target the finding is on.
|
|
265
|
+
*
|
|
266
|
+
* Part of identity, which has a surprising consequence worth stating: the
|
|
267
|
+
* same weakness in staging and in production is **two issues**. They are two
|
|
268
|
+
* systems, fixed separately, and a verification of one must never authorise
|
|
269
|
+
* the other.
|
|
270
|
+
*/
|
|
271
|
+
readonly targetId: string;
|
|
272
|
+
|
|
273
|
+
/** The engine-independent weakness key, from {@link vulnKey}. */
|
|
274
|
+
readonly vulnKey: string;
|
|
275
|
+
|
|
276
|
+
/** Where it was found. Normalised by {@link normaliseLocation}. */
|
|
277
|
+
readonly location: string;
|
|
278
|
+
|
|
279
|
+
/** The parameter implicated, where the weakness has one. */
|
|
280
|
+
readonly parameter?: string;
|
|
281
|
+
|
|
282
|
+
/** The port, for findings that are about a service rather than a path. */
|
|
283
|
+
readonly port?: number;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* The content address of a weakness: `sha256(targetId | vulnKey | normalised
|
|
288
|
+
* location | parameter ?? port ?? '')`.
|
|
289
|
+
*
|
|
290
|
+
* Deterministic and pure — the same input always gives the same digest, on any
|
|
291
|
+
* machine, in any order, at any time. That is what lets findings from different
|
|
292
|
+
* runs and different engines reconcile into one issue.
|
|
293
|
+
*
|
|
294
|
+
* Uses Node's `node:crypto`, which is a builtin rather than a dependency, so
|
|
295
|
+
* the package still installs nothing. It does mean fingerprinting requires
|
|
296
|
+
* Node; report rendering does not, and rendering is the only part of this
|
|
297
|
+
* package a browser was ever going to run.
|
|
298
|
+
*
|
|
299
|
+
* @param input - The identifying facts.
|
|
300
|
+
* @returns A lowercase hex SHA-256 digest.
|
|
301
|
+
*
|
|
302
|
+
* @example
|
|
303
|
+
* ```ts
|
|
304
|
+
* const key = vulnKey({ sourceEngine: 'zap', sourceRuleId: '40012' });
|
|
305
|
+
* fingerprint({ targetId: 'tgt_1', vulnKey: key, location: '/search', parameter: 'q' });
|
|
306
|
+
* ```
|
|
307
|
+
*/
|
|
308
|
+
export function fingerprint(input: FingerprintInput): string {
|
|
309
|
+
const tail = input.parameter ?? (input.port !== undefined ? String(input.port) : '');
|
|
310
|
+
const material = [input.targetId, input.vulnKey, normaliseLocation(input.location), tail].join(
|
|
311
|
+
'|',
|
|
312
|
+
);
|
|
313
|
+
|
|
314
|
+
return createHash('sha256').update(material, 'utf8').digest('hex');
|
|
315
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { Finding } from '../finding.js';
|
|
2
|
+
import type { Severity } from '../severity.js';
|
|
3
|
+
import { fingerprint, vulnKey, FINGERPRINT_VERSION } from '../fingerprint.js';
|
|
4
|
+
import { childText, findAll, parseXml } from './xml.js';
|
|
5
|
+
import type { ImportOptions } from './nuclei.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Burp's severity vocabulary, mapped onto {@link Severity}.
|
|
9
|
+
*
|
|
10
|
+
* **Burp has no "critical" either.** Like ZAP it tops out at High, and
|
|
11
|
+
* `Information` is the bottom of the scale rather than a separate category.
|
|
12
|
+
*/
|
|
13
|
+
const BURP_SEVERITY: Readonly<Record<string, Severity>> = Object.freeze({
|
|
14
|
+
high: 'high',
|
|
15
|
+
medium: 'medium',
|
|
16
|
+
low: 'low',
|
|
17
|
+
information: 'advisory',
|
|
18
|
+
info: 'advisory',
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Burp reports confidence in words. Mapped to a number so the model does not
|
|
23
|
+
* have to carry a second vocabulary for it.
|
|
24
|
+
*/
|
|
25
|
+
const BURP_CONFIDENCE: Readonly<Record<string, number>> = Object.freeze({
|
|
26
|
+
certain: 1,
|
|
27
|
+
firm: 0.7,
|
|
28
|
+
tentative: 0.4,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Burp writes the affected parameter into the location, not a field of its own.
|
|
33
|
+
*
|
|
34
|
+
* `/search [q parameter]` means the `q` parameter of `/search`. Pulling it out
|
|
35
|
+
* matters: the parameter is part of the fingerprint, so leaving it embedded in
|
|
36
|
+
* the path would make Burp's finding a different issue from ZAP's finding of the
|
|
37
|
+
* same weakness in the same place.
|
|
38
|
+
*/
|
|
39
|
+
function splitLocation(location: string): { path: string; parameter?: string } {
|
|
40
|
+
const match = /^(.*?)\s*\[\s*(.+?)\s+parameter\s*\]\s*$/iu.exec(location);
|
|
41
|
+
if (match) return { path: match[1].trim(), parameter: match[2].trim() };
|
|
42
|
+
return { path: location.trim() };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Turns a Burp Suite XML export into {@link Finding}s.
|
|
47
|
+
*
|
|
48
|
+
* Burp exports a flat `<issues>` document, one `<issue>` per detection, with the
|
|
49
|
+
* host and path in separate elements — so the location is assembled rather than
|
|
50
|
+
* read. Prose fields arrive as CDATA containing HTML, which is stripped.
|
|
51
|
+
*
|
|
52
|
+
* `<type>` is Burp's numeric issue type and is used as the rule id, because it
|
|
53
|
+
* is stable across versions where the human-readable `<name>` is not.
|
|
54
|
+
*
|
|
55
|
+
* @param xml - The contents of a Burp XML export.
|
|
56
|
+
* @param options - Ownership, and the injected clock and id source.
|
|
57
|
+
* @returns One finding per issue, in document order.
|
|
58
|
+
* @throws SyntaxError If the document is not well-formed XML.
|
|
59
|
+
*/
|
|
60
|
+
export function importBurp(xml: string, options: ImportOptions): Finding[] {
|
|
61
|
+
const root = parseXml(xml);
|
|
62
|
+
const findings: Finding[] = [];
|
|
63
|
+
|
|
64
|
+
for (const issue of findAll(root, 'issue')) {
|
|
65
|
+
const name = childText(issue, 'name');
|
|
66
|
+
const type = childText(issue, 'type');
|
|
67
|
+
if (name === undefined || type === undefined) continue;
|
|
68
|
+
|
|
69
|
+
const host = childText(issue, 'host') ?? '';
|
|
70
|
+
const raw = childText(issue, 'location') ?? childText(issue, 'path') ?? '';
|
|
71
|
+
const { path, parameter } = splitLocation(raw);
|
|
72
|
+
const location = path.startsWith('http') ? path : `${host}${path}`;
|
|
73
|
+
if (location === '') continue;
|
|
74
|
+
|
|
75
|
+
const cwe = childText(issue, 'vulnerabilityClassifications')
|
|
76
|
+
?.match(/CWE-\d+/iu)?.[0]
|
|
77
|
+
?.toUpperCase();
|
|
78
|
+
|
|
79
|
+
const key = vulnKey({
|
|
80
|
+
sourceEngine: 'burp',
|
|
81
|
+
sourceRuleId: type,
|
|
82
|
+
...(cwe === undefined ? {} : { cwe }),
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const confidence = BURP_CONFIDENCE[childText(issue, 'confidence')?.toLowerCase() ?? ''];
|
|
86
|
+
const background = childText(issue, 'issueBackground');
|
|
87
|
+
const remediation = childText(issue, 'remediationBackground');
|
|
88
|
+
|
|
89
|
+
findings.push({
|
|
90
|
+
id: options.newId(),
|
|
91
|
+
orgId: options.orgId,
|
|
92
|
+
runId: options.runId,
|
|
93
|
+
fingerprint: fingerprint({
|
|
94
|
+
targetId: options.targetId,
|
|
95
|
+
vulnKey: key,
|
|
96
|
+
location,
|
|
97
|
+
...(parameter === undefined ? {} : { parameter }),
|
|
98
|
+
}),
|
|
99
|
+
fingerprintVersion: FINGERPRINT_VERSION,
|
|
100
|
+
title: name,
|
|
101
|
+
...(background === undefined ? {} : { description: stripHtml(background) }),
|
|
102
|
+
detectedSeverity:
|
|
103
|
+
BURP_SEVERITY[childText(issue, 'severity')?.toLowerCase() ?? ''] ?? 'advisory',
|
|
104
|
+
severitySource: 'engine_default',
|
|
105
|
+
...(cwe === undefined ? {} : { cwe }),
|
|
106
|
+
vulnKey: key,
|
|
107
|
+
location,
|
|
108
|
+
...(parameter === undefined ? {} : { parameter }),
|
|
109
|
+
...(remediation === undefined ? {} : { recommendation: stripHtml(remediation) }),
|
|
110
|
+
sourceEngine: 'burp',
|
|
111
|
+
sourceRuleId: type,
|
|
112
|
+
...(confidence === undefined ? {} : { confidence }),
|
|
113
|
+
createdAt: options.now,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return findings;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Burp's prose fields are HTML inside CDATA. */
|
|
121
|
+
function stripHtml(value: string): string {
|
|
122
|
+
return value
|
|
123
|
+
.replace(/<[^>]*>/gu, ' ')
|
|
124
|
+
.replace(/\s+/gu, ' ')
|
|
125
|
+
.trim();
|
|
126
|
+
}
|