@shieldaai/security-watch 1.2.1 → 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 +24 -0
- package/README.md +5 -4
- package/SECURITY.md +4 -1
- package/dist/cli.js +186 -4
- 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 +64 -4
- package/dist/index.d.ts +8 -1
- package/dist/index.js +3 -0
- package/dist/inventory.js +1 -1
- package/dist/mitigations.d.ts +137 -0
- package/dist/mitigations.js +426 -0
- 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 +6 -4
- 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 +4 -4
- package/docs/shirudo.md +113 -0
- package/package.json +1 -1
package/dist/engine.js
CHANGED
|
@@ -4,6 +4,8 @@ import { cvssV4BaseScore } from './cvss4.js';
|
|
|
4
4
|
import { assess, decide } from './assessment.js';
|
|
5
5
|
import { collectSources } from './sources.js';
|
|
6
6
|
import { attachEpss, findingCves, readEpssCache, refreshEpss } from './epss.js';
|
|
7
|
+
import { evidenceContent } from './shield-inputs.js';
|
|
8
|
+
import { attachMitigations, exportProblems, MitigationIndex, readMitigationExport, unmatchedSystems, } from './mitigations.js';
|
|
7
9
|
import { attachLocation, attachRemediation, compareInventories } from './inventory-evidence.js';
|
|
8
10
|
import { ModelAnalyzer, PROMPT_VERSION } from './models.js';
|
|
9
11
|
import { Store } from './store.js';
|
|
@@ -58,6 +60,38 @@ export const evidenceSchema = z
|
|
|
58
60
|
withdrawn: z.boolean().optional(),
|
|
59
61
|
exploited: z.boolean().optional(),
|
|
60
62
|
malware: z.boolean().optional(),
|
|
63
|
+
references: z
|
|
64
|
+
.array(z.strictObject({
|
|
65
|
+
type: z.enum([
|
|
66
|
+
'fix',
|
|
67
|
+
'evidence',
|
|
68
|
+
'advisory',
|
|
69
|
+
'report',
|
|
70
|
+
'detection',
|
|
71
|
+
'introduced',
|
|
72
|
+
'package',
|
|
73
|
+
'source',
|
|
74
|
+
'web',
|
|
75
|
+
]),
|
|
76
|
+
url: z.url({ protocol: /^https$/ }).max(2048),
|
|
77
|
+
}))
|
|
78
|
+
.max(40)
|
|
79
|
+
.optional(),
|
|
80
|
+
fix_commits: z
|
|
81
|
+
.array(z.strictObject({
|
|
82
|
+
repo: z.url({ protocol: /^https$/ }).max(2048),
|
|
83
|
+
commit: z.string().regex(/^[0-9a-f]{7,64}$/),
|
|
84
|
+
}))
|
|
85
|
+
.max(20)
|
|
86
|
+
.optional(),
|
|
87
|
+
weaknesses: z
|
|
88
|
+
.array(z.string().regex(/^CWE-\d{1,5}$/))
|
|
89
|
+
.max(20)
|
|
90
|
+
.optional(),
|
|
91
|
+
exploit_sources: z
|
|
92
|
+
.array(z.enum(['exploit-db', 'metasploit', 'nuclei', 'github-poc']))
|
|
93
|
+
.max(4)
|
|
94
|
+
.optional(),
|
|
61
95
|
})
|
|
62
96
|
.strict();
|
|
63
97
|
export function readFixture(path) {
|
|
@@ -148,8 +182,32 @@ export async function runScan(options) {
|
|
|
148
182
|
// its revision and review: a score that changes daily must not re-send, reopen or re-analyse.
|
|
149
183
|
let epssCache = config.sources.epss ? readEpssCache(store.getMeta('epss:cache')) : {};
|
|
150
184
|
let epssEvidence = new Map(remediationEvidence.map((item) => [item.id, item]));
|
|
185
|
+
// Runtime mitigation status is read from the operator's export files and, like EPSS, is shown only.
|
|
186
|
+
const mitigationProblems = [];
|
|
187
|
+
const mitigationIndexes = [];
|
|
188
|
+
for (const source of config.mitigations ?? [])
|
|
189
|
+
try {
|
|
190
|
+
const exported = readMitigationExport(source, now);
|
|
191
|
+
mitigationIndexes.push(new MitigationIndex(exported, source));
|
|
192
|
+
const messages = exportProblems(exported, source, now);
|
|
193
|
+
// Rows that all miss the inventory are a mapping mistake (an image watched under another
|
|
194
|
+
// system ID, a typo in systems:), not a fleet without findings.
|
|
195
|
+
const missed = unmatchedSystems(exported, source, new Set(inventory.systems.map((system) => system.id)));
|
|
196
|
+
if (exported.rows.length && missed.length === new Set(exported.rows.map((row) => row.system)).size)
|
|
197
|
+
messages.push(`${source.name}: no system key in the export is a system in the inventory (${missed.slice(0, 5).join(', ')}${missed.length > 5 ? ', …' : ''}); map them with systems: or watch those systems.`);
|
|
198
|
+
for (const message of messages)
|
|
199
|
+
mitigationProblems.push({ source: `mitigations:${source.name}`, message });
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
mitigationProblems.push({
|
|
203
|
+
source: `mitigations:${source.name}`,
|
|
204
|
+
message: `${source.name}: the export could not be read, so its mitigation status is not shown: ${error.code === 'ENOENT'
|
|
205
|
+
? 'the file does not exist'
|
|
206
|
+
: error.message}.`,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
151
209
|
const persist = (assessment) => {
|
|
152
|
-
assessment = attachEpss(attachLocation(attachRemediation(assessment, inventory, remediationEvidence, config, now), inventory), epssCache, findingCves(assessment, epssEvidence));
|
|
210
|
+
assessment = attachMitigations(attachEpss(attachLocation(attachRemediation(assessment, inventory, remediationEvidence, config, now), inventory), epssCache, findingCves(assessment, epssEvidence)), mitigationIndexes, epssEvidence, inventory);
|
|
153
211
|
const decision = decide(assessment, config);
|
|
154
212
|
decisions[assessment.id] = decision;
|
|
155
213
|
store.saveAssessment(assessment, decision, now, config.digest_interval_hours * 3_600_000, decision.review
|
|
@@ -161,8 +219,8 @@ export async function runScan(options) {
|
|
|
161
219
|
: undefined);
|
|
162
220
|
};
|
|
163
221
|
const retire = (previous) => {
|
|
164
|
-
// A retired finding is not looked up any more; an ageing score would only mislead.
|
|
165
|
-
const { epss: _epss, ...assessment } = previous;
|
|
222
|
+
// A retired finding is not looked up any more; an ageing score or shield status would only mislead.
|
|
223
|
+
const { epss: _epss, mitigations: _mitigations, ...assessment } = previous;
|
|
166
224
|
store.saveAssessment({
|
|
167
225
|
...assessment,
|
|
168
226
|
active: false,
|
|
@@ -204,7 +262,8 @@ export async function runScan(options) {
|
|
|
204
262
|
const item = evidenceById.get(id);
|
|
205
263
|
if (!item)
|
|
206
264
|
return null;
|
|
207
|
-
|
|
265
|
+
// Shield inputs (links, commits, weaknesses) are never analysed, so they never ask for analysis.
|
|
266
|
+
const content = evidenceContent(item);
|
|
208
267
|
const fetched = Date.parse(item.fetched_at);
|
|
209
268
|
return {
|
|
210
269
|
...content,
|
|
@@ -296,6 +355,7 @@ export async function runScan(options) {
|
|
|
296
355
|
...result.errors,
|
|
297
356
|
...(inventory.import_warnings ?? []).map((message) => ({ source: 'inventory:sbom', message })),
|
|
298
357
|
];
|
|
358
|
+
errors.push(...mitigationProblems);
|
|
299
359
|
const notices = [...(inventory.name_notices ?? [])];
|
|
300
360
|
if (!options.fixture && missingCredentials(config).length)
|
|
301
361
|
errors.push({
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
export type { Severity, Category, Applicability, Channel, Provenance, DeploymentObservation, ArtifactKind, DeclaredVerification, DependencyLink, DependencyRelationship, DeclaredRemediation, InventoryEvidence, Component, Product, FindingLocation, System, Inventory, PackageClaim, CvssV4BaseScore, Evidence, ModelSpec, Config, Rule, Assessment, AiReviewReason, AiReview, Decision, Notification, HttpOptions, HttpResult, HttpClient, CoverageReceipt, InventoryDrift, RemediationEvidence, SourceResult, AiAnalysis, NewsAnalysis, NewsSignals, NewsStatement, EpssScore, } from './types.js';
|
|
1
|
+
export type { Severity, Category, Applicability, Channel, Provenance, DeploymentObservation, ArtifactKind, DeclaredVerification, DependencyLink, DependencyRelationship, DeclaredRemediation, InventoryEvidence, Component, Product, FindingLocation, System, Inventory, PackageClaim, CvssV4BaseScore, Evidence, ModelSpec, Config, Rule, Assessment, AiReviewReason, AiReview, Decision, Notification, HttpOptions, HttpResult, HttpClient, CoverageReceipt, InventoryDrift, RemediationEvidence, SourceResult, AiAnalysis, NewsAnalysis, NewsSignals, NewsStatement, EpssScore, AdvisoryReference, FixCommit, ReferenceType, } from './types.js';
|
|
2
|
+
export { shieldCandidates } from './shield-candidates.js';
|
|
3
|
+
export type { ShieldCandidate, ShieldCandidateReport, ShieldCandidateInput, ShieldReadiness, FindingControls, } from './shield-candidates.js';
|
|
4
|
+
export type { MitigationStatus, MitigationState, MitigationSource, MitigationFormat } from './mitigations.js';
|
|
5
|
+
export { openVex } from './vex.js';
|
|
6
|
+
export type { VexInput, VexDocument, VexStatement } from './vex.js';
|
|
7
|
+
export { syncShirudoSboms } from './shirudo-sboms.js';
|
|
8
|
+
export type { ShirudoSyncOptions, ShirudoSyncPlan, ShirudoSyncImage } from './shirudo-sboms.js';
|
|
2
9
|
export { scorePilotResponses, type PilotResponseRegister, type PilotResponseScore, } from './pilot-responses.js';
|
|
3
10
|
export { loadConfig, parseConfig, configSchema } from './config.js';
|
|
4
11
|
export { loadInventory } from './inventory.js';
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export { shieldCandidates } from './shield-candidates.js';
|
|
2
|
+
export { openVex } from './vex.js';
|
|
3
|
+
export { syncShirudoSboms } from './shirudo-sboms.js';
|
|
1
4
|
export { scorePilotResponses, } from './pilot-responses.js';
|
|
2
5
|
export { loadConfig, parseConfig, configSchema } from './config.js';
|
|
3
6
|
export { loadInventory } from './inventory.js';
|
package/dist/inventory.js
CHANGED
|
@@ -278,7 +278,7 @@ export function systemFromSbom(path, file, label) {
|
|
|
278
278
|
// data), which is a known limit rather than a fault, so it is said once as a notice instead of
|
|
279
279
|
// degrading every scan, together with the dependency edges that lead to them.
|
|
280
280
|
const warnings = [];
|
|
281
|
-
const notices = [];
|
|
281
|
+
const notices = (imported.notices ?? []).map((notice) => `${id}: ${notice}`);
|
|
282
282
|
const unmatched = new Map();
|
|
283
283
|
for (const warning of imported.warnings) {
|
|
284
284
|
const kind = UNMATCHED_KIND.exec(warning)?.[1]?.toLowerCase();
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type { Assessment, Evidence, Inventory } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Runtime mitigation status (a shield, a blocking policy, a firewall rule, a live patch) read from
|
|
4
|
+
* JSON Lines files that the operator writes on a timer: Shirudo's `node_vulns` export, or the generic
|
|
5
|
+
* format any tool can produce. Security Watch never connects to the tool and holds no credential for it.
|
|
6
|
+
*
|
|
7
|
+
* The status is shown only, like EPSS: it never changes applicability, priority, routing or a
|
|
8
|
+
* finding's revision, and a mitigation never closes a finding. It is temporary; the fix is not.
|
|
9
|
+
*/
|
|
10
|
+
export declare const MITIGATION_STATES: readonly ['mitigated', 'pending', 'failed', 'excluded', 'withdrawn', 'expired', 'unmitigated', 'unknown'];
|
|
11
|
+
export type MitigationState = (typeof MITIGATION_STATES)[number];
|
|
12
|
+
export type MitigationFormat = 'shirudo' | 'generic';
|
|
13
|
+
/** One host's state for one finding, from either format. */
|
|
14
|
+
export interface MitigationRow {
|
|
15
|
+
/** The system key: Shirudo's image ID, or the generic `system_id`; `systems` maps it to a system ID. */
|
|
16
|
+
system: string;
|
|
17
|
+
host: string;
|
|
18
|
+
/** The advisory identifier (CVE, GHSA, ...), upper case; empty for a `none` row. */
|
|
19
|
+
identifier: string;
|
|
20
|
+
package?: string;
|
|
21
|
+
/** A kernel row matches by identifier alone. */
|
|
22
|
+
kernel?: boolean;
|
|
23
|
+
/** `none`: a host with nothing to report, counted among the hosts of its system. */
|
|
24
|
+
state: MitigationState | 'none';
|
|
25
|
+
/** The shield, policy or patch that mitigates it. */
|
|
26
|
+
mitigation?: string;
|
|
27
|
+
/** When a mitigated or pending row stops counting, in milliseconds (generic `expires_at`). */
|
|
28
|
+
expires?: number;
|
|
29
|
+
}
|
|
30
|
+
export interface MitigationSource {
|
|
31
|
+
/** Shown in alerts. Unique among sources. */
|
|
32
|
+
name: string;
|
|
33
|
+
format: MitigationFormat;
|
|
34
|
+
file: string;
|
|
35
|
+
max_age_minutes: number;
|
|
36
|
+
/** Row system key to Security Watch system ID; an unmapped key is the system ID. */
|
|
37
|
+
systems: Record<string, string>;
|
|
38
|
+
}
|
|
39
|
+
export interface MitigationExport {
|
|
40
|
+
/** The file's modification time. */
|
|
41
|
+
exported_at: string;
|
|
42
|
+
stale: boolean;
|
|
43
|
+
rows: MitigationRow[];
|
|
44
|
+
/** Lines that could not be read, with the first reason. */
|
|
45
|
+
skipped: number;
|
|
46
|
+
first_problem?: string;
|
|
47
|
+
/** Rows with a status or exposure value this release does not know; read as `unknown`. */
|
|
48
|
+
unknown_values: number;
|
|
49
|
+
/** Shirudo rows of machines bound to no image: they belong to no system and are left out. */
|
|
50
|
+
unbound: number;
|
|
51
|
+
}
|
|
52
|
+
/** What one source reports for one finding across the hosts running the finding's system. */
|
|
53
|
+
export interface MitigationStatus {
|
|
54
|
+
/** The source's `name`. */
|
|
55
|
+
source: string;
|
|
56
|
+
format: MitigationFormat;
|
|
57
|
+
exported_at: string;
|
|
58
|
+
/** The export is older than the source's `max_age_minutes`. */
|
|
59
|
+
stale: boolean;
|
|
60
|
+
/** Hosts of the system in the export. */
|
|
61
|
+
hosts: number;
|
|
62
|
+
/** Hosts per state, each host counted once by its worst row for this finding. */
|
|
63
|
+
states: Partial<Record<MitigationState, number>>;
|
|
64
|
+
/** The source has no row for this finding on those hosts: it does not know about it. */
|
|
65
|
+
not_listed?: boolean;
|
|
66
|
+
/** Mitigations in place or waiting to load. A withdrawn, expired or failed one is not named. */
|
|
67
|
+
mitigations: string[];
|
|
68
|
+
/** The earliest time a mitigation counted here expires; after it, `mitigated` is no longer proven. */
|
|
69
|
+
expires_at?: string;
|
|
70
|
+
/**
|
|
71
|
+
* Why `stale` is true when it was set on reading rather than at the scan: the export is now older than
|
|
72
|
+
* the source's limit, the source is no longer configured, or a mitigation counted here has expired.
|
|
73
|
+
*/
|
|
74
|
+
stale_reason?: 'old_export' | 'source_removed' | 'expired';
|
|
75
|
+
/** One line for people. */
|
|
76
|
+
summary: string;
|
|
77
|
+
}
|
|
78
|
+
export declare const MAX_EXPORT_BYTES: number;
|
|
79
|
+
export declare const MAX_EXPORT_ROWS = 500000;
|
|
80
|
+
/** A row and whether one of its values was one this release does not know. */
|
|
81
|
+
type Parsed = {
|
|
82
|
+
row: MitigationRow;
|
|
83
|
+
unknown_value: boolean;
|
|
84
|
+
} | {
|
|
85
|
+
unbound: true;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* One line of a Shirudo `node_vulns` export; throws with a short reason when it is not one. A node
|
|
89
|
+
* that has stopped reporting (`status: stale`) proves nothing about its shields: its rows are
|
|
90
|
+
* `unknown`. A row of a node bound to no image belongs to no system and is set aside.
|
|
91
|
+
*/
|
|
92
|
+
export declare function parseShirudoRow(line: string): Parsed;
|
|
93
|
+
/**
|
|
94
|
+
* One line of the generic format:
|
|
95
|
+
* `{"system_id", "host", "identifier", "package"?, "kernel"?, "status", "mitigation"?, "expires_at"?}`.
|
|
96
|
+
* A mitigated or pending row whose `expires_at` has passed is `expired`.
|
|
97
|
+
*/
|
|
98
|
+
export declare function parseGenericRow(line: string, now: number): Parsed;
|
|
99
|
+
/**
|
|
100
|
+
* Reads an export. Throws when the file is missing, not a regular file, too large, not UTF-8 text or
|
|
101
|
+
* has no readable row at all; individual bad lines are skipped and counted, so one odd row never
|
|
102
|
+
* hides the rest.
|
|
103
|
+
*/
|
|
104
|
+
export declare function readMitigationExport(source: MitigationSource, now: number): MitigationExport;
|
|
105
|
+
/** Problems with an export that should reach monitoring health. */
|
|
106
|
+
export declare function exportProblems(exported: MitigationExport, source: MitigationSource, now: number): string[];
|
|
107
|
+
/** Whether an export says anything about the inventory's systems: rows that all miss is a mapping mistake. */
|
|
108
|
+
export declare function unmatchedSystems(exported: MitigationExport, source: MitigationSource, systemIds: ReadonlySet<string>): string[];
|
|
109
|
+
/**
|
|
110
|
+
* Finds one source's rows for a finding: rows whose system key belongs to the finding's system, whose
|
|
111
|
+
* identifier is the finding's event or one of its current advisories' aliases, and, for a library
|
|
112
|
+
* finding, whose package is the finding's package. A row without a package says nothing about a
|
|
113
|
+
* library (one CVE can name several packages); a kernel row matches by identifier alone.
|
|
114
|
+
*/
|
|
115
|
+
export declare class MitigationIndex {
|
|
116
|
+
#private;
|
|
117
|
+
constructor(exported: MitigationExport, source: MitigationSource);
|
|
118
|
+
status(finding: Assessment, evidence: Map<string, Evidence>, inventory?: Inventory): MitigationStatus | undefined;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Whether a status proves that every host it covers is mitigated now: fresh, listed, all hosts
|
|
122
|
+
* mitigated, and no counted mitigation expired since the export.
|
|
123
|
+
*/
|
|
124
|
+
export declare function mitigatedEverywhere(status: MitigationStatus, now?: number): boolean;
|
|
125
|
+
/**
|
|
126
|
+
* A saved status as it stands now. Statuses are saved at each scan; when scans stop, or a mitigation
|
|
127
|
+
* expires between scans, a reader must not show the saved one as current. `maxAgeByName` holds each
|
|
128
|
+
* configured source's `max_age_minutes`; a source that is no longer configured proves nothing.
|
|
129
|
+
*/
|
|
130
|
+
export declare function currentStatus(status: MitigationStatus, maxAgeByName: Readonly<Record<string, number>> | undefined, now: number): MitigationStatus;
|
|
131
|
+
/** A finding with its saved statuses as they stand now. */
|
|
132
|
+
export declare function withCurrentMitigations<T extends Assessment>(finding: T, maxAgeByName: Readonly<Record<string, number>> | undefined, now: number): T;
|
|
133
|
+
/** Each configured source's limit, by name, for `currentStatus`. */
|
|
134
|
+
export declare function maxAges(sources: readonly MitigationSource[] | undefined): Record<string, number>;
|
|
135
|
+
/** Attaches the current statuses, or removes earlier ones when there are none now. */
|
|
136
|
+
export declare function attachMitigations(finding: Assessment, indexes: readonly MitigationIndex[], evidence: Map<string, Evidence>, inventory?: Inventory): Assessment;
|
|
137
|
+
export {};
|