@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/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
- const { fetched_at: _fetched, ...content } = item;
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,
@@ -235,6 +294,35 @@ export async function runScan(options) {
235
294
  }
236
295
  return canRetainPriority(previous, finding) ? { ...finding, priority: previous.priority } : finding;
237
296
  };
297
+ // Before analysis, a news finding whose basis changed loses its previous analysis. Saving it so
298
+ // would make a new revision, and the same conclusion after analysis would be sent again.
299
+ const reconcile = (finding, basisHash) => {
300
+ const current = interim(finding, basisHash);
301
+ const previous = previousById.get(finding.id);
302
+ if (!config.models.enabled ||
303
+ !previous?.ai ||
304
+ previous.active === false ||
305
+ current.ai ||
306
+ !(current.news_candidate || current.news_only) ||
307
+ current.applicability === 'not_affected' ||
308
+ current.withdrawn)
309
+ return persist(current);
310
+ const decision = decide(current, config);
311
+ // Its routing waits for the model: hold its queued notifications, so that an old conclusion
312
+ // cannot escape meanwhile, and send them if analysis confirms it.
313
+ if (decision.action === 'record')
314
+ return store.holdPending(finding.id);
315
+ // Routing that does not depend on the model (an override, a source severity) is applied at
316
+ // once; the previous analysis is shown until it is redone.
317
+ const kept = {
318
+ ...current,
319
+ ...(previous.applicability === 'unknown' ? { applicability: 'unknown' } : {}),
320
+ ...(previous.relevance ? { relevance: previous.relevance } : {}),
321
+ ...(previous.news_analysis ? { news_analysis: previous.news_analysis } : {}),
322
+ ai: previous.ai,
323
+ };
324
+ persist(decide(kept, config).action === decision.action ? kept : current);
325
+ };
238
326
  const cached = store.evidence();
