@shieldaai/security-watch 1.2.1 → 1.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.
Files changed (47) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/CONTRIBUTING.md +2 -0
  3. package/README.md +69 -42
  4. package/SECURITY.md +4 -1
  5. package/dist/check.d.ts +193 -0
  6. package/dist/check.js +1000 -0
  7. package/dist/cli.js +301 -6
  8. package/dist/config.d.ts +22 -0
  9. package/dist/config.js +32 -0
  10. package/dist/cve-now.js +2 -0
  11. package/dist/delivery.js +30 -0
  12. package/dist/engine.d.ts +25 -0
  13. package/dist/engine.js +64 -4
  14. package/dist/index.d.ts +8 -1
  15. package/dist/index.js +3 -0
  16. package/dist/inventory.d.ts +2 -1
  17. package/dist/inventory.js +2 -3
  18. package/dist/manifests.d.ts +7 -0
  19. package/dist/manifests.js +16 -0
  20. package/dist/mcp-server.d.ts +256 -0
  21. package/dist/mcp-server.js +755 -0
  22. package/dist/mitigations.d.ts +137 -0
  23. package/dist/mitigations.js +426 -0
  24. package/dist/rehearsal.d.ts +25 -0
  25. package/dist/rehearsal.js +2 -0
  26. package/dist/sbom.d.ts +12 -1
  27. package/dist/sbom.js +37 -7
  28. package/dist/shield-candidates.d.ts +97 -0
  29. package/dist/shield-candidates.js +251 -0
  30. package/dist/shield-inputs.d.ts +49 -0
  31. package/dist/shield-inputs.js +297 -0
  32. package/dist/shirudo-sboms.d.ts +62 -0
  33. package/dist/shirudo-sboms.js +598 -0
  34. package/dist/sources.d.ts +2 -0
  35. package/dist/sources.js +14 -0
  36. package/dist/store.js +6 -4
  37. package/dist/types.d.ts +31 -0
  38. package/dist/vex.d.ts +62 -0
  39. package/dist/vex.js +246 -0
  40. package/docs/agents.md +139 -0
  41. package/docs/configuration.md +20 -1
  42. package/docs/mitigations.md +139 -0
  43. package/docs/offline-advisory-preview.md +2 -2
  44. package/docs/sbom.md +4 -4
  45. package/docs/shirudo.md +113 -0
  46. package/npm-shrinkwrap.json +237 -0
  47. package/package.json +10 -5
package/dist/sbom.js CHANGED
@@ -27,7 +27,7 @@ export function importCycloneDx(path) {
27
27
  return importCycloneDxDocument(document, digest);
28
28
  }
29
29
  /**
30
- * Imports a CycloneDX (1.4 to 1.6) or SPDX (2.2, 2.3) JSON document, whichever the file is. This
30
+ * Imports a CycloneDX (1.2 to 1.7, and later 1.x) or SPDX (2.2, 2.3) JSON document, whichever the file is. This
31
31
  * accepts the output of `security-watch sbom`, Trivy, Syft, cdxgen and GitHub's dependency-graph
32
32
  * export ("Export SBOM", or the REST API's `{ "sbom": ... }` response) without conversion.
33
33
  */
@@ -38,7 +38,7 @@ export function importSbom(path) {
38
38
  const spdx = object(document) && object(document.sbom) ? document.sbom : document;
39
39
  if (object(spdx) && typeof spdx.spdxVersion === 'string')
40
40
  return importSpdxDocument(spdx, digest);
41
- throw new Error('Expected a CycloneDX JSON (1.4 to 1.6) or SPDX JSON (2.2, 2.3) SBOM');
41
+ throw new Error('Expected a CycloneDX JSON (1.2 or later 1.x) or SPDX JSON (2.2, 2.3) SBOM');
42
42
  }
43
43
  const SPDX_RELATIONSHIPS = 100_000;
44
44
  /** SPDX packages become CycloneDX-shaped components so that both formats pass the same checks. */
@@ -129,17 +129,47 @@ function importSpdxDocument(spdx, digest) {
129
129
  result.subject = { ...(name ? { name } : {}), ...(created ? { created } : {}), properties: {} };
130
130
  return result;
131
131
  }
