@shieldaai/security-watch 0.0.0-stage → 0.1.0-alpha.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 (62) hide show
  1. package/CONTRIBUTING.md +90 -0
  2. package/LICENSE +202 -0
  3. package/README.md +269 -2
  4. package/SECURITY.md +47 -0
  5. package/dist/assessment.d.ts +5 -0
  6. package/dist/assessment.js +398 -0
  7. package/dist/cli.d.ts +2 -0
  8. package/dist/cli.js +792 -0
  9. package/dist/config.d.ts +242 -0
  10. package/dist/config.js +298 -0
  11. package/dist/cve-now.d.ts +5 -0
  12. package/dist/cve-now.js +413 -0
  13. package/dist/delivery.d.ts +26 -0
  14. package/dist/delivery.js +394 -0
  15. package/dist/ecosystems.d.ts +25 -0
  16. package/dist/ecosystems.js +254 -0
  17. package/dist/engine.d.ts +26 -0
  18. package/dist/engine.js +307 -0
  19. package/dist/health.d.ts +17 -0
  20. package/dist/health.js +70 -0
  21. package/dist/heartbeat.d.ts +13 -0
  22. package/dist/heartbeat.js +74 -0
  23. package/dist/http.d.ts +8 -0
  24. package/dist/http.js +251 -0
  25. package/dist/index.d.ts +18 -0
  26. package/dist/index.js +15 -0
  27. package/dist/inventory.d.ts +3 -0
  28. package/dist/inventory.js +143 -0
  29. package/dist/lock.d.ts +3 -0
  30. package/dist/lock.js +112 -0
  31. package/dist/maintenance.d.ts +43 -0
  32. package/dist/maintenance.js +227 -0
  33. package/dist/models.d.ts +20 -0
  34. package/dist/models.js +602 -0
  35. package/dist/operations.d.ts +17 -0
  36. package/dist/operations.js +117 -0
  37. package/dist/providers.d.ts +209 -0
  38. package/dist/providers.js +459 -0
  39. package/dist/setup.d.ts +113 -0
  40. package/dist/setup.js +100 -0
  41. package/dist/source-error.d.ts +22 -0
  42. package/dist/source-error.js +56 -0
  43. package/dist/sources.d.ts +3 -0
  44. package/dist/sources.js +1071 -0
  45. package/dist/store.d.ts +71 -0
  46. package/dist/store.js +651 -0
  47. package/dist/types.d.ts +247 -0
  48. package/dist/types.js +1 -0
  49. package/dist/util.d.ts +6 -0
  50. package/dist/util.js +14 -0
  51. package/dist/vendor-sources.d.ts +24 -0
  52. package/dist/vendor-sources.js +56 -0
  53. package/docs/configuration.md +406 -0
  54. package/docs/quality-review.md +104 -0
  55. package/examples/advisories.json +17 -0
  56. package/examples/common-systems.yaml +243 -0
  57. package/examples/libraries.example.txt +16 -0
  58. package/examples/libraries.example.yaml +38 -0
  59. package/examples/library-watch.example.yaml +27 -0
  60. package/examples/security-watch.example.yaml +86 -0
  61. package/examples/systems.example.yaml +31 -0
  62. package/package.json +69 -4
