@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,459 @@
1
+ import { z } from 'zod';
2
+ const catalog = [
3
+ {
4
+ id: 'openai',
5
+ name: 'OpenAI',
6
+ protocol: 'openai-responses',
7
+ endpoint: 'https://api.openai.com/v1/responses',
8
+ apiKeyEnv: 'OPENAI_API_KEY',
9
+ defaultFormat: 'json_schema',
10
+ documentationUrl: 'https://developers.openai.com/api/reference/resources/responses/methods/create',
11
+ },
12
+ {
13
+ id: 'azure-openai',
14
+ name: 'Azure OpenAI',
15
+ protocol: 'openai-responses',
16
+ apiKeyEnv: 'AZURE_OPENAI_API_KEY',
17
+ defaultFormat: 'json_schema',
18
+ documentationUrl: 'https://learn.microsoft.com/en-us/rest/api/aifoundry/azureopenai/responses',
19
+ },
20
+ {
21
+ id: 'anthropic',
22
+ name: 'Anthropic',
23
+ protocol: 'anthropic',
24
+ endpoint: 'https://api.anthropic.com/v1/messages',
25
+ apiKeyEnv: 'ANTHROPIC_API_KEY',
26
+ defaultFormat: 'json_schema',
27
+ formats: ['json_schema', 'prompt'],
28
+ documentationUrl: 'https://platform.claude.com/docs/en/build-with-claude/structured-outputs',
29
+ },
30
+ {
31
+ id: 'gemini',
32
+ name: 'Google Gemini',
33
+ protocol: 'gemini',
34
+ endpoint: 'https://generativelanguage.googleapis.com/v1beta/models/{model}:generateContent',
35
+ apiKeyEnv: 'GEMINI_API_KEY',
36
+ defaultFormat: 'json_schema',
37
+ documentationUrl: 'https://ai.google.dev/api/generate-content',
38
+ },
39
+ {
40
+ id: 'cohere',
41
+ name: 'Cohere',
42
+ protocol: 'cohere',
43
+ endpoint: 'https://api.cohere.com/v2/chat',
44
+ apiKeyEnv: 'COHERE_API_KEY',
45
+ defaultFormat: 'json_schema',
46
+ documentationUrl: 'https://docs.cohere.com/v2/reference/chat',
47
+ },
48
+ {
49
+ id: 'groq',
50
+ name: 'Groq',
51
+ protocol: 'openai-chat',
52
+ endpoint: 'https://api.groq.com/openai/v1/chat/completions',
53
+ apiKeyEnv: 'GROQ_API_KEY',
54
+ defaultFormat: 'json_object',
55
+ tokenParameter: 'max_completion_tokens',
56
+ documentationUrl: 'https://console.groq.com/docs/api-reference',
57
+ },
58
+ {
59
+ id: 'deepseek',
60
+ name: 'DeepSeek',
61
+ protocol: 'openai-chat',
62
+ endpoint: 'https://api.deepseek.com/chat/completions',
63
+ apiKeyEnv: 'DEEPSEEK_API_KEY',
64
+ defaultFormat: 'json_object',
65
+ formats: ['json_object', 'prompt'],
66
+ documentationUrl: 'https://api-docs.deepseek.com/api/create-chat-completion/',
67
+ },
68
+ {
69
+ id: 'xai',
70
+ name: 'xAI',
71
+ protocol: 'openai-responses',
72
+ endpoint: 'https://api.x.ai/v1/responses',
73
+ apiKeyEnv: 'XAI_API_KEY',
74
+ defaultFormat: 'json_schema',
75
+ documentationUrl: 'https://docs.x.ai/developers/model-capabilities/text/structured-outputs',
76
+ },
77
+ {
78
+ id: 'mistral',
79
+ name: 'Mistral',
80
+ protocol: 'openai-chat',
81
+ endpoint: 'https://api.mistral.ai/v1/chat/completions',
82
+ apiKeyEnv: 'MISTRAL_API_KEY',
83
+ defaultFormat: 'json_schema',
84
+ documentationUrl: 'https://docs.mistral.ai/api',
85
+ },
86
+ {
87
+ id: 'together',
88
+ name: 'Together AI',
89
+ protocol: 'openai-chat',
90
+ endpoint: 'https://api.together.ai/v1/chat/completions',
91
+ apiKeyEnv: 'TOGETHER_API_KEY',
92
+ defaultFormat: 'json_object',
93
+ documentationUrl: 'https://docs.together.ai/reference/chat-completions',
94
+ },
95
+ {
96
+ id: 'fireworks',
97
+ name: 'Fireworks AI',
98
+ protocol: 'openai-chat',
99
+ endpoint: 'https://api.fireworks.ai/inference/v1/chat/completions',
100
+ apiKeyEnv: 'FIREWORKS_API_KEY',
101
+ defaultFormat: 'json_object',
102
+ documentationUrl: 'https://docs.fireworks.ai/api-reference/post-chatcompletions',
103
+ },
104
+ {
105
+ id: 'openrouter',
106
+ name: 'OpenRouter',
107
+ protocol: 'openai-chat',
108
+ endpoint: 'https://openrouter.ai/api/v1/chat/completions',
109
+ apiKeyEnv: 'OPENROUTER_API_KEY',
110
+ defaultFormat: 'json_object',
111
+ documentationUrl: 'https://openrouter.ai/docs/guides/features/structured-outputs',
112
+ },
113
+ {
114
+ id: 'cerebras',
115
+ name: 'Cerebras',
116
+ protocol: 'openai-chat',
117
+ endpoint: 'https://api.cerebras.ai/v1/chat/completions',
118
+ apiKeyEnv: 'CEREBRAS_API_KEY',
119
+ defaultFormat: 'json_object',
120
+ tokenParameter: 'max_completion_tokens',
121
+ documentationUrl: 'https://inference-docs.cerebras.ai/api-reference/chat-completions',
122
+ },
123
+ {
124
+ id: 'nvidia',
125
+ name: 'NVIDIA NIM',
126
+ protocol: 'openai-chat',
127
+ endpoint: 'https://integrate.api.nvidia.com/v1/chat/completions',
128
+ apiKeyEnv: 'NVIDIA_API_KEY',
129
+ defaultFormat: 'prompt',
130
+ documentationUrl: 'https://docs.api.nvidia.com/nim/reference/openai-gpt-oss-120b-infer',
131
+ },
132
+ {
133
+ id: 'sambanova',
134
+ name: 'SambaNova',
135
+ protocol: 'openai-chat',
136
+ endpoint: 'https://api.sambanova.ai/v1/chat/completions',
137
+ apiKeyEnv: 'SAMBANOVA_API_KEY',
138
+ defaultFormat: 'json_object',
139
+ documentationUrl: 'https://raw.githubusercontent.com/sambanova/sambanova-inference-api-spec/refs/heads/main/openapi.documented.json',
140
+ },
141
+ {
142
+ id: 'huggingface',
143
+ name: 'Hugging Face Inference Providers',
144
+ protocol: 'openai-chat',
145
+ endpoint: 'https://router.huggingface.co/v1/chat/completions',
146
+ apiKeyEnv: 'HF_TOKEN',
147
+ defaultFormat: 'prompt',
148
+ documentationUrl: 'https://huggingface.co/docs/inference-providers/en/tasks/chat-completion',
149
+ },
150
+ {
151
+ id: 'perplexity',
152
+ name: 'Perplexity Agent API',
153
+ protocol: 'perplexity',
154
+ endpoint: 'https://api.perplexity.ai/v1/agent',
155
+ apiKeyEnv: 'PERPLEXITY_API_KEY',
156
+ defaultFormat: 'json_schema',
157
+ formats: ['json_schema', 'prompt'],
158
+ documentationUrl: 'https://docs.perplexity.ai/api-reference/agent-post',
159
+ },
160
+ {
161
+ id: 'openai-compatible',
162
+ name: 'OpenAI-compatible endpoint',
163
+ protocol: 'openai-chat',
164
+ apiKeyEnv: 'OPENAI_API_KEY',
165
+ defaultFormat: 'json_schema',
166
+ documentationUrl: 'https://developers.openai.com/api/reference/resources/chat/subresources/completions/methods/create',
167
+ },
168
+ {
169
+ id: 'ollama',
170
+ name: 'Ollama local server',
171
+ protocol: 'openai-chat',
172
+ apiKeyEnv: 'OLLAMA_API_KEY',
173
+ defaultFormat: 'json_schema',
174
+ local: true,
175
+ documentationUrl: 'https://docs.ollama.com/api/openai-compatibility',
176
+ },
177
+ {
178
+ id: 'lmstudio',
179
+ name: 'LM Studio local server',
180
+ protocol: 'openai-chat',
181
+ apiKeyEnv: 'LM_STUDIO_API_KEY',
182
+ defaultFormat: 'json_schema',
183
+ local: true,
184
+ documentationUrl: 'https://lmstudio.ai/docs/developer/openai-compat/structured-output',
185
+ },
186
+ {
187
+ id: 'vllm',
188
+ name: 'vLLM server',
189
+ protocol: 'openai-chat',
190
+ apiKeyEnv: 'VLLM_API_KEY',
191
+ defaultFormat: 'json_schema',
192
+ local: true,
193
+ documentationUrl: 'https://docs.vllm.ai/en/latest/features/structured_outputs/',
194
+ },
195
+ {
196
+ id: 'litellm',
197
+ name: 'LiteLLM gateway',
198
+ protocol: 'openai-chat',
199
+ apiKeyEnv: 'LITELLM_API_KEY',
200
+ defaultFormat: 'json_object',
201
+ local: true,
202
+ documentationUrl: 'https://docs.litellm.ai/docs/completion/json_mode',
203
+ },
204
+ ];
205
+ export const PROVIDERS = Object.freeze(catalog.map((entry) => Object.freeze({
206
+ ...entry,
207
+ ...('formats' in entry ? { formats: Object.freeze([...entry.formats]) } : {}),
208
+ })));
209
+ export const PROVIDER_IDS = Object.freeze(catalog.map((entry) => entry.id));
210
+ export function providerDefinition(id) {
211
+ const definition = PROVIDERS.find((entry) => entry.id === id);
212
+ if (!definition)
213
+ throw new Error('MODEL_PROVIDER_UNKNOWN');
214
+ return definition;
215
+ }
216
+ export function allowsMissingKey(spec) {
217
+ return Boolean(spec.allow_private_endpoint &&
218
+ (spec.provider === 'openai-compatible' || providerDefinition(spec.provider).local));
219
+ }
220
+ export function modelOutputFormat(spec) {
221
+ const definition = providerDefinition(spec.provider);
222
+ const format = !spec.output_format || spec.output_format === 'auto' ? definition.defaultFormat : spec.output_format;
223
+ if (definition.formats && !definition.formats.includes(format))
224
+ throw new Error('MODEL_OUTPUT_FORMAT_UNSUPPORTED');
225
+ return format;
226
+ }
227
+ export function modelEndpoint(spec) {
228
+ if (spec.endpoint)
229
+ return spec.endpoint;
230
+ const definition = providerDefinition(spec.provider);
231
+ if (!definition.endpoint)
232
+ throw new Error('MODEL_ENDPOINT_MISSING');
233
+ if (definition.protocol !== 'gemini')
234
+ return definition.endpoint;
235
+ const model = spec.model.replace(/^models\//, '');
236
+ if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(model))
237
+ throw new Error('MODEL_ID_INVALID');
238
+ return definition.endpoint.replace('{model}', encodeURIComponent(model));
239
+ }
240
+ export function buildModelRequest(spec, token, instruction, input, schema, maxOutput) {
241
+ const definition = providerDefinition(spec.provider);
242
+ if (!token && !allowsMissingKey(spec))
243
+ throw new Error('MODEL_CREDENTIAL_MISSING');
244
+ const url = modelEndpoint(spec);
245
+ const format = modelOutputFormat(spec);
246
+ const headers = { 'content-type': 'application/json' };
247
+ const guidance = instruction + `\nReturn only JSON matching this JSON schema: ${JSON.stringify(schema)}`;
248
+ if (definition.protocol === 'anthropic') {
249
+ headers['x-api-key'] = token;
250
+ headers['anthropic-version'] = '2023-06-01';
251
+ return {
252
+ url,
253
+ headers,
254
+ body: {
255
+ model: spec.model,
256
+ max_tokens: maxOutput,
257
+ system: guidance,
258
+ messages: [{ role: 'user', content: input }],
259
+ ...(format === 'json_schema' ? { output_config: { format: { type: 'json_schema', schema } } } : {}),
260
+ },
261
+ };
262
+ }
263
+ if (definition.protocol === 'gemini') {
264
+ headers['x-goog-api-key'] = token;
265
+ return {
266
+ url,
267
+ headers,
268
+ body: {
269
+ systemInstruction: { parts: [{ text: guidance }] },
270
+ contents: [{ role: 'user', parts: [{ text: input }] }],
271
+ generationConfig: {
272
+ maxOutputTokens: maxOutput,
273
+ candidateCount: 1,
274
+ ...(format === 'prompt'
275
+ ? {}
276
+ : {
277
+ responseFormat: {
278
+ text: { mimeType: 'APPLICATION_JSON', ...(format === 'json_schema' ? { schema } : {}) },
279
+ },
280
+ }),
281
+ },
282
+ },
283
+ };
284
+ }
285
+ if (token) {
286
+ if (spec.provider === 'azure-openai')
287
+ headers['api-key'] = token;
288
+ else
289
+ headers.authorization = `Bearer ${token}`;
290
+ }
291
+ if (definition.protocol === 'openai-responses' || definition.protocol === 'perplexity') {
292
+ const body = {
293
+ model: spec.model,
294
+ instructions: guidance,
295
+ input,
296
+ store: false,
297
+ background: false,
298
+ max_output_tokens: maxOutput,
299
+ };
300
+ if (definition.protocol === 'perplexity') {
301
+ Object.assign(body, { tools: [], tool_choice: 'none', max_steps: 1, stream: false });
302
+ if (format === 'json_schema')
303
+ body.response_format = { type: 'json_schema', json_schema: { name: 'securityassessment', schema } };
304
+ }
305
+ else if (format !== 'prompt') {
306
+ body.text = {
307
+ format: format === 'json_schema'
308
+ ? { type: 'json_schema', name: 'security_assessment', strict: true, schema }
309
+ : { type: 'json_object' },
310
+ };
311
+ }
312
+ return { url, headers, body };
313
+ }
314
+ const body = {
315
+ model: spec.model,
316
+ [definition.tokenParameter ?? 'max_tokens']: maxOutput,
317
+ stream: false,
318
+ messages: [
319
+ { role: 'system', content: guidance },
320
+ { role: 'user', content: input },
321
+ ],
322
+ };
323
+ if (format !== 'prompt') {
324
+ body.response_format =
325
+ definition.protocol === 'cohere'
326
+ ? { type: 'json_object', ...(format === 'json_schema' ? { schema } : {}) }
327
+ : format === 'json_schema'
328
+ ? { type: 'json_schema', json_schema: { name: 'security_assessment', strict: true, schema } }
329
+ : { type: 'json_object' };
330
+ }
331
+ if (spec.provider === 'openrouter' && format !== 'prompt')
332
+ body.provider = { require_parameters: true };
333
+ return { url, headers, body };
334
+ }
335
+ const recordSchema = z.record(z.string(), z.unknown());
336
+ const textBlocks = z.array(z.object({ type: z.string(), text: z.string().optional() }));
337
+ function responseText(text) {
338
+ if (!text.trim())
339
+ throw new Error('MODEL_EMPTY_OUTPUT');
340
+ return text;
341
+ }
342
+ export function parseModelResponse(spec, value) {
343
+ const protocol = providerDefinition(spec.provider).protocol;
344
+ const record = recordSchema.parse(value);
345
+ if (record.error)
346
+ throw new Error('MODEL_PROVIDER_ERROR');
347
+ if (protocol === 'openai-responses' || protocol === 'perplexity') {
348
+ if (record.status !== 'completed')
349
+ throw new Error('MODEL_INCOMPLETE');
350
+ const output = z
351
+ .array(z.object({ type: z.string(), status: z.string().optional(), content: textBlocks.optional() }))
352
+ .parse(record.output);
353
+ if (output.some((item) => item.content?.some((part) => part.type === 'refusal')))
354
+ throw new Error('MODEL_REFUSAL');
355
+ if (output.some((item) => !['message', 'reasoning'].includes(item.type)))
356
+ throw new Error('MODEL_UNEXPECTED_TOOL');
357
+ if (output.some((item) => item.status && item.status !== 'completed'))
358
+ throw new Error('MODEL_INCOMPLETE');
359
+ return responseText(output
360
+ .filter((item) => item.type === 'message')
361
+ .flatMap((item) => item.content ?? [])
362
+ .filter((part) => part.type === 'output_text')
363
+ .map((part) => part.text ?? '')
364
+ .join(''));
365
+ }
366
+ if (protocol === 'gemini') {
367
+ const feedback = record.promptFeedback === undefined ? undefined : recordSchema.parse(record.promptFeedback);
368
+ if (feedback?.blockReason)
369
+ throw new Error('MODEL_REFUSAL');
370
+ const candidates = z
371
+ .array(z.object({
372
+ finishReason: z.string(),
373
+ content: z.object({
374
+ parts: z.array(z.object({
375
+ text: z.string().optional(),
376
+ thought: z.boolean().optional(),
377
+ functionCall: z.unknown().optional(),
378
+ functionResponse: z.unknown().optional(),
379
+ executableCode: z.unknown().optional(),
380
+ codeExecutionResult: z.unknown().optional(),
381
+ toolCall: z.unknown().optional(),
382
+ toolResponse: z.unknown().optional(),
383
+ })),
384
+ }),
385
+ safetyRatings: z.array(z.object({ blocked: z.boolean().optional() })).optional(),
386
+ }))
387
+ .length(1)
388
+ .parse(record.candidates);
389
+ const candidate = candidates[0];
390
+ if (candidate.safetyRatings?.some((rating) => rating.blocked) ||
391
+ ['SAFETY', 'RECITATION', 'BLOCKLIST', 'PROHIBITED_CONTENT', 'SPII', 'IMAGE_SAFETY'].includes(candidate.finishReason))
392
+ throw new Error('MODEL_REFUSAL');
393
+ if (candidate.finishReason !== 'STOP')
394
+ throw new Error('MODEL_INCOMPLETE');
395
+ if (candidate.content.parts.some((part) => [
396
+ part.functionCall,
397
+ part.functionResponse,
398
+ part.executableCode,
399
+ part.codeExecutionResult,
400
+ part.toolCall,
401
+ part.toolResponse,
402
+ ].some((value) => value !== undefined)))
403
+ throw new Error('MODEL_UNEXPECTED_TOOL');
404
+ return responseText(candidate.content.parts
405
+ .filter((part) => !part.thought)
406
+ .map((part) => part.text ?? '')
407
+ .join(''));
408
+ }
409
+ if (protocol === 'anthropic') {
410
+ if (record.stop_reason === 'refusal')
411
+ throw new Error('MODEL_REFUSAL');
412
+ if (record.stop_reason !== 'end_turn')
413
+ throw new Error('MODEL_INCOMPLETE');
414
+ const content = textBlocks.parse(record.content);
415
+ if (content.some((part) => !['text', 'thinking', 'redacted_thinking'].includes(part.type)))
416
+ throw new Error('MODEL_UNEXPECTED_TOOL');
417
+ return responseText(content
418
+ .filter((part) => part.type === 'text')
419
+ .map((part) => part.text ?? '')
420
+ .join(''));
421
+ }
422
+ if (protocol === 'cohere') {
423
+ if (record.finish_reason !== 'COMPLETE')
424
+ throw new Error('MODEL_INCOMPLETE');
425
+ const message = z
426
+ .object({ content: textBlocks, tool_calls: z.array(z.unknown()).optional() })
427
+ .parse(record.message);
428
+ if (message.tool_calls?.length)
429
+ throw new Error('MODEL_UNEXPECTED_TOOL');
430
+ if (message.content.some((part) => part.type === 'refusal'))
431
+ throw new Error('MODEL_REFUSAL');
432
+ if (message.content.some((part) => part.type !== 'text'))
433
+ throw new Error('MODEL_UNEXPECTED_TOOL');
434
+ return responseText(message.content
435
+ .filter((part) => part.type === 'text')
436
+ .map((part) => part.text ?? '')
437
+ .join(''));
438
+ }
439
+ const choices = z
440
+ .array(z.object({
441
+ finish_reason: z.string(),
442
+ message: z.object({
443
+ content: z.string(),
444
+ refusal: z.string().nullable().optional(),
445
+ tool_calls: z.array(z.unknown()).optional(),
446
+ function_call: z.unknown().optional(),
447
+ }),
448
+ }))
449
+ .length(1)
450
+ .parse(record.choices);
451
+ const choice = choices[0];
452
+ if (choice.message.refusal || choice.finish_reason === 'content_filter')
453
+ throw new Error('MODEL_REFUSAL');
454
+ if (choice.finish_reason !== 'stop')
455
+ throw new Error('MODEL_INCOMPLETE');
456
+ if (choice.message.tool_calls?.length || choice.message.function_call)
457
+ throw new Error('MODEL_UNEXPECTED_TOOL');
458
+ return responseText(choice.message.content);
459
+ }
@@ -0,0 +1,113 @@
1
+ export declare const SYSTEM_TEMPLATES: readonly [{
2
+ readonly id: 'nodejs';
3
+ readonly name: 'Node.js';
4
+ readonly keywords: readonly ['NodeJS', 'Node.js runtime'];
5
+ }, {
6
+ readonly id: 'python';
7
+ readonly name: 'Python';
8
+ readonly keywords: readonly ['CPython'];
9
+ }, {
10
+ readonly id: 'java';
11
+ readonly name: 'Java';
12
+ readonly keywords: readonly ['OpenJDK', 'Java SE', 'Oracle JDK'];
13
+ }, {
14
+ readonly id: 'go';
15
+ readonly name: 'Go';
16
+ readonly keywords: readonly ['Golang', 'Go runtime', 'Go standard library'];
17
+ }, {
18
+ readonly id: 'rust';
19
+ readonly name: 'Rust';
20
+ readonly keywords: readonly ['rustc', 'Cargo'];
21
+ }, {
22
+ readonly id: 'php';
23
+ readonly name: 'PHP';
24
+ readonly keywords: readonly [];
25
+ }, {
26
+ readonly id: 'ruby';
27
+ readonly name: 'Ruby';
28
+ readonly keywords: readonly ['Ruby on Rails'];
29
+ }, {
30
+ readonly id: 'dotnet';
31
+ readonly name: '.NET';
32
+ readonly keywords: readonly ['ASP.NET', '.NET Core'];
33
+ }, {
34
+ readonly id: 'linux';
35
+ readonly name: 'Linux';
36
+ readonly keywords: readonly ['Linux kernel'];
37
+ }, {
38
+ readonly id: 'windows';
39
+ readonly name: 'Windows';
40
+ readonly keywords: readonly ['Windows Server'];
41
+ }, {
42
+ readonly id: 'docker';
43
+ readonly name: 'Docker';
44
+ readonly keywords: readonly ['Docker Engine', 'Docker Desktop', 'Moby'];
45
+ }, {
46
+ readonly id: 'kubernetes';
47
+ readonly name: 'Kubernetes';
48
+ readonly keywords: readonly ['kubelet', 'kube-apiserver'];
49
+ }, {
50
+ readonly id: 'nginx';
51
+ readonly name: 'NGINX';
52
+ readonly keywords: readonly [];
53
+ }, {
54
+ readonly id: 'apache-http';
55
+ readonly name: 'Apache HTTP Server';
56
+ readonly keywords: readonly ['Apache httpd'];
57
+ }, {
58
+ readonly id: 'openssl';
59
+ readonly name: 'OpenSSL';
60
+ readonly keywords: readonly [];
61
+ }, {
62
+ readonly id: 'openssh';
63
+ readonly name: 'OpenSSH';
64
+ readonly keywords: readonly [];
65
+ }, {
66
+ readonly id: 'postgresql';
67
+ readonly name: 'PostgreSQL';
68
+ readonly keywords: readonly ['Postgres'];
69
+ }, {
70
+ readonly id: 'mysql';
71
+ readonly name: 'MySQL';
72
+ readonly keywords: readonly [];
73
+ }, {
74
+ readonly id: 'redis';
75
+ readonly name: 'Redis';
76
+ readonly keywords: readonly [];
77
+ }, {
78
+ readonly id: 'mongodb';
79
+ readonly name: 'MongoDB';
80
+ readonly keywords: readonly [];
81
+ }, {
82
+ readonly id: 'git';
83
+ readonly name: 'Git';
84
+ readonly keywords: readonly [];
85
+ }, {
86
+ readonly id: 'jenkins';
87
+ readonly name: 'Jenkins';
88
+ readonly keywords: readonly [];
89
+ }, {
90
+ readonly id: 'elasticsearch';
91
+ readonly name: 'Elasticsearch';
92
+ readonly keywords: readonly [];
93
+ }, {
94
+ readonly id: 'sqlite';
95
+ readonly name: 'SQLite';
96
+ readonly keywords: readonly [];
97
+ }];
98
+ export declare function starterSystems(selection: string, now?: number): {
99
+ id: "apache-http" | "docker" | "dotnet" | "elasticsearch" | "git" | "go" | "java" | "jenkins" | "kubernetes" | "linux" | "mongodb" | "mysql" | "nginx" | "nodejs" | "openssh" | "openssl" | "php" | "postgresql" | "python" | "redis" | "ruby" | "rust" | "sqlite" | "windows";
100
+ name: ".NET" | "Apache HTTP Server" | "Docker" | "Elasticsearch" | "Git" | "Go" | "Java" | "Jenkins" | "Kubernetes" | "Linux" | "MongoDB" | "MySQL" | "NGINX" | "Node.js" | "OpenSSH" | "OpenSSL" | "PHP" | "PostgreSQL" | "Python" | "Redis" | "Ruby" | "Rust" | "SQLite" | "Windows";
101
+ environment: string;
102
+ exposure: string;
103
+ criticality: string;
104
+ updated_at: string;
105
+ components: never[];
106
+ products: {
107
+ name: ".NET" | "Apache HTTP Server" | "Docker" | "Elasticsearch" | "Git" | "Go" | "Java" | "Jenkins" | "Kubernetes" | "Linux" | "MongoDB" | "MySQL" | "NGINX" | "Node.js" | "OpenSSH" | "OpenSSL" | "PHP" | "PostgreSQL" | "Python" | "Redis" | "Ruby" | "Rust" | "SQLite" | "Windows";
108
+ keywords: (".NET Core" | "ASP.NET" | "Apache httpd" | "CPython" | "Cargo" | "Docker Desktop" | "Docker Engine" | "Go runtime" | "Go standard library" | "Golang" | "Java SE" | "Linux kernel" | "Moby" | "Node.js runtime" | "NodeJS" | "OpenJDK" | "Oracle JDK" | "Postgres" | "Ruby on Rails" | "Windows Server" | "kube-apiserver" | "kubelet" | "rustc")[];
109
+ }[];
110
+ keywords: never[];
111
+ }[];
112
+ /** Load dotenv data only when requested. Existing environment values take precedence. */
113
+ export declare function loadEnvFile(path: string): void;
package/dist/setup.js ADDED
@@ -0,0 +1,100 @@
1
+ import { closeSync, constants, fstatSync, lstatSync, openSync, readSync } from 'node:fs';
2
+ import { parseEnv } from 'node:util';
3
+ export const SYSTEM_TEMPLATES = [
4
+ { id: 'nodejs', name: 'Node.js', keywords: ['NodeJS', 'Node.js runtime'] },
5
+ { id: 'python', name: 'Python', keywords: ['CPython'] },
6
+ { id: 'java', name: 'Java', keywords: ['OpenJDK', 'Java SE', 'Oracle JDK'] },
7
+ { id: 'go', name: 'Go', keywords: ['Golang', 'Go runtime', 'Go standard library'] },
8
+ { id: 'rust', name: 'Rust', keywords: ['rustc', 'Cargo'] },
9
+ { id: 'php', name: 'PHP', keywords: [] },
10
+ { id: 'ruby', name: 'Ruby', keywords: ['Ruby on Rails'] },
11
+ { id: 'dotnet', name: '.NET', keywords: ['ASP.NET', '.NET Core'] },
12
+ { id: 'linux', name: 'Linux', keywords: ['Linux kernel'] },
13
+ { id: 'windows', name: 'Windows', keywords: ['Windows Server'] },
14
+ { id: 'docker', name: 'Docker', keywords: ['Docker Engine', 'Docker Desktop', 'Moby'] },
15
+ { id: 'kubernetes', name: 'Kubernetes', keywords: ['kubelet', 'kube-apiserver'] },
16
+ { id: 'nginx', name: 'NGINX', keywords: [] },
17
+ { id: 'apache-http', name: 'Apache HTTP Server', keywords: ['Apache httpd'] },
18
+ { id: 'openssl', name: 'OpenSSL', keywords: [] },
19
+ { id: 'openssh', name: 'OpenSSH', keywords: [] },
20
+ { id: 'postgresql', name: 'PostgreSQL', keywords: ['Postgres'] },
21
+ { id: 'mysql', name: 'MySQL', keywords: [] },
22
+ { id: 'redis', name: 'Redis', keywords: [] },
23
+ { id: 'mongodb', name: 'MongoDB', keywords: [] },
24
+ { id: 'git', name: 'Git', keywords: [] },
25
+ { id: 'jenkins', name: 'Jenkins', keywords: [] },
26
+ { id: 'elasticsearch', name: 'Elasticsearch', keywords: [] },
27
+ { id: 'sqlite', name: 'SQLite', keywords: [] },
28
+ ];
29
+ export function starterSystems(selection, now = Date.now()) {
30
+ const ids = selection.split(',').map((id) => id.trim());
31
+ if (!ids.length || ids.some((id) => !SYSTEM_TEMPLATES.some((template) => template.id === id)))
32
+ throw new Error('Unknown system template. Run security-watch templates for the available names.');
33
+ return [...new Set(ids)].map((id) => {
34
+ const template = SYSTEM_TEMPLATES.find((entry) => entry.id === id);
35
+ return {
36
+ id: template.id,
37
+ name: template.name,
38
+ environment: 'unknown',
39
+ exposure: 'unknown',
40
+ criticality: 'unknown',
41
+ updated_at: new Date(now).toISOString(),
42
+ components: [],
43
+ products: [{ name: template.name, keywords: [...template.keywords] }],
44
+ keywords: [],
45
+ };
46
+ });
47
+ }
48
+ /** Load dotenv data only when requested. Existing environment values take precedence. */
49
+ export function loadEnvFile(path) {
50
+ let fd;
51
+ try {
52
+ if (!lstatSync(path).isFile())
53
+ throw new Error('Not a regular file');
54
+ fd = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0));
55
+ }
56
+ catch {
57
+ throw new Error('Cannot open the env file. Use a regular private file.');
58
+ }
59
+ try {
60
+ const stat = fstatSync(fd);
61
+ if (!stat.isFile() || stat.size > 131_072)
62
+ throw new Error('The env file must be a regular file no larger than 128 KiB.');
63
+ if (process.platform !== 'win32' && (stat.mode & 0o077) !== 0)
64
+ throw new Error('The env file is readable by other users. Run chmod 600 on it first.');
65
+ const buffer = Buffer.alloc(131_073);
66
+ let size = 0;
67
+ while (size < buffer.length) {
68
+ const count = readSync(fd, buffer, size, buffer.length - size, null);
69
+ if (!count)
70
+ break;
71
+ size += count;
72
+ }
73
+ if (size > 131_072)
74
+ throw new Error('The env file exceeds 128 KiB.');
75
+ const text = buffer.toString('utf8', 0, size);
76
+ const values = parseEnv(text);
77
+ if (Object.keys(values)
78
+ .map((name) => name.toUpperCase())
79
+ .some((name) => /^(LD_|DYLD_)/.test(name) ||
80
+ [
81
+ 'PATH',
82
+ 'HOME',
83
+ 'SHELL',
84
+ 'NODE_OPTIONS',
85
+ 'NODE_TLS_REJECT_UNAUTHORIZED',
86
+ 'NODE_EXTRA_CA_CERTS',
87
+ 'NODE_USE_SYSTEM_CA',
88
+ 'NODE_USE_ENV_PROXY',
89
+ 'SSL_CERT_FILE',
90
+ 'SSL_CERT_DIR',
91
+ ].includes(name)))
92
+ throw new Error('Use the env file for application settings and credentials, not shell or TLS runtime settings.');
93
+ for (const [name, value] of Object.entries(values))
94
+ if (process.env[name] === undefined)
95
+ process.env[name] = value;
96
+ }
97
+ finally {
98
+ closeSync(fd);
99
+ }
100
+ }