@shieldaai/security-watch 0.1.0-alpha.0 → 1.0.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 (92) hide show
  1. package/CHANGELOG.md +170 -0
  2. package/CONTRIBUTING.md +4 -2
  3. package/README.md +173 -48
  4. package/SECURITY.md +24 -9
  5. package/dist/assessment.d.ts +12 -1
  6. package/dist/assessment.js +223 -52
  7. package/dist/cli.js +340 -27
  8. package/dist/config.d.ts +62 -2
  9. package/dist/config.js +88 -5
  10. package/dist/coverage.d.ts +4 -0
  11. package/dist/coverage.js +11 -0
  12. package/dist/cve-now.d.ts +32 -2
  13. package/dist/cve-now.js +715 -126
  14. package/dist/cvss4.d.ts +3 -0
  15. package/dist/cvss4.js +39 -0
  16. package/dist/delivery.d.ts +34 -2
  17. package/dist/delivery.js +391 -98
  18. package/dist/ecosystems.d.ts +23 -0
  19. package/dist/ecosystems.js +88 -10
  20. package/dist/engine.d.ts +55 -1
  21. package/dist/engine.js +101 -20
  22. package/dist/everyday-words.d.ts +11 -0
  23. package/dist/everyday-words.js +256 -0
  24. package/dist/health.d.ts +7 -0
  25. package/dist/health.js +55 -3
  26. package/dist/http.d.ts +7 -0
  27. package/dist/http.js +31 -2
  28. package/dist/index.d.ts +22 -4
  29. package/dist/index.js +12 -4
  30. package/dist/inventory-evidence.d.ts +10 -0
  31. package/dist/inventory-evidence.js +206 -0
  32. package/dist/inventory.d.ts +273 -0
  33. package/dist/inventory.js +210 -17
  34. package/dist/maintenance.d.ts +5 -0
  35. package/dist/maintenance.js +73 -5
  36. package/dist/matching.d.ts +29 -0
  37. package/dist/matching.js +537 -0
  38. package/dist/models.d.ts +17 -4
  39. package/dist/models.js +359 -29
  40. package/dist/pilot-cases.d.ts +171 -0
  41. package/dist/pilot-cases.js +330 -0
  42. package/dist/pilot-input.d.ts +16 -0
  43. package/dist/pilot-input.js +125 -0
  44. package/dist/pilot-recall.d.ts +166 -0
  45. package/dist/pilot-recall.js +231 -0
  46. package/dist/pilot-report.d.ts +113 -0
  47. package/dist/pilot-report.js +279 -0
  48. package/dist/pilot-responses.d.ts +111 -0
  49. package/dist/pilot-responses.js +159 -0
  50. package/dist/python-version.d.ts +3 -0
  51. package/dist/python-version.js +30 -0
  52. package/dist/rehearsal.d.ts +440 -0
  53. package/dist/rehearsal.js +372 -0
  54. package/dist/sbom.d.ts +13 -0
  55. package/dist/sbom.js +193 -0
  56. package/dist/source-error.d.ts +17 -1
  57. package/dist/source-error.js +18 -3
  58. package/dist/sources.d.ts +2 -2
  59. package/dist/sources.js +699 -45
  60. package/dist/store.d.ts +38 -13
  61. package/dist/store.js +325 -23
  62. package/dist/types.d.ts +159 -2
  63. package/dist/util.d.ts +23 -0
  64. package/dist/util.js +81 -1
  65. package/dist/vendor/cvss4-reference.d.ts +2 -0
  66. package/dist/vendor/cvss4-reference.js +789 -0
  67. package/dist/word-filter.d.ts +3 -0
  68. package/dist/word-filter.js +3291 -0
  69. package/docs/alert-outcome-evaluation.md +150 -0
  70. package/docs/compatibility.md +35 -0
  71. package/docs/configuration.md +289 -29
  72. package/docs/cvss-v4-support.md +41 -0
  73. package/docs/offline-advisory-preview.md +114 -0
  74. package/docs/offline-rehearsal.md +44 -0
  75. package/docs/pilot-cases.md +58 -0
  76. package/docs/pilot-recall.md +124 -0
  77. package/docs/pilot-report.md +52 -0
  78. package/docs/validation/alert-outcome-evaluation-2026-11-05.json +2935 -0
  79. package/docs/validation/cvss-v4-reference-parity-2026-11-05.json +93 -0
  80. package/docs/validation/rehearsal-accepted-2026-11-05.json +175 -0
  81. package/docs/validation/rehearsal-unknown-2026-11-05.json +175 -0
  82. package/docs/vendor/cvss-v4-LICENSE.txt +22 -0
  83. package/docs/vendor/cvss-v4-provenance.json +38 -0
  84. package/examples/agent-advisories-2026.json +145 -0
  85. package/examples/agent-advisory-cases-2026.json +397 -0
  86. package/examples/libraries.example.txt +4 -2
  87. package/examples/libraries.example.yaml +2 -0
  88. package/examples/offline-advisory-preview.mjs +42 -0
  89. package/examples/rehearsal.json +75 -0
  90. package/examples/systems.example.yaml +4 -0
  91. package/package.json +23 -7
  92. package/docs/quality-review.md +0 -104