132
+ /** The newest CycloneDX version this release was checked against. */
133
+ export const CYCLONEDX_KNOWN_MINOR = 7;
134
+ /**
135
+ * The CycloneDX 1.x minor version, or nothing. 1.2 is the first with `metadata` and `dependencies`.
136
+ * Minor versions add fields and deprecate, they do not remove what is read here (components, package
137
+ * URLs, references, dependencies, metadata, properties), so a later 1.x is read by the 1.7 rules.
138
+ * A 2.x is a different format and is refused.
139
+ */
140
+ export function cycloneDxMinor(specVersion) {
141
+ // Only text or a number: String(['1.6']) is '1.6', and a one-element array is not a version.
142
+ const match = typeof specVersion === 'string' || typeof specVersion === 'number'
143
+ ? // No leading zero: no generator writes "1.07", and "1.07" is not "1.7".
144
+ /^1\.(0|[1-9]\d{0,2})$/.exec(String(specVersion))
145
+ : null;
146
+ const minor = match ? Number(match[1]) : undefined;
147
+ return minor !== undefined && minor >= 2 ? minor : undefined;
148
+ }
149
+ /** @internal Checks a CycloneDX document held in memory, as a scan will read it. */
150
+ export function importCycloneDxValue(bom, digest) {
151
+ return importCycloneDxDocument(bom, digest);
152
+ }
132
153
  function importCycloneDxDocument(bom, digest, provenance = 'CycloneDX') {
154
+ const minor = object(bom) ? cycloneDxMinor(bom.specVersion) : undefined;
155
+ // `components` is optional in CycloneDX: an image with no packages is a valid, empty list.
133
156
  if (!object(bom) ||
134
157
  bom.bomFormat !== 'CycloneDX' ||
135
- !['1.4', '1.5', '1.6'].includes(String(bom.specVersion)) ||
136
- !Array.isArray(bom.components))
137
- throw new Error('Expected CycloneDX JSON 1.4, 1.5 or 1.6 with components');
158
+ minor === undefined ||
159
+ (bom.components !== undefined && !Array.isArray(bom.components)))
160
+ throw new Error('Expected CycloneDX JSON 1.2 or later 1.x');
138
161
  const result = {
139
162
  components: [],
140
163
  warnings: [],
141
164
  dependencies: [],
142
- source: { format: 'CycloneDX', spec_version: String(bom.specVersion), digest },
165
+ source: { format: 'CycloneDX', spec_version: `1.${minor}`, digest },
166
+ ...(minor > CYCLONEDX_KNOWN_MINOR
167
+ ? {
168
+ notices: [
169
+ `CycloneDX 1.${minor} is newer than this release knows (1.${CYCLONEDX_KNOWN_MINOR}); it was read by the 1.${CYCLONEDX_KNOWN_MINOR} rules.`,
170
+ ],
171
+ }
172
+ : {}),
143
173
  };
144
174
  const ids = new Set();
145
175
  const componentIds = new Set();
@@ -287,7 +317,7 @@ function importCycloneDxDocument(bom, digest, provenance = 'CycloneDX') {
287
317
  result.components.push(component);
288
318
  }
289
319
  };
