@clear-capabilities/agentic-security-scanner 0.172.1 → 0.173.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 +15 -0
- package/bin/agentic-security.js +37 -0
- package/dist/119.index.js +197 -0
- package/dist/128.index.js +129 -0
- package/dist/1293.index.js +5689 -0
- package/dist/1351.index.js +133 -0
- package/dist/1387.index.js +271 -0
- package/dist/1437.index.js +23 -0
- package/dist/1445.index.js +110 -0
- package/dist/1505.index.js +151 -0
- package/dist/1557.index.js +293 -0
- package/dist/1621.index.js +311 -0
- package/dist/1751.index.js +160 -0
- package/dist/1765.index.js +727 -0
- package/dist/1861.index.js +690 -0
- package/dist/1898.index.js +116 -0
- package/dist/1906.index.js +433 -0
- package/dist/1920.index.js +1 -291
- package/dist/208.index.js +1631 -0
- package/dist/2199.index.js +0 -239
- package/dist/2223.index.js +159 -0
- package/dist/2530.index.js +152 -0
- package/dist/2565.index.js +116 -0
- package/dist/2574.index.js +127 -0
- package/dist/2620.index.js +345 -0
- package/dist/2773.index.js +98 -0
- package/dist/2775.index.js +32 -0
- package/dist/2966.index.js +171 -0
- package/dist/2972.index.js +87 -0
- package/dist/2991.index.js +131 -0
- package/dist/3063.index.js +833 -0
- package/dist/3075.index.js +227 -0
- package/dist/3121.index.js +297 -0
- package/dist/3314.index.js +263 -0
- package/dist/3480.index.js +1822 -0
- package/dist/3481.index.js +24 -0
- package/dist/3506.index.js +268 -0
- package/dist/3533.index.js +591 -0
- package/dist/3653.index.js +450 -0
- package/dist/3822.index.js +131 -0
- package/dist/3868.index.js +292 -0
- package/dist/3917.index.js +152 -0
- package/dist/3918.index.js +192 -0
- package/dist/4090.index.js +288 -0
- package/dist/4121.index.js +1190 -0
- package/dist/4142.index.js +0 -239
- package/dist/4336.index.js +436 -0
- package/dist/4387.index.js +532 -0
- package/dist/4413.index.js +302 -0
- package/dist/4476.index.js +4510 -0
- package/dist/4491.index.js +133 -0
- package/dist/4538.index.js +185 -0
- package/dist/4684.index.js +319 -0
- package/dist/4740.index.js +165 -0
- package/dist/4780.index.js +209 -0
- package/dist/4802.index.js +225 -0
- package/dist/4812.index.js +379 -0
- package/dist/4835.index.js +126 -0
- package/dist/494.index.js +226 -0
- package/dist/4991.index.js +549 -0
- package/dist/5199.index.js +305 -0
- package/dist/5216.index.js +109 -0
- package/dist/5439.index.js +301 -0
- package/dist/5443.index.js +97 -0
- package/dist/5496.index.js +377 -0
- package/dist/550.index.js +2 -1
- package/dist/5801.index.js +588 -0
- package/dist/5858.index.js +223 -0
- package/dist/5933.index.js +143 -0
- package/dist/601.index.js +23 -0
- package/dist/6173.index.js +273 -0
- package/dist/6291.index.js +1871 -0
- package/dist/6312.index.js +666 -0
- package/dist/634.index.js +16182 -0
- package/dist/644.index.js +87 -0
- package/dist/6508.index.js +283 -0
- package/dist/6560.index.js +645 -0
- package/dist/6576.index.js +422 -0
- package/dist/6579.index.js +271 -0
- package/dist/6745.index.js +305 -0
- package/dist/6818.index.js +21642 -0
- package/dist/6972.index.js +167 -0
- package/dist/6995.index.js +163 -0
- package/dist/7249.index.js +191 -0
- package/dist/7372.index.js +1197 -0
- package/dist/7546.index.js +541 -0
- package/dist/76.index.js +448 -0
- package/dist/7879.index.js +163 -0
- package/dist/8025.index.js +130 -0
- package/dist/8054.index.js +248 -0
- package/dist/8097.index.js +201 -0
- package/dist/8126.index.js +191 -0
- package/dist/8178.index.js +78 -0
- package/dist/818.index.js +212 -0
- package/dist/8382.index.js +93 -0
- package/dist/8408.index.js +261 -0
- package/dist/8540.index.js +174 -0
- package/dist/8635.index.js +802 -0
- package/dist/8688.index.js +410 -0
- package/dist/8699.index.js +779 -0
- package/dist/8891.index.js +457 -0
- package/dist/8916.index.js +885 -0
- package/dist/9146.index.js +170 -0
- package/dist/9168.index.js +841 -0
- package/dist/9292.index.js +369 -0
- package/dist/9382.index.js +135 -11
- package/dist/9422.index.js +866 -0
- package/dist/9440.index.js +453 -0
- package/dist/9479.index.js +152 -0
- package/dist/9481.index.js +220 -0
- package/dist/9539.index.js +100 -0
- package/dist/9547.index.js +103 -0
- package/dist/9560.index.js +41 -61
- package/dist/9692.index.js +90 -0
- package/dist/9800.index.js +213 -1
- package/dist/9899.index.js +138 -0
- package/dist/9981.index.js +206 -0
- package/dist/999.index.js +117 -0
- package/dist/agentic-security.mjs +27 -27
- package/dist/agentic-security.mjs.sha256 +1 -1
- package/package.json +28 -3
- package/src/context-intelligence/candidates.js +2 -1
- package/src/context-intelligence/capabilities.js +2 -1
- package/src/context-intelligence/cli.js +2 -0
- package/src/context-intelligence/config.js +3 -1
- package/src/context-intelligence/controls.js +49 -1
- package/src/context-intelligence/counterexample.js +200 -0
- package/src/context-intelligence/cross-route.js +111 -0
- package/src/context-intelligence/findings.js +166 -0
- package/src/context-intelligence/invariants.js +197 -0
- package/src/context-intelligence/queue.js +6 -1
- package/src/context-intelligence/reachability.js +2 -2
- package/src/context-intelligence/review.js +68 -4
- package/src/dataflow/access-paths.js +11 -0
- package/src/dataflow/analysis-limits.js +66 -0
- package/src/dataflow/engine.js +272 -20
- package/src/dataflow/service-edges.js +174 -0
- package/src/dataflow/summaries.js +7 -1
- package/src/discovery/judge.js +2 -1
- package/src/engine.js +82 -14
- package/src/fix/apply-fix-service.js +55 -8
- package/src/fix/batch-journal.js +84 -0
- package/src/fix/exploit-replay.js +51 -0
- package/src/fix/footprint.js +65 -0
- package/src/fix/patch-policy.js +49 -0
- package/src/fix/secret-persistence.js +39 -0
- package/src/fix/test-commands.js +84 -0
- package/src/fix/verification-adapters.js +97 -0
- package/src/fix/verification-record.js +243 -0
- package/src/fix/verify-patch.js +89 -0
- package/src/ir/CLAUDE.md +5 -0
- package/src/ir/callgraph.js +23 -1
- package/src/ir/module-resolver.js +315 -0
- package/src/ir/parser-js.js +21 -2
- package/src/ir/semantic-graph.js +245 -0
- package/src/lineage/build-attested-correlation.js +63 -0
- package/src/lineage/deployment-identity.js +76 -0
- package/src/mcp/tools.js +13 -34
- package/src/pipeline/canonical-output.js +64 -0
- package/src/pipeline/detector-runner.js +7 -0
- package/src/pipeline/scan-health.js +14 -0
- package/src/pipeline/supervised-analyzers.js +125 -0
- package/src/pipeline/supervised-child.js +17 -0
- package/src/pipeline/telemetry.js +79 -0
- package/src/posture/accuracy-scorecard.js +98 -9
- package/src/posture/artifact-registry.js +5 -0
- package/src/posture/assurance/evidence-registry.js +215 -0
- package/src/posture/assurance/release-package-verify.js +135 -0
- package/src/posture/assurance/release-package.js +118 -0
- package/src/posture/assurance/release-verdict.js +94 -0
- package/src/posture/assurance/waiver.js +200 -0
- package/src/posture/compliance-truth.js +100 -0
- package/src/posture/evaluation/scan-child.js +3 -1
- package/src/posture/evaluation/why-missed.js +3 -1
- package/src/posture/exploitability-evidence.js +141 -0
- package/src/posture/fix-verify.js +4 -2
- package/src/posture/fleet/exposure-ranking.js +115 -0
- package/src/posture/fleet/service-chain-graph.js +150 -0
- package/src/posture/graph-reconciliation.js +154 -0
- package/src/posture/provenance/coverage.js +103 -0
- package/src/posture/provenance/git-evidence.js +84 -0
- package/src/posture/provenance/origin-resolver.js +7 -1
- package/src/posture/provenance/predicate-replay.js +14 -4
- package/src/posture/runtime-correlation.js +61 -15
- package/src/posture/runtime-explanation.js +116 -0
- package/src/posture/runtime-trace-ingest.js +194 -0
- package/src/posture/scan-checkpoint.js +38 -10
- package/src/posture/waf-ingest.js +7 -2
- package/src/report/index.js +4 -0
- package/src/report/oscal.js +38 -0
- package/src/report/perspectives.js +150 -0
- package/src/sast/_comment-strip.js +8 -1
- package/src/sast/ruby.js +26 -0
- package/src/util/string-memo.js +38 -0
|
@@ -0,0 +1,645 @@
|
|
|
1
|
+
export const id = 6560;
|
|
2
|
+
export const ids = [6560,9292,119,9692];
|
|
3
|
+
export const modules = {
|
|
4
|
+
|
|
5
|
+
/***/ 69292:
|
|
6
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
7
|
+
|
|
8
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
9
|
+
/* harmony export */ ImageArchiveError: () => (/* binding */ ImageArchiveError),
|
|
10
|
+
/* harmony export */ t: () => (/* binding */ parseImageArchive)
|
|
11
|
+
/* harmony export */ });
|
|
12
|
+
/* harmony import */ var node_crypto__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(77598);
|
|
13
|
+
/* harmony import */ var _safe_tar_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(30119);
|
|
14
|
+
// Parses a Docker-save ("docker-archive") or OCI-layout ("oci-archive") tar
|
|
15
|
+
// into one normalized shape, without executing or daemon-mounting the image
|
|
16
|
+
// (PRD 5 Safety Requirements: "OCI inspection should not require executing
|
|
17
|
+
// the image"). Built entirely on `safe-tar.js` — every byte read here passes
|
|
18
|
+
// through the same entry-count/size/path/decompression guards.
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ImageArchiveError extends Error {
|
|
23
|
+
constructor(message, code) {
|
|
24
|
+
super(message);
|
|
25
|
+
this.name = 'ImageArchiveError';
|
|
26
|
+
this.code = code;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function safeJsonParse(buf, what) {
|
|
31
|
+
try {
|
|
32
|
+
return JSON.parse(buf.toString('utf8'));
|
|
33
|
+
} catch (err) {
|
|
34
|
+
throw new ImageArchiveError(`${what} is not valid JSON: ${err.message}`, 'malformed_manifest');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function readOuterEntries(buf, limits) {
|
|
39
|
+
const outer = (0,_safe_tar_js__WEBPACK_IMPORTED_MODULE_1__/* .decompressIfGzip */ .zr)(buf, limits);
|
|
40
|
+
const byName = new Map();
|
|
41
|
+
const unsafeEntries = [];
|
|
42
|
+
for (const e of (0,_safe_tar_js__WEBPACK_IMPORTED_MODULE_1__/* .readTarEntries */ .ET)(outer, limits)) {
|
|
43
|
+
if (e.unsafe) {
|
|
44
|
+
unsafeEntries.push({ name: e.name });
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
byName.set(e.name, e);
|
|
48
|
+
}
|
|
49
|
+
return { byName, unsafeEntries };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function extractConfigShape(configObj) {
|
|
53
|
+
const cfg = (configObj && configObj.config) || {};
|
|
54
|
+
return {
|
|
55
|
+
architecture: configObj.architecture || null,
|
|
56
|
+
os: configObj.os || null,
|
|
57
|
+
labels: (cfg.Labels && typeof cfg.Labels === 'object') ? { ...cfg.Labels } : {},
|
|
58
|
+
entrypoint: Array.isArray(cfg.Entrypoint) ? [...cfg.Entrypoint] : null,
|
|
59
|
+
cmd: Array.isArray(cfg.Cmd) ? [...cfg.Cmd] : null,
|
|
60
|
+
history: Array.isArray(configObj.history)
|
|
61
|
+
? configObj.history.map((h) => ({ createdBy: h.created_by || null, created: h.created || null, emptyLayer: !!h.empty_layer }))
|
|
62
|
+
: [],
|
|
63
|
+
rootfsDiffIds: (configObj.rootfs && Array.isArray(configObj.rootfs.diff_ids)) ? [...configObj.rootfs.diff_ids] : [],
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function parseDockerArchive(byName, outerUnsafe, limits) {
|
|
68
|
+
const manifestEntry = byName.get('manifest.json');
|
|
69
|
+
const manifestArr = safeJsonParse(manifestEntry.data, 'manifest.json');
|
|
70
|
+
if (!Array.isArray(manifestArr) || manifestArr.length === 0) {
|
|
71
|
+
throw new ImageArchiveError('manifest.json contains no images', 'empty_manifest');
|
|
72
|
+
}
|
|
73
|
+
if (manifestArr.length > 1) {
|
|
74
|
+
throw new ImageArchiveError(`manifest.json describes ${manifestArr.length} images; image scan expects exactly one`, 'multi_image_archive');
|
|
75
|
+
}
|
|
76
|
+
const m = manifestArr[0];
|
|
77
|
+
if (typeof m.Config !== 'string' || !Array.isArray(m.Layers)) {
|
|
78
|
+
throw new ImageArchiveError('manifest.json entry is missing Config or Layers', 'malformed_manifest');
|
|
79
|
+
}
|
|
80
|
+
const configEntry = byName.get(m.Config);
|
|
81
|
+
if (!configEntry) throw new ImageArchiveError(`manifest.json references missing config "${m.Config}"`, 'missing_blob');
|
|
82
|
+
const configObj = safeJsonParse(configEntry.data, m.Config);
|
|
83
|
+
const configDigest = `sha256:${node_crypto__WEBPACK_IMPORTED_MODULE_0__.createHash('sha256').update(configEntry.data).digest('hex')}`;
|
|
84
|
+
|
|
85
|
+
const layers = [];
|
|
86
|
+
for (let i = 0; i < m.Layers.length; i++) {
|
|
87
|
+
const layerPath = m.Layers[i];
|
|
88
|
+
const entry = byName.get(layerPath);
|
|
89
|
+
if (!entry) throw new ImageArchiveError(`manifest.json references missing layer "${layerPath}"`, 'missing_blob');
|
|
90
|
+
const tar = (0,_safe_tar_js__WEBPACK_IMPORTED_MODULE_1__/* .decompressIfGzip */ .zr)(entry.data, limits);
|
|
91
|
+
layers.push({ index: i, path: layerPath, diffId: configObj?.rootfs?.diff_ids?.[i] || null, tar, sizeBytes: entry.size });
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
format: 'docker-archive',
|
|
96
|
+
digest: configDigest,
|
|
97
|
+
digestKind: 'config',
|
|
98
|
+
repoTags: Array.isArray(m.RepoTags) ? m.RepoTags : [],
|
|
99
|
+
config: extractConfigShape(configObj),
|
|
100
|
+
layers,
|
|
101
|
+
unsafeEntries: outerUnsafe,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function parseOciArchive(byName, outerUnsafe, limits) {
|
|
106
|
+
const indexObj = safeJsonParse(byName.get('index.json').data, 'index.json');
|
|
107
|
+
const manifests = Array.isArray(indexObj.manifests) ? indexObj.manifests : [];
|
|
108
|
+
if (manifests.length === 0) throw new ImageArchiveError('index.json lists no manifests', 'empty_manifest');
|
|
109
|
+
if (manifests.length > 1) {
|
|
110
|
+
throw new ImageArchiveError(`index.json describes ${manifests.length} manifests; image scan expects exactly one`, 'multi_image_archive');
|
|
111
|
+
}
|
|
112
|
+
const manifestDigest = manifests[0].digest;
|
|
113
|
+
if (typeof manifestDigest !== 'string' || !manifestDigest.startsWith('sha256:')) {
|
|
114
|
+
throw new ImageArchiveError('index.json manifest entry has no sha256 digest', 'malformed_manifest');
|
|
115
|
+
}
|
|
116
|
+
const manifestBlobPath = `blobs/sha256/${manifestDigest.slice('sha256:'.length)}`;
|
|
117
|
+
const manifestEntry = byName.get(manifestBlobPath);
|
|
118
|
+
if (!manifestEntry) throw new ImageArchiveError(`index.json references missing manifest blob "${manifestBlobPath}"`, 'missing_blob');
|
|
119
|
+
const manifestObj = safeJsonParse(manifestEntry.data, manifestBlobPath);
|
|
120
|
+
|
|
121
|
+
const configDigest = manifestObj.config && manifestObj.config.digest;
|
|
122
|
+
if (typeof configDigest !== 'string' || !configDigest.startsWith('sha256:')) {
|
|
123
|
+
throw new ImageArchiveError('image manifest has no config digest', 'malformed_manifest');
|
|
124
|
+
}
|
|
125
|
+
const configBlobPath = `blobs/sha256/${configDigest.slice('sha256:'.length)}`;
|
|
126
|
+
const configEntry = byName.get(configBlobPath);
|
|
127
|
+
if (!configEntry) throw new ImageArchiveError(`manifest references missing config blob "${configBlobPath}"`, 'missing_blob');
|
|
128
|
+
const configObj = safeJsonParse(configEntry.data, configBlobPath);
|
|
129
|
+
|
|
130
|
+
const layerDescs = Array.isArray(manifestObj.layers) ? manifestObj.layers : [];
|
|
131
|
+
const layers = [];
|
|
132
|
+
for (let i = 0; i < layerDescs.length; i++) {
|
|
133
|
+
const d = layerDescs[i];
|
|
134
|
+
if (typeof d.digest !== 'string' || !d.digest.startsWith('sha256:')) {
|
|
135
|
+
throw new ImageArchiveError(`layer ${i} has no sha256 digest`, 'malformed_manifest');
|
|
136
|
+
}
|
|
137
|
+
const blobPath = `blobs/sha256/${d.digest.slice('sha256:'.length)}`;
|
|
138
|
+
const entry = byName.get(blobPath);
|
|
139
|
+
if (!entry) throw new ImageArchiveError(`manifest references missing layer blob "${blobPath}"`, 'missing_blob');
|
|
140
|
+
const tar = (0,_safe_tar_js__WEBPACK_IMPORTED_MODULE_1__/* .decompressIfGzip */ .zr)(entry.data, limits);
|
|
141
|
+
layers.push({ index: i, path: blobPath, diffId: d.digest, mediaType: d.mediaType || null, tar, sizeBytes: entry.size });
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return {
|
|
145
|
+
format: 'oci-archive',
|
|
146
|
+
digest: manifestDigest,
|
|
147
|
+
digestKind: 'manifest',
|
|
148
|
+
repoTags: [],
|
|
149
|
+
config: extractConfigShape(configObj),
|
|
150
|
+
layers,
|
|
151
|
+
unsafeEntries: outerUnsafe,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Parses an in-memory tar buffer (already read from disk/stdin by the
|
|
157
|
+
* caller — this module never touches the filesystem or network) as either a
|
|
158
|
+
* `docker save`-shaped archive or an OCI-layout archive. Throws
|
|
159
|
+
* ImageArchiveError for anything it cannot recognize or whose manifest
|
|
160
|
+
* references a blob that isn't present — never guesses or substitutes a
|
|
161
|
+
* default.
|
|
162
|
+
*/
|
|
163
|
+
function parseImageArchive(buf, limits = _safe_tar_js__WEBPACK_IMPORTED_MODULE_1__/* .DEFAULT_LIMITS */ .dR) {
|
|
164
|
+
if (!Buffer.isBuffer(buf)) throw new ImageArchiveError('image archive input must be a Buffer', 'bad_input');
|
|
165
|
+
const { byName, unsafeEntries } = readOuterEntries(buf, limits);
|
|
166
|
+
if (byName.has('manifest.json')) return parseDockerArchive(byName, unsafeEntries, limits);
|
|
167
|
+
if (byName.has('index.json') && byName.has('oci-layout')) return parseOciArchive(byName, unsafeEntries, limits);
|
|
168
|
+
throw new ImageArchiveError(
|
|
169
|
+
'archive is neither a docker-archive (manifest.json) nor an oci-archive (oci-layout + index.json)',
|
|
170
|
+
'unrecognized_format',
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
/***/ }),
|
|
176
|
+
|
|
177
|
+
/***/ 46560:
|
|
178
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
// EXPORTS
|
|
182
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
183
|
+
buildImageInventory: () => (/* binding */ buildImageInventory)
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
// EXTERNAL MODULE: ./src/artifact/image-archive.js
|
|
187
|
+
var image_archive = __webpack_require__(69292);
|
|
188
|
+
// EXTERNAL MODULE: ./src/artifact/safe-tar.js
|
|
189
|
+
var safe_tar = __webpack_require__(30119);
|
|
190
|
+
;// CONCATENATED MODULE: ./src/artifact/filesystem.js
|
|
191
|
+
// Merges an image's layers (in order) into one virtual filesystem view,
|
|
192
|
+
// applying AUFS/overlay whiteout semantics (`.wh.<name>` deletes a file,
|
|
193
|
+
// `.wh..wh..opq` makes a directory opaque to everything below it in earlier
|
|
194
|
+
// layers). Nothing here ever writes to a real filesystem path — the merged
|
|
195
|
+
// view is an in-memory Map keyed by the tar entry's (already path-safety-
|
|
196
|
+
// checked) name, which is what makes this immune to zip-slip by construction
|
|
197
|
+
// rather than by convention.
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
const DEFAULT_FS_LIMITS = Object.freeze({
|
|
201
|
+
maxFileBytes: 1 * 1024 * 1024, // per-file materialization cap
|
|
202
|
+
maxMaterializedTotalBytes: 256 * 1024 * 1024, // total content kept in memory
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Reads every layer's tar into per-layer entry lists (bounded by the same
|
|
207
|
+
* safe-tar limits as the outer archive) without merging — the raw, ordered
|
|
208
|
+
* per-layer view that layer-secrets.js needs to see what a LATER layer
|
|
209
|
+
* deleted while it was still present in an EARLIER one.
|
|
210
|
+
*/
|
|
211
|
+
function readLayers(layers, tarLimits = safe_tar/* DEFAULT_LIMITS */.dR) {
|
|
212
|
+
const result = [];
|
|
213
|
+
const unsafeEntries = [];
|
|
214
|
+
for (const layer of layers) {
|
|
215
|
+
const entries = [];
|
|
216
|
+
for (const e of (0,safe_tar/* readTarEntries */.ET)(layer.tar, tarLimits)) {
|
|
217
|
+
if (e.unsafe) {
|
|
218
|
+
unsafeEntries.push({ layerIndex: layer.index, name: e.name });
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
entries.push(e);
|
|
222
|
+
}
|
|
223
|
+
result.push({ layerIndex: layer.index, entries });
|
|
224
|
+
}
|
|
225
|
+
return { layers: result, unsafeEntries };
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Merges the per-layer entry lists (from readLayers) into one final
|
|
230
|
+
* filesystem view, applying whiteouts in layer order. Returns:
|
|
231
|
+
* - `files`: Map<path, { sizeBytes, sourceLayerIndex, typeflag }> — every
|
|
232
|
+
* surviving path, metadata only.
|
|
233
|
+
* - `fileContents`: { path: string } — decoded text content, capped per
|
|
234
|
+
* file and in total (see DEFAULT_FS_LIMITS); large/binary files are
|
|
235
|
+
* present in `files` but absent here.
|
|
236
|
+
* - `deletedPaths`: [{ path, deletedAtLayer, opaque }] — every whiteout
|
|
237
|
+
* seen, in order, regardless of whether the path ever existed.
|
|
238
|
+
* - `materializationTruncated`: true once the total content cap was hit —
|
|
239
|
+
* disclosed, not silent.
|
|
240
|
+
*/
|
|
241
|
+
function mergeLayers(readLayersResult, fsLimits = DEFAULT_FS_LIMITS) {
|
|
242
|
+
const files = new Map(); // path -> { sizeBytes, sourceLayerIndex, typeflag, data }
|
|
243
|
+
const deletedPaths = [];
|
|
244
|
+
let materializedTotal = 0;
|
|
245
|
+
let materializationTruncated = false;
|
|
246
|
+
|
|
247
|
+
for (const { layerIndex, entries } of readLayersResult.layers) {
|
|
248
|
+
const opaqueDirs = [];
|
|
249
|
+
for (const e of entries) {
|
|
250
|
+
if ((0,safe_tar/* isWhiteoutName */.l0)(e.name)) {
|
|
251
|
+
const wh = (0,safe_tar/* whiteoutTarget */.Jn)(e.name);
|
|
252
|
+
if (wh.opaque) {
|
|
253
|
+
opaqueDirs.push(wh.dir);
|
|
254
|
+
deletedPaths.push({ path: wh.dir, deletedAtLayer: layerIndex, opaque: true });
|
|
255
|
+
for (const existing of [...files.keys()]) {
|
|
256
|
+
if (existing === wh.dir || existing.startsWith(`${wh.dir}/`)) files.delete(existing);
|
|
257
|
+
}
|
|
258
|
+
} else {
|
|
259
|
+
deletedPaths.push({ path: wh.path, deletedAtLayer: layerIndex, opaque: false });
|
|
260
|
+
files.delete(wh.path);
|
|
261
|
+
}
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
// An opaque marker earlier in THIS layer hides any further entry in
|
|
265
|
+
// this same layer that would resurrect something under that dir —
|
|
266
|
+
// real overlay semantics scope opaque to "everything from layers
|
|
267
|
+
// BELOW this one", so same-layer adds after the marker still apply.
|
|
268
|
+
files.set(e.name, { sizeBytes: e.size, sourceLayerIndex: layerIndex, typeflag: e.typeflag, data: e.data });
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const fileContents = {};
|
|
273
|
+
for (const [path, meta] of files) {
|
|
274
|
+
if (meta.typeflag !== '0' && meta.typeflag !== '') continue; // only regular files get content
|
|
275
|
+
if (meta.sizeBytes > fsLimits.maxFileBytes) continue;
|
|
276
|
+
if (materializedTotal + meta.sizeBytes > fsLimits.maxMaterializedTotalBytes) {
|
|
277
|
+
materializationTruncated = true;
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
fileContents[path] = meta.data.toString('utf8');
|
|
281
|
+
materializedTotal += meta.sizeBytes;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const fileMeta = new Map();
|
|
285
|
+
for (const [path, meta] of files) {
|
|
286
|
+
fileMeta.set(path, { sizeBytes: meta.sizeBytes, sourceLayerIndex: meta.sourceLayerIndex, typeflag: meta.typeflag });
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return { files: fileMeta, fileContents, deletedPaths, materializationTruncated };
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// EXTERNAL MODULE: ./src/sca/image-packages.js
|
|
293
|
+
var image_packages = __webpack_require__(99692);
|
|
294
|
+
;// CONCATENATED MODULE: ./src/artifact/inventory.js
|
|
295
|
+
// PRD 5 P0 §1-2 — OCI image scanning + inventory. Ties image-archive.js
|
|
296
|
+
// (manifest/config/layer parsing) and filesystem.js (whiteout-aware layer
|
|
297
|
+
// merge) into the single inventory shape the PRD names: digest, OS, OS
|
|
298
|
+
// packages, application packages, architecture, base image, layers,
|
|
299
|
+
// entrypoint, build labels.
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
// Buildkit/Docker provenance convention — not an OCI spec requirement, so
|
|
306
|
+
// its absence is reported as "not declared", never guessed from layer
|
|
307
|
+
// heuristics (no base-image fingerprint table exists in this codebase, and
|
|
308
|
+
// inventing one would produce a confident-looking wrong answer, which is the
|
|
309
|
+
// one failure mode PRD 5's own Safety Requirements single out by name for
|
|
310
|
+
// signature state — the same discipline applies here).
|
|
311
|
+
const BASE_IMAGE_NAME_LABEL = 'org.opencontainers.image.base.name';
|
|
312
|
+
const BASE_IMAGE_DIGEST_LABEL = 'org.opencontainers.image.base.digest';
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* `buf` is an already-read image archive buffer (tar, optionally
|
|
316
|
+
* gzip-wrapped). `manifestParser` is the engine's existing
|
|
317
|
+
* `parseManifests(allFileContents)` (injected, mirroring
|
|
318
|
+
* `src/posture/secret-history.js`'s detectFn injection, so this module never
|
|
319
|
+
* imports `engine.js` directly and `src/sca/index.js` stays the one seam).
|
|
320
|
+
* Returns `{ image, inventory }` where `image` is the raw parsed archive
|
|
321
|
+
* (image-archive.js's shape, kept for callers that need layer tars — vuln
|
|
322
|
+
* correlation, signature verification) and `inventory` is the PRD-named
|
|
323
|
+
* report.
|
|
324
|
+
*/
|
|
325
|
+
function buildImageInventory(buf, { manifestParser, tarLimits = safe_tar/* DEFAULT_LIMITS */.dR, fsLimits = DEFAULT_FS_LIMITS } = {}) {
|
|
326
|
+
if (typeof manifestParser !== 'function') throw new TypeError('buildImageInventory requires manifestParser(allFileContents)');
|
|
327
|
+
const image = (0,image_archive/* parseImageArchive */.t)(buf, tarLimits);
|
|
328
|
+
const rl = readLayers(image.layers, tarLimits);
|
|
329
|
+
const merged = mergeLayers(rl, fsLimits);
|
|
330
|
+
|
|
331
|
+
const osPackages = (0,image_packages.extractImagePackages)(merged.fileContents);
|
|
332
|
+
let appPackages = [];
|
|
333
|
+
try {
|
|
334
|
+
appPackages = manifestParser(merged.fileContents) || [];
|
|
335
|
+
} catch {
|
|
336
|
+
appPackages = []; // a parser failure on hostile layer content must never abort inventory extraction
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const labels = image.config.labels || {};
|
|
340
|
+
const baseImage = labels[BASE_IMAGE_NAME_LABEL]
|
|
341
|
+
? { name: labels[BASE_IMAGE_NAME_LABEL], digest: labels[BASE_IMAGE_DIGEST_LABEL] || null, source: 'label' }
|
|
342
|
+
: null;
|
|
343
|
+
|
|
344
|
+
const inventory = {
|
|
345
|
+
digest: image.digest,
|
|
346
|
+
digestKind: image.digestKind,
|
|
347
|
+
repoTags: image.repoTags,
|
|
348
|
+
os: image.config.os,
|
|
349
|
+
architecture: image.config.architecture,
|
|
350
|
+
baseImage,
|
|
351
|
+
osPackages,
|
|
352
|
+
appPackages,
|
|
353
|
+
layers: image.layers.map((l) => ({ index: l.index, sizeBytes: l.sizeBytes, diffId: l.diffId || null })),
|
|
354
|
+
entrypoint: image.config.entrypoint,
|
|
355
|
+
cmd: image.config.cmd,
|
|
356
|
+
buildLabels: { ...labels },
|
|
357
|
+
history: image.config.history,
|
|
358
|
+
unsafeEntries: [...image.unsafeEntries, ...rl.unsafeEntries],
|
|
359
|
+
materializationTruncated: merged.materializationTruncated,
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
return { image, inventory, mergedFilesystem: merged, readLayersResult: rl };
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
/***/ }),
|
|
367
|
+
|
|
368
|
+
/***/ 30119:
|
|
369
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
370
|
+
|
|
371
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
372
|
+
/* harmony export */ ET: () => (/* binding */ readTarEntries),
|
|
373
|
+
/* harmony export */ Jn: () => (/* binding */ whiteoutTarget),
|
|
374
|
+
/* harmony export */ TarSafetyError: () => (/* binding */ TarSafetyError),
|
|
375
|
+
/* harmony export */ dR: () => (/* binding */ DEFAULT_LIMITS),
|
|
376
|
+
/* harmony export */ l0: () => (/* binding */ isWhiteoutName),
|
|
377
|
+
/* harmony export */ zr: () => (/* binding */ decompressIfGzip)
|
|
378
|
+
/* harmony export */ });
|
|
379
|
+
/* unused harmony export isSafeEntryName */
|
|
380
|
+
/* harmony import */ var node_zlib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(38522);
|
|
381
|
+
// Hand-rolled, hardened POSIX/GNU tar reader for OCI/Docker image archives.
|
|
382
|
+
//
|
|
383
|
+
// Why hand-rolled instead of a dependency: this repo has no tar library (see
|
|
384
|
+
// `src/artifact/CLAUDE.md`), and PRD 5's own Safety Requirements ask for exact
|
|
385
|
+
// control over the failure modes a generic tar library treats as implementation
|
|
386
|
+
// detail: malicious entry paths, decompression bombs, giant layers, oversized
|
|
387
|
+
// archives. Rolling it ourselves means every one of those limits is a named,
|
|
388
|
+
// tested constant in this file rather than a library default we'd have to audit.
|
|
389
|
+
//
|
|
390
|
+
// Scope: ustar + GNU longname ('L' typeflag) + base-256 size fields. PAX extended
|
|
391
|
+
// headers ('x'/'g') and GNU longlink ('K') are structurally skipped (their data
|
|
392
|
+
// block is consumed so offsets stay correct, but their content is not applied) —
|
|
393
|
+
// a disclosed limitation, not a silent one. Real docker-save/oci-archive output
|
|
394
|
+
// from Go's archive/tar for images in this size/complexity class essentially
|
|
395
|
+
// never needs them; synthetic fixtures in this codebase never emit them either.
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
const BLOCK = 512;
|
|
399
|
+
|
|
400
|
+
const DEFAULT_LIMITS = Object.freeze({
|
|
401
|
+
maxEntries: 200_000,
|
|
402
|
+
maxEntrySize: 512 * 1024 * 1024, // 512MB per tar entry
|
|
403
|
+
maxTotalSize: 4 * 1024 * 1024 * 1024, // 4GB per archive (sum of entry sizes)
|
|
404
|
+
maxGunzipOutput: 4 * 1024 * 1024 * 1024, // decompression-bomb guard
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
class TarSafetyError extends Error {
|
|
408
|
+
constructor(message, code) {
|
|
409
|
+
super(message);
|
|
410
|
+
this.name = 'TarSafetyError';
|
|
411
|
+
this.code = code;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function parseSizeField(buf) {
|
|
416
|
+
if (buf[0] & 0x80) {
|
|
417
|
+
// GNU base-256 extension for sizes that don't fit in octal-ASCII.
|
|
418
|
+
let n = 0n;
|
|
419
|
+
for (let i = 1; i < buf.length; i++) n = (n << 8n) | BigInt(buf[i]);
|
|
420
|
+
return Number(n);
|
|
421
|
+
}
|
|
422
|
+
const s = buf.toString('ascii').replace(/\0.*$/, '').trim();
|
|
423
|
+
if (!s) return 0;
|
|
424
|
+
const n = parseInt(s, 8);
|
|
425
|
+
return Number.isFinite(n) ? n : 0;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
function cstr(buf) {
|
|
429
|
+
return buf.toString('utf8').replace(/\0.*$/, '');
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// A tar entry name is unsafe when it would escape a virtual extraction root:
|
|
433
|
+
// absolute paths, `..` segments, embedded NULs, or an unreasonable length.
|
|
434
|
+
// Because this module never writes to a real filesystem path (every caller
|
|
435
|
+
// keeps extracted content in an in-memory Map keyed by this string), the
|
|
436
|
+
// classic zip-slip *write* vulnerability cannot occur here — but a hostile
|
|
437
|
+
// name must still never be silently treated as an ordinary path by downstream
|
|
438
|
+
// manifest/package-DB matching, so unsafe entries are flagged, never dropped
|
|
439
|
+
// silently and never accepted as-is.
|
|
440
|
+
function isSafeEntryName(name) {
|
|
441
|
+
if (typeof name !== 'string' || name.length === 0 || name.length > 4096) return false;
|
|
442
|
+
if (name.includes('\0')) return false;
|
|
443
|
+
const norm = name.replace(/\\/g, '/');
|
|
444
|
+
if (norm.startsWith('/')) return false;
|
|
445
|
+
if (norm.split('/').some((p) => p === '..')) return false;
|
|
446
|
+
return true;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
function isWhiteoutName(name) {
|
|
450
|
+
return (name.split('/').pop() || '').startsWith('.wh.');
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// Resolves a whiteout entry name to what it deletes. `.wh..wh..opq` marks a
|
|
454
|
+
// directory as "opaque" (everything from earlier layers under it is hidden,
|
|
455
|
+
// not individually deleted) — reported distinctly so callers don't conflate
|
|
456
|
+
// it with a single-file deletion.
|
|
457
|
+
function whiteoutTarget(name) {
|
|
458
|
+
const parts = name.split('/');
|
|
459
|
+
const base = parts.pop();
|
|
460
|
+
if (base === '.wh..wh..opq') return { opaque: true, dir: parts.join('/') };
|
|
461
|
+
return { opaque: false, path: [...parts, base.slice(4)].join('/') };
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// Decompresses a gzip member with a hard output-size cap (Node's native
|
|
465
|
+
// ERR_BUFFER_TOO_LARGE on overflow — no custom streaming counter needed).
|
|
466
|
+
// Returns the input unchanged when it isn't gzip-magic (plain tar).
|
|
467
|
+
function decompressIfGzip(buf, limits = DEFAULT_LIMITS) {
|
|
468
|
+
if (buf.length >= 2 && buf[0] === 0x1f && buf[1] === 0x8b) {
|
|
469
|
+
try {
|
|
470
|
+
return node_zlib__WEBPACK_IMPORTED_MODULE_0__.gunzipSync(buf, { maxOutputLength: limits.maxGunzipOutput });
|
|
471
|
+
} catch (err) {
|
|
472
|
+
if (err && err.code === 'ERR_BUFFER_TOO_LARGE') {
|
|
473
|
+
throw new TarSafetyError('decompressed layer exceeds the decompression-bomb guard', 'gunzip_too_large');
|
|
474
|
+
}
|
|
475
|
+
throw new TarSafetyError(`gzip stream is malformed: ${err.message}`, 'gunzip_malformed');
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
return buf;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Reads a decompressed tar buffer and yields one record per entry:
|
|
483
|
+
* { name, size, typeflag, linkname, data, unsafe }
|
|
484
|
+
* `data` is a Buffer view into `buf` (never copied) for safe entries, `null`
|
|
485
|
+
* for unsafe ones. Throws TarSafetyError (never returns a partial result) the
|
|
486
|
+
* moment any configured limit is exceeded.
|
|
487
|
+
*/
|
|
488
|
+
function* readTarEntries(buf, limits = DEFAULT_LIMITS) {
|
|
489
|
+
if (!Buffer.isBuffer(buf)) throw new TarSafetyError('tar input must be a Buffer', 'bad_input');
|
|
490
|
+
let offset = 0;
|
|
491
|
+
let count = 0;
|
|
492
|
+
let totalSize = 0;
|
|
493
|
+
let pendingLongName = null;
|
|
494
|
+
|
|
495
|
+
while (offset + BLOCK <= buf.length) {
|
|
496
|
+
const header = buf.subarray(offset, offset + BLOCK);
|
|
497
|
+
if (header.every((b) => b === 0)) {
|
|
498
|
+
offset += BLOCK;
|
|
499
|
+
continue; // end-of-archive zero-fill padding
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
count += 1;
|
|
503
|
+
if (count > limits.maxEntries) {
|
|
504
|
+
throw new TarSafetyError(`tar archive has more than ${limits.maxEntries} entries`, 'too_many_entries');
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
let name = cstr(header.subarray(0, 100));
|
|
508
|
+
const typeflag = String.fromCharCode(header[156] || 0);
|
|
509
|
+
const linkname = cstr(header.subarray(157, 257));
|
|
510
|
+
const magic = header.subarray(257, 263).toString('ascii');
|
|
511
|
+
const prefix = magic.startsWith('ustar') ? cstr(header.subarray(345, 500)) : '';
|
|
512
|
+
if (prefix) name = `${prefix}/${name}`;
|
|
513
|
+
const size = parseSizeField(header.subarray(124, 136));
|
|
514
|
+
|
|
515
|
+
offset += BLOCK;
|
|
516
|
+
|
|
517
|
+
if (size < 0 || !Number.isFinite(size)) {
|
|
518
|
+
throw new TarSafetyError(`tar entry "${name}" has an invalid size field`, 'bad_size');
|
|
519
|
+
}
|
|
520
|
+
if (size > limits.maxEntrySize) {
|
|
521
|
+
throw new TarSafetyError(`tar entry "${name}" (${size} bytes) exceeds the per-entry size limit`, 'entry_too_large');
|
|
522
|
+
}
|
|
523
|
+
totalSize += size;
|
|
524
|
+
if (totalSize > limits.maxTotalSize) {
|
|
525
|
+
throw new TarSafetyError('tar archive exceeds the total-size limit', 'archive_too_large');
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
const dataBlocks = Math.ceil(size / BLOCK);
|
|
529
|
+
if (offset + size > buf.length) {
|
|
530
|
+
throw new TarSafetyError(`tar entry "${name}" claims more data than the archive contains`, 'truncated');
|
|
531
|
+
}
|
|
532
|
+
const data = size > 0 ? buf.subarray(offset, offset + size) : Buffer.alloc(0);
|
|
533
|
+
offset += dataBlocks * BLOCK;
|
|
534
|
+
|
|
535
|
+
const resolvedName = pendingLongName ? pendingLongName : name;
|
|
536
|
+
pendingLongName = null;
|
|
537
|
+
|
|
538
|
+
if (typeflag === 'L') {
|
|
539
|
+
// GNU longname: this entry's data IS the next entry's real name.
|
|
540
|
+
pendingLongName = cstr(data);
|
|
541
|
+
continue;
|
|
542
|
+
}
|
|
543
|
+
if (typeflag === 'K' || typeflag === 'x' || typeflag === 'g') {
|
|
544
|
+
// GNU longlink / PAX extended header — structurally skipped (see header comment).
|
|
545
|
+
continue;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
if (!isSafeEntryName(resolvedName)) {
|
|
549
|
+
yield { name: resolvedName, size, typeflag, linkname, data: null, unsafe: true };
|
|
550
|
+
continue;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
yield { name: resolvedName.replace(/\\/g, '/'), size, typeflag, linkname, data, unsafe: false };
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
/***/ }),
|
|
559
|
+
|
|
560
|
+
/***/ 99692:
|
|
561
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
562
|
+
|
|
563
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
564
|
+
/* harmony export */ extractImagePackages: () => (/* binding */ extractImagePackages)
|
|
565
|
+
/* harmony export */ });
|
|
566
|
+
/* unused harmony exports parseDpkgStatus, parseApkInstalled */
|
|
567
|
+
// R8 (PRD §5) — container-image OS-package inventory.
|
|
568
|
+
//
|
|
569
|
+
// container.js reads the Dockerfile (FROM + apt/apk install lines). This reads
|
|
570
|
+
// the ACTUAL installed-package databases from an extracted image filesystem
|
|
571
|
+
// (or the host), catching packages baked into the base image that the
|
|
572
|
+
// Dockerfile never names. Components flow into the existing OSV pipeline + SBOM.
|
|
573
|
+
//
|
|
574
|
+
// Pure parsers (unit-tested) + a path-matching extractor. No daemon; reads the
|
|
575
|
+
// package-DB files that appear when an image layer/tarball is unpacked.
|
|
576
|
+
|
|
577
|
+
// Debian/Ubuntu: /var/lib/dpkg/status — RFC822-style blocks separated by blank
|
|
578
|
+
// lines. Only "install ok installed" entries count (not removed/config-files).
|
|
579
|
+
function parseDpkgStatus(text) {
|
|
580
|
+
const out = [];
|
|
581
|
+
for (const block of String(text || '').split(/\n\s*\n/)) {
|
|
582
|
+
const name = (block.match(/^Package:\s*(.+)$/m) || [])[1];
|
|
583
|
+
const version = (block.match(/^Version:\s*(.+)$/m) || [])[1];
|
|
584
|
+
const status = (block.match(/^Status:\s*(.+)$/m) || [])[1] || '';
|
|
585
|
+
if (!name || !version) continue;
|
|
586
|
+
if (!/\binstalled\b/.test(status)) continue;
|
|
587
|
+
out.push({ name: name.trim(), version: version.trim(), ecosystem: 'Debian' });
|
|
588
|
+
}
|
|
589
|
+
return out;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// Alpine: /lib/apk/db/installed — blocks separated by blank lines; P:=name V:=version.
|
|
593
|
+
function parseApkInstalled(text) {
|
|
594
|
+
const out = [];
|
|
595
|
+
for (const block of String(text || '').split(/\n\s*\n/)) {
|
|
596
|
+
const name = (block.match(/^P:(.+)$/m) || [])[1];
|
|
597
|
+
const version = (block.match(/^V:(.+)$/m) || [])[1];
|
|
598
|
+
if (!name || !version) continue;
|
|
599
|
+
out.push({ name: name.trim(), version: version.trim(), ecosystem: 'Alpine' });
|
|
600
|
+
}
|
|
601
|
+
return out;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
const _PURL = { Debian: (n, v) => `pkg:deb/debian/${n}@${v}`, Alpine: (n, v) => `pkg:apk/alpine/${n}@${v}` };
|
|
605
|
+
|
|
606
|
+
// File-path tells for an unpacked image. Match on path suffix so it works
|
|
607
|
+
// whether the scan root is the rootfs or a subdirectory of it.
|
|
608
|
+
function _dbKind(path) {
|
|
609
|
+
const p = path.replace(/\\/g, '/');
|
|
610
|
+
if (/(?:^|\/)var\/lib\/dpkg\/status$/.test(p)) return 'dpkg';
|
|
611
|
+
if (/(?:^|\/)lib\/apk\/db\/installed$/.test(p)) return 'apk';
|
|
612
|
+
return null;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* Extract OS-package components from any image package-DBs present in the scanned
|
|
617
|
+
* files. Returns components in the engine's component shape so they ride the
|
|
618
|
+
* existing OSV/SBOM pipeline. De-dups by ecosystem:name:version.
|
|
619
|
+
*/
|
|
620
|
+
function extractImagePackages(fileContents) {
|
|
621
|
+
const comps = [];
|
|
622
|
+
const seen = new Set();
|
|
623
|
+
for (const [file, content] of Object.entries(fileContents || {})) {
|
|
624
|
+
const kind = _dbKind(file);
|
|
625
|
+
if (!kind) continue;
|
|
626
|
+
const pkgs = kind === 'dpkg' ? parseDpkgStatus(content) : parseApkInstalled(content);
|
|
627
|
+
for (const p of pkgs) {
|
|
628
|
+
const key = `${p.ecosystem}:${p.name}:${p.version}`;
|
|
629
|
+
if (seen.has(key)) continue;
|
|
630
|
+
seen.add(key);
|
|
631
|
+
comps.push({
|
|
632
|
+
name: p.name, version: p.version, group: '', ecosystem: p.ecosystem,
|
|
633
|
+
purl: (_PURL[p.ecosystem] || (() => null))(p.name, p.version),
|
|
634
|
+
filePath: file, isUnpinned: false, isTransitive: false, isOsPackage: true,
|
|
635
|
+
scope: 'required', reachable: true,
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
return comps;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
/***/ })
|
|
644
|
+
|
|
645
|
+
};
|