@shieldaai/security-watch 0.0.0-stage → 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.
- package/CHANGELOG.md +170 -0
- package/CONTRIBUTING.md +92 -0
- package/LICENSE +202 -0
- package/README.md +394 -2
- package/SECURITY.md +62 -0
- package/dist/assessment.d.ts +16 -0
- package/dist/assessment.js +569 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +1105 -0
- package/dist/config.d.ts +302 -0
- package/dist/config.js +381 -0
- package/dist/coverage.d.ts +4 -0
- package/dist/coverage.js +11 -0
- package/dist/cve-now.d.ts +35 -0
- package/dist/cve-now.js +1002 -0
- package/dist/cvss4.d.ts +3 -0
- package/dist/cvss4.js +39 -0
- package/dist/delivery.d.ts +58 -0
- package/dist/delivery.js +687 -0
- package/dist/ecosystems.d.ts +48 -0
- package/dist/ecosystems.js +332 -0
- package/dist/engine.d.ts +80 -0
- package/dist/engine.js +388 -0
- package/dist/everyday-words.d.ts +11 -0
- package/dist/everyday-words.js +256 -0
- package/dist/health.d.ts +24 -0
- package/dist/health.js +122 -0
- package/dist/heartbeat.d.ts +13 -0
- package/dist/heartbeat.js +74 -0
- package/dist/http.d.ts +15 -0
- package/dist/http.js +280 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +23 -0
- package/dist/inventory-evidence.d.ts +10 -0
- package/dist/inventory-evidence.js +206 -0
- package/dist/inventory.d.ts +276 -0
- package/dist/inventory.js +336 -0
- package/dist/lock.d.ts +3 -0
- package/dist/lock.js +112 -0
- package/dist/maintenance.d.ts +48 -0
- package/dist/maintenance.js +295 -0
- package/dist/matching.d.ts +29 -0
- package/dist/matching.js +537 -0
- package/dist/models.d.ts +33 -0
- package/dist/models.js +932 -0
- package/dist/operations.d.ts +17 -0
- package/dist/operations.js +117 -0
- package/dist/pilot-cases.d.ts +171 -0
- package/dist/pilot-cases.js +330 -0
- package/dist/pilot-input.d.ts +16 -0
- package/dist/pilot-input.js +125 -0
- package/dist/pilot-recall.d.ts +166 -0
- package/dist/pilot-recall.js +231 -0
- package/dist/pilot-report.d.ts +113 -0
- package/dist/pilot-report.js +279 -0
- package/dist/pilot-responses.d.ts +111 -0
- package/dist/pilot-responses.js +159 -0
- package/dist/providers.d.ts +209 -0
- package/dist/providers.js +459 -0
- package/dist/python-version.d.ts +3 -0
- package/dist/python-version.js +30 -0
- package/dist/rehearsal.d.ts +440 -0
- package/dist/rehearsal.js +372 -0
- package/dist/sbom.d.ts +13 -0
- package/dist/sbom.js +193 -0
- package/dist/setup.d.ts +113 -0
- package/dist/setup.js +100 -0
- package/dist/source-error.d.ts +38 -0
- package/dist/source-error.js +71 -0
- package/dist/sources.d.ts +3 -0
- package/dist/sources.js +1725 -0
- package/dist/store.d.ts +96 -0
- package/dist/store.js +953 -0
- package/dist/types.d.ts +404 -0
- package/dist/types.js +1 -0
- package/dist/util.d.ts +29 -0
- package/dist/util.js +94 -0
- package/dist/vendor/cvss4-reference.d.ts +2 -0
- package/dist/vendor/cvss4-reference.js +789 -0
- package/dist/vendor-sources.d.ts +24 -0
- package/dist/vendor-sources.js +56 -0
- package/dist/word-filter.d.ts +3 -0
- package/dist/word-filter.js +3291 -0
- package/docs/alert-outcome-evaluation.md +150 -0
- package/docs/compatibility.md +35 -0
- package/docs/configuration.md +666 -0
- package/docs/cvss-v4-support.md +41 -0
- package/docs/offline-advisory-preview.md +114 -0
- package/docs/offline-rehearsal.md +44 -0
- package/docs/pilot-cases.md +58 -0
- package/docs/pilot-recall.md +124 -0
- package/docs/pilot-report.md +52 -0
- package/docs/validation/alert-outcome-evaluation-2026-11-05.json +2935 -0
- package/docs/validation/cvss-v4-reference-parity-2026-11-05.json +93 -0
- package/docs/validation/rehearsal-accepted-2026-11-05.json +175 -0
- package/docs/validation/rehearsal-unknown-2026-11-05.json +175 -0
- package/docs/vendor/cvss-v4-LICENSE.txt +22 -0
- package/docs/vendor/cvss-v4-provenance.json +38 -0
- package/examples/advisories.json +17 -0
- package/examples/agent-advisories-2026.json +145 -0
- package/examples/agent-advisory-cases-2026.json +397 -0
- package/examples/common-systems.yaml +243 -0
- package/examples/libraries.example.txt +18 -0
- package/examples/libraries.example.yaml +40 -0
- package/examples/library-watch.example.yaml +27 -0
- package/examples/offline-advisory-preview.mjs +42 -0
- package/examples/rehearsal.json +75 -0
- package/examples/security-watch.example.yaml +86 -0
- package/examples/systems.example.yaml +35 -0
- package/package.json +85 -4
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Component } from './types.js';
|
|
2
|
+
/** Package identities follow the registry named by the OSV ecosystem. */
|
|
3
|
+
export declare const ECOSYSTEMS: readonly ['npm', 'PyPI', 'Packagist', 'Go', 'Maven', 'crates.io', 'RubyGems', 'NuGet', 'Hex', 'Pub', 'Hackage', 'SwiftURL'];
|
|
4
|
+
export type Ecosystem = (typeof ECOSYSTEMS)[number];
|
|
5
|
+
export declare function normalizeEcosystem(value: string): Ecosystem;
|
|
6
|
+
export declare function normalizePackageName(ecosystem: Ecosystem, value: string): string;
|
|
7
|
+
/** Keep the published spelling: OSV does not consistently normalize registry aliases. */
|
|
8
|
+
export declare function osvPackageNames(ecosystem: Ecosystem, value: string): string[];
|
|
9
|
+
/** One comparable key per package identity, or undefined when the ecosystem or name is not recognised. */
|
|
10
|
+
export declare function packageKey(value: {
|
|
11
|
+
ecosystem: string;
|
|
12
|
+
name: string;
|
|
13
|
+
}): string | undefined;
|
|
14
|
+
export declare function samePackage(left: {
|
|
15
|
+
ecosystem: string;
|
|
16
|
+
name: string;
|
|
17
|
+
}, right: {
|
|
18
|
+
ecosystem: string;
|
|
19
|
+
name: string;
|
|
20
|
+
}): boolean;
|
|
21
|
+
/** A declared version, never a dependency constraint or an inferred latest release. */
|
|
22
|
+
export declare function exactLibraryVersion(value: string, ecosystem?: Ecosystem): string;
|
|
23
|
+
/**
|
|
24
|
+
* What to tell the operator about a name typed by hand with capital letters, in a registry that
|
|
25
|
+
* compares names by exact spelling and publishes them in lower case. npm: every name registered
|
|
26
|
+
* since 2017 is lower case, so `Lodash` is not `lodash` and matches no advisory; a few packages
|
|
27
|
+
* from before that rule keep their capitals, so the name is accepted, and anything but a known
|
|
28
|
+
* legacy name is pointed out. RubyGems, Hex and Pub: `Rails`, `Phoenix` and `Flutter_Bloc` are not
|
|
29
|
+
* the published `rails`, `phoenix` and `flutter_bloc`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function capitalisedName(component: {
|
|
32
|
+
ecosystem: Ecosystem;
|
|
33
|
+
name: string;
|
|
34
|
+
}): string | undefined;
|
|
35
|
+
export interface Library {
|
|
36
|
+
ecosystem: Ecosystem;
|
|
37
|
+
name: string;
|
|
38
|
+
version?: string;
|
|
39
|
+
/** Where this library is used, in the operator's words. */
|
|
40
|
+
note?: string;
|
|
41
|
+
}
|
|
42
|
+
/** A short, single-line pointer written by the operator, such as a service, repository path or owner. */
|
|
43
|
+
export declare function libraryNote(value: string): string;
|
|
44
|
+
/** Keep each distinct note once, in the order given, within the note length limit. */
|
|
45
|
+
export declare function mergeNotes(first: string | undefined, second: string | undefined): string | undefined;
|
|
46
|
+
export declare function parseLibrary(value: unknown, defaultEcosystem?: string): Library;
|
|
47
|
+
/** Parse one entry per line; the ecosystem is explicit or supplied for the whole list. */
|
|
48
|
+
export declare function parseLibraryList(text: string, ecosystem?: string): Component[];
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { hash, LINE_BREAKING } from './util.js';
|
|
2
|
+
import { valid } from 'semver';
|
|
3
|
+
import { valid as validPython } from '@renovatebot/pep440';
|
|
4
|
+
/** Package identities follow the registry named by the OSV ecosystem. */
|
|
5
|
+
export const ECOSYSTEMS = [
|
|
6
|
+
'npm',
|
|
7
|
+
'PyPI',
|
|
8
|
+
'Packagist',
|
|
9
|
+
'Go',
|
|
10
|
+
'Maven',
|
|
11
|
+
'crates.io',
|
|
12
|
+
'RubyGems',
|
|
13
|
+
'NuGet',
|
|
14
|
+
'Hex',
|
|
15
|
+
'Pub',
|
|
16
|
+
'Hackage',
|
|
17
|
+
'SwiftURL',
|
|
18
|
+
];
|
|
19
|
+
const aliases = {
|
|
20
|
+
npm: 'npm',
|
|
21
|
+
node: 'npm',
|
|
22
|
+
nodejs: 'npm',
|
|
23
|
+
javascript: 'npm',
|
|
24
|
+
js: 'npm',
|
|
25
|
+
pypi: 'PyPI',
|
|
26
|
+
python: 'PyPI',
|
|
27
|
+
pip: 'PyPI',
|
|
28
|
+
packagist: 'Packagist',
|
|
29
|
+
php: 'Packagist',
|
|
30
|
+
composer: 'Packagist',
|
|
31
|
+
go: 'Go',
|
|
32
|
+
golang: 'Go',
|
|
33
|
+
maven: 'Maven',
|
|
34
|
+
java: 'Maven',
|
|
35
|
+
'crates.io': 'crates.io',
|
|
36
|
+
rust: 'crates.io',
|
|
37
|
+
cargo: 'crates.io',
|
|
38
|
+
rubygems: 'RubyGems',
|
|
39
|
+
ruby: 'RubyGems',
|
|
40
|
+
gem: 'RubyGems',
|
|
41
|
+
nuget: 'NuGet',
|
|
42
|
+
dotnet: 'NuGet',
|
|
43
|
+
'.net': 'NuGet',
|
|
44
|
+
hex: 'Hex',
|
|
45
|
+
erlang: 'Hex',
|
|
46
|
+
elixir: 'Hex',
|
|
47
|
+
pub: 'Pub',
|
|
48
|
+
dart: 'Pub',
|
|
49
|
+
flutter: 'Pub',
|
|
50
|
+
hackage: 'Hackage',
|
|
51
|
+
haskell: 'Hackage',
|
|
52
|
+
swifturl: 'SwiftURL',
|
|
53
|
+
swift: 'SwiftURL',
|
|
54
|
+
};
|
|
55
|
+
export function normalizeEcosystem(value) {
|
|
56
|
+
const ecosystem = Object.hasOwn(aliases, value.trim().toLowerCase())
|
|
57
|
+
? aliases[value.trim().toLowerCase()]
|
|
58
|
+
: undefined;
|
|
59
|
+
if (!ecosystem)
|
|
60
|
+
throw new Error(`Unsupported library ecosystem: ${value}`);
|
|
61
|
+
return ecosystem;
|
|
62
|
+
}
|
|
63
|
+
export function normalizePackageName(ecosystem, value) {
|
|
64
|
+
const name = value.trim();
|
|
65
|
+
let normalized = name;
|
|
66
|
+
let valid = name.length > 0 && name.length <= 500 && !/\s/u.test(name) && !LINE_BREAKING.test(name);
|
|
67
|
+
switch (ecosystem) {
|
|
68
|
+
case 'npm':
|
|
69
|
+
// Names registered before 2017 may contain capitals (JSONStream) and are case-sensitive.
|
|
70
|
+
valid &&=
|
|
71
|
+
name.length <= 214 && /^(?:@[a-z0-9][a-z0-9._-]*\/[a-z0-9]|[A-Za-z0-9])[A-Za-z0-9._-]*$/.test(name);
|
|
72
|
+
valid &&= !name.startsWith('@') || name === name.toLowerCase();
|
|
73
|
+
break;
|
|
74
|
+
case 'PyPI':
|
|
75
|
+
valid &&= /^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$/.test(name);
|
|
76
|
+
normalized = name.toLowerCase().replace(/[-_.]+/g, '-');
|
|
77
|
+
break;
|
|
78
|
+
case 'Packagist':
|
|
79
|
+
// Composer treats names as case-insensitive and publishes them in lower case.
|
|
80
|
+
normalized = name.toLowerCase();
|
|
81
|
+
valid &&= /^[a-z0-9](?:[a-z0-9_.-]*[a-z0-9])?\/[a-z0-9](?:[a-z0-9_.-]*[a-z0-9])?$/.test(normalized);
|
|
82
|
+
break;
|
|
83
|
+
case 'Maven':
|
|
84
|
+
valid &&= /^[A-Za-z0-9_.-]+:[A-Za-z0-9_.-]+$/.test(name);
|
|
85
|
+
break;
|
|
86
|
+
case 'Go':
|
|
87
|
+
valid &&=
|
|
88
|
+
/^[A-Za-z0-9][A-Za-z0-9._~/-]*$/.test(name) &&
|
|
89
|
+
!name.split('/').some((p) => !p || p === '.' || p === '..');
|
|
90
|
+
break;
|
|
91
|
+
case 'NuGet':
|
|
92
|
+
valid &&= /^[A-Za-z0-9][A-Za-z0-9_.-]*$/.test(name);
|
|
93
|
+
break;
|
|
94
|
+
case 'crates.io':
|
|
95
|
+
valid &&= /^[A-Za-z][A-Za-z0-9_-]*$/.test(name);
|
|
96
|
+
normalized = name.toLowerCase();
|
|
97
|
+
break;
|
|
98
|
+
case 'SwiftURL':
|
|
99
|
+
try {
|
|
100
|
+
const url = new URL(name.startsWith('https://') ? name : `https://${name}`);
|
|
101
|
+
valid &&=
|
|
102
|
+
url.protocol === 'https:' &&
|
|
103
|
+
!url.username &&
|
|
104
|
+
!url.password &&
|
|
105
|
+
!url.port &&
|
|
106
|
+
!url.search &&
|
|
107
|
+
!url.hash &&
|
|
108
|
+
url.hostname.includes('.') &&
|
|
109
|
+
!/[\\%]/.test(name) &&
|
|
110
|
+
url.pathname !== '/' &&
|
|
111
|
+
!name
|
|
112
|
+
.replace(/^https:\/\//, '')
|
|
113
|
+
.split('/')
|
|
114
|
+
.some((part) => !part || part === '.' || part === '..');
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
valid = false;
|
|
118
|
+
}
|
|
119
|
+
break;
|
|
120
|
+
default:
|
|
121
|
+
valid &&= /^[A-Za-z0-9][A-Za-z0-9_.-]*$/.test(name);
|
|
122
|
+
}
|
|
123
|
+
if (!valid)
|
|
124
|
+
throw new Error(`Invalid ${ecosystem} package name: ${value}`);
|
|
125
|
+
return normalized;
|
|
126
|
+
}
|
|
127
|
+
function packageIdentity(ecosystem, name) {
|
|
128
|
+
const normalized = normalizePackageName(ecosystem, name);
|
|
129
|
+
if (ecosystem === 'NuGet')
|
|
130
|
+
return normalized.toLowerCase();
|
|
131
|
+
if (ecosystem === 'crates.io')
|
|
132
|
+
return normalized.replace(/_/g, '-');
|
|
133
|
+
if (ecosystem === 'SwiftURL') {
|
|
134
|
+
const url = new URL(normalized.startsWith('https://') ? normalized : `https://${normalized}`);
|
|
135
|
+
return `${url.hostname}${url.pathname.replace(/\.git$/, '')}`;
|
|
136
|
+
}
|
|
137
|
+
return normalized;
|
|
138
|
+
}
|
|
139
|
+
/** Keep the published spelling: OSV does not consistently normalize registry aliases. */
|
|
140
|
+
export function osvPackageNames(ecosystem, value) {
|
|
141
|
+
const name = normalizePackageName(ecosystem, value);
|
|
142
|
+
if (ecosystem === 'crates.io')
|
|
143
|
+
return [...new Set([name, name.replace(/_/g, '-'), name.replace(/-/g, '_')])];
|
|
144
|
+
if (ecosystem === 'NuGet')
|
|
145
|
+
return [...new Set([name, name.toLowerCase()])];
|
|
146
|
+
if (ecosystem === 'SwiftURL') {
|
|
147
|
+
const identity = packageIdentity(ecosystem, name);
|
|
148
|
+
return [
|
|
149
|
+
...new Set([name, identity, `${identity}.git`, `https://${identity}`, `https://${identity}.git`]),
|
|
150
|
+
];
|
|
151
|
+
}
|
|
152
|
+
return [name];
|
|
153
|
+
}
|
|
154
|
+
const identityKeys = new Map();
|
|
155
|
+
/** One comparable key per package identity, or undefined when the ecosystem or name is not recognised. */
|
|
156
|
+
export function packageKey(value) {
|
|
157
|
+
const cacheKey = `${value.ecosystem}\u0000${value.name}`;
|
|
158
|
+
let key = identityKeys.get(cacheKey);
|
|
159
|
+
if (key === undefined) {
|
|
160
|
+
try {
|
|
161
|
+
const ecosystem = normalizeEcosystem(value.ecosystem);
|
|
162
|
+
key = `${ecosystem}\u0000${packageIdentity(ecosystem, value.name)}`;
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
key = null;
|
|
166
|
+
}
|
|
167
|
+
if (identityKeys.size >= 200_000)
|
|
168
|
+
identityKeys.clear();
|
|
169
|
+
identityKeys.set(cacheKey, key);
|
|
170
|
+
}
|
|
171
|
+
return key ?? undefined;
|
|
172
|
+
}
|
|
173
|
+
export function samePackage(left, right) {
|
|
174
|
+
try {
|
|
175
|
+
const ecosystem = normalizeEcosystem(left.ecosystem);
|
|
176
|
+
return (ecosystem === normalizeEcosystem(right.ecosystem) &&
|
|
177
|
+
packageIdentity(ecosystem, left.name) === packageIdentity(ecosystem, right.name));
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/** A declared version, never a dependency constraint or an inferred latest release. */
|
|
184
|
+
export function exactLibraryVersion(value, ecosystem) {
|
|
185
|
+
const version = value.trim();
|
|
186
|
+
if (!version ||
|
|
187
|
+
version.length > 500 ||
|
|
188
|
+
!/^[A-Za-z0-9][A-Za-z0-9.!+_-]*$/.test(version) ||
|
|
189
|
+
/^(?:latest|\*)$/i.test(version))
|
|
190
|
+
throw new Error('Use an exact installed library version, or omit the version');
|
|
191
|
+
if (ecosystem &&
|
|
192
|
+
['npm', 'Go', 'crates.io', 'Hex', 'Pub', 'SwiftURL'].includes(ecosystem) &&
|
|
193
|
+
!valid(version))
|
|
194
|
+
throw new Error(`Use an exact installed ${ecosystem} version, or omit the version`);
|
|
195
|
+
// Keep the declared spelling; assessment separately restricts supported ordering.
|
|
196
|
+
if (ecosystem === 'PyPI' && !validPython(version))
|
|
197
|
+
throw new Error('Use an exact installed Python version in PEP 440 syntax, or omit the version');
|
|
198
|
+
return version;
|
|
199
|
+
}
|
|
200
|
+
/** Packages published before npm required lower-case names. Their capitals are part of the name. */
|
|
201
|
+
const LEGACY_NPM_NAMES = new Set(['JSONStream', 'Base64', 'JSONPath', 'JSONSelect']);
|
|
202
|
+
/**
|
|
203
|
+
* What to tell the operator about a name typed by hand with capital letters, in a registry that
|
|
204
|
+
* compares names by exact spelling and publishes them in lower case. npm: every name registered
|
|
205
|
+
* since 2017 is lower case, so `Lodash` is not `lodash` and matches no advisory; a few packages
|
|
206
|
+
* from before that rule keep their capitals, so the name is accepted, and anything but a known
|
|
207
|
+
* legacy name is pointed out. RubyGems, Hex and Pub: `Rails`, `Phoenix` and `Flutter_Bloc` are not
|
|
208
|
+
* the published `rails`, `phoenix` and `flutter_bloc`.
|
|
209
|
+
*/
|
|
210
|
+
export function capitalisedName(component) {
|
|
211
|
+
const { ecosystem, name } = component;
|
|
212
|
+
if (name === name.toLowerCase())
|
|
213
|
+
return undefined;
|
|
214
|
+
if (ecosystem === 'npm') {
|
|
215
|
+
if (LEGACY_NPM_NAMES.has(name))
|
|
216
|
+
return undefined;
|
|
217
|
+
return `npm package name ${name} contains capital letters. npm names are case-sensitive and current names are lower case, so this entry matches only advisories published for exactly that spelling. Write ${name.toLowerCase()} unless this is a package from before 2017 that kept its capitals; names imported from a lockfile or SBOM are taken as published.`;
|
|
218
|
+
}
|
|
219
|
+
if (ecosystem === 'RubyGems' || ecosystem === 'Hex' || ecosystem === 'Pub')
|
|
220
|
+
return `${ecosystem} package name ${name} contains capital letters. Names are compared by exact spelling and are almost always published in lower case, so this entry matches only advisories published for exactly that spelling. Write ${name.toLowerCase()} unless the package really is published with capitals; names imported from an SBOM are taken as published.`;
|
|
221
|
+
return undefined;
|
|
222
|
+
}
|
|
223
|
+
/** A short, single-line pointer written by the operator, such as a service, repository path or owner. */
|
|
224
|
+
export function libraryNote(value) {
|
|
225
|
+
const note = value.trim();
|
|
226
|
+
if (!note || note.length > 500 || LINE_BREAKING.test(note))
|
|
227
|
+
throw new Error('A library note must be 1 to 500 characters on one line');
|
|
228
|
+
return note;
|
|
229
|
+
}
|
|
230
|
+
/** Keep each distinct note once, in the order given, within the note length limit. */
|
|
231
|
+
export function mergeNotes(first, second) {
|
|
232
|
+
if (!first || !second)
|
|
233
|
+
return first ?? second;
|
|
234
|
+
if (first.split(' | ').includes(second))
|
|
235
|
+
return first;
|
|
236
|
+
const merged = `${first} | ${second}`;
|
|
237
|
+
return merged.length > 500 ? first : merged;
|
|
238
|
+
}
|
|
239
|
+
export function parseLibrary(value, defaultEcosystem) {
|
|
240
|
+
let ecosystem;
|
|
241
|
+
let name;
|
|
242
|
+
let version;
|
|
243
|
+
let note;
|
|
244
|
+
if (typeof value === 'string') {
|
|
245
|
+
let entry = value.trim();
|
|
246
|
+
// "npm:lodash@4.17.21 # checkout service, apps/checkout" keeps the text after # as the note.
|
|
247
|
+
const comment = /\s#/.exec(entry);
|
|
248
|
+
if (comment) {
|
|
249
|
+
const text = entry.slice(comment.index + comment[0].length).trim();
|
|
250
|
+
if (text)
|
|
251
|
+
note = libraryNote(text);
|
|
252
|
+
entry = entry.slice(0, comment.index).trim();
|
|
253
|
+
}
|
|
254
|
+
if (defaultEcosystem)
|
|
255
|
+
ecosystem = normalizeEcosystem(defaultEcosystem);
|
|
256
|
+
else {
|
|
257
|
+
const separator = entry.indexOf(':');
|
|
258
|
+
if (separator < 1)
|
|
259
|
+
throw new Error('Library entries require an ecosystem prefix, such as python:requests');
|
|
260
|
+
ecosystem = normalizeEcosystem(entry.slice(0, separator));
|
|
261
|
+
entry = entry.slice(separator + 1).trim();
|
|
262
|
+
}
|
|
263
|
+
const parts = entry.split(/\s+/);
|
|
264
|
+
if (parts.length > 2)
|
|
265
|
+
throw new Error('Expected a library name and optional exact version');
|
|
266
|
+
if (parts.length === 2)
|
|
267
|
+
[name, version] = parts;
|
|
268
|
+
else if (ecosystem === 'PyPI' && entry.includes('==')) {
|
|
269
|
+
const split = entry.split('==');
|
|
270
|
+
if (split.length !== 2)
|
|
271
|
+
throw new Error('Expected one exact library version');
|
|
272
|
+
[name, version] = split;
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
const separator = entry.lastIndexOf('@');
|
|
276
|
+
if (separator > 0)
|
|
277
|
+
[name, version] = [entry.slice(0, separator), entry.slice(separator + 1)];
|
|
278
|
+
else
|
|
279
|
+
name = entry;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
else if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
283
|
+
const input = value;
|
|
284
|
+
if (Object.keys(input).some((key) => !['name', 'version', 'ecosystem', 'note'].includes(key)) ||
|
|
285
|
+
typeof input.name !== 'string' ||
|
|
286
|
+
(input.note !== undefined && typeof input.note !== 'string') ||
|
|
287
|
+
(input.version !== undefined && typeof input.version !== 'string') ||
|
|
288
|
+
(input.ecosystem !== undefined && typeof input.ecosystem !== 'string'))
|
|
289
|
+
throw new Error('Library objects accept name, optional version, ecosystem and note only');
|
|
290
|
+
if (!defaultEcosystem && typeof input.ecosystem !== 'string')
|
|
291
|
+
throw new Error('Library ecosystem is required');
|
|
292
|
+
ecosystem = normalizeEcosystem(defaultEcosystem ?? String(input.ecosystem));
|
|
293
|
+
if (input.ecosystem !== undefined && normalizeEcosystem(input.ecosystem) !== ecosystem)
|
|
294
|
+
throw new Error('Library ecosystem does not match its group');
|
|
295
|
+
name = input.name;
|
|
296
|
+
version = input.version;
|
|
297
|
+
if (input.note !== undefined)
|
|
298
|
+
note = libraryNote(input.note);
|
|
299
|
+
}
|
|
300
|
+
else
|
|
301
|
+
throw new Error('Expected a library string or object');
|
|
302
|
+
return {
|
|
303
|
+
ecosystem,
|
|
304
|
+
name: normalizePackageName(ecosystem, name),
|
|
305
|
+
...(version === undefined ? {} : { version: exactLibraryVersion(version, ecosystem) }),
|
|
306
|
+
...(note === undefined ? {} : { note }),
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
/** Parse one entry per line; the ecosystem is explicit or supplied for the whole list. */
|
|
310
|
+
export function parseLibraryList(text, ecosystem) {
|
|
311
|
+
if (ecosystem !== undefined)
|
|
312
|
+
normalizeEcosystem(ecosystem);
|
|
313
|
+
if (Buffer.byteLength(text, 'utf8') > 2 * 1024 * 1024)
|
|
314
|
+
throw new Error('Library list exceeds 2 MiB');
|
|
315
|
+
const entries = text
|
|
316
|
+
.split(/\r?\n/)
|
|
317
|
+
.map((line) => line.trim())
|
|
318
|
+
.filter((line) => line && !line.startsWith('#'));
|
|
319
|
+
if (entries.length > 20_000)
|
|
320
|
+
throw new Error('Library list exceeds 20000 entries');
|
|
321
|
+
const unique = new Map();
|
|
322
|
+
for (const entry of entries) {
|
|
323
|
+
const library = parseLibrary(entry, ecosystem);
|
|
324
|
+
const key = JSON.stringify([library.ecosystem, library.name, library.version ?? null]);
|
|
325
|
+
const note = mergeNotes(unique.get(key)?.note, library.note);
|
|
326
|
+
unique.set(key, { ...library, ...(note ? { note } : {}) });
|
|
327
|
+
}
|
|
328
|
+
return [...unique.values()].map((library) => ({
|
|
329
|
+
id: `library:${hash(JSON.stringify([library.ecosystem, library.name, library.version ?? null])).slice(0, 24)}`,
|
|
330
|
+
...library,
|
|
331
|
+
}));
|
|
332
|
+
}
|
package/dist/engine.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Store } from './store.js';
|
|
3
|
+
import type { Assessment, Config, Decision, Evidence, HttpClient, Inventory, CoverageReceipt, InventoryDrift } from './types.js';
|
|
4
|
+
export interface ScanReport {
|
|
5
|
+
at: string;
|
|
6
|
+
completed_at: string;
|
|
7
|
+
findings: Assessment[];
|
|
8
|
+
decisions: Record<string, Decision>;
|
|
9
|
+
degraded: boolean;
|
|
10
|
+
errors: {
|
|
11
|
+
source: string;
|
|
12
|
+
message: string;
|
|
13
|
+
}[];
|
|
14
|
+
/** Information about how the monitor is set up. A notice is not a fault and does not degrade a scan. */
|
|
15
|
+
notices: string[];
|
|
16
|
+
evidence_count: number;
|
|
17
|
+
coverage: CoverageReceipt[];
|
|
18
|
+
inventory_drift: InventoryDrift[];
|
|
19
|
+
}
|
|
20
|
+
export declare const evidenceSchema: z.ZodObject<{
|
|
21
|
+
id: z.ZodString;
|
|
22
|
+
source: z.ZodString;
|
|
23
|
+
kind: z.ZodEnum<{
|
|
24
|
+
advisory: "advisory";
|
|
25
|
+
health: "health";
|
|
26
|
+
kev: "kev";
|
|
27
|
+
news: "news";
|
|
28
|
+
}>;
|
|
29
|
+
title: z.ZodString;
|
|
30
|
+
url: z.ZodString;
|
|
31
|
+
description: z.ZodString;
|
|
32
|
+
aliases: z.ZodArray<z.ZodString>;
|
|
33
|
+
severity: z.ZodEnum<{
|
|
34
|
+
critical: "critical";
|
|
35
|
+
high: "high";
|
|
36
|
+
low: "low";
|
|
37
|
+
medium: "medium";
|
|
38
|
+
unknown: "unknown";
|
|
39
|
+
}>;
|
|
40
|
+
cvss_v4: z.ZodOptional<z.ZodObject<{
|
|
41
|
+
base_scores: z.ZodArray<z.ZodObject<{
|
|
42
|
+
vector: z.ZodString;
|
|
43
|
+
base_vector: z.ZodString;
|
|
44
|
+
score: z.ZodNumber;
|
|
45
|
+
context_removed: z.ZodBoolean;
|
|
46
|
+
}, z.core.$strict>>;
|
|
47
|
+
unsupported_vectors: z.ZodNumber;
|
|
48
|
+
}, z.core.$strict>>;
|
|
49
|
+
modified_at: z.ZodISODateTime;
|
|
50
|
+
fetched_at: z.ZodISODateTime;
|
|
51
|
+
published_at: z.ZodOptional<z.ZodISODateTime>;
|
|
52
|
+
content_status: z.ZodOptional<z.ZodEnum<{
|
|
53
|
+
excerpt: "excerpt";
|
|
54
|
+
full: "full";
|
|
55
|
+
unavailable: "unavailable";
|
|
56
|
+
}>>;
|
|
57
|
+
packages: z.ZodArray<z.ZodObject<{
|
|
58
|
+
ecosystem: z.ZodString;
|
|
59
|
+
name: z.ZodString;
|
|
60
|
+
range: z.ZodOptional<z.ZodString>;
|
|
61
|
+
versions: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
62
|
+
matched_versions: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
63
|
+
fixed: z.ZodOptional<z.ZodString>;
|
|
64
|
+
}, z.core.$strict>>;
|
|
65
|
+
withdrawn: z.ZodOptional<z.ZodBoolean>;
|
|
66
|
+
exploited: z.ZodOptional<z.ZodBoolean>;
|
|
67
|
+
malware: z.ZodOptional<z.ZodBoolean>;
|
|
68
|
+
}, z.core.$strict>;
|
|
69
|
+
export declare function readFixture(path: string): Evidence[];
|
|
70
|
+
export declare function healthFinding(source: string, message: string, now?: number): Assessment;
|
|
71
|
+
export declare function runScan(options: {
|
|
72
|
+
config: Config;
|
|
73
|
+
inventory: Inventory;
|
|
74
|
+
store: Store;
|
|
75
|
+
http?: HttpClient;
|
|
76
|
+
fixture?: Evidence[];
|
|
77
|
+
now?: number;
|
|
78
|
+
onUrgent?: () => Promise<void>;
|
|
79
|
+
signal?: AbortSignal;
|
|
80
|
+
}): Promise<ScanReport>;
|