@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
@@ -0,0 +1,247 @@
1
+ import type { ModelProvider, OutputFormat } from './providers.js';
2
+ import type { Ecosystem } from './ecosystems.js';
3
+ export type Severity = 'unknown' | 'low' | 'medium' | 'high' | 'critical';
4
+ export type Category = 'library' | 'product' | 'news' | 'malware' | 'health';
5
+ export type Applicability = 'affected' | 'not_affected' | 'unknown' | 'conflicting' | 'relevant';
6
+ export type Channel = 'slack' | 'email';
7
+ export interface Component {
8
+ id: string;
9
+ ecosystem: Ecosystem;
10
+ name: string;
11
+ version?: string;
12
+ }
13
+ export interface Product {
14
+ name: string;
15
+ version?: string;
16
+ keywords: string[];
17
+ }
18
+ export interface System {
19
+ id: string;
20
+ name: string;
21
+ environment: string;
22
+ owner?: string;
23
+ exposure: 'internet' | 'internal' | 'unknown';
24
+ criticality: Severity;
25
+ updated_at: string;
26
+ components: Component[];
27
+ products: Product[];
28
+ keywords: string[];
29
+ }
30
+ export interface Inventory {
31
+ systems: System[];
32
+ }
33
+ export interface PackageClaim {
34
+ ecosystem: string;
35
+ name: string;
36
+ range?: string;
37
+ versions?: string[];
38
+ matched_versions?: string[];
39
+ fixed?: string;
40
+ }
41
+ export interface Evidence {
42
+ id: string;
43
+ source: string;
44
+ kind: 'advisory' | 'news' | 'kev' | 'health';
45
+ title: string;
46
+ url: string;
47
+ description: string;
48
+ /** Whether the adapter retrieved full text, an excerpt or no usable content. */
49
+ content_status?: 'full' | 'excerpt' | 'unavailable';
50
+ aliases: string[];
51
+ severity: Severity;
52
+ modified_at: string;
53
+ fetched_at: string;
54
+ published_at?: string;
55
+ packages: PackageClaim[];
56
+ withdrawn?: boolean;
57
+ exploited?: boolean;
58
+ malware?: boolean;
59
+ }
60
+ export interface ModelSpec {
61
+ provider: ModelProvider;
62
+ output_format?: OutputFormat;
63
+ model: string;
64
+ api_key_env: string;
65
+ endpoint?: string;
66
+ allow_private_endpoint: boolean;
67
+ input_usd_per_million?: number;
68
+ output_usd_per_million?: number;
69
+ }
70
+ export interface Config {
71
+ version: 1;
72
+ inventory: string;
73
+ database: string;
74
+ poll_interval_minutes: number;
75
+ news_lookback_minutes: number;
76
+ inventory_stale_days: number;
77
+ digest_interval_hours: number;
78
+ sources: {
79
+ cve_now: boolean;
80
+ hacker_news: boolean;
81
+ osv: boolean;
82
+ github: boolean;
83
+ github_token_env: string;
84
+ kev: boolean;
85
+ feeds: string[];
86
+ vendor_feeds?: ('nodejs' | 'python' | 'php')[];
87
+ };
88
+ models: {
89
+ enabled: boolean;
90
+ analysis?: ModelSpec;
91
+ verification?: ModelSpec;
92
+ daily_request_limit: number;
93
+ daily_token_limit: number;
94
+ daily_budget_usd?: number;
95
+ max_input_chars: number;
96
+ max_output_tokens: number;
97
+ timeout_seconds: number;
98
+ };
99
+ policy: {
100
+ library: Rule;
101
+ product: Rule;
102
+ news: Rule;
103
+ urgent_unknown: boolean;
104
+ exploited_override: boolean;
105
+ malware_override: boolean;
106
+ health_channels: Channel[];
107
+ };
108
+ notifications: {
109
+ slack?: {
110
+ webhook_url_env: string;
111
+ };
112
+ email?: {
113
+ smtp_url_env: string;
114
+ from: string;
115
+ to: string[];
116
+ };
117
+ max_attempts: number;
118
+ };
119
+ monitoring?: {
120
+ heartbeat_url_env: string;
121
+ interval_seconds: number;
122
+ allow_private_endpoint: boolean;
123
+ };
124
+ maintenance?: {
125
+ interval_hours: number;
126
+ retention?: {
127
+ analysis_cache_days?: number;
128
+ evidence_history_days?: number;
129
+ finding_history_days?: number;
130
+ accepted_delivery_days?: number;
131
+ inactive_findings_days?: number;
132
+ unreferenced_evidence_days?: number;
133
+ batch_size?: number;
134
+ };
135
+ backup?: {
136
+ directory: string;
137
+ keep: number;
138
+ max_bytes: number;
139
+ };
140
+ };
141
+ }
142
+ export interface Rule {
143
+ levels: Severity[];
144
+ basis: 'source_severity' | 'priority';
145
+ channels: Channel[];
146
+ }
147
+ export interface Assessment {
148
+ /** Only news evidence supports this candidate; AI impact remains a separate claim. */
149
+ news_only?: boolean;
150
+ /** News-only or generic product context without deterministic package applicability. */
151
+ news_candidate?: boolean;
152
+ active?: boolean;
153
+ id: string;
154
+ event_id: string;
155
+ system_id: string;
156
+ component_id?: string;
157
+ category: Category;
158
+ applicability: Applicability;
159
+ source_severity: Severity;
160
+ priority: Severity;
161
+ title: string;
162
+ summary: string;
163
+ reasons: string[];
164
+ evidence_ids: string[];
165
+ urls: string[];
166
+ exploited: boolean;
167
+ fix?: string;
168
+ updated_at: string;
169
+ withdrawn?: boolean;
170
+ relevance?: 'relevant' | 'irrelevant' | 'unknown';
171
+ /** Model assessment of the article, separate from version-range applicability. */
172
+ news_analysis?: NewsAnalysis;
173
+ ai?: {
174
+ model: string;
175
+ provider: string;
176
+ prompt_version: string;
177
+ status: 'complete' | 'unavailable' | 'conflicting';
178
+ };
179
+ }
180
+ export interface Decision {
181
+ action: 'notify' | 'digest' | 'record';
182
+ channels: Channel[];
183
+ reason: string;
184
+ }
185
+ export interface Notification {
186
+ id: string;
187
+ finding_id: string;
188
+ channel: Channel;
189
+ payload: string;
190
+ status: 'pending' | 'sending' | 'accepted' | 'unknown' | 'failed';
191
+ attempts: number;
192
+ available_at: number;
193
+ last_error?: string;
194
+ }
195
+ export interface HttpOptions {
196
+ method?: 'GET' | 'POST';
197
+ headers?: Record<string, string>;
198
+ body?: string;
199
+ maxBytes?: number;
200
+ timeoutMs?: number;
201
+ /** Minimum delay between request starts to an origin; shared by concurrent calls. */
202
+ minIntervalMs?: number;
203
+ allowPrivate?: boolean;
204
+ redirects?: number;
205
+ /** When present, every redirect must remain within one of these exact origins. */
206
+ allowedRedirectOrigins?: string[];
207
+ signal?: AbortSignal;
208
+ }
209
+ export interface HttpResult {
210
+ status: number;
211
+ headers: Record<string, string>;
212
+ body: string;
213
+ }
214
+ export type HttpClient = (url: string, options?: HttpOptions) => Promise<HttpResult>;
215
+ export interface SourceResult {
216
+ evidence: Evidence[];
217
+ errors: {
218
+ source: string;
219
+ message: string;
220
+ }[];
221
+ checkpoints: Record<string, string>;
222
+ }
223
+ export interface AiAnalysis {
224
+ relevance: 'relevant' | 'irrelevant' | 'unknown';
225
+ priority: Severity;
226
+ summary: string;
227
+ evidence_ids: string[];
228
+ quotes: {
229
+ evidence_id: string;
230
+ quote: string;
231
+ }[];
232
+ news_analysis?: NewsAnalysis | null;
233
+ }
234
+ export interface NewsAnalysis {
235
+ classification: 'new_vulnerability' | 'known_vulnerability_update' | 'general_news' | 'unknown';
236
+ impact: 'affected' | 'not_affected' | 'unknown' | 'not_applicable';
237
+ affected_products: string[];
238
+ /** Affected or fixed versions quoted from the source. */
239
+ affected_versions: string[];
240
+ /** Source wording describing the conditions necessary for exploitation. */
241
+ prerequisites: string[];
242
+ rationale: string;
243
+ quotes: {
244
+ evidence_id: string;
245
+ quote: string;
246
+ }[];
247
+ }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/dist/util.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import type { Severity } from './types.js';
2
+ export declare const severityRank: Record<Severity, number>;
3
+ export declare function highest(...values: Severity[]): Severity;
4
+ export declare function hash(value: unknown): string;
5
+ export declare function timestamp(now?: number): string;
6
+ export declare function cleanText(value: string, max?: number): string;
package/dist/util.js ADDED
@@ -0,0 +1,14 @@
1
+ import { createHash } from 'node:crypto';
2
+ export const severityRank = { unknown: 0, low: 1, medium: 2, high: 3, critical: 4 };
3
+ export function highest(...values) {
4
+ return values.reduce((a, b) => (severityRank[a] >= severityRank[b] ? a : b), 'unknown');
5
+ }
6
+ export function hash(value) {
7
+ return createHash('sha256').update(JSON.stringify(value)).digest('hex');
8
+ }
9
+ export function timestamp(now = Date.now()) {
10
+ return new Date(now).toISOString();
11
+ }
12
+ export function cleanText(value, max = 4000) {
13
+ return value.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/g, '').slice(0, max);
14
+ }
@@ -0,0 +1,24 @@
1
+ import type { DefaultTreeAdapterTypes } from 'parse5';
2
+ export type VendorFeed = 'nodejs' | 'python' | 'php';
3
+ type HtmlNode = DefaultTreeAdapterTypes.Node;
4
+ /** Fixed official feeds; article extraction is opt-in for each vendor. */
5
+ export declare const VENDOR_FEEDS: {
6
+ readonly nodejs: {
7
+ readonly feed: 'https://nodejs.org/en/feed/vulnerability.xml';
8
+ readonly origin: 'https://nodejs.org';
9
+ };
10
+ readonly python: {
11
+ readonly feed: 'https://blog.python.org/rss.xml';
12
+ readonly origin: 'https://blog.python.org';
13
+ };
14
+ readonly php: {
15
+ readonly feed: 'https://www.php.net/feed.atom';
16
+ readonly origin: 'https://www.php.net';
17
+ };
18
+ };
19
+ export declare function vendorArticleTarget(vendor: VendorFeed, value: string): {
20
+ url: string;
21
+ anchor?: string;
22
+ } | undefined;
23
+ export declare function vendorArticleBody(vendor: VendorFeed, nodes: Iterable<HtmlNode>, anchor?: string): HtmlNode | undefined;
24
+ export {};
@@ -0,0 +1,56 @@
1
+ /** Fixed official feeds; article extraction is opt-in for each vendor. */
2
+ export const VENDOR_FEEDS = {
3
+ nodejs: { feed: 'https://nodejs.org/en/feed/vulnerability.xml', origin: 'https://nodejs.org' },
4
+ python: { feed: 'https://blog.python.org/rss.xml', origin: 'https://blog.python.org' },
5
+ php: { feed: 'https://www.php.net/feed.atom', origin: 'https://www.php.net' },
6
+ };
7
+ export function vendorArticleTarget(vendor, value) {
8
+ try {
9
+ const url = new URL(value);
10
+ if (url.origin !== VENDOR_FEEDS[vendor].origin || url.username || url.password || url.search)
11
+ return undefined;
12
+ if (vendor === 'nodejs' && !/^\/en\/blog\/vulnerability\/[a-z0-9-]+\/?$/.test(url.pathname))
13
+ return undefined;
14
+ if (vendor === 'python' && !/^\/\d{4}\/\d{2}\/[a-z0-9-]+(?:\.html|\/)$/.test(url.pathname))
15
+ return undefined;
16
+ if (vendor === 'php') {
17
+ if (!/^\/(?:index\.php|archive\/\d{4}\.php)$/.test(url.pathname) ||
18
+ !/^#\d{4}-\d{2}-\d{2}-\d+$/.test(url.hash))
19
+ return undefined;
20
+ const anchor = url.hash.slice(1);
21
+ url.hash = '';
22
+ return { url: url.href, anchor };
23
+ }
24
+ if (url.hash)
25
+ return undefined;
26
+ return { url: url.href };
27
+ }
28
+ catch {
29
+ return undefined;
30
+ }
31
+ }
32
+ export function vendorArticleBody(vendor, nodes, anchor) {
33
+ const complete = (node) => 'tagName' in node &&
34
+ node.namespaceURI === 'http://www.w3.org/1999/xhtml' &&
35
+ node.sourceCodeLocation?.startTag &&
36
+ node.sourceCodeLocation.endTag;
37
+ const classes = (node) => (node.attrs.find((attr) => attr.name === 'class')?.value ?? '').split(/\s+/);
38
+ for (const node of nodes) {
39
+ if (!('tagName' in node) || node.namespaceURI !== 'http://www.w3.org/1999/xhtml')
40
+ continue;
41
+ if (vendor === 'nodejs' &&
42
+ node.tagName === 'main' &&
43
+ node.attrs.some((attr) => attr.name === 'id' && attr.value === 'main'))
44
+ return complete(node) ? node : undefined;
45
+ if (vendor === 'python' && node.tagName === 'article' && classes(node).includes('prose'))
46
+ return complete(node) ? node : undefined;
47
+ if (vendor === 'php' && node.attrs.some((attr) => attr.name === 'id' && attr.value === anchor)) {
48
+ let parent = node;
49
+ for (let depth = 0; parent && depth < 8; depth++, parent = 'parentNode' in parent ? (parent.parentNode ?? undefined) : undefined)
50
+ if ('tagName' in parent && parent.tagName === 'article' && classes(parent).includes('newsentry'))
51
+ return complete(parent) ? parent : undefined;
52
+ return undefined;
53
+ }
54
+ }
55
+ return undefined;
56
+ }