package/SECURITY.md ADDED
@@ -0,0 +1,47 @@
1
+ # Security policy and boundaries
2
+
3
+ Security Watch is an experimental monitoring tool without an independent security audit or a patch-response SLA. Validate findings against your deployment before using them to make remediation decisions.
4
+
5
+ ## Report a vulnerability
6
+
7
+ Use [GitHub's private vulnerability reporting form](https://github.com/ShieldaAI/security-watch/security/advisories/new). If that option is unavailable, ask a maintainer for a private reporting channel without posting exploit details, credentials, private inventory or affected customer data publicly. Do not send real secrets in examples. There is no dedicated security reporting address yet.
8
+
9
+ Include the relevant commit/version, Node version, a minimal synthetic reproduction, expected versus observed behavior, and which trust boundary is crossed. Reports involving lost alerts, false safety conclusions, credential disclosure, unsafe network access or duplicate/incorrect delivery are particularly useful.
10
+
11
+ ## Trust model
12
+
13
+ Trusted inputs are the operator's configuration, inventory, chosen model/SMTP endpoints, environment, local filesystem and installed application/dependencies. Feed bodies, article text, advisory text and model output are untrusted evidence. The application does not protect against a malicious local administrator, compromised dependency, hostile model endpoint explicitly trusted by the operator, or altered system clock.
14
+
15
+ Implemented boundaries include:
16
+
17
+ - Strict configuration/inventory parsing, bounded input sizes and metadata-only lockfile import. No package installation or lifecycle-script execution occurs during monitoring.
18
+ - Public HTTPS fetching with checks on the addresses used by the connection, bounded redirects/timeouts/response sizes, and removal of authentication headers on cross-origin redirects. Model and external-heartbeat endpoints may explicitly opt into private addressing; SMTP endpoints are operator-selected.
19
+ - Models receive no shell, browser, filesystem or notification tools. Output is schema-checked, evidence IDs must exist, and supporting quotes must appear in the supplied evidence.
20
+ - The Hacker News article requests are restricted to its publication hosts and have size limits. Article links to other sites are not crawled. Missing, excerpted, stale or truncated evidence cannot support a new decisive AI impact conclusion. Historical general-news classifications are retained; current affected/excluded claims require fresh evidence.
21
+ - Deterministic package matching and source-severity floors govern library/product decisions. AI cannot rewrite recipients, authoritative version constraints or dependency applicability.
22
+ - AI news classification and claimed system impact are stored separately from authoritative applicability. Evidence-backed general news or an AI-reported exclusion can suppress noncritical news alerts, but cannot override source-critical or enabled known-exploitation safeguards.
23
+ - Slack destinations come only from operator configuration and are restricted to standard `hooks.slack.com` incoming webhooks. SMTP requires TLS. Notification content is rendered as text and cannot enable attachments, filesystem reads or URL-fetching features in the email transport.
24
+ - Findings and their delivery jobs are committed together. Ambiguous delivery is visible and requires a manual receipt check before retrying.
25
+
26
+ Models can misinterpret sources, feeds can omit important facts, and advisories can be wrong or delayed. Check source failures and uncertain findings during operational review. The bot does not provide a general prompt-injection detector or execution sandbox.
27
+
28
+ ## Data handling
29
+
30
+ cve.now stack requests reveal deduplicated npm package names and exact versions through URL query parameters; lockfiles and system/deployment metadata are not uploaded. The Hacker News feed and article servers receive normal HTTP request metadata. Optional OSV requests reveal library ecosystem, package name and the installed version when supplied. Official vendor feeds receive normal request metadata. Other enabled advisory/feed servers receive normal request metadata, and GitHub may receive the configured API token. The configured AI provider receives selected relevant inventory entries and deployment context from the matched system plus selected evidence. Notifications disclose finding context and source links to Slack or the configured email recipients. There is no automatic application telemetry. An optional, operator-configured heartbeat endpoint receives bodyless success pings and normal request metadata. It receives no inventory, finding content or logs.
31
+
32
+ Credential values are read from environment variables, not placed in model prompts or intentionally persisted in SQLite. Do not insert keys into model names, feed URLs, inventory text or configuration substitutions. Use your service manager or secret manager to supply credentials; the CLI does not automatically load `.env` files. Do not commit configuration, database files, backups or `.env` files to source control.
33
+
34
+ SQLite stores evidence, finding revisions, model analysis excerpts, caches, budgets and delivery state. Database files use private permissions but are not application-encrypted. Use appropriate host access controls and encrypted storage. Retention and scheduled backups are disabled until configured. Cleanup preserves active or unresolved findings, unresolved delivery audit, source checkpoints and budgets; it is bounded and has a read-only preview. Scheduled backup rotation removes only managed snapshots after a new snapshot verifies successfully. Backups can contain the same sensitive material as the live database. Verification copies a standalone snapshot into a private temporary directory and checks structural restoration, including migrations, without replacing live state. This is not validation of every stored security claim; plan disk capacity and protect backup destinations.
35
+
36
+ ## Coverage limitations
37
+
38
+ - Library inventory supports 12 ecosystems. Only npm uses supported version-range evaluation and exclusions. Other ecosystems require a positive exact OSV query or an explicitly listed affected version; a missing version, unmatched result or unsupported range stays unknown. Lockfile entries include dependencies that may not be present in production.
39
+ - Generic products, operating systems and SaaS services have name/keyword candidate matching plus optional AI news/impact analysis. AI impact is an evidence-backed opinion, not a deterministic product-version result. Vendor backports, enabled features and exploit reachability are not automatically established.
40
+ - Missing versions, unknown constraints and stale inventory remain uncertain. An empty advisory search does not establish that a system has no vulnerabilities.
41
+ - CVSS v3.0/v3.1 calculation and supplied source labels/scores are supported; CVSS v4 vectors are not calculated in this alpha.
42
+ - Source requests and model inputs have size and request limits. Incomplete collection or analysis reports degraded monitoring and requires review.
43
+ - Recent cve.now entry collection, tracked/news-cited refreshes and exact npm stack queries do not establish exhaustive historical coverage for every product. The Hacker News may block article access; the feed excerpt remains available for review without a confident impact conclusion.
44
+ - There is no general SBOM ingestion, authenticated web crawling, automatic remediation, distributed lock, multi-host worker or independent penetration-test certification.
45
+ - Notifications are not exactly-once delivery. A timeout can occur after a destination accepts a message. Verify receipt before retrying an `unknown` job.
46
+
47
+ Review `status`, `deliveries`, source-health findings and service logs. Optional external success pings stop when monitoring is unhealthy, but the receiving service must be configured to detect missing pings. Loss of the host or every delivery channel cannot be reported through that same failed infrastructure.
@@ -0,0 +1,5 @@
1
+ import type { Assessment, Config, Decision, Evidence, Inventory } from './types.js';
2
+ /** Assess each deployment independently against package identity and version evidence. */
3
+ export declare function assess(inventory: Inventory, evidence: Evidence[], config: Config, now?: number): Assessment[];
4
+ /** The source severity is always a floor; AI-proposed priority reductions cannot suppress it. */
5
+ export declare function decide(assessment: Assessment, config: Config): Decision;
@@ -0,0 +1,398 @@
1
+ import { satisfies, validRange } from 'semver';
2
+ import { hash, highest, severityRank, timestamp } from './util.js';
3
+ import { exactLibraryVersion, normalizeEcosystem, samePackage } from './ecosystems.js';
4
+ function identity(id) {
5
+ return /^(?:CVE-|GHSA-)/i.test(id) ? id.toUpperCase() : id;
6
+ }
7
+ function identifiers(evidence) {
8
+ return [...new Set([evidence.id, ...evidence.aliases].map(identity))];
9
+ }
10
+ function advisoryIdentifier(value) {
11
+ return /^(?:CVE-\d{4}-\d{4,}|GHSA-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4})$/i.test(value);
12
+ }
13
+ function newestEvidence(evidence) {
14
+ const byOrigin = new Map();
15
+ for (const item of evidence) {
16
+ const key = `${item.source}\u0000${item.id}`;
17
+ const old = byOrigin.get(key);
18
+ const modified = Date.parse(item.modified_at);
19
+ const previousModified = old ? Date.parse(old.modified_at) : -Infinity;
20
+ if (!old ||
21
+ modified > previousModified ||
22
+ (modified === previousModified && Date.parse(item.fetched_at) > Date.parse(old.fetched_at)))
23
+ byOrigin.set(key, item);
24
+ }
25
+ return [...byOrigin.values()].sort((a, b) => a.id.localeCompare(b.id) || a.source.localeCompare(b.source));
26
+ }
27
+ function eventId(ids) {
28
+ return [...ids].sort((a, b) => {
29
+ const rank = (id) => (id.startsWith('GHSA-') ? 0 : id.startsWith('CVE-') ? 1 : 2);
30
+ return rank(a) - rank(b) || a.localeCompare(b);
31
+ })[0];
32
+ }
33
+ /** Only advisory alias claims merge events. A multi-CVE news story must not merge its subjects. */
34
+ function groupEvidence(input) {
35
+ const evidence = newestEvidence(input);
36
+ const parents = new Map();
37
+ const find = (value) => {
38
+ let root = value;
39
+ while (parents.has(root) && parents.get(root) !== root)
40
+ root = parents.get(root);
41
+ let cursor = value;
42
+ while (parents.has(cursor) && parents.get(cursor) !== root) {
43
+ const next = parents.get(cursor);
44
+ parents.set(cursor, root);
45
+ cursor = next;
46
+ }
47
+ if (!parents.has(root))
48
+ parents.set(root, root);
49
+ return root;
50
+ };
51
+ const advisory = evidence.filter((item) => item.kind === 'advisory');
52
+ for (const item of advisory) {
53
+ const ids = identifiers(item);
54
+ for (const id of ids.slice(1))
55
+ parents.set(find(id), find(ids[0]));
56
+ }
57
+ const groups = new Map();
58
+ for (const item of advisory) {
59
+ const root = find(identity(item.id));
60
+ if (!groups.has(root))
61
+ groups.set(root, { event: '', evidence: [] });
62
+ groups.get(root).evidence.push(item);
63
+ }
64
+ const aliasGroups = new Map();
65
+ for (const group of groups.values()) {
66
+ const ids = [...new Set(group.evidence.flatMap(identifiers))];
67
+ group.event = eventId(ids);
68
+ for (const id of ids)
69
+ aliasGroups.set(id, group);
70
+ }
71
+ const news = new Map();
72
+ for (const item of evidence.filter((item) => item.kind === 'news' || item.kind === 'kev')) {
73
+ const matches = new Set(identifiers(item)
74
+ .map((id) => aliasGroups.get(id))
75
+ .filter((group) => group !== undefined));
76
+ for (const group of matches)
77
+ group.evidence.push(item);
78
+ if (item.kind === 'news') {
79
+ // Keep unmatched CVEs in a roundup as separate candidates for review.
80
+ // News mentions cannot establish that two CVEs/GHSAs are aliases of the same event.
81
+ const advisoryIds = identifiers(item).filter(advisoryIdentifier);
82
+ const residual = advisoryIds.filter((id) => !aliasGroups.has(id));
83
+ for (const event of advisoryIds.length ? residual : matches.size ? [] : [item.id]) {
84
+ if (!news.has(event))
85
+ news.set(event, { event, evidence: [] });
86
+ news.get(event).evidence.push(item);
87
+ }
88
+ }
89
+ }
90
+ return [...groups.values(), ...news.values()];
91
+ }
92
+ /** Word/identifier boundaries prevent "express" matching "expressions" or another npm scope. */
93
+ function mentions(text, needle) {
94
+ if (needle.trim().length < 3)
95
+ return false;
96
+ const escaped = needle.trim().replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
97
+ return new RegExp(`(?<![\\p{L}\\p{N}_@/\\-])${escaped}(?![\\p{L}\\p{N}_@/\\-])`, 'iu').test(text);
98
+ }
99
+ function stale(system, config, now) {
100
+ const updated = Date.parse(system.updated_at);
101
+ return (!Number.isFinite(updated) ||
102
+ updated > now + 5 * 60_000 ||
103
+ now - updated > config.inventory_stale_days * 86_400_000);
104
+ }
105
+ function claimStatus(claim, version) {
106
+ if (!version)
107
+ return 'unknown';
108
+ const ecosystem = normalizeEcosystem(claim.ecosystem);
109
+ try {
110
+ version = exactLibraryVersion(version, ecosystem);
111
+ }
112
+ catch {
113
+ return 'unknown';
114
+ }
115
+ if (claim.matched_versions?.includes(version) || claim.versions?.includes(version))
116
+ return 'affected';
117
+ // Other registries have their own ordering, epochs and prerelease rules.
118
+ // Exact positive queries/listed versions are evidence; a missing match is not an exclusion.
119
+ if (ecosystem !== 'npm')
120
+ return 'unknown';
121
+ if (!claim.range)
122
+ return 'unknown';
123
+ // GitHub renders some npm range intersections with commas; semver uses spaces.
124
+ const range = claim.range.replace(/,\s*/g, ' ');
125
+ if (!range.trim() || !validRange(range))
126
+ return 'unknown';
127
+ const matches = satisfies(version, range);
128
+ // npm semver deliberately excludes most prereleases: that is not evidence of safety.
129
+ if (version.includes('-') && !matches)
130
+ return 'unknown';
131
+ return matches ? 'affected' : 'not_affected';
132
+ }
133
+ function recordStatus(claims, version) {
134
+ const states = claims.map((claim) => claimStatus(claim, version));
135
+ if (states.includes('affected'))
136
+ return 'affected';
137
+ if (states.every((state) => state === 'not_affected'))
138
+ return 'not_affected';
139
+ return 'unknown';
140
+ }
141
+ function contextualPriority(severity, system, exploited) {
142
+ if (exploited)
143
+ return highest(severity, 'high');
144
+ if (severity === 'high' && system.exposure === 'internet' && system.criticality === 'critical')
145
+ return 'critical';
146
+ return severity;
147
+ }
148
+ function base(group, system, now, category, component) {
149
+ const sourceSeverity = highest(...group.evidence.filter((item) => !item.withdrawn).map((item) => item.severity));
150
+ const exploited = group.evidence.some((item) => item.exploited || item.kind === 'kev');
151
+ const title = group.evidence.find((item) => item.kind === 'advisory' && !item.withdrawn)?.title ??
152
+ group.evidence[0].title;
153
+ return {
154
+ id: hash([group.event, system.id, component ?? null]),
155
+ event_id: group.event,
156
+ system_id: system.id,
157
+ ...(component ? { component_id: component } : {}),
158
+ category,
159
+ news_only: group.evidence.every((item) => item.kind === 'news'),
160
+ news_candidate: group.evidence.every((item) => item.kind === 'news') ||
161
+ (category === 'product' && group.evidence.some((item) => item.kind === 'news')),
162
+ applicability: 'unknown',
163
+ source_severity: sourceSeverity,
164
+ priority: contextualPriority(sourceSeverity, system, exploited),
165
+ title,
166
+ summary: '',
167
+ reasons: [],
168
+ evidence_ids: [...new Set(group.evidence.map((item) => item.id))].sort(),
169
+ urls: [...new Set(group.evidence.map((item) => item.url).filter(Boolean))].sort(),
170
+ exploited,
171
+ updated_at: timestamp(now),
172
+ };
173
+ }
174
+ /** Assess each deployment independently against package identity and version evidence. */
175
+ export function assess(inventory, evidence, config, now = Date.now()) {
176
+ const output = [];
177
+ for (const group of groupEvidence(evidence)) {
178
+ const advisories = group.evidence.filter((item) => item.kind === 'advisory');
179
+ const isNews = advisories.length === 0;
180
+ const identifiedNews = isNews && group.evidence.some((item) => identifiers(item).some(advisoryIdentifier));
181
+ const text = group.evidence
182
+ .filter((item) => item.kind !== 'kev')
183
+ .map((item) => `${item.title}\n${item.description}`)
184
+ .join('\n');
185
+ for (const system of inventory.systems) {
186
+ let componentMatched = false;
187
+ for (const component of system.components) {
188
+ const matching = advisories
189
+ .map((item) => ({
190
+ item,
191
+ claims: item.packages.filter((claim) => samePackage(claim, component)),
192
+ }))
193
+ .filter((item) => item.claims.length);
194
+ if (!matching.length) {
195
+ if (identifiedNews && mentions(text, component.name)) {
196
+ componentMatched = true;
197
+ const result = base(group, system, now, 'library', component.id);
198
+ result.reasons.push(`News identifies an advisory and mentions the ${component.ecosystem} package name ${component.name}; no structured affected-version evidence is available yet.`);
199
+ if (stale(system, config, now))
200
+ result.reasons.push('Inventory is stale; confirm the installed version before assessing applicability.');
201
+ result.summary = `Reported advisory for ${component.name}${component.version ? `@${component.version}` : ''} in ${system.name}: applicability unknown.`;
202
+ output.push(result);
203
+ }
204
+ continue;
205
+ }
206
+ componentMatched = true;
207
+ const applicableEvidence = group.evidence.filter((item) => item.kind !== 'advisory' || matching.some((match) => match.item === item));
208
+ const selected = { ...group, evidence: applicableEvidence };
209
+ const result = base(selected, system, now, matching.some((match) => match.item.malware) ? 'malware' : 'library', component.id);
210
+ const active = matching.filter((match) => !match.item.withdrawn);
211
+ const states = active.map((match) => recordStatus(match.claims, component.version));
212
+ const withdrewSome = active.length !== matching.length;
213
+ result.withdrawn = active.length === 0;
214
+ if (result.withdrawn) {
215
+ result.reasons.push('All matched advisory sources withdrew this finding; withdrawal alone does not prove this installation safe.');
216
+ }
217
+ else if (withdrewSome || (states.includes('affected') && states.includes('not_affected'))) {
218
+ result.applicability = 'conflicting';
219
+ result.reasons.push('Advisory sources disagree about affected versions or withdrawal; investigate the conflicting evidence.');
220
+ }
221
+ else if (states.includes('affected')) {
222
+ result.applicability = 'affected';
223
+ result.reasons.push(`The exact ${component.ecosystem} identity ${component.name} and installed version ${component.version} match affected advisory evidence.`);
224
+ }
225
+ else if (states.every((state) => state === 'not_affected')) {
226
+ result.applicability = 'not_affected';
227
+ result.reasons.push(`Installed ${component.name}@${component.version} is excluded by every matched advisory's supported affected version ranges.`);
228
+ }
229
+ else {
230
+ result.reasons.push(`The ${component.ecosystem} identity ${component.name} matches, but a missing version or unsupported affected-version constraint prevents a conclusion.`);
231
+ }
232
+ if (!result.withdrawn && stale(system, config, now)) {
233
+ if (result.applicability !== 'conflicting')
234
+ result.applicability = 'unknown';
235
+ result.reasons.push('Inventory is stale or has an invalid/future timestamp; confirm the currently installed version before relying on this assessment.');
236
+ }
237
+ const fixes = [
238
+ ...new Set(active.flatMap((match) => match.claims.map((claim) => claim.fixed).filter((value) => Boolean(value)))),
239
+ ];
240
+ if (fixes.length)
241
+ result.fix = fixes.sort().join('; ');
242
+ result.summary = `${component.name}${component.version ? `@${component.version}` : ''} in ${system.name}: ${result.applicability}.`;
243
+ output.push(result);
244
+ }
245
+ // Apply the component's policy to linked news as well as the advisory itself.
246
+ if (componentMatched && !isNews)
247
+ continue;
248
+ let productMatched = false;
249
+ for (const product of system.products) {
250
+ if (![product.name, ...product.keywords].some((keyword) => mentions(text, keyword)))
251
+ continue;
252
+ productMatched = true;
253
+ const result = base(group, system, now, isNews ? 'news' : 'product', `product:${product.name.toLowerCase()}`);
254
+ result.applicability = isNews ? 'relevant' : 'unknown';
255
+ result.withdrawn = !isNews && advisories.every((item) => item.withdrawn);
256
+ if (!isNews && advisories.some((item) => item.withdrawn) && !result.withdrawn)
257
+ result.applicability = 'conflicting';
258
+ result.reasons.push(`The product name or an explicit keyword matches ${product.name}; no supported product adapter establishes version or backport applicability.`);
259
+ if (stale(system, config, now)) {
260
+ result.applicability = 'unknown';
261
+ result.reasons.push('Inventory is stale; confirm the product and deployment details.');
262
+ }
263
+ result.summary = `${product.name}${product.version ? ` ${product.version}` : ''} in ${system.name}: ${result.applicability}.`;
264
+ output.push(result);
265
+ }
266
+ if (componentMatched || productMatched || !isNews)
267
+ continue;
268
+ const keywords = [...system.keywords, ...system.components.map((component) => component.name)];
269
+ if (!keywords.some((keyword) => mentions(text, keyword)))
270
+ continue;
271
+ const result = base(group, system, now, 'news');
272
+ result.applicability = stale(system, config, now) ? 'unknown' : 'relevant';
273
+ result.reasons.push('An explicit system keyword or installed package name matches this news; relevance does not establish vulnerability applicability.');
274
+ result.summary = `Security news relevant to ${system.name}; review the linked evidence.`;
275
+ output.push(result);
276
+ }
277
+ }
278
+ return output.sort((a, b) => a.id.localeCompare(b.id));
279
+ }
280
+ /** The source severity is always a floor; AI-proposed priority reductions cannot suppress it. */
281
+ export function decide(assessment, config) {
282
+ const policy = config.policy;
283
+ if (assessment.category === 'health')
284
+ return {
285
+ action: policy.health_channels.length ? 'notify' : 'record',
286
+ channels: policy.health_channels,
287
+ reason: 'Monitoring health policy.',
288
+ };
289
+ const rule = policy[assessment.category === 'malware' ? 'library' : assessment.category];
290
+ const channels = [...new Set(rule.channels)];
291
+ if (assessment.withdrawn)
292
+ return {
293
+ action: 'record',
294
+ channels: [],
295
+ reason: 'All matched advisory sources withdrew this finding; retained in history.',
296
+ };
297
+ if (assessment.applicability === 'not_affected')
298
+ return {
299
+ action: 'record',
300
+ channels: [],
301
+ reason: 'Supported advisory version ranges exclude this installed version.',
302
+ };
303
+ const uncertain = assessment.applicability === 'unknown' || assessment.applicability === 'conflicting';
304
+ const severity = rule.basis === 'source_severity'
305
+ ? assessment.source_severity
306
+ : highest(assessment.source_severity, assessment.priority);
307
+ if (!channels.length)
308
+ return { action: 'record', channels: [], reason: 'This category has no configured delivery channels.' };
309
+ if (assessment.category === 'malware' && policy.malware_override)
310
+ return {
311
+ action: 'notify',
312
+ channels,
313
+ reason: 'Malicious-package override; investigate immediately even without a severity score.',
314
+ };
315
+ if (assessment.exploited && policy.exploited_override)
316
+ return { action: 'notify', channels, reason: 'Known-exploitation override; investigate immediately.' };
317
+ if ((assessment.news_candidate || assessment.news_only) && assessment.source_severity !== 'critical') {
318
+ const news = assessment.news_analysis;
319
+ if (assessment.ai?.status === 'complete' && news) {
320
+ if (news.classification === 'general_news' && news.impact === 'not_applicable')
321
+ return {
322
+ action: 'record',
323
+ channels: [],
324
+ reason: 'AI reviewed this as general system news, with no newly reported vulnerability or actionable vulnerability update.',
325
+ };
326
+ if (news.impact === 'not_affected')
327
+ return {
328
+ action: 'record',
329
+ channels: [],
330
+ reason: 'AI found that the reported news does not affect this deployment; this is a news assessment, not a verified safety conclusion.',
331
+ };
332
+ if (news.impact === 'affected' &&
333
+ ['new_vulnerability', 'known_vulnerability_update'].includes(news.classification))
334
+ return rule.levels.includes(severity)
335
+ ? {
336
+ action: 'notify',
337
+ channels,
338
+ reason: `AI reports an impacted system in ${news.classification}; matched ${assessment.category} rule at ${severity}. Verify the cited versions and prerequisites.`,
339
+ }
340
+ : {
341
+ action: 'record',
342
+ channels: [],
343
+ reason: `${severity} does not match the configured ${assessment.category} severity levels.`,
344
+ };
345
+ }
346
+ if (config.models.enabled && !assessment.ai)
347
+ return {
348
+ action: 'record',
349
+ channels: [],
350
+ reason: 'News candidate awaiting AI classification before delivery.',
351
+ };
352
+ if (policy.urgent_unknown && highest(assessment.source_severity, assessment.priority) === 'critical')
353
+ return {
354
+ action: 'notify',
355
+ channels,
356
+ reason: 'Potentially critical news impact remains uncertain; investigation required.',
357
+ };
358
+ return {
359
+ action: 'digest',
360
+ channels,
361
+ reason: 'News impact is unclassified, incomplete or uncertain; included in the review digest.',
362
+ };
363
+ }
364
+ if (assessment.category === 'news' &&
365
+ assessment.relevance === 'irrelevant' &&
366
+ assessment.source_severity !== 'critical')
367
+ return {
368
+ action: 'record',
369
+ channels: [],
370
+ reason: 'Evidence-backed news relevance assessment found no relevant deployment context.',
371
+ };
372
+ if (uncertain) {
373
+ if (policy.urgent_unknown &&
374
+ severityRank[highest(assessment.source_severity, assessment.priority)] >= severityRank.critical) {
375
+ return {
376
+ action: 'notify',
377
+ channels,
378
+ reason: 'Investigation required: potentially critical finding with uncertain or conflicting applicability.',
379
+ };
380
+ }
381
+ return {
382
+ action: 'digest',
383
+ channels,
384
+ reason: 'Uncertain applicability requires review; included in the review digest.',
385
+ };
386
+ }
387
+ if (rule.levels.includes(severity))
388
+ return {
389
+ action: 'notify',
390
+ channels,
391
+ reason: `Matched ${assessment.category} rule at ${severity} severity; source severity remains the minimum.`,
392
+ };
393
+ return {
394
+ action: 'record',
395
+ channels: [],
396
+ reason: `${severity} does not match the configured ${assessment.category} severity levels.`,
397
+ };
398
+ }
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};