290
- visit(bom.components, 0);
320
+ visit(bom.components ?? [], 0);
291
321
  if (bom.dependencies !== undefined) {
292
322
  if (!Array.isArray(bom.dependencies) || bom.dependencies.length > 20_000)
293
323
  throw new Error('Invalid SBOM dependencies');
@@ -0,0 +1,97 @@
1
+ import type { AdvisoryReference, Assessment, EpssScore, Evidence, FindingLocation, FixCommit, Inventory, Severity } from './types.js';
2
+ import { type MitigationStatus } from './mitigations.js';
3
+ /**
4
+ * Findings worth a temporary runtime shield (for example a Shirudo upatch) while the real fix is
5
+ * deployed, with what is known that a person or an agent needs to write one.
6
+ *
7
+ * A shield blocks one code path, so it can only be written when the vulnerable code can be found.
8
+ * `readiness` says how far the sources get there; `missing` says what is not known yet. This is a
9
+ * handoff, not advice that a shield is safe: whoever writes it tests it, and the operator approves it.
10
+ */
11
+ export type ShieldReadiness = 'fix_known' | 'fixed_version_known' | 'advisory_only' | 'news_only';
12
+ export interface ShieldCandidate {
13
+ finding_id: string;
14
+ revision?: number;
15
+ readiness: ShieldReadiness;
16
+ /** What is not known yet, in plain words. Empty only when nothing listed below is missing. */
17
+ missing: string[];
18
+ event_id: string;
19
+ /** The event and the CVE, GHSA and other identifiers of the advisories behind it. */
20
+ identifiers: string[];
21
+ title: string;
22
+ category: Assessment['category'];
23
+ applicability: Assessment['applicability'];
24
+ source_severity: Severity;
25
+ priority: Severity;
26
+ /** Listed in a known-exploited catalog (CISA KEV) or marked exploited by an advisory source. */
27
+ exploited: boolean;
28
+ /** A news article reports exploitation; not a catalog entry. */
29
+ exploitation_reported: boolean;
30
+ /** Published exploit code reported by a source (`exploit-db`, `github-poc`, ...) or by news (`news`). */
31
+ public_exploit: string[];
32
+ epss?: EpssScore;
33
+ /** Left out with `omitLocation`: a system ID is often its name. */
34
+ system_id?: string;
35
+ location?: FindingLocation;
36
+ package?: {
37
+ ecosystem: string;
38
+ name: string;
39
+ installed?: string;
40
+ fixed?: string;
41
+ purl?: string;
42
+ };
43
+ /** Links that are code changes: fix commits, pull requests, patches. The best input for a shield. */
44
+ fix_links: string[];
45
+ fix_commits: FixCommit[];
46
+ /** Other links the advisories publish: advisories, reports, exploit evidence. */
47
+ references: AdvisoryReference[];
48
+ weaknesses: string[];
49
+ /** Conditions for exploitation quoted from articles by the analysis model, when one ran. */
50
+ prerequisites?: string[];
51
+ advisories: {
52
+ id: string;
53
+ source: string;
54
+ url: string;
55
+ }[];
56
+ /** Runtime shield status read from Shirudo, when configured. */
57
+ /** Runtime mitigation status per configured source, when any covers the system. */
58
+ mitigations?: MitigationStatus[];
59
+ /** With `omitLocation`, in place of `mitigations`: whether every source proves every host mitigated. */
60
+ mitigated_everywhere?: boolean;
61
+ acknowledged?: boolean;
62
+ suppressed_until?: string;
63
+ }
64
+ export interface ShieldCandidateReport {
65
+ generated_at: string;
66
+ selection: 'urgent' | 'all';
67
+ location: 'included' | 'omitted';
68
+ counts: Record<ShieldReadiness, number>;
69
+ candidates: ShieldCandidate[];
70
+ notes: string[];
71
+ }
72
+ export interface FindingControls {
73
+ revision: number;
74
+ acknowledged: boolean;
75
+ suppressed: boolean;
76
+ suppressed_until: number | null;
77
+ }
78
+ export interface ShieldCandidateInput {
79
+ findings: Assessment[];
80
+ evidence: (ids: readonly string[]) => Evidence[];
81
+ /** The inventory as it is now, for package versions. Without it the stored location is used. */
82
+ inventory?: Inventory;
83
+ controls?: (id: string) => FindingControls | undefined;
84
+ all?: boolean;
85
+ omitLocation?: boolean;
86
+ /**
87
+ * Each configured mitigation source's `max_age_minutes`, by name: an older saved status, or one of a
88
+ * source no longer configured, is marked out of date.
89
+ */
90
+ mitigationMaxAge?: Record<string, number>;
91
+ /** Leave out findings that a fresh status shows mitigated on every host. */
92
+ unmitigatedOnly?: boolean;
93
+ now?: number;
94
+ }
95
+ /** A finding that matters enough to consider a shield: critical, or exploited in any reported way. */
96
+ export declare function urgent(finding: Assessment): boolean;
97
+ export declare function shieldCandidates(input: ShieldCandidateInput): ShieldCandidateReport;
@@ -0,0 +1,251 @@
1
+ import { currentStatus, mitigatedEverywhere } from './mitigations.js';
2
+ import { severityRank, timestamp } from './util.js';
3
+ const READINESS_RANK = {
4
+ fix_known: 0,
5
+ fixed_version_known: 1,
6
+ advisory_only: 2,
7
+ news_only: 3,
8
+ };
9
+ const MAX_IDENTIFIERS = 20;
10
+ /** A finding that matters enough to consider a shield: critical, or exploited in any reported way. */
11
+ export function urgent(finding) {
12
+ return (finding.exploited ||
13
+ Boolean(finding.news_signals?.exploitation) ||
14
+ finding.priority === 'critical' ||
15
+ finding.source_severity === 'critical');
16
+ }
17
+ function eligible(finding) {
18
+ return (finding.active !== false &&
19
+ !finding.withdrawn &&
20
+ finding.category !== 'health' &&
21
+ // A malicious package is removed, not shielded.
22
+ finding.category !== 'malware' &&
23
+ finding.applicability !== 'not_affected' &&
24
+ finding.relevance !== 'irrelevant');
25
+ }
26
+ function componentOf(finding, inventory) {
27
+ if (!inventory || !finding.component_id)
28
+ return undefined;
29
+ return inventory.systems
30
+ .find((system) => system.id === finding.system_id)
31
+ ?.components.find((component) => component.id === finding.component_id);
32
+ }
33
+ export function shieldCandidates(input) {
34
+ const now = input.now ?? Date.now();
35
+ const candidates = [];
36
+ for (const finding of input.findings) {
37
+ if (!eligible(finding))
38
+ continue;
39
+ const controls = input.controls?.(finding.id);
40
+ if (!input.all && (!urgent(finding) || controls?.suppressed))
41
+ continue;
42
+ const item = candidate(finding, input.evidence(finding.evidence_ids), input, controls);
43
+ // Left out only when every source that covers the system proves every host mitigated now.
44
+ if (input.unmitigatedOnly &&
45
+ item.mitigations?.length &&
46
+ item.mitigations.every((status) => mitigatedEverywhere(status, input.now ?? Date.now())))
47
+ continue;
48
+ candidates.push(item);
49
+ }
50
+ candidates.sort((a, b) => READINESS_RANK[a.readiness] - READINESS_RANK[b.readiness] ||
51
+ Number(b.exploited) - Number(a.exploited) ||
52
+ Number(b.exploitation_reported) - Number(a.exploitation_reported) ||
53
+ severityRank[b.priority] - severityRank[a.priority] ||
54
+ a.finding_id.localeCompare(b.finding_id));
55
+ const counts = {
56
+ fix_known: 0,
57
+ fixed_version_known: 0,
58
+ advisory_only: 0,
59
+ news_only: 0,
60
+ };
61
+ for (const item of candidates)
62
+ counts[item.readiness]++;
63
+ return {
64
+ generated_at: timestamp(now),
65
+ selection: input.all ? 'all' : 'urgent',
66
+ location: input.omitLocation ? 'omitted' : 'included',
67
+ counts,
68
+ candidates,
69
+ notes: [
70
+ 'A shield blocks one code path. It can be written only when the vulnerable code can be found: fix_known gives the fix itself, fixed_version_known the two releases to compare. advisory_only and news_only findings need more information first.',
71
+ 'This list is input for a person or an agent. Test every shield against the fix and, where one exists, the public exploit, run it in a trial mode first, and keep the finding open until the real fix is deployed.',
72
+ ...(input.omitLocation
73
+ ? []
74
+ : [
75
+ 'System IDs, names, owners and notes from your inventory are included. Use --omit-location before handing this file to a service outside your network.',
76
+ ]),
77
+ ],
78
+ };
79
+ }
80
+ function candidate(finding, evidence, input, controls) {
81
+ const current = evidence.filter((item) => !item.withdrawn);
82
+ const advisories = current.filter((item) => item.kind === 'advisory' || item.kind === 'kev');
83
+ const references = new Map();
84
+ const commits = new Map();
85
+ const weaknesses = new Set();
86
+ const exploitSources = new Set();
87
+ for (const item of advisories) {
88
+ for (const reference of item.references ?? []) {
89
+ const known = references.get(reference.url);
90
+ if (!known || (reference.type === 'fix' && known.type !== 'fix'))
91
+ references.set(reference.url, reference);
92
+ }
93
+ for (const commit of item.fix_commits ?? [])
94
+ commits.set(`${commit.repo} ${commit.commit}`, commit);
95
+ for (const weakness of item.weaknesses ?? [])
96
+ weaknesses.add(weakness);
97
+ for (const source of item.exploit_sources ?? [])
98
+ exploitSources.add(source);
99
+ }
100
+ if (finding.news_signals?.public_exploit)
101
+ exploitSources.add('news');
102
+ const fixLinks = [...references.values()].filter((r) => r.type === 'fix').map((r) => r.url);
103
+ const otherReferences = [...references.values()].filter((r) => r.type !== 'fix');
104
+ const component = componentOf(finding, input.inventory);
105
+ const claims = advisories
106
+ .flatMap((item) => item.packages)
107
+ .filter((claim) => claim.matched_versions?.length);
108
+ // Without the inventory entry (the inventory changed or cannot be read), a library finding's package
109
+ // is the one the advisories matched by exact version, when they matched exactly one.
110
+ const matchedPackages = [
111
+ ...new Map(claims.map((claim) => [`${claim.ecosystem}\u0000${claim.name}`, claim])).values(),
112
+ ];
113
+ const fallback = !component && finding.category === 'library' && matchedPackages.length === 1
114
+ ? matchedPackages[0]
115
+ : undefined;
116
+ const identity = component ?? (fallback ? { ecosystem: fallback.ecosystem, name: fallback.name } : undefined);
117
+ const matchedVersion = claims.find((claim) => identity && claim.ecosystem === identity.ecosystem && claim.name === identity.name)?.matched_versions?.[0];
118
+ const installed = component?.version ?? matchedVersion;
119
+ const packageConfirmed = finding.category === 'library' && finding.applicability === 'affected' && installed !== undefined;
120
+ const hasAdvisory = advisories.length > 0;
121
+ // An advisory that names several packages (a Python and a Java library under one CVE) publishes the
122
+ // fixes of all of them: its fix links count for this finding only when they name this package.
123
+ const shortName = identity?.name.split(/[/:]/).pop()?.toLowerCase();
124
+ // An advisory is about this package alone when it claims no package or only this one.
125
+ const own = (item) => {
126
+ const claimed = new Set(item.packages.map((claim) => `${claim.ecosystem}\u0000${claim.name}`));
127
+ return (claimed.size === 0 ||
128
+ (claimed.size === 1 && (!identity || claimed.has(`${identity.ecosystem}\u0000${identity.name}`))));
129
+ };
130
+ // A link names the package when a path segment is its name (a repository, a directory), not when
131
+ // the name is part of another word: `core` is not named by `other-core-utils`.
132
+ const mentions = (url) => {
133
+ if (!shortName)
134
+ return false;
135
+ try {
136
+ return new URL(url).pathname
137
+ .toLowerCase()
138
+ .split('/')
139
+ .some((segment) => segment.replace(/\.git$/, '') === shortName);
140
+ }
141
+ catch {
142
+ return false;
143
+ }
144
+ };
145
+ let ambiguousFix = false;
146
+ let fixKnown = false;
147
+ for (const item of advisories) {
148
+ const links = [
149
+ ...(item.references ?? []).filter((r) => r.type === 'fix').map((r) => r.url),
150
+ ...(item.fix_commits ?? []).map((commit) => commit.repo),
151
+ ];
152
+ if (!links.length)
153
+ continue;
154
+ if (own(item) || links.some(mentions))
155
+ fixKnown = true;
156
+ else
157
+ ambiguousFix = true;
158
+ }
159
+ const readiness = !hasAdvisory
160
+ ? 'news_only'
161
+ : packageConfirmed && fixKnown
162
+ ? 'fix_known'
163
+ : packageConfirmed && finding.fix
164
+ ? 'fixed_version_known'
165
+ : 'advisory_only';
166
+ const missing = [];
167
+ if (!hasAdvisory)
168
+ missing.push('No advisory yet. A news report rarely names the vulnerable code or the fixed version; wait for an advisory or a vendor bulletin.');
169
+ if (!packageConfirmed) {
170
+ if (finding.category === 'library' && installed === undefined)
171
+ missing.push('The installed version is unknown, so it is not confirmed that this system runs an affected version.');
172
+ else if (finding.category === 'library')
173
+ missing.push(`Applicability is ${finding.applicability}: the installed version is not confirmed affected.`);
174
+ else if (hasAdvisory)
175
+ missing.push('Matched by product or keyword, not by package and version: the installed version is not confirmed affected.');
176
+ }
177
+ if (hasAdvisory && !fixKnown && ambiguousFix)
178
+ missing.push(`The advisory covers several packages and its fix links do not name ${identity?.name ?? 'this package'}; check which of them fixes it.`);
179
+ else if (hasAdvisory && !fixKnown)
180
+ missing.push(finding.fix
181
+ ? 'No fix commit or patch link in the advisories; compare the installed and fixed releases, or find the fix in the project history.'
182
+ : 'No fix commit, patch link or fixed version published yet; a shield would have to be built from the description alone.');
183
+ if (hasAdvisory && !finding.fix)
184
+ missing.push('No fixed version published.');
185
+ if (!exploitSources.size)
186
+ missing.push('No public exploit code reported by the sources read, so a shield cannot be tested against a real attack; test it against the fix instead.');
187
+ const identifiers = [
188
+ ...new Set([finding.event_id, ...advisories.flatMap((item) => [...item.aliases])]),
189
+ ].slice(0, MAX_IDENTIFIERS);
190
+ const location = finding.location;
191
+ const omit = Boolean(input.omitLocation);
192
+ // A package URL's qualifiers can name a private registry (`?repository_url=...`).
193
+ const purl = component?.purl ? (omit ? component.purl.split(/[?#]/)[0] : component.purl) : undefined;
194
+ // A saved status is as old as the last scan: when scans have stopped, it is out of date now.
195
+ const mitigations = finding.mitigations?.map((status) => currentStatus(status, input.mitigationMaxAge, input.now ?? Date.now()));
196
+ return {
197
+ finding_id: finding.id,
198
+ ...(controls ? { revision: controls.revision } : {}),
199
+ readiness,
200
+ missing,
201
+ event_id: finding.event_id,
202
+ identifiers,
203
+ title: finding.title,
204
+ category: finding.category,
205
+ applicability: finding.applicability,
206
+ source_severity: finding.source_severity,
207
+ priority: finding.priority,
208
+ exploited: finding.exploited,
209
+ exploitation_reported: Boolean(finding.news_signals?.exploitation),
210
+ public_exploit: [...exploitSources].sort(),
211
+ ...(finding.epss ? { epss: finding.epss } : {}),
212
+ // A system ID is often its name (an SBOM file name, a Shirudo image ID).
213
+ ...(omit ? {} : { system_id: finding.system_id }),
214
+ ...(location && !omit ? { location } : {}),
215
+ ...(identity
216
+ ? {
217
+ package: {
218
+ ecosystem: identity.ecosystem,
219
+ name: identity.name,
220
+ ...(installed ? { installed } : {}),
221
+ ...(finding.fix ? { fixed: finding.fix } : {}),
222
+ ...(purl ? { purl } : {}),
223
+ },
224
+ }
225
+ : {}),
226
+ fix_links: fixLinks,
227
+ fix_commits: [...commits.values()],
228
+ references: otherReferences,
229
+ weaknesses: [...weaknesses].sort((a, b) => Number(a.slice(4)) - Number(b.slice(4))),
230
+ ...(finding.news_analysis?.prerequisites?.length
231
+ ? { prerequisites: finding.news_analysis.prerequisites }
232
+ : {}),
233
+ // A news article can come from a feed on an internal address; advisories are public records.
234
+ advisories: current
235
+ .filter((item) => !omit || item.kind === 'advisory' || item.kind === 'kev')
236
+ .map((item) => ({ id: item.id, source: item.source, url: item.url })),
237
+ // Source names, host counts and mitigation names describe the fleet: with --omit-location only
238
+ // whether every host is proven mitigated is kept.
239
+ ...(mitigations?.length
240
+ ? omit
241
+ ? {
242
+ mitigated_everywhere: mitigations.every((status) => mitigatedEverywhere(status, input.now ?? Date.now())),
243
+ }
244
+ : { mitigations }
245
+ : {}),
246
+ ...(controls?.acknowledged ? { acknowledged: true } : {}),
247
+ ...(controls?.suppressed && controls.suppressed_until
248
+ ? { suppressed_until: timestamp(controls.suppressed_until) }
249
+ : {}),
250
+ };
251
+ }
@@ -0,0 +1,49 @@
1
+ import type { AdvisoryReference, Evidence, FixCommit } from './types.js';
2
+ /**
3
+ * What an advisory publishes beyond its text that helps someone write a fix or a temporary runtime
4
+ * shield: typed links, the commits that fixed it, weakness (CWE) identifiers and public exploit code.
5
+ *
6
+ * These parsers never throw. A malformed link is dropped; it must never cost the advisory itself.
7
+ * The fields are kept out of the evidence content hash and the analysis basis (see `evidenceContent`),
8
+ * so an upgrade that starts reading them neither records new evidence revisions nor asks a model again,
9
+ * and they are never sent to a model.
10
+ */
11
+ export declare const MAX_REFERENCES = 40;
12
+ export declare const MAX_FIX_COMMITS = 20;
13
+ export declare const MAX_WEAKNESSES = 20;
14
+ /** Evidence without its fetch time and without the shield inputs: what revisions and analysis compare. */
15
+ export declare function evidenceContent(evidence: Evidence): Omit<Evidence, 'fetched_at' | 'references' | 'fix_commits' | 'weaknesses' | 'exploit_sources'>;
16
+ /**
17
+ * An https URL to a public name, without credentials, of bounded length, or nothing. These links are
18
+ * handed to people and agents that may open them, so an address inside a network (an IP literal in any
19
+ * notation, a private name) is dropped, and so is a value with whitespace or control characters
20
+ * inside it, which a URL parser would silently remove, keeping a different address.
21
+ */
22
+ export declare function safeHttpsUrl(value: unknown): string | undefined;
23
+ /** A link that is a code change: a commit, a pull or merge request, a compare view or a patch file. */
24
+ export declare function codeChangeUrl(url: string): boolean;
25
+ /**
26
+ * OSV `references`: typed. A code-change link typed only as a web page is a fix link; one the
27
+ * advisory types as evidence, a report or an advisory (a proof-of-concept commit, say) keeps its type.
28
+ */
29
+ export declare const osvReferences: (raw: unknown) => AdvisoryReference[];
30
+ /** GitHub's `references`: plain URLs. Code changes are fix links, advisory databases are advisories. */
31
+ export declare const githubReferences: (raw: unknown) => AdvisoryReference[];
32
+ /** The commits OSV records as fixing the problem: `GIT` ranges with a repository and `fixed` events. */
33
+ export declare const osvFixCommits: (affected: unknown) => FixCommit[];
34
+ /** OSV: `database_specific.cwe_ids`, as GitHub-reviewed records carry, on the record or an entry. */
35
+ export declare const osvWeaknesses: (data: Record<string, unknown>) => string[];
36
+ /** GitHub: `cwes: [{cwe_id, name}]`. */
37
+ export declare const githubWeaknesses: (raw: unknown) => string[];
38
+ /**
39
+ * cve.now's public exploit entries: Exploit-DB, Metasploit, Nuclei and GitHub proof-of-concept code.
40
+ * Published code, not exploitation in the wild; that is `exploited` (the KEV catalog).
41
+ */
42
+ export declare const cveNowExploitSources: (exploitation: unknown) => string[];
43
+ /** The shield inputs to spread into an Evidence record; empty lists are left out. */
44
+ export declare function shieldInputs(parts: {
45
+ references?: AdvisoryReference[];
46
+ fix_commits?: FixCommit[];
47
+ weaknesses?: string[];
48
+ exploit_sources?: string[];
49
+ }): Pick<Evidence, 'references' | 'fix_commits' | 'weaknesses' | 'exploit_sources'>;