239
327
  if (!options.fixture && previousById.size) {
240
328
  // Apply known inventory changes before yielding to network I/O. The worker can deliver concurrently.
@@ -247,7 +335,7 @@ export async function runScan(options) {
247
335
  const ids = new Set(current.map((a) => a.id));
248
336
  for (const finding of current)
249
337
  if (previousById.has(finding.id))
250
- persist(interim(finding, basis(finding, cachedById, collectedAt)));
338
+ reconcile(finding, basis(finding, cachedById, collectedAt));
251
339
  for (const previous of previousById.values())
252
340
  if (previous.category !== 'health' && previous.active !== false && !ids.has(previous.id))
253
341
  retire(previous);
@@ -267,6 +355,7 @@ export async function runScan(options) {
267
355
  ...result.errors,
268
356
  ...(inventory.import_warnings ?? []).map((message) => ({ source: 'inventory:sbom', message })),
269
357
  ];
358
+ errors.push(...mitigationProblems);
270
359
  const notices = [...(inventory.name_notices ?? [])];
271
360
  if (!options.fixture && missingCredentials(config).length)
272
361
  errors.push({
@@ -315,7 +404,7 @@ export async function runScan(options) {
315
404
  }
316
405
  // Reconcile every finding before delivery, including exclusions, withdrawals and removals.
317
406
  // Otherwise an old pending alert could be sent while unrelated AI analysis is running.
318
- findings.forEach((finding) => persist(interim(finding, bases.get(finding.id))));
407
+ findings.forEach((finding) => reconcile(finding, bases.get(finding.id)));
319
408
  const currentIds = new Set(findings.map((a) => a.id));
320
409
  for (const previous of store.findings())
321
410
  if (previous.category !== 'health' && previous.active !== false && !currentIds.has(previous.id))
package/dist/heartbeat.js CHANGED
@@ -5,7 +5,10 @@ export class HeartbeatMonitor {
5
5
  nextAt = 0;
6
6
  async tick(store, config, http, now = Date.now(), signal) {
7
7
  const settings = config.monitoring;
8
- if (!settings || signal?.aborted || now < this.nextAt)
8
+ if (!settings || signal?.aborted)
9
+ return undefined;
10
+ // A next time further away than one interval means the clock was set back.
11
+ if (now < this.nextAt && this.nextAt - now <= settings.interval_seconds * 1000)
9
12
  return undefined;
10
13
  this.nextAt = now + settings.interval_seconds * 1000;
11
14
  let lastSuccess = null;
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
@@ -187,7 +187,7 @@ function record(value) {
187
187
  }
188
188
  /** Imports metadata only. No install scripts or package manager commands are executed. */
189
189
  function importLockfile(path) {
190
- const lock = JSON.parse(readBounded(path, 20 * 1024 * 1024));
190
+ const lock = JSON.parse(readBounded(path, 20 * 1024 * 1024).replace(/^\uFEFF/, ''));
191
191
  if (!record(lock) || (lock.lockfileVersion !== 2 && lock.lockfileVersion !== 3) || !record(lock.packages)) {
192
192
  throw new Error(`Expected package-lock v2 or v3 with a packages map: ${path}`);
193
193
  }
@@ -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();
package/dist/manifests.js CHANGED
@@ -93,14 +93,12 @@ const npmPackageLock = (text) => {
93
93
  if (!record(value))
94
94
  continue;
95
95
  const version = string(value.version) ? value.version : undefined;
96
- if (version?.startsWith('npm:')) {
97
- const target = npmSpecifier(name, version);
98
- packages.push(found('npm', target.name, target.range, value.dev === true));
99
- }
100
- else if (version && /^(?:file|link|git|git\+|https?):/.test(version))
96
+ // `npm:` aliases, and Git (`github:user/repo#sha`), file and URL sources, as in package.json.
97
+ const target = version === undefined ? { name, range: undefined } : npmSpecifier(name, version);
98
+ if (!target)
101
99
  skipped++;
102
100
  else
103
- packages.push(found('npm', name, version, value.dev === true));
101
+ packages.push(found('npm', target.name, target.range, value.dev === true));
104
102
  visit(value.dependencies, depth + 1);
105
103
  }
106
104
  };
@@ -120,8 +118,9 @@ const yarnLock = (text) => {
120
118
  if (fields.resolution !== undefined) {
121
119
  const resolution = unquote(fields.resolution);
122
120
  const match = /^((?:@[^@/]+\/)?[^@]+)@npm:(.+)$/.exec(resolution);
121
+ // `lodash@npm:4.17.21::__archiveUrl=…`: the parameters after `::` are not the version.
123
122
  if (match)
124
- packages.push(found('npm', match[1], match[2]));
123
+ packages.push(found('npm', match[1], match[2].split('::')[0]));
125
124
  else
126
125
  skipped++;
127
126
  return;
@@ -319,7 +318,8 @@ const poetryLock = (text) => {
319
318
  if (!string(table.name))
320
319
  continue;
321
320
  const source = table['source.type'];
322
- if (source && source !== 'legacy') {
321
+ // pdm.lock writes these sources as keys of the package itself.
322
+ if ((source && source !== 'legacy') || table.git || table.path || table.url) {
323
323
  skipped++;
324
324
  continue;
325
325
  }
@@ -411,13 +411,14 @@ const pyprojectToml = (text) => {
411
411
  // ------------------------------------------------------------------------------------- Go and Rust
412
412
  const goMod = (text) => {
413
413
  const required = [];
414
+ // Keyed by module, or by module and version: `replace a v1.0.0 => b v1.1.0` applies to a v1.0.0 only.
414
415
  const replaced = new Map();
415
416
  let block;
416
417
  const replace = (line) => {
417
- const match = /^(\S+)(?:\s+\S+)?\s*=>\s*(\S+)(?:\s+(\S+))?$/.exec(line);
418
+ const match = /^(\S+)(?:\s+(\S+))?\s*=>\s*(\S+)(?:\s+(\S+))?$/.exec(line);
418
419
  if (!match)
419
420
  return;
420
- replaced.set(match[1], /^(?:\.|\/)/.test(match[2]) || !match[3] ? null : { name: match[2], version: match[3] });
421
+ replaced.set(match[2] ? `${match[1]} ${match[2]}` : match[1], /^(?:\.|\/)/.test(match[3]) || !match[4] ? null : { name: match[3], version: match[4] });
421
422
  };
422
423
  for (const raw of text.split(/\r?\n/)) {
423
424
  const line = raw.replace(/\/\/.*$/, '').trim();
@@ -451,7 +452,8 @@ const goMod = (text) => {
451
452
  const packages = [];
452
453
  let skipped = 0;
453
454
  for (const module of required) {
454
- const replacement = replaced.get(module.name);
455
+ const exact = `${module.name} ${module.version}`;
456
+ const replacement = replaced.has(exact) ? replaced.get(exact) : replaced.get(module.name);
455
457
  if (replacement === null)
456
458
  skipped++;
457
459
  else
@@ -948,6 +950,11 @@ function discover(root, warnings) {
948
950
  const locked = new Set(candidates
949
951
  .filter((file) => file.kind === 'lockfile')
950
952
  .map((file) => `${dirname(file.absolute)}\0${file.ecosystem}`));
953
+ // A requirements file often lists only some packages (requirements-dev.txt), so it does not hide
954
+ // the pyproject.toml beside it: that is read like a workspace member, for what the file lacks.
955
+ const resolved = new Set(candidates
956
+ .filter((file) => file.kind === 'lockfile' && file.read !== requirementsTxt)
957
+ .map((file) => `${dirname(file.absolute)}\0${file.ecosystem}`));
951
958
  const coveredBy = (file) => {
952
959
  for (let folder = dirname(dirname(file.absolute)); folder.length >= root.length; folder = dirname(folder)) {
953
960
  if (locked.has(`${folder}\0${file.ecosystem}`))
@@ -958,8 +965,11 @@ function discover(root, warnings) {
958
965
  return false;
959
966
  };
960
967
  return candidates
961
- .filter((file) => file.kind === 'lockfile' || !locked.has(`${dirname(file.absolute)}\0${file.ecosystem}`))
962
- .map((file) => (file.kind === 'manifest' && coveredBy(file) ? { ...file, workspace: true } : file))
968
+ .filter((file) => file.kind === 'lockfile' || !resolved.has(`${dirname(file.absolute)}\0${file.ecosystem}`))
969
+ .map((file) => file.kind === 'manifest' &&
970
+ (coveredBy(file) || locked.has(`${dirname(file.absolute)}\0${file.ecosystem}`))
971
+ ? { ...file, workspace: true }
972
+ : file)
963
973
  .sort((a, b) => Number(a.kind === 'manifest') - Number(b.kind === 'manifest'));
964
974
  }
965
975
  // ---------------------------------------------------------------------------------------- Package URLs
package/dist/matching.js CHANGED
@@ -229,6 +229,12 @@ export function packageMentioned(text, component) {
229
229
  const artifact = mavenArtifact(component);
230
230
  if (artifact && packageMentioned(text, { ecosystem: 'Maven', name: artifact }))
231
231
  return true;
232
+ // PyPI names are kept in their normalised form (`ruamel-yaml`); prose writes the published one,
233
+ // `ruamel.yaml` or `typing_extensions`.
234
+ if (component.ecosystem === 'PyPI' && name.includes('-'))
235
+ for (const separator of ['.', '_'])
236
+ if (packageMentioned(text, { ecosystem: 'PyPI', name: name.replaceAll('-', separator) }))
237
+ return true;
232
238
  // One story is compared with every component, and a story that cites many advisories is
233
239
  // compared again for each of them: remember the answers for the texts seen last.
234
240
  let seen = recent.get(text);
@@ -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 {};