package/dist/config.d.ts CHANGED
@@ -49,6 +49,10 @@ export declare const configSchema: z.ZodObject<{
49
49
  vllm: "vllm";
50
50
  xai: "xai";
51
51
  }>;
52
+ disclosure_profile: z.ZodDefault<z.ZodEnum<{
53
+ "deployment-context": "deployment-context";
54
+ minimal: "minimal";
55
+ }>>;
52
56
  output_format: z.ZodDefault<z.ZodEnum<{
53
57
  auto: "auto";
54
58
  json_object: "json_object";
@@ -63,6 +67,7 @@ export declare const configSchema: z.ZodObject<{
63
67
  output_usd_per_million: z.ZodOptional<z.ZodNumber>;
64
68
  }, z.core.$strict>, z.ZodTransform<{
65
69
  provider: "anthropic" | "azure-openai" | "cerebras" | "cohere" | "deepseek" | "fireworks" | "gemini" | "groq" | "huggingface" | "litellm" | "lmstudio" | "mistral" | "nvidia" | "ollama" | "openai" | "openai-compatible" | "openrouter" | "perplexity" | "sambanova" | "together" | "vllm" | "xai";
70
+ disclosure_profile: "deployment-context" | "minimal";
66
71
  output_format: "auto" | "json_object" | "json_schema" | "prompt";
67
72
  model: string;
68
73
  endpoint?: string | undefined;
@@ -72,6 +77,7 @@ export declare const configSchema: z.ZodObject<{
72
77
  api_key_env: string;
73
78
  }, {
74
79
  provider: "anthropic" | "azure-openai" | "cerebras" | "cohere" | "deepseek" | "fireworks" | "gemini" | "groq" | "huggingface" | "litellm" | "lmstudio" | "mistral" | "nvidia" | "ollama" | "openai" | "openai-compatible" | "openrouter" | "perplexity" | "sambanova" | "together" | "vllm" | "xai";
80
+ disclosure_profile: "deployment-context" | "minimal";
75
81
  output_format: "auto" | "json_object" | "json_schema" | "prompt";
76
82
  model: string;
77
83
  api_key_env?: string | undefined;
@@ -105,6 +111,10 @@ export declare const configSchema: z.ZodObject<{
105
111
  vllm: "vllm";
106
112
  xai: "xai";
107
113
  }>;
114
+ disclosure_profile: z.ZodDefault<z.ZodEnum<{
115
+ "deployment-context": "deployment-context";
116
+ minimal: "minimal";
117
+ }>>;
108
118
  output_format: z.ZodDefault<z.ZodEnum<{
109
119
  auto: "auto";
110
120
  json_object: "json_object";
@@ -119,6 +129,7 @@ export declare const configSchema: z.ZodObject<{
119
129
  output_usd_per_million: z.ZodOptional<z.ZodNumber>;
120
130
  }, z.core.$strict>, z.ZodTransform<{
121
131
  provider: "anthropic" | "azure-openai" | "cerebras" | "cohere" | "deepseek" | "fireworks" | "gemini" | "groq" | "huggingface" | "litellm" | "lmstudio" | "mistral" | "nvidia" | "ollama" | "openai" | "openai-compatible" | "openrouter" | "perplexity" | "sambanova" | "together" | "vllm" | "xai";
132
+ disclosure_profile: "deployment-context" | "minimal";
122
133
  output_format: "auto" | "json_object" | "json_schema" | "prompt";
123
134
  model: string;
124
135
  endpoint?: string | undefined;
@@ -128,6 +139,7 @@ export declare const configSchema: z.ZodObject<{
128
139
  api_key_env: string;
129
140
  }, {
130
141
  provider: "anthropic" | "azure-openai" | "cerebras" | "cohere" | "deepseek" | "fireworks" | "gemini" | "groq" | "huggingface" | "litellm" | "lmstudio" | "mistral" | "nvidia" | "ollama" | "openai" | "openai-compatible" | "openrouter" | "perplexity" | "sambanova" | "together" | "vllm" | "xai";
142
+ disclosure_profile: "deployment-context" | "minimal";
131
143
  output_format: "auto" | "json_object" | "json_schema" | "prompt";
132
144
  model: string;
133
145
  api_key_env?: string | undefined;
@@ -143,7 +155,7 @@ export declare const configSchema: z.ZodObject<{
143
155
  max_output_tokens: z.ZodDefault<z.ZodNumber>;
144
156
  timeout_seconds: z.ZodDefault<z.ZodNumber>;
145
157
  }, z.core.$strict>>;
146
- policy: z.ZodDefault<z.ZodObject<{
158
+ policy: z.ZodPipe<z.ZodDefault<z.ZodObject<{
147
159
  library: z.ZodDefault<z.ZodObject<{
148
160
  levels: z.ZodArray<z.ZodEnum<{
149
161
  critical: "critical";
@@ -198,11 +210,59 @@ export declare const configSchema: z.ZodObject<{
198
210
  urgent_unknown: z.ZodDefault<z.ZodBoolean>;
199
211
  exploited_override: z.ZodDefault<z.ZodBoolean>;
200
212
  malware_override: z.ZodDefault<z.ZodBoolean>;
213
+ ai_dismissals: z.ZodOptional<z.ZodEnum<{
214
+ record: "record";
215
+ review: "review";
216
+ }>>;
217
+ review_before_news_suppression: z.ZodOptional<z.ZodBoolean>;
201
218
  health_channels: z.ZodDefault<z.ZodArray<z.ZodEnum<{
202
219
  email: "email";
203
220
  slack: "slack";
204
221
  }>>>;
205
- }, z.core.$strict>>;
222
+ }, z.core.$strict>>, z.ZodTransform<{
223
+ library: {
224
+ levels: ("critical" | "high" | "low" | "medium" | "unknown")[];
225
+ basis: "priority" | "source_severity";
226
+ channels: ("email" | "slack")[];
227
+ };
228
+ product: {
229
+ levels: ("critical" | "high" | "low" | "medium" | "unknown")[];
230
+ basis: "priority" | "source_severity";
231
+ channels: ("email" | "slack")[];
232
+ };
233
+ news: {
234
+ levels: ("critical" | "high" | "low" | "medium" | "unknown")[];
235
+ basis: "priority" | "source_severity";
236
+ channels: ("email" | "slack")[];
237
+ };
238
+ urgent_unknown: boolean;
239
+ exploited_override: boolean;
240
+ malware_override: boolean;
241
+ health_channels: ("email" | "slack")[];
242
+ ai_dismissals: "record" | "review";
243
+ }, {
244
+ library: {
245
+ levels: ("critical" | "high" | "low" | "medium" | "unknown")[];
246
+ basis: "priority" | "source_severity";
247
+ channels: ("email" | "slack")[];
248
+ };
249
+ product: {
250
+ levels: ("critical" | "high" | "low" | "medium" | "unknown")[];
251
+ basis: "priority" | "source_severity";
252
+ channels: ("email" | "slack")[];
253
+ };
254
+ news: {
255
+ levels: ("critical" | "high" | "low" | "medium" | "unknown")[];
256
+ basis: "priority" | "source_severity";
257
+ channels: ("email" | "slack")[];
258
+ };
259
+ urgent_unknown: boolean;
260
+ exploited_override: boolean;
261
+ malware_override: boolean;
262
+ ai_dismissals?: "record" | "review" | undefined;
263
+ review_before_news_suppression?: boolean | undefined;
264
+ health_channels: ("email" | "slack")[];
265
+ }>>;
206
266
  notifications: z.ZodDefault<z.ZodObject<{
207
267
  slack: z.ZodOptional<z.ZodObject<{
208
268
  webhook_url_env: z.ZodString;
package/dist/config.js CHANGED
@@ -2,7 +2,66 @@ import { readFileSync, statSync } from 'node:fs';
2
2
  import { dirname, resolve } from 'node:path';
3
3
  import { parse } from 'yaml';
4
4
  import { z } from 'zod';
5
+ import { isIP } from 'node:net';
6
+ import { privateAddress } from './http.js';
5
7
  import { PROVIDER_IDS, providerDefinition, allowsMissingKey, modelOutputFormat, modelEndpoint, } from './providers.js';
8
+ /**
9
+ * A host that is plainly on this machine or a private network; cleartext HTTP is allowed only there.
10
+ * An address is judged by its range. A name cannot be resolved here, so it is accepted when it has
11
+ * no public form: a single label (a container or service name), a special-use or private suffix, or
12
+ * a last label that cannot be a public top-level domain (`ollama.ml-tools`). The request itself is
13
+ * refused if such a name turns out to resolve to a public address.
14
+ */
15
+ function localHost(hostname) {
16
+ const host = hostname
17
+ .replace(/^\[|\]$/g, '')
18
+ .toLowerCase()
19
+ .replace(/\.$/, '');
20
+ if (isIP(host))
21
+ return privateAddress(host);
22
+ if (!host || /^[0-9.]+$/.test(host))
23
+ return false;
24
+ const last = host.slice(host.lastIndexOf('.') + 1);
25
+ return (host === 'localhost' ||
26
+ !host.includes('.') ||
27
+ /\.(?:localhost|local|internal|intranet|private|corp|lan|home|home\.arpa|test|svc|cluster\.local|ts\.net)$/.test(host) ||
28
+ // Public top-level domains are letters only, or punycode.
29
+ (/[0-9_-]/.test(last) && !last.startsWith('xn--')));
30
+ }
31
+ /** Two model settings that reach the same model at the same address, however each is written. */
32
+ function sameModel(first, second) {
33
+ const address = (spec) => {
34
+ try {
35
+ const url = new URL(modelEndpoint(spec));
36
+ let path = url.pathname;
37
+ try {
38
+ path = decodeURIComponent(path);
39
+ }
40
+ catch {
41
+ // Keep the path as written.
42
+ }
43
+ // A trailing dot on the host, doubled or trailing slashes, percent-encoding and letter case
44
+ // are different spellings of one address.
45
+ let host = url.hostname.toLowerCase().replace(/\.$/, '');
46
+ // Every name for this machine is one address.
47
+ if (['localhost', '[::1]', '0.0.0.0', '[::]'].includes(host) ||
48
+ host.endsWith('.localhost') ||
49
+ /^127\.\d+\.\d+\.\d+$/.test(host) ||
50
+ /^\[::ffff:7f[0-9a-f]{2}:[0-9a-f]{1,4}\]$/.test(host))
51
+ host = 'localhost';
52
+ return `${url.protocol}//${host}:${url.port}${path.replace(/\/+/g, '/').replace(/\/$/, '').toLowerCase()}`;
53
+ }
54
+ catch {
55
+ return (spec.endpoint ?? '').trim().toLowerCase();
56
+ }
57
+ };
58
+ // "models/gemini-x" and "gemini-x", or "library/llama3", "llama3" and "llama3:latest", are one model.
59
+ const name = (spec) => spec.model
60
+ .toLowerCase()
61
+ .replace(/^(?:models|library)\//, '')
62
+ .replace(/:latest$/, '');
63
+ return name(first) === name(second) && address(first) === address(second);
64
+ }
6
65
  const envName = z.string().regex(/^[A-Za-z_][A-Za-z0-9_]*$/);
7
66
  const severity = z.enum(['unknown', 'low', 'medium', 'high', 'critical']);
8
67
  const channels = z
@@ -13,6 +72,7 @@ const retentionDays = z.number().int().min(1).max(3650).optional();
13
72
  const model = z
14
73
  .object({
15
74
  provider: z.enum(PROVIDER_IDS),
75
+ disclosure_profile: z.enum(['minimal', 'deployment-context']).default('minimal'),
16
76
  output_format: z.enum(['auto', 'json_schema', 'json_object', 'prompt']).default('auto'),
17
77
  model: z.string().min(1).max(200),
18
78
  api_key_env: envName.optional(),
@@ -74,7 +134,7 @@ export const configSchema = z
74
134
  analysis: model.optional(),
75
135
  verification: model.optional(),
76
136
  daily_request_limit: z.number().int().min(1).max(10000).default(100),
77
- daily_token_limit: z.number().int().min(100).max(10_000_000).default(100_000),
137
+ daily_token_limit: z.number().int().min(100).max(10_000_000).default(1_000_000),
78
138
  daily_budget_usd: z.number().positive().max(10000).optional(),
79
139
  max_input_chars: z.number().int().min(1000).max(100_000).default(12_000),
80
140
  max_output_tokens: z.number().int().min(128).max(8192).default(1500),
@@ -84,7 +144,7 @@ export const configSchema = z
84
144
  .default({
85
145
  enabled: false,
86
146
  daily_request_limit: 100,
87
- daily_token_limit: 100000,
147
+ daily_token_limit: 1_000_000,
88
148
  max_input_chars: 12000,
89
149
  max_output_tokens: 1500,
90
150
  timeout_seconds: 45,
@@ -97,6 +157,8 @@ export const configSchema = z
97
157
  urgent_unknown: z.boolean().default(true),
98
158
  exploited_override: z.boolean().default(true),
99
159
  malware_override: z.boolean().default(true),
160
+ ai_dismissals: z.enum(['review', 'record']).optional(),
161
+ review_before_news_suppression: z.boolean().optional(),
100
162
  health_channels: channels.default([]),
101
163
  })
102
164
  .strict()
@@ -107,8 +169,22 @@ export const configSchema = z
107
169
  urgent_unknown: true,
108
170
  exploited_override: true,
109
171
  malware_override: true,
172
+ ai_dismissals: 'review',
110
173
  health_channels: [],
111
- }),
174
+ })
175
+ .superRefine((policy, ctx) => {
176
+ if (policy.ai_dismissals !== undefined &&
177
+ policy.review_before_news_suppression !== undefined &&
178
+ policy.ai_dismissals !== (policy.review_before_news_suppression ? 'review' : 'record'))
179
+ ctx.addIssue({
180
+ code: 'custom',
181
+ message: 'Conflicting AI dismissal policies; use ai_dismissals only.',
182
+ });
183
+ })
184
+ .transform(({ review_before_news_suppression, ...policy }) => ({
185
+ ...policy,
186
+ ai_dismissals: policy.ai_dismissals ?? (review_before_news_suppression === false ? 'record' : 'review'),
187
+ })),
112
188
  notifications: z
113
189
  .object({
114
190
  slack: z.object({ webhook_url_env: envName }).strict().optional(),
@@ -164,6 +240,13 @@ export const configSchema = z
164
240
  })
165
241
  .strict()
166
242
  .superRefine((config, ctx) => {
243
+ const { analysis, verification } = config.models;
244
+ if (analysis && verification && sameModel(analysis, verification))
245
+ ctx.addIssue({
246
+ code: 'custom',
247
+ message: 'The verification model must differ from the analysis model; an identical model only repeats the first answer. Remove models.verification or choose another model.',
248
+ path: ['models', 'verification'],
249
+ });
167
250
  if (config.models.enabled && !config.models.analysis)
168
251
  ctx.addIssue({
169
252
  code: 'custom',
@@ -210,11 +293,11 @@ export const configSchema = z
210
293
  url.password ||
211
294
  url.search ||
212
295
  url.hash ||
213
- (!spec.allow_private_endpoint && url.protocol !== 'https:') ||
296
+ (url.protocol !== 'https:' && !(spec.allow_private_endpoint && localHost(url.hostname))) ||
214
297
  !['https:', 'http:'].includes(url.protocol))
215
298
  ctx.addIssue({
216
299
  code: 'custom',
217
- message: 'Endpoint must be HTTPS, with no credentials/query/fragment; explicit private endpoints may use HTTP',
300
+ message: 'Endpoint must be HTTPS, with no credentials/query/fragment; only an explicit private or local endpoint may use HTTP',
218
301
  path: ['models', name, 'endpoint'],
219
302
  });
220
303
  }
@@ -0,0 +1,4 @@
1
+ import type { CoverageReceipt } from './types.js';
2
+ export declare function coverageFreshness(receipt: Pick<CoverageReceipt, 'last_success_at' | 'fresh_until'>, now: number): CoverageReceipt['freshness'];
3
+ /** Re-evaluate saved receipts at read time so a stopped monitor cannot look perpetually fresh. */
4
+ export declare function refreshCoverage(receipts: CoverageReceipt[], now?: number): CoverageReceipt[];
@@ -0,0 +1,11 @@
1
+ export function coverageFreshness(receipt, now) {
2
+ const success = receipt.last_success_at ? Date.parse(receipt.last_success_at) : NaN;
3
+ const expiry = receipt.fresh_until ? Date.parse(receipt.fresh_until) : NaN;
4
+ if (!Number.isFinite(success))
5
+ return 'never';
6
+ return success <= now + 300_000 && Number.isFinite(expiry) && now <= expiry ? 'fresh' : 'stale';
7
+ }
8
+ /** Re-evaluate saved receipts at read time so a stopped monitor cannot look perpetually fresh. */
9
+ export function refreshCoverage(receipts, now = Date.now()) {
10
+ return receipts.map((receipt) => ({ ...receipt, freshness: coverageFreshness(receipt, now) }));
11
+ }
package/dist/cve-now.d.ts CHANGED
@@ -1,5 +1,35 @@
1
1
  import type { Evidence, HttpClient, Inventory } from './types.js';
2
+ /** What the collector remembers between polls, besides its checkpoint. */
3
+ export interface CveNowState {
4
+ /** In: cited identifiers the service did not have, with the time each was last asked for (JSON). */
5
+ missing?: string | undefined;
6
+ /** Out: the same list after this poll. Unset when the poll did not get as far as asking. */
7
+ next?: string;
8
+ /** In: identifiers whose requests failed on the last poll (JSON). They are asked for last. */
9
+ troubled?: string | undefined;
10
+ /** Out: the identifiers whose requests failed on this poll. */
11
+ nextTroubled?: string;
12
+ /** In: for each package version, when its lookup was last tried (JSON). */
13
+ lookups?: string | undefined;
14
+ /** Out: the same after this poll. */
15
+ nextLookups?: string;
16
+ /** In: new records still to be read, each with the time of its first failure and its arrival (JSON). */
17
+ owed?: string | undefined;
18
+ /** Out: the same list after this poll. */
19
+ nextOwed?: string;
20
+ /** In: since when a listing entry without a usable identifier has held the checkpoint. */
21
+ refusedSince?: number | undefined;
22
+ /** Out: the same, or null when no such entry is waited for. */
23
+ nextRefusedSince?: number | null;
24
+ }
25
+ /**
26
+ * Whether a record concerns this inventory. Advisory text is matched only against terms the operator
27
+ * declared (products and keywords): an advisory names its packages in structured claims, and package
28
+ * names such as "send" or "buffer" appear in unrelated descriptions. News has no structured claims,
29
+ * so a package named in a story about packages also counts.
30
+ */
2
31
  export declare function evidenceRelevant(item: Evidence, inventory: Inventory): boolean;
3
32
  /** Collect recent CVEs, exact npm matches and updates to relevant tracked IDs.
4
- * The publication-ordered listing does not cover every historical modification. */
5
- export declare function collectCveNow(inventory: Inventory, checkpoint: string | undefined, previous: Evidence[], news: Evidence[], http: HttpClient, now: number): Promise<Evidence[]>;
33
+ * The publication-ordered listing does not cover every historical modification, and a record the
34
+ * service ingests more than LATE_INGEST_DAYS after its publication date is not found by it. */
35
+ export declare function collectCveNow(inventory: Inventory, checkpoint: string | undefined, previous: Evidence[], news: Evidence[], http: HttpClient, now: number, state?: CveNowState): Promise<Evidence[]>;