@clear-capabilities/agentic-security-scanner 0.169.0 → 0.170.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 +37 -0
- package/bin/agentic-security.js +331 -0
- package/dist/2199.index.js +1 -1
- package/dist/2675.index.js +174 -0
- package/dist/4142.index.js +6 -6
- package/dist/5014.index.js +2 -2
- package/dist/5086.index.js +645 -0
- package/dist/5144.index.js +2 -2
- package/dist/5206.index.js +32 -0
- package/dist/642.index.js +197 -0
- package/dist/6447.index.js +131 -0
- package/dist/6645.index.js +87 -0
- package/dist/6730.index.js +2 -2
- package/dist/6932.index.js +2 -2
- package/dist/7055.index.js +369 -0
- package/dist/7232.index.js +24 -0
- package/dist/7552.index.js +2 -2
- package/dist/7952.index.js +301 -0
- package/dist/8714.index.js +2 -2
- package/dist/9102.index.js +110 -0
- package/dist/9800.index.js +1 -1
- package/dist/agentic-security.mjs +2 -2
- package/dist/agentic-security.mjs.sha256 +1 -1
- package/package.json +2 -2
- package/src/artifact/CLAUDE.md +100 -0
- package/src/artifact/filesystem.js +100 -0
- package/src/artifact/image-archive.js +159 -0
- package/src/artifact/inventory.js +69 -0
- package/src/artifact/layer-secrets.js +92 -0
- package/src/artifact/mismatch.js +72 -0
- package/src/artifact/provenance-graph.js +115 -0
- package/src/artifact/safe-tar.js +175 -0
- package/src/artifact/signature.js +156 -0
- package/src/artifact/vex.js +94 -0
- package/src/artifact/vuln-correlate.js +17 -0
- package/src/posture/artifact-registry.js +8 -0
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
export const id = 7952;
|
|
2
|
+
export const ids = [7952,642];
|
|
3
|
+
export const modules = {
|
|
4
|
+
|
|
5
|
+
/***/ 47952:
|
|
6
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
7
|
+
|
|
8
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
9
|
+
/* harmony export */ analyzeLayerSecrets: () => (/* binding */ analyzeLayerSecrets)
|
|
10
|
+
/* harmony export */ });
|
|
11
|
+
/* unused harmony export DEFAULT_SECRET_SCAN_LIMITS */
|
|
12
|
+
/* harmony import */ var _safe_tar_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(90642);
|
|
13
|
+
// PRD 5 P0 §3 — Layer Secret Analysis: a secret added in one layer and later
|
|
14
|
+
// deleted (via an overlay whiteout) is still sitting in that earlier layer's
|
|
15
|
+
// raw tar bytes inside the image archive — recoverable by anyone who has the
|
|
16
|
+
// archive, even though it is invisible in `docker run`'s final filesystem.
|
|
17
|
+
//
|
|
18
|
+
// The actual credential detection is INJECTED as `detectFn` (the exact
|
|
19
|
+
// `(filePath, rawText) -> Finding[]` shape `src/posture/secret-history.js`
|
|
20
|
+
// already uses for the git-history analog of this same idea), so this module
|
|
21
|
+
// never imports `engine.js` and stays a pure, independently-testable
|
|
22
|
+
// transform over the layer data `filesystem.js` already extracted. The
|
|
23
|
+
// injected detector (`scanCredentials`) already returns only redacted/masked
|
|
24
|
+
// values (`masked`, a redacted `snippet`) — this module never re-touches raw
|
|
25
|
+
// file content once a finding exists, so there is no second place a value
|
|
26
|
+
// could leak back in.
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
const DEFAULT_SECRET_SCAN_LIMITS = Object.freeze({
|
|
30
|
+
maxFileBytes: 512 * 1024,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* `readLayersResult` is `filesystem.js#readLayers`'s output (ordered,
|
|
35
|
+
* per-layer, pre-merge entries — the only shape that preserves "this path
|
|
36
|
+
* existed in layer 3" even after a later layer's whiteout removes it from
|
|
37
|
+
* the merged view). `deletedPaths` is `mergeLayers`'s output.
|
|
38
|
+
*
|
|
39
|
+
* Returns `{ findings, deletedButRecoverable, materializationSkipped }`:
|
|
40
|
+
* - `findings`: every detector hit across every layer's added files, each
|
|
41
|
+
* tagged with `path`/`layerIndex` and the detector's own (already
|
|
42
|
+
* redacted) finding fields — this is the full history sweep, not just
|
|
43
|
+
* the deleted-but-recoverable subset.
|
|
44
|
+
* - `deletedButRecoverable`: the subset of `findings` whose `path` was
|
|
45
|
+
* later removed by a whiteout in a LATER layer — PRD 5's named scenario.
|
|
46
|
+
* - `materializationSkipped`: paths whose content was too large to scan
|
|
47
|
+
* (disclosed, never silently treated as "no secret found").
|
|
48
|
+
*/
|
|
49
|
+
function analyzeLayerSecrets({ readLayersResult, deletedPaths, detectFn, limits = DEFAULT_SECRET_SCAN_LIMITS }) {
|
|
50
|
+
if (typeof detectFn !== 'function') throw new TypeError('analyzeLayerSecrets requires a detectFn(filePath, rawText) -> Finding[]');
|
|
51
|
+
if (!readLayersResult || !Array.isArray(readLayersResult.layers)) throw new TypeError('analyzeLayerSecrets requires filesystem.js#readLayers output');
|
|
52
|
+
|
|
53
|
+
const deletedAtByPath = new Map(); // path -> earliest layer index that deleted it
|
|
54
|
+
for (const d of deletedPaths || []) {
|
|
55
|
+
if (d.opaque) continue; // opaque-directory deletions are reported separately below
|
|
56
|
+
if (!deletedAtByPath.has(d.path) || d.deletedAtLayer < deletedAtByPath.get(d.path)) {
|
|
57
|
+
deletedAtByPath.set(d.path, d.deletedAtLayer);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const opaqueDirs = (deletedPaths || []).filter((d) => d.opaque);
|
|
61
|
+
|
|
62
|
+
const findings = [];
|
|
63
|
+
const materializationSkipped = [];
|
|
64
|
+
|
|
65
|
+
for (const { layerIndex, entries } of readLayersResult.layers) {
|
|
66
|
+
for (const e of entries) {
|
|
67
|
+
if ((0,_safe_tar_js__WEBPACK_IMPORTED_MODULE_0__/* .isWhiteoutName */ .l0)(e.name)) continue;
|
|
68
|
+
if (e.typeflag !== '0' && e.typeflag !== '') continue; // regular files only
|
|
69
|
+
if (e.size > limits.maxFileBytes) {
|
|
70
|
+
materializationSkipped.push({ path: e.name, layerIndex, sizeBytes: e.size });
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
let text;
|
|
74
|
+
try {
|
|
75
|
+
text = e.data.toString('utf8');
|
|
76
|
+
} catch {
|
|
77
|
+
continue; // not decodable as text — not a candidate for a text-pattern secret scan
|
|
78
|
+
}
|
|
79
|
+
let hits;
|
|
80
|
+
try {
|
|
81
|
+
hits = detectFn(e.name, text) || [];
|
|
82
|
+
} catch {
|
|
83
|
+
hits = []; // a detector failure on hostile/malformed content must never abort the sweep
|
|
84
|
+
}
|
|
85
|
+
for (const hit of hits) {
|
|
86
|
+
const deletedAtLayer = deletedAtByPath.has(e.name) && deletedAtByPath.get(e.name) > layerIndex
|
|
87
|
+
? deletedAtByPath.get(e.name)
|
|
88
|
+
: null;
|
|
89
|
+
const underOpaqueDir = opaqueDirs.some((d) => d.deletedAtLayer > layerIndex && (e.name === d.path || e.name.startsWith(`${d.path}/`)));
|
|
90
|
+
findings.push({
|
|
91
|
+
...hit,
|
|
92
|
+
path: e.name,
|
|
93
|
+
addedAtLayer: layerIndex,
|
|
94
|
+
deletedAtLayer: deletedAtLayer ?? (underOpaqueDir ? opaqueDirs.find((d) => d.deletedAtLayer > layerIndex && (e.name === d.path || e.name.startsWith(`${d.path}/`))).deletedAtLayer : null),
|
|
95
|
+
recoverable: deletedAtLayer != null || underOpaqueDir,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const deletedButRecoverable = findings.filter((f) => f.recoverable);
|
|
102
|
+
|
|
103
|
+
return { findings, deletedButRecoverable, materializationSkipped };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
/***/ }),
|
|
108
|
+
|
|
109
|
+
/***/ 90642:
|
|
110
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
111
|
+
|
|
112
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
113
|
+
/* harmony export */ ET: () => (/* binding */ readTarEntries),
|
|
114
|
+
/* harmony export */ Jn: () => (/* binding */ whiteoutTarget),
|
|
115
|
+
/* harmony export */ TarSafetyError: () => (/* binding */ TarSafetyError),
|
|
116
|
+
/* harmony export */ dR: () => (/* binding */ DEFAULT_LIMITS),
|
|
117
|
+
/* harmony export */ l0: () => (/* binding */ isWhiteoutName),
|
|
118
|
+
/* harmony export */ zr: () => (/* binding */ decompressIfGzip)
|
|
119
|
+
/* harmony export */ });
|
|
120
|
+
/* unused harmony export isSafeEntryName */
|
|
121
|
+
/* harmony import */ var node_zlib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(38522);
|
|
122
|
+
// Hand-rolled, hardened POSIX/GNU tar reader for OCI/Docker image archives.
|
|
123
|
+
//
|
|
124
|
+
// Why hand-rolled instead of a dependency: this repo has no tar library (see
|
|
125
|
+
// `src/artifact/CLAUDE.md`), and PRD 5's own Safety Requirements ask for exact
|
|
126
|
+
// control over the failure modes a generic tar library treats as implementation
|
|
127
|
+
// detail: malicious entry paths, decompression bombs, giant layers, oversized
|
|
128
|
+
// archives. Rolling it ourselves means every one of those limits is a named,
|
|
129
|
+
// tested constant in this file rather than a library default we'd have to audit.
|
|
130
|
+
//
|
|
131
|
+
// Scope: ustar + GNU longname ('L' typeflag) + base-256 size fields. PAX extended
|
|
132
|
+
// headers ('x'/'g') and GNU longlink ('K') are structurally skipped (their data
|
|
133
|
+
// block is consumed so offsets stay correct, but their content is not applied) —
|
|
134
|
+
// a disclosed limitation, not a silent one. Real docker-save/oci-archive output
|
|
135
|
+
// from Go's archive/tar for images in this size/complexity class essentially
|
|
136
|
+
// never needs them; synthetic fixtures in this codebase never emit them either.
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
const BLOCK = 512;
|
|
140
|
+
|
|
141
|
+
const DEFAULT_LIMITS = Object.freeze({
|
|
142
|
+
maxEntries: 200_000,
|
|
143
|
+
maxEntrySize: 512 * 1024 * 1024, // 512MB per tar entry
|
|
144
|
+
maxTotalSize: 4 * 1024 * 1024 * 1024, // 4GB per archive (sum of entry sizes)
|
|
145
|
+
maxGunzipOutput: 4 * 1024 * 1024 * 1024, // decompression-bomb guard
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
class TarSafetyError extends Error {
|
|
149
|
+
constructor(message, code) {
|
|
150
|
+
super(message);
|
|
151
|
+
this.name = 'TarSafetyError';
|
|
152
|
+
this.code = code;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function parseSizeField(buf) {
|
|
157
|
+
if (buf[0] & 0x80) {
|
|
158
|
+
// GNU base-256 extension for sizes that don't fit in octal-ASCII.
|
|
159
|
+
let n = 0n;
|
|
160
|
+
for (let i = 1; i < buf.length; i++) n = (n << 8n) | BigInt(buf[i]);
|
|
161
|
+
return Number(n);
|
|
162
|
+
}
|
|
163
|
+
const s = buf.toString('ascii').replace(/\0.*$/, '').trim();
|
|
164
|
+
if (!s) return 0;
|
|
165
|
+
const n = parseInt(s, 8);
|
|
166
|
+
return Number.isFinite(n) ? n : 0;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function cstr(buf) {
|
|
170
|
+
return buf.toString('utf8').replace(/\0.*$/, '');
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// A tar entry name is unsafe when it would escape a virtual extraction root:
|
|
174
|
+
// absolute paths, `..` segments, embedded NULs, or an unreasonable length.
|
|
175
|
+
// Because this module never writes to a real filesystem path (every caller
|
|
176
|
+
// keeps extracted content in an in-memory Map keyed by this string), the
|
|
177
|
+
// classic zip-slip *write* vulnerability cannot occur here — but a hostile
|
|
178
|
+
// name must still never be silently treated as an ordinary path by downstream
|
|
179
|
+
// manifest/package-DB matching, so unsafe entries are flagged, never dropped
|
|
180
|
+
// silently and never accepted as-is.
|
|
181
|
+
function isSafeEntryName(name) {
|
|
182
|
+
if (typeof name !== 'string' || name.length === 0 || name.length > 4096) return false;
|
|
183
|
+
if (name.includes('\0')) return false;
|
|
184
|
+
const norm = name.replace(/\\/g, '/');
|
|
185
|
+
if (norm.startsWith('/')) return false;
|
|
186
|
+
if (norm.split('/').some((p) => p === '..')) return false;
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function isWhiteoutName(name) {
|
|
191
|
+
return (name.split('/').pop() || '').startsWith('.wh.');
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Resolves a whiteout entry name to what it deletes. `.wh..wh..opq` marks a
|
|
195
|
+
// directory as "opaque" (everything from earlier layers under it is hidden,
|
|
196
|
+
// not individually deleted) — reported distinctly so callers don't conflate
|
|
197
|
+
// it with a single-file deletion.
|
|
198
|
+
function whiteoutTarget(name) {
|
|
199
|
+
const parts = name.split('/');
|
|
200
|
+
const base = parts.pop();
|
|
201
|
+
if (base === '.wh..wh..opq') return { opaque: true, dir: parts.join('/') };
|
|
202
|
+
return { opaque: false, path: [...parts, base.slice(4)].join('/') };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Decompresses a gzip member with a hard output-size cap (Node's native
|
|
206
|
+
// ERR_BUFFER_TOO_LARGE on overflow — no custom streaming counter needed).
|
|
207
|
+
// Returns the input unchanged when it isn't gzip-magic (plain tar).
|
|
208
|
+
function decompressIfGzip(buf, limits = DEFAULT_LIMITS) {
|
|
209
|
+
if (buf.length >= 2 && buf[0] === 0x1f && buf[1] === 0x8b) {
|
|
210
|
+
try {
|
|
211
|
+
return node_zlib__WEBPACK_IMPORTED_MODULE_0__.gunzipSync(buf, { maxOutputLength: limits.maxGunzipOutput });
|
|
212
|
+
} catch (err) {
|
|
213
|
+
if (err && err.code === 'ERR_BUFFER_TOO_LARGE') {
|
|
214
|
+
throw new TarSafetyError('decompressed layer exceeds the decompression-bomb guard', 'gunzip_too_large');
|
|
215
|
+
}
|
|
216
|
+
throw new TarSafetyError(`gzip stream is malformed: ${err.message}`, 'gunzip_malformed');
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return buf;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Reads a decompressed tar buffer and yields one record per entry:
|
|
224
|
+
* { name, size, typeflag, linkname, data, unsafe }
|
|
225
|
+
* `data` is a Buffer view into `buf` (never copied) for safe entries, `null`
|
|
226
|
+
* for unsafe ones. Throws TarSafetyError (never returns a partial result) the
|
|
227
|
+
* moment any configured limit is exceeded.
|
|
228
|
+
*/
|
|
229
|
+
function* readTarEntries(buf, limits = DEFAULT_LIMITS) {
|
|
230
|
+
if (!Buffer.isBuffer(buf)) throw new TarSafetyError('tar input must be a Buffer', 'bad_input');
|
|
231
|
+
let offset = 0;
|
|
232
|
+
let count = 0;
|
|
233
|
+
let totalSize = 0;
|
|
234
|
+
let pendingLongName = null;
|
|
235
|
+
|
|
236
|
+
while (offset + BLOCK <= buf.length) {
|
|
237
|
+
const header = buf.subarray(offset, offset + BLOCK);
|
|
238
|
+
if (header.every((b) => b === 0)) {
|
|
239
|
+
offset += BLOCK;
|
|
240
|
+
continue; // end-of-archive zero-fill padding
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
count += 1;
|
|
244
|
+
if (count > limits.maxEntries) {
|
|
245
|
+
throw new TarSafetyError(`tar archive has more than ${limits.maxEntries} entries`, 'too_many_entries');
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
let name = cstr(header.subarray(0, 100));
|
|
249
|
+
const typeflag = String.fromCharCode(header[156] || 0);
|
|
250
|
+
const linkname = cstr(header.subarray(157, 257));
|
|
251
|
+
const magic = header.subarray(257, 263).toString('ascii');
|
|
252
|
+
const prefix = magic.startsWith('ustar') ? cstr(header.subarray(345, 500)) : '';
|
|
253
|
+
if (prefix) name = `${prefix}/${name}`;
|
|
254
|
+
const size = parseSizeField(header.subarray(124, 136));
|
|
255
|
+
|
|
256
|
+
offset += BLOCK;
|
|
257
|
+
|
|
258
|
+
if (size < 0 || !Number.isFinite(size)) {
|
|
259
|
+
throw new TarSafetyError(`tar entry "${name}" has an invalid size field`, 'bad_size');
|
|
260
|
+
}
|
|
261
|
+
if (size > limits.maxEntrySize) {
|
|
262
|
+
throw new TarSafetyError(`tar entry "${name}" (${size} bytes) exceeds the per-entry size limit`, 'entry_too_large');
|
|
263
|
+
}
|
|
264
|
+
totalSize += size;
|
|
265
|
+
if (totalSize > limits.maxTotalSize) {
|
|
266
|
+
throw new TarSafetyError('tar archive exceeds the total-size limit', 'archive_too_large');
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const dataBlocks = Math.ceil(size / BLOCK);
|
|
270
|
+
if (offset + size > buf.length) {
|
|
271
|
+
throw new TarSafetyError(`tar entry "${name}" claims more data than the archive contains`, 'truncated');
|
|
272
|
+
}
|
|
273
|
+
const data = size > 0 ? buf.subarray(offset, offset + size) : Buffer.alloc(0);
|
|
274
|
+
offset += dataBlocks * BLOCK;
|
|
275
|
+
|
|
276
|
+
const resolvedName = pendingLongName ? pendingLongName : name;
|
|
277
|
+
pendingLongName = null;
|
|
278
|
+
|
|
279
|
+
if (typeflag === 'L') {
|
|
280
|
+
// GNU longname: this entry's data IS the next entry's real name.
|
|
281
|
+
pendingLongName = cstr(data);
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
if (typeflag === 'K' || typeflag === 'x' || typeflag === 'g') {
|
|
285
|
+
// GNU longlink / PAX extended header — structurally skipped (see header comment).
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (!isSafeEntryName(resolvedName)) {
|
|
290
|
+
yield { name: resolvedName, size, typeflag, linkname, data: null, unsafe: true };
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
yield { name: resolvedName.replace(/\\/g, '/'), size, typeflag, linkname, data, unsafe: false };
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
/***/ })
|
|
300
|
+
|
|
301
|
+
};
|
package/dist/8714.index.js
CHANGED
|
@@ -81,8 +81,8 @@ function persistLanguageArtifacts(root, scan) {
|
|
|
81
81
|
const out = [];
|
|
82
82
|
const put = (name, body) => {
|
|
83
83
|
const fp = (0,_posture_state_dir_js__WEBPACK_IMPORTED_MODULE_1__.statePath)(root, name);
|
|
84
|
-
if (!(0,_posture_state_dir_js__WEBPACK_IMPORTED_MODULE_1__
|
|
85
|
-
try { (0,_posture_state_dir_js__WEBPACK_IMPORTED_MODULE_1__
|
|
84
|
+
if (!(0,_posture_state_dir_js__WEBPACK_IMPORTED_MODULE_1__.safeWriteState)(fp, body)) return false;
|
|
85
|
+
try { (0,_posture_state_dir_js__WEBPACK_IMPORTED_MODULE_1__.safeWriteState)(`${fp}.sig`, (0,_posture_integrity_js__WEBPACK_IMPORTED_MODULE_2__/* .signLastScan */ .lU)(body)); } catch { /* the signature is best effort, as for last-scan.json */ }
|
|
86
86
|
out.push({ name, sha256: sha256(body) });
|
|
87
87
|
return true;
|
|
88
88
|
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
export const id = 9102;
|
|
2
|
+
export const ids = [9102];
|
|
3
|
+
export const modules = {
|
|
4
|
+
|
|
5
|
+
/***/ 49102:
|
|
6
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
7
|
+
|
|
8
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
9
|
+
/* harmony export */ deriveVexStatus: () => (/* binding */ deriveVexStatus)
|
|
10
|
+
/* harmony export */ });
|
|
11
|
+
/* unused harmony export VEX_STATUSES */
|
|
12
|
+
// PRD 5 P0 §8 — VEX (Vulnerability Exploitability eXchange). Statuses are the
|
|
13
|
+
// PRD's own four. The PRD's one explicit rule — "`not affected` requires
|
|
14
|
+
// positive evidence" — is enforced structurally: `not_affected` is only ever
|
|
15
|
+
// returned from one of two named, checked evidence paths below; there is no
|
|
16
|
+
// code path that reaches it by default or by absence of information.
|
|
17
|
+
// Justification strings follow the CISA VEX vocabulary this repo's other VEX
|
|
18
|
+
// output (`toVex` in `src/posture/sbom.js`'s neighborhood) already uses,
|
|
19
|
+
// where applicable.
|
|
20
|
+
//
|
|
21
|
+
// `affected` likewise requires positive evidence (confirmed reachability),
|
|
22
|
+
// not just "OSV lists this version as vulnerable" — a scanner result alone
|
|
23
|
+
// only tells you the CVE/version pair matches; it doesn't tell you the
|
|
24
|
+
// vulnerable code path is reachable in THIS artifact. Absent that
|
|
25
|
+
// confirmation, the honest status is `under_investigation`, never a
|
|
26
|
+
// confident `affected` the evidence doesn't support.
|
|
27
|
+
const VEX_STATUSES = Object.freeze(['affected', 'not_affected', 'fixed', 'under_investigation']);
|
|
28
|
+
|
|
29
|
+
// Loose dotted-numeric version comparison. Returns -1/0/1, or null when
|
|
30
|
+
// either side isn't a clean dotted-numeric form — a "fixed" verdict is only
|
|
31
|
+
// ever returned when this does NOT return null; an unparseable version
|
|
32
|
+
// means that evidence path is skipped, never guessed through.
|
|
33
|
+
function compareVersions(a, b) {
|
|
34
|
+
const pa = String(a).split(/[.-]/).map((s) => (/^\d+$/.test(s) ? parseInt(s, 10) : null));
|
|
35
|
+
const pb = String(b).split(/[.-]/).map((s) => (/^\d+$/.test(s) ? parseInt(s, 10) : null));
|
|
36
|
+
if (pa.some((n) => n === null) || pb.some((n) => n === null)) return null;
|
|
37
|
+
const len = Math.max(pa.length, pb.length);
|
|
38
|
+
for (let i = 0; i < len; i++) {
|
|
39
|
+
const x = pa[i] ?? 0;
|
|
40
|
+
const y = pb[i] ?? 0;
|
|
41
|
+
if (x !== y) return x < y ? -1 : 1;
|
|
42
|
+
}
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function componentKeyOf(c) {
|
|
47
|
+
return c.purl || (c.ecosystem && c.name && c.version ? `${c.ecosystem}:${c.name}@${c.version}` : null);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* `vulnerability` is one `vulnerable_dep`-shaped entry already confirmed
|
|
52
|
+
* present via `vuln-correlate.js` against THIS artifact. `artifactComponents`
|
|
53
|
+
* is the artifact's own inventory (`osPackages`/`appPackages` concatenated).
|
|
54
|
+
* `reachability`, if supplied, is `{ reachable: true|false, reason }` from
|
|
55
|
+
* this codebase's existing dataflow/reachability evidence (never computed
|
|
56
|
+
* here — this module does no new analysis, only statuses the evidence it's
|
|
57
|
+
* handed).
|
|
58
|
+
*/
|
|
59
|
+
function deriveVexStatus({ vulnerability, artifactComponents, reachability = null }) {
|
|
60
|
+
if (!vulnerability || typeof vulnerability !== 'object') {
|
|
61
|
+
throw new TypeError('deriveVexStatus requires a vulnerability object');
|
|
62
|
+
}
|
|
63
|
+
if (!Array.isArray(artifactComponents)) {
|
|
64
|
+
throw new TypeError('deriveVexStatus requires an artifactComponents array');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const vulnKey = vulnerability.purl
|
|
68
|
+
|| (vulnerability.ecosystem && vulnerability.name && vulnerability.version ? `${vulnerability.ecosystem}:${vulnerability.name}@${vulnerability.version}` : null);
|
|
69
|
+
const present = vulnKey != null && artifactComponents.some((c) => componentKeyOf(c) === vulnKey);
|
|
70
|
+
|
|
71
|
+
if (!present) {
|
|
72
|
+
return {
|
|
73
|
+
status: 'not_affected',
|
|
74
|
+
justification: 'component_not_present',
|
|
75
|
+
evidence: 'the affected component (by purl/ecosystem+name+version) is not present in this artifact\'s inventory',
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (reachability && reachability.reachable === false) {
|
|
80
|
+
return {
|
|
81
|
+
status: 'not_affected',
|
|
82
|
+
justification: 'vulnerable_code_not_in_execute_path',
|
|
83
|
+
evidence: reachability.reason || 'static reachability analysis found no path to the vulnerable function in this artifact',
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (Array.isArray(vulnerability.fixedVersions) && vulnerability.fixedVersions.length && vulnerability.version) {
|
|
88
|
+
for (const fv of vulnerability.fixedVersions) {
|
|
89
|
+
const cmp = compareVersions(vulnerability.version, fv);
|
|
90
|
+
if (cmp !== null && cmp >= 0) {
|
|
91
|
+
return { status: 'fixed', justification: null, evidence: `installed version ${vulnerability.version} is >= the fixed version ${fv}` };
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (reachability && reachability.reachable === true) {
|
|
97
|
+
return { status: 'affected', justification: null, evidence: reachability.reason || 'static reachability analysis confirmed a path to the vulnerable function in this artifact' };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
status: 'under_investigation',
|
|
102
|
+
justification: null,
|
|
103
|
+
evidence: 'the affected component is present and not confirmed fixed, but reachability has not been established — not a confident "affected" claim',
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
/***/ })
|
|
109
|
+
|
|
110
|
+
};
|
package/dist/9800.index.js
CHANGED
|
@@ -210,7 +210,7 @@ function saveProof(scanRoot, record) {
|
|
|
210
210
|
const enc = (0,_encryption_provider_js__WEBPACK_IMPORTED_MODULE_3__/* .maybeEncryptForWrite */ .v2)(scanRoot, PROOFS_DIR, text);
|
|
211
211
|
if (!enc.ok) return { ok: false, reason: enc.reason };
|
|
212
212
|
const file = (0,_state_dir_js__WEBPACK_IMPORTED_MODULE_2__.statePath)(scanRoot, PROOFS_DIR, findingKey(record.findingId), `${safe.recordDigest}.json`);
|
|
213
|
-
if (!(0,_state_dir_js__WEBPACK_IMPORTED_MODULE_2__
|
|
213
|
+
if (!(0,_state_dir_js__WEBPACK_IMPORTED_MODULE_2__.safeWriteState)(file, enc.content)) return { ok: false, reason: 'state write refused' };
|
|
214
214
|
return { ok: true, file, digest: safe.recordDigest, encrypted: enc.encrypted };
|
|
215
215
|
}
|
|
216
216
|
|