@shieldaai/security-watch 1.2.0 → 1.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/CHANGELOG.md +40 -0
- package/README.md +5 -4
- package/SECURITY.md +4 -1
- package/dist/cli.js +192 -7
- package/dist/config.d.ts +22 -0
- package/dist/config.js +32 -0
- package/dist/cve-now.js +2 -0
- package/dist/delivery.js +30 -0
- package/dist/engine.d.ts +25 -0
- package/dist/engine.js +95 -6
- package/dist/heartbeat.js +4 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +3 -0
- package/dist/inventory.js +2 -2
- package/dist/manifests.js +23 -13
- package/dist/matching.js +6 -0
- package/dist/mitigations.d.ts +137 -0
- package/dist/mitigations.js +426 -0
- package/dist/operations.js +2 -1
- package/dist/rehearsal.d.ts +25 -0
- package/dist/rehearsal.js +2 -0
- package/dist/sbom.d.ts +12 -1
- package/dist/sbom.js +37 -7
- package/dist/shield-candidates.d.ts +97 -0
- package/dist/shield-candidates.js +251 -0
- package/dist/shield-inputs.d.ts +49 -0
- package/dist/shield-inputs.js +297 -0
- package/dist/shirudo-sboms.d.ts +62 -0
- package/dist/shirudo-sboms.js +598 -0
- package/dist/sources.js +10 -0
- package/dist/store.js +30 -12
- package/dist/types.d.ts +31 -0
- package/dist/vex.d.ts +62 -0
- package/dist/vex.js +246 -0
- package/docs/configuration.md +20 -1
- package/docs/mitigations.md +139 -0
- package/docs/offline-advisory-preview.md +2 -2
- package/docs/sbom.md +5 -5
- package/docs/shirudo.md +113 -0
- package/package.json +1 -1
package/dist/store.js
CHANGED
|
@@ -3,10 +3,14 @@ import { closeSync, constants, existsSync, linkSync, lstatSync, mkdirSync, mkdte
|
|
|
3
3
|
import { dirname, join, resolve } from 'node:path';
|
|
4
4
|
import { randomUUID } from 'node:crypto';
|
|
5
5
|
import { hash, canonicalHash } from './util.js';
|
|
6
|
+
import { evidenceContent } from './shield-inputs.js';
|
|
6
7
|
import { decide } from './assessment.js';
|
|
7
8
|
import { aggregatePilotReport, validatePilotWindow, PilotReportError, } from './pilot-report.js';
|
|
8
9
|
import { validateRetentionPolicy, } from './maintenance.js';
|
|
9
10
|
export const SCHEMA_VERSION = 7;
|
|
11
|
+
/** A queued notification held back while its finding waits for a new analysis. */
|
|
12
|
+
const HELD = 'Held for reassessment';
|
|
13
|
+
const OPEN = `(status='pending' OR (status='failed' AND last_error='${HELD}'))`;
|
|
10
14
|
function verifyFile(path) {
|
|
11
15
|
// Closing any descriptor for a live SQLite inode releases this process's POSIX locks.
|
|
12
16
|
// Inspect existing files without opening them, including when another Store is already open.
|
|
@@ -56,8 +60,8 @@ function notification(row) {
|
|
|
56
60
|
};
|
|
57
61
|
}
|
|
58
62
|
function evidenceFingerprint(evidence) {
|
|
59
|
-
|
|
60
|
-
return hash(
|
|
63
|
+
// Links, fix commits, weaknesses and exploit-code entries are shield inputs, not a new revision.
|
|
64
|
+
return hash(evidenceContent(evidence));
|
|
61
65
|
}
|
|
62
66
|
function fingerprint(a, decision) {
|
|
63
67
|
// Article wording, source arrival order and AI phrasing are not new security events.
|
|
@@ -388,8 +392,9 @@ export class Store {
|
|
|
388
392
|
: [];
|
|
389
393
|
// Where the finding lives (inventory names and notes) is shown to the reader; it is not part
|
|
390
394
|
// of the conclusion a reviewer approves, so editing a note does not ask for a new review.
|
|
391
|
-
// EPSS changes daily and
|
|
392
|
-
|
|
395
|
+
// EPSS changes daily and mitigation status with every export; both are shown only and are
|
|
396
|
+
// not part of the conclusion either.
|
|
397
|
+
const { updated_at: _updated, location: _location, epss: _epss, mitigations: _mitigations, ...reviewedAssessment } = assessment;
|
|
393
398
|
// Ordinary alert deduplication stays semantic. A human review instead binds the exact
|
|
394
399
|
// supplied conclusion, source content and host inventory/model context, excluding scan time.
|
|
395
400
|
const signature = decision.review
|
|
@@ -424,14 +429,14 @@ export class Store {
|
|
|
424
429
|
.run(assessment.id, revision, decision.review, JSON.stringify(references), now);
|
|
425
430
|
if (changed)
|
|
426
431
|
this.#db
|
|
427
|
-
.prepare(
|
|
432
|
+
.prepare(`UPDATE notifications SET status='failed',last_error='Superseded by a newer assessment' WHERE finding_id=? AND ${OPEN}`)
|
|
428
433
|
.run(assessment.id);
|
|
429
434
|
// A changed routing configuration can stop a pending delivery without creating a duplicate in retained channels.
|
|
430
435
|
const channels = decision.action === 'record' ? [] : [...new Set(decision.channels)];
|
|
431
436
|
for (const channel of ['slack', 'email'])
|
|
432
437
|
if (!channels.includes(channel)) {
|
|
433
438
|
this.#db
|
|
434
|
-
.prepare(
|
|
439
|
+
.prepare(`UPDATE notifications SET status='failed',last_error='Notification policy no longer selects this destination' WHERE finding_id=? AND channel=? AND ${OPEN}`)
|
|
435
440
|
.run(assessment.id, channel);
|
|
436
441
|
}
|
|
437
442
|
const payload = JSON.stringify({ assessment, reason: decision.reason, mode: decision.action });
|
|
@@ -449,8 +454,9 @@ export class Store {
|
|
|
449
454
|
this.#db
|
|
450
455
|
.prepare(`INSERT INTO notifications(id,finding_id,revision,channel,payload,status,available_at)
|
|
451
456
|
VALUES(?,?,?,?,?,'pending',?) ON CONFLICT(finding_id,revision,channel) DO UPDATE SET
|
|
452
|
-
payload=excluded.payload,status='pending',available_at=
|
|
453
|
-
|
|
457
|
+
payload=excluded.payload,status='pending',last_error=NULL,available_at=CASE WHEN notifications.last_error='${HELD}'
|
|
458
|
+
THEN notifications.available_at ELSE MAX(notifications.available_at,excluded.available_at) END
|
|
459
|
+
WHERE notifications.status='failed' AND notifications.last_error IN ('Notification policy no longer selects this destination','${HELD}')`)
|
|
454
460
|
.run(randomUUID(), assessment.id, revision, channel, payload, availableAt);
|
|
455
461
|
});
|
|
456
462
|
}
|
|
@@ -617,7 +623,7 @@ export class Store {
|
|
|
617
623
|
.prepare(`SELECT
|
|
618
624
|
SUM(CASE WHEN n.status='failed' AND COALESCE(n.last_error,'') NOT IN (
|
|
619
625
|
'Notification policy no longer selects this destination', 'Notification urgency changed under the current policy',
|
|
620
|
-
'Finding is no longer active', 'Superseded by a newer assessment', 'Finding acknowledged before delivery') THEN 1 ELSE 0 END) AS failed,
|
|
626
|
+
'Finding is no longer active', 'Superseded by a newer assessment', 'Finding acknowledged before delivery', '${HELD}') THEN 1 ELSE 0 END) AS failed,
|
|
621
627
|
SUM(CASE WHEN n.status='unknown' THEN 1 ELSE 0 END) AS unknown,
|
|
622
628
|
SUM(CASE WHEN n.status='pending' AND MAX(n.available_at,CASE WHEN n.channel='slack' THEN ? ELSE 0 END)<=? THEN 1 ELSE 0 END) AS overdue_pending
|
|
623
629
|
FROM notifications n JOIN findings f ON f.id=n.finding_id
|
|
@@ -740,6 +746,16 @@ export class Store {
|
|
|
740
746
|
.run(now, id);
|
|
741
747
|
});
|
|
742
748
|
}
|
|
749
|
+
/**
|
|
750
|
+
* Keep a finding's queued notifications from being sent until it is saved again. Saving the same
|
|
751
|
+
* revision queues them again with their schedule; a new revision supersedes them.
|
|
752
|
+
* @internal Used by the scan worker; not part of the public API.
|
|
753
|
+
*/
|
|
754
|
+
holdPending(findingId) {
|
|
755
|
+
this.#db
|
|
756
|
+
.prepare(`UPDATE notifications SET status='failed',last_error=? WHERE finding_id=? AND status='pending'`)
|
|
757
|
+
.run(HELD, findingId);
|
|
758
|
+
}
|
|
743
759
|
/** @internal Used by the scan and delivery workers; not part of the public API. */
|
|
744
760
|
recoverSending(now = Date.now()) {
|
|
745
761
|
this.#db
|
|
@@ -782,13 +798,15 @@ export class Store {
|
|
|
782
798
|
if (!Number.isSafeInteger(until) || until <= Date.now() || !reason.trim())
|
|
783
799
|
throw new Error('Suppression needs a future expiry and a reason');
|
|
784
800
|
this.#transaction(() => {
|
|
801
|
+
// A delivery held until an earlier expiry follows the new one, also when it is shorter.
|
|
802
|
+
this.#db
|
|
803
|
+
.prepare(`UPDATE notifications SET available_at=MAX(?,CASE WHEN available_at=(SELECT suppressed_until FROM findings WHERE id=?)
|
|
804
|
+
THEN 0 ELSE available_at END) WHERE finding_id=? AND status='pending'`)
|
|
805
|
+
.run(until, id, id);
|
|
785
806
|
if (!this.#db
|
|
786
807
|
.prepare('UPDATE findings SET suppressed_until=?,suppression_reason=? WHERE id=?')
|
|
787
808
|
.run(until, reason.trim(), id).changes)
|
|
788
809
|
throw new Error('Finding not found');
|
|
789
|
-
this.#db
|
|
790
|
-
.prepare("UPDATE notifications SET available_at=MAX(available_at,?) WHERE finding_id=? AND status='pending'")
|
|
791
|
-
.run(until, id);
|
|
792
810
|
});
|
|
793
811
|
}
|
|
794
812
|
/** @internal Used by the scan and delivery workers; not part of the public API. */
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ModelProvider, OutputFormat } from './providers.js';
|
|
2
2
|
import type { Ecosystem } from './ecosystems.js';
|
|
3
|
+
import type { MitigationSource, MitigationStatus } from './mitigations.js';
|
|
3
4
|
export type Severity = 'unknown' | 'low' | 'medium' | 'high' | 'critical';
|
|
4
5
|
export type Category = 'library' | 'product' | 'news' | 'malware' | 'health';
|
|
5
6
|
export type Applicability = 'affected' | 'not_affected' | 'unknown' | 'conflicting' | 'relevant';
|
|
@@ -155,6 +156,29 @@ export interface Evidence {
|
|
|
155
156
|
withdrawn?: boolean;
|
|
156
157
|
exploited?: boolean;
|
|
157
158
|
malware?: boolean;
|
|
159
|
+
/**
|
|
160
|
+
* Links the advisory publishes, most specific first. Inputs for whoever writes a fix or a runtime
|
|
161
|
+
* shield. Never sent to models; not part of the evidence content hash.
|
|
162
|
+
*/
|
|
163
|
+
references?: AdvisoryReference[];
|
|
164
|
+
/** Commits the advisory records as fixing the problem (OSV `GIT` ranges). Same rules as references. */
|
|
165
|
+
fix_commits?: FixCommit[];
|
|
166
|
+
/** Weakness identifiers such as CWE-502. Same rules as references. */
|
|
167
|
+
weaknesses?: string[];
|
|
168
|
+
/**
|
|
169
|
+
* Public exploit code the source reports, such as `exploit-db` or `github-poc` (cve.now). Published
|
|
170
|
+
* code, not exploitation in the wild. Same rules as references.
|
|
171
|
+
*/
|
|
172
|
+
exploit_sources?: string[];
|
|
173
|
+
}
|
|
174
|
+
export type ReferenceType = 'fix' | 'evidence' | 'advisory' | 'report' | 'detection' | 'introduced' | 'package' | 'source' | 'web';
|
|
175
|
+
export interface AdvisoryReference {
|
|
176
|
+
type: ReferenceType;
|
|
177
|
+
url: string;
|
|
178
|
+
}
|
|
179
|
+
export interface FixCommit {
|
|
180
|
+
repo: string;
|
|
181
|
+
commit: string;
|
|
158
182
|
}
|
|
159
183
|
export interface ModelSpec {
|
|
160
184
|
provider: ModelProvider;
|
|
@@ -247,6 +271,11 @@ export interface Config {
|
|
|
247
271
|
/** Required to listen beyond loopback without TLS, for example behind a TLS proxy. */
|
|
248
272
|
allow_plain_http: boolean;
|
|
249
273
|
};
|
|
274
|
+
/**
|
|
275
|
+
* Runtime mitigation status read from JSON Lines exports (Shirudo's `node_vulns`, or the generic
|
|
276
|
+
* format). Shown in alerts and `shield-candidates`; never changes applicability, priority or routing.
|
|
277
|
+
*/
|
|
278
|
+
mitigations?: MitigationSource[];
|
|
250
279
|
maintenance?: {
|
|
251
280
|
interval_hours: number;
|
|
252
281
|
retention?: {
|
|
@@ -278,6 +307,8 @@ export interface Assessment {
|
|
|
278
307
|
location?: FindingLocation;
|
|
279
308
|
/** EPSS for the finding's CVE when `sources.epss` is on. Shown only; changes nothing. */
|
|
280
309
|
epss?: EpssScore;
|
|
310
|
+
/** Runtime mitigation status, one per configured source that covers the system. Shown only; changes nothing. */
|
|
311
|
+
mitigations?: MitigationStatus[];
|
|
281
312
|
/** News-only or generic product context without deterministic package applicability. */
|
|
282
313
|
news_candidate?: boolean;
|
|
283
314
|
/**
|
package/dist/vex.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Assessment, Component, Evidence, Inventory } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* An OpenVEX v0.2.0 document for the findings Security Watch holds about installed libraries.
|
|
4
|
+
*
|
|
5
|
+
* A VEX statement says whether a product is affected by a vulnerability, so only findings that name
|
|
6
|
+
* one exact package version can be written. News, product and health findings have no package to
|
|
7
|
+
* point at and are counted as skipped, not guessed at.
|
|
8
|
+
*/
|
|
9
|
+
export interface VexInput {
|
|
10
|
+
findings: Assessment[];
|
|
11
|
+
evidence: (ids: readonly string[]) => Evidence[];
|
|
12
|
+
inventory: Inventory;
|
|
13
|
+
/** Only this system's findings. */
|
|
14
|
+
systemId?: string;
|
|
15
|
+
/** Also write `not_affected` statements. Default false: they are a claim consumers rely on. */
|
|
16
|
+
includeNotAffected?: boolean;
|
|
17
|
+
/** Default `Security Watch`. */
|
|
18
|
+
author?: string;
|
|
19
|
+
now?: number;
|
|
20
|
+
/** One line about runtime mitigations for a finding, from elsewhere. Appended to action statements. */
|
|
21
|
+
mitigationNote?: (finding: Assessment) => string | undefined;
|
|
22
|
+
}
|
|
23
|
+
export interface VexStatement {
|
|
24
|
+
vulnerability: {
|
|
25
|
+
name: string;
|
|
26
|
+
aliases?: string[];
|
|
27
|
+
};
|
|
28
|
+
products: {
|
|
29
|
+
'@id': string;
|
|
30
|
+
}[];
|
|
31
|
+
status: 'affected' | 'not_affected' | 'under_investigation';
|
|
32
|
+
/** Required by OpenVEX for `affected`. */
|
|
33
|
+
action_statement?: string;
|
|
34
|
+
/** OpenVEX requires a justification or an impact statement for `not_affected`. */
|
|
35
|
+
justification?: 'vulnerable_code_not_present';
|
|
36
|
+
impact_statement?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface VexDocument {
|
|
39
|
+
'@context': 'https://openvex.dev/ns/v0.2.0';
|
|
40
|
+
'@id': string;
|
|
41
|
+
author: string;
|
|
42
|
+
timestamp: string;
|
|
43
|
+
version: 1;
|
|
44
|
+
tooling: 'Security Watch';
|
|
45
|
+
statements: VexStatement[];
|
|
46
|
+
}
|
|
47
|
+
/** Undefined when the ecosystem has no package URL type or the name has no usable parts. */
|
|
48
|
+
export declare function buildPurl(component: Pick<Component, 'ecosystem' | 'name' | 'version'>): string | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* The inventory's package URL, made fit to publish: the type in lower case, only descriptive
|
|
51
|
+
* qualifiers, no subpath, a scoped npm `@` written as `%40`, and the component's version added when
|
|
52
|
+
* the URL has none. `mismatch` when its version is not the component's: the statement would be about
|
|
53
|
+
* another version. Nothing when it cannot be read; the caller builds one instead.
|
|
54
|
+
*/
|
|
55
|
+
export declare function publishablePurl(purl: string, version: string): {
|
|
56
|
+
purl?: string;
|
|
57
|
+
mismatch?: boolean;
|
|
58
|
+
};
|
|
59
|
+
export declare function openVex(input: VexInput): {
|
|
60
|
+
document: VexDocument;
|
|
61
|
+
skipped: Record<string, number>;
|
|
62
|
+
};
|
package/dist/vex.js
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { timestamp } from './util.js';
|
|
3
|
+
/** The package URL type for each ecosystem. This inverts the mapping the SBOM import reads. */
|
|
4
|
+
const PURL_TYPES = {
|
|
5
|
+
npm: 'npm',
|
|
6
|
+
PyPI: 'pypi',
|
|
7
|
+
Packagist: 'composer',
|
|
8
|
+
Go: 'golang',
|
|
9
|
+
Maven: 'maven',
|
|
10
|
+
'crates.io': 'cargo',
|
|
11
|
+
RubyGems: 'gem',
|
|
12
|
+
NuGet: 'nuget',
|
|
13
|
+
Hex: 'hex',
|
|
14
|
+
Pub: 'pub',
|
|
15
|
+
Hackage: 'hackage',
|
|
16
|
+
SwiftURL: 'swift',
|
|
17
|
+
};
|
|
18
|
+
/** The package URL specification encodes everything but unreserved characters; a colon stays as is. */
|
|
19
|
+
function encode(segment) {
|
|
20
|
+
return encodeURIComponent(segment)
|
|
21
|
+
.replace(/[!'()*]/g, (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`)
|
|
22
|
+
.replace(/%3A/gi, ':');
|
|
23
|
+
}
|
|
24
|
+
/** Undefined when the ecosystem has no package URL type or the name has no usable parts. */
|
|
25
|
+
export function buildPurl(component) {
|
|
26
|
+
const type = PURL_TYPES[component.ecosystem];
|
|
27
|
+
if (!type || !component.version)
|
|
28
|
+
return undefined;
|
|
29
|
+
let name = component.name;
|
|
30
|
+
// Maven names are group:artifact; the group is the namespace. Anything else is not a Maven name.
|
|
31
|
+
if (component.ecosystem === 'Maven') {
|
|
32
|
+
if (name.split(':').length !== 2)
|
|
33
|
+
return undefined;
|
|
34
|
+
name = name.replace(':', '/');
|
|
35
|
+
}
|
|
36
|
+
// The specification lowercases PyPI names and writes underscores as dashes, and lowercases the
|
|
37
|
+
// case-insensitive Composer, Hex and Pub names.
|
|
38
|
+
if (component.ecosystem === 'PyPI')
|
|
39
|
+
name = name.toLowerCase().replace(/_/g, '-');
|
|
40
|
+
if (component.ecosystem === 'Packagist' || component.ecosystem === 'Hex' || component.ecosystem === 'Pub')
|
|
41
|
+
name = name.toLowerCase();
|
|
42
|
+
const parts = name.split('/').filter((part) => part.length > 0);
|
|
43
|
+
if (parts.length === 0)
|
|
44
|
+
return undefined;
|
|
45
|
+
try {
|
|
46
|
+
return `pkg:${type}/${parts.map(encode).join('/')}@${encode(component.version)}`;
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// A lone surrogate cannot be encoded: the component is skipped, not the document.
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** The CVE, GHSA and other identifiers the finding's advisories publish, without the event itself. */
|
|
54
|
+
function aliasesOf(finding, evidence) {
|
|
55
|
+
const ids = new Set();
|
|
56
|
+
for (const item of evidence) {
|
|
57
|
+
// News only mentions identifiers; an advisory or the exploited-vulnerability catalog states them.
|
|
58
|
+
if (item.withdrawn || (item.kind !== 'advisory' && item.kind !== 'kev'))
|
|
59
|
+
continue;
|
|
60
|
+
for (const alias of item.aliases)
|
|
61
|
+
if (alias.trim())
|
|
62
|
+
ids.add(alias.trim());
|
|
63
|
+
}
|
|
64
|
+
ids.delete(finding.event_id);
|
|
65
|
+
return [...ids].sort();
|
|
66
|
+
}
|
|
67
|
+
function actionStatement(finding, name, note) {
|
|
68
|
+
const base = finding.category === 'malware'
|
|
69
|
+
? `Remove ${name}: it is reported as a malicious package.`
|
|
70
|
+
: finding.fix
|
|
71
|
+
? `Update ${name} to ${finding.fix}.`
|
|
72
|
+
: 'No fixed version is published; follow the advisory.';
|
|
73
|
+
const extra = note?.trim();
|
|
74
|
+
return extra ? `${base} ${extra}` : base;
|
|
75
|
+
}
|
|
76
|
+
/** The same statements give the same identifier, so an unchanged state is the same document. */
|
|
77
|
+
function documentId(author, statements) {
|
|
78
|
+
const hex = createHash('sha256').update(JSON.stringify({ author, statements })).digest('hex');
|
|
79
|
+
// Shaped as a version 4 UUID: version nibble 4, variant bits 10.
|
|
80
|
+
const variant = ((parseInt(hex[16], 16) & 0x3) | 0x8).toString(16);
|
|
81
|
+
return `urn:uuid:${hex.slice(0, 8)}-${hex.slice(8, 12)}-4${hex.slice(13, 16)}-${variant}${hex.slice(17, 20)}-${hex.slice(20, 32)}`;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Qualifiers that describe the package itself and are kept. Others (`repository_url`, `download_url`,
|
|
85
|
+
* `vcs_url`, a vendor's `registry=`) can name a private registry, and a VEX document is read outside.
|
|
86
|
+
*/
|
|
87
|
+
const PUBLIC_QUALIFIERS = new Set(['classifier', 'type', 'arch', 'distro', 'os', 'epoch']);
|
|
88
|
+
/**
|
|
89
|
+
* The inventory's package URL, made fit to publish: the type in lower case, only descriptive
|
|
90
|
+
* qualifiers, no subpath, a scoped npm `@` written as `%40`, and the component's version added when
|
|
91
|
+
* the URL has none. `mismatch` when its version is not the component's: the statement would be about
|
|
92
|
+
* another version. Nothing when it cannot be read; the caller builds one instead.
|
|
93
|
+
*/
|
|
94
|
+
export function publishablePurl(purl, version) {
|
|
95
|
+
const text = purl.trim().split('#')[0];
|
|
96
|
+
const [head, query] = text.split('?', 2);
|
|
97
|
+
const match = /^pkg:([A-Za-z][A-Za-z0-9.+-]*)\/(.+)$/.exec(head);
|
|
98
|
+
if (!match)
|
|
99
|
+
return {};
|
|
100
|
+
const [, type, rest] = match;
|
|
101
|
+
// The version follows the last @ after the last slash; an @ that starts a namespace is part of it.
|
|
102
|
+
const slash = rest.lastIndexOf('/');
|
|
103
|
+
const at = rest.lastIndexOf('@');
|
|
104
|
+
const path = at > slash && at > 0 ? rest.slice(0, at) : rest;
|
|
105
|
+
const given = at > slash && at > 0 ? rest.slice(at + 1) : undefined;
|
|
106
|
+
if (!path || path.split('/').some((part) => !part))
|
|
107
|
+
return {};
|
|
108
|
+
let decoded;
|
|
109
|
+
try {
|
|
110
|
+
decoded = given === undefined ? undefined : decodeURIComponent(given);
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return {};
|
|
114
|
+
}
|
|
115
|
+
if (decoded !== undefined && decoded !== version)
|
|
116
|
+
return { mismatch: true };
|
|
117
|
+
const qualifiers = (query ?? '')
|
|
118
|
+
.split('&')
|
|
119
|
+
.filter((pair) => PUBLIC_QUALIFIERS.has(pair.split('=')[0].toLowerCase()) && pair.includes('='))
|
|
120
|
+
.sort();
|
|
121
|
+
try {
|
|
122
|
+
const namespace = path.replace(/^@/, '%40');
|
|
123
|
+
return {
|
|
124
|
+
purl: `pkg:${type.toLowerCase()}/${namespace}@${given ?? encode(version)}${qualifiers.length ? `?${qualifiers.join('&')}` : ''}`,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return {};
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const STATUS_ORDER = {
|
|
132
|
+
affected: 0,
|
|
133
|
+
under_investigation: 1,
|
|
134
|
+
not_affected: 2,
|
|
135
|
+
};
|
|
136
|
+
function compare(first, second) {
|
|
137
|
+
return first < second ? -1 : first > second ? 1 : 0;
|
|
138
|
+
}
|
|
139
|
+
export function openVex(input) {
|
|
140
|
+
const skipped = {};
|
|
141
|
+
const skip = (reason) => {
|
|
142
|
+
skipped[reason] = (skipped[reason] ?? 0) + 1;
|
|
143
|
+
};
|
|
144
|
+
const components = new Map(input.inventory.systems.map((system) => [
|
|
145
|
+
system.id,
|
|
146
|
+
new Map(system.components.map((item) => [item.id, item])),
|
|
147
|
+
]));
|
|
148
|
+
const statements = [];
|
|
149
|
+
for (const finding of input.findings) {
|
|
150
|
+
if (input.systemId !== undefined && finding.system_id !== input.systemId)
|
|
151
|
+
continue;
|
|
152
|
+
if (finding.active === false || finding.withdrawn) {
|
|
153
|
+
skip('inactive');
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (finding.category !== 'library' && finding.category !== 'malware') {
|
|
157
|
+
skip('not_library');
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
const component = finding.component_id
|
|
161
|
+
? components.get(finding.system_id)?.get(finding.component_id)
|
|
162
|
+
: undefined;
|
|
163
|
+
if (!component) {
|
|
164
|
+
skip('no_component');
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
if (!component.version) {
|
|
168
|
+
skip('no_version');
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
// The inventory's own package URL is what other tools match on, so it is kept, made fit to publish.
|
|
172
|
+
// The inventory's own package URL when it can be published, else one built from the component.
|
|
173
|
+
const published = component.purl?.trim() ? publishablePurl(component.purl, component.version) : {};
|
|
174
|
+
if (published.mismatch) {
|
|
175
|
+
skip('purl_version_mismatch');
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
const purl = published.purl ?? buildPurl(component);
|
|
179
|
+
if (!purl) {
|
|
180
|
+
skip('no_purl_type');
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
const vulnerability = { name: finding.event_id };
|
|
184
|
+
const aliases = aliasesOf(finding, input.evidence(finding.evidence_ids));
|
|
185
|
+
if (aliases.length > 0)
|
|
186
|
+
vulnerability.aliases = aliases;
|
|
187
|
+
// Statements carry no time of their own (they inherit the document's), so an unchanged state
|
|
188
|
+
// gives the same statements and the same document identifier on every run.
|
|
189
|
+
const base = { vulnerability, products: [{ '@id': purl }] };
|
|
190
|
+
if (finding.applicability === 'affected') {
|
|
191
|
+
statements.push({
|
|
192
|
+
...base,
|
|
193
|
+
status: 'affected',
|
|
194
|
+
action_statement: actionStatement(finding, component.name, input.mitigationNote?.(finding)),
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
else if (finding.applicability === 'unknown' || finding.applicability === 'conflicting') {
|
|
198
|
+
statements.push({ ...base, status: 'under_investigation' });
|
|
199
|
+
}
|
|
200
|
+
else if (finding.applicability === 'not_affected') {
|
|
201
|
+
if (!input.includeNotAffected) {
|
|
202
|
+
skip('not_affected_omitted');
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
statements.push({
|
|
206
|
+
...base,
|
|
207
|
+
status: 'not_affected',
|
|
208
|
+
justification: 'vulnerable_code_not_present',
|
|
209
|
+
impact_statement: 'The installed version is outside the affected versions the advisories publish.',
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
skip('applicability_not_reportable');
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
// The same package version in several systems is one statement. When systems disagree, the most
|
|
217
|
+
// severe status stands (affected, then under investigation, then not affected): a consumer must
|
|
218
|
+
// never hide a vulnerability that one of the systems is affected by.
|
|
219
|
+
const byProduct = new Map();
|
|
220
|
+
for (const statement of statements) {
|
|
221
|
+
const key = `${statement.vulnerability.name}\u0000${statement.products[0]['@id']}`;
|
|
222
|
+
const known = byProduct.get(key);
|
|
223
|
+
if (!known ||
|
|
224
|
+
STATUS_ORDER[statement.status] < STATUS_ORDER[known.status] ||
|
|
225
|
+
(statement.status === known.status &&
|
|
226
|
+
compare(statement.action_statement ?? '', known.action_statement ?? '') < 0))
|
|
227
|
+
byProduct.set(key, statement);
|
|
228
|
+
}
|
|
229
|
+
statements.length = 0;
|
|
230
|
+
statements.push(...byProduct.values());
|
|
231
|
+
statements.sort((a, b) => compare(a.vulnerability.name, b.vulnerability.name) ||
|
|
232
|
+
compare(a.products[0]['@id'], b.products[0]['@id']));
|
|
233
|
+
const author = input.author ?? 'Security Watch';
|
|
234
|
+
return {
|
|
235
|
+
document: {
|
|
236
|
+
'@context': 'https://openvex.dev/ns/v0.2.0',
|
|
237
|
+
'@id': documentId(author, statements),
|
|
238
|
+
author,
|
|
239
|
+
timestamp: timestamp(input.now),
|
|
240
|
+
version: 1,
|
|
241
|
+
tooling: 'Security Watch',
|
|
242
|
+
statements,
|
|
243
|
+
},
|
|
244
|
+
skipped,
|
|
245
|
+
};
|
|
246
|
+
}
|
package/docs/configuration.md
CHANGED
|
@@ -267,6 +267,25 @@ For an existing installation, configuration fields set to `true` stay enabled. T
|
|
|
267
267
|
|
|
268
268
|
References: [cve.now machine-readable API guide](https://cve.now/llms.txt), [The Hacker News](https://thehackernews.com/), [OSV batch queries](https://google.github.io/osv.dev/post-v1-querybatch/), [GitHub global advisory API](https://docs.github.com/en/rest/security-advisories/global-advisories), [CISA KEV data](https://github.com/cisagov/kev-data).
|
|
269
269
|
|
|
270
|
+
## Temporary mitigations
|
|
271
|
+
|
|
272
|
+
Advisories from OSV and GitHub keep their typed links (fix commits, pull requests and patches first), OSV's fix commits and both sources' CWE identifiers; cve.now records keep their Exploit-DB, Metasploit, Nuclei and GitHub proof-of-concept entries. Only https links without credentials are kept, at most 40 links, 20 commits and 20 weaknesses per advisory. They are never sent to models and are not part of an advisory's revision. `explain` shows them per advisory.
|
|
273
|
+
|
|
274
|
+
`security-watch shield-candidates [--all] [--unmitigated] [--omit-location] [--output NEW.json]` lists the findings worth a temporary mitigation, with a `readiness` from `fix_known` to `news_only` and what is still `missing`. `security-watch vex [--system ID] [--include-not-affected] [--omit-mitigations] [--author TEXT] [--output NEW.json]` writes an OpenVEX document. Both read the database and change nothing.
|
|
275
|
+
|
|
276
|
+
An optional `mitigations` list (at most ten) shows how many hosts of an affected system a mitigation covers, read from JSON Lines files that your tools write:
|
|
277
|
+
|
|
278
|
+
```yaml
|
|
279
|
+
mitigations:
|
|
280
|
+
- format: shirudo # shirudo (Shirudo's node_vulns export) or generic
|
|
281
|
+
file: ./shirudo/node-vulns.jsonl # relative to this file
|
|
282
|
+
name: Shirudo # optional; default Shirudo or Mitigations; unique
|
|
283
|
+
max_age_minutes: 120 # 5 to 10080; an older file is a monitoring-health error
|
|
284
|
+
systems: {} # the file's system key -> system ID; an unmapped key is the system ID
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
The status is shown in alerts, digests, `explain`, `findings`, `shield-candidates` and `vex` as `mitigations`. Like EPSS it is shown only: it changes no applicability, priority, rule or decision, creates no revision and never closes a finding. Files are limited to 64 MiB and 500,000 rows. See [temporary mitigations](mitigations.md) for the generic format, and [Security Watch with Shirudo](shirudo.md) for the export query and `shirudo-sboms`.
|
|
288
|
+
|
|
270
289
|
## Model configuration
|
|
271
290
|
|
|
272
291
|
Before enabling real delivery, [offline rehearsal](offline-rehearsal.md) can replay a bounded sequence of normalized evidence and optional inventory snapshots through the existing policy, queue and simulated delivery transports. It preserves configured channel selection while replacing destinations with in-process sinks, forces models/sources off, and verifies a temporary SQLite backup/restore. The command does not load credentials or open the configured database. Its private report omits raw identifiers, source text and destinations; it does not measure live coverage or model/analyst quality.
|
|
@@ -622,7 +641,7 @@ systems:
|
|
|
622
641
|
LANGFLOW_WEBHOOK_AUTH_ENABLE: true
|
|
623
642
|
```
|
|
624
643
|
|
|
625
|
-
`sbom` imports a local CycloneDX JSON 1.
|
|
644
|
+
`sbom` imports a local CycloneDX JSON 1.2 to 1.7 file (a later 1.x is read by the 1.7 rules, with a notice), or an SPDX JSON 2.2 or 2.3 file (including
|
|
626
645
|
GitHub's `{"sbom": ...}` API response). To have every SBOM in a folder become a system of its own, set
|
|
627
646
|
`sbom_directory` at the top of the inventory instead; see [the SBOM folder](sbom.md#the-sbom-folder).
|
|
628
647
|
`security-watch sbom` writes such a file from a project's lockfiles ([guide](sbom.md)). A component's
|