@clear-capabilities/agentic-security-scanner 0.185.0 → 0.186.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/bin/agentic-security.js +66 -18
  3. package/dist/1128.index.js +25 -21
  4. package/dist/{5817.index.js → 1602.index.js} +378 -29
  5. package/dist/2584.index.js +1 -1
  6. package/dist/4171.index.js +2 -2
  7. package/dist/{0b301d45b231f144a1b4.json → 4d06c8944ae121d7085c.json} +8 -8
  8. package/dist/5752.index.js +466 -0
  9. package/dist/7405.index.js +1 -1
  10. package/dist/8158.index.js +1713 -0
  11. package/dist/8798.index.js +1 -1
  12. package/dist/9382.index.js +2 -2
  13. package/dist/9560.index.js +1 -1
  14. package/dist/9579.index.js +1 -1
  15. package/dist/agentic-security.mjs +29 -29
  16. package/dist/agentic-security.mjs.sha256 +1 -1
  17. package/package.json +8 -8
  18. package/src/dataflow/CLAUDE.md +6 -3
  19. package/src/dataflow/access-paths.js +12 -2
  20. package/src/dataflow/demand-query.js +279 -40
  21. package/src/dataflow/dep-fingerprint.js +1 -1
  22. package/src/dataflow/exploit-prover.js +6 -2
  23. package/src/dataflow/ir-cache.js +268 -0
  24. package/src/dataflow/privacy-taint.js +7 -0
  25. package/src/engine.js +62 -5
  26. package/src/ir/CLAUDE.md +4 -0
  27. package/src/ir/callgraph.js +36 -8
  28. package/src/ir/index.js +18 -4
  29. package/src/ir/parser-js.js +10 -0
  30. package/src/language/CLAUDE.md +13 -0
  31. package/src/language/nix-option-types.js +170 -0
  32. package/src/language/nix-script-taint.js +46 -3
  33. package/src/language/nix-secrets.js +20 -2
  34. package/src/lineage/CLAUDE.md +2 -1
  35. package/src/lineage/smt-orchestrator.js +47 -11
  36. package/src/lineage/smt-z3-backend.js +294 -0
  37. package/src/posture/CLAUDE.md +5 -1
  38. package/src/posture/business-logic.js +16 -7
  39. package/src/posture/dag-commands.js +442 -0
  40. package/src/posture/finding-defaults.js +19 -0
  41. package/src/posture/git-history.js +91 -1
  42. package/src/posture/proof-fabric/cli.js +1 -1
  43. package/src/posture/proof-fabric/container.js +2 -2
  44. package/src/posture/proof-fabric/generate-haskell.js +205 -0
  45. package/src/posture/proof-fabric/generate.js +6 -3
  46. package/src/posture/proof-fabric/reproducer.js +4 -2
  47. package/src/posture/proof-fabric/runner.js +4 -4
  48. package/src/sast/CLAUDE.md +2 -0
  49. package/src/sast/_call-args.js +70 -0
  50. package/src/sast/init-scope.js +87 -0
  51. package/src/sast/listen-bind-address.js +49 -0
  52. package/src/sast/redirect-target.js +106 -0
  53. package/src/sast/reflected-input.js +76 -0
  54. package/src/sast/send-file-root.js +27 -0
  55. package/src/sast/sensitive-data-logging.js +38 -1
  56. package/dist/119.index.js +0 -197
  57. package/dist/128.index.js +0 -129
  58. package/dist/1293.index.js +0 -5689
  59. package/dist/1336.index.js +0 -16331
  60. package/dist/1351.index.js +0 -133
  61. package/dist/1387.index.js +0 -271
  62. package/dist/1437.index.js +0 -23
  63. package/dist/1445.index.js +0 -110
  64. package/dist/1505.index.js +0 -151
  65. package/dist/1557.index.js +0 -293
  66. package/dist/1621.index.js +0 -311
  67. package/dist/1751.index.js +0 -160
  68. package/dist/1765.index.js +0 -727
  69. package/dist/1861.index.js +0 -690
  70. package/dist/1906.index.js +0 -433
  71. package/dist/208.index.js +0 -1631
  72. package/dist/2223.index.js +0 -159
  73. package/dist/2238.index.js +0 -295
  74. package/dist/2530.index.js +0 -152
  75. package/dist/2565.index.js +0 -116
  76. package/dist/2574.index.js +0 -127
  77. package/dist/2620.index.js +0 -345
  78. package/dist/2773.index.js +0 -98
  79. package/dist/2775.index.js +0 -32
  80. package/dist/2966.index.js +0 -171
  81. package/dist/2972.index.js +0 -87
  82. package/dist/2991.index.js +0 -131
  83. package/dist/3063.index.js +0 -833
  84. package/dist/3075.index.js +0 -227
  85. package/dist/3121.index.js +0 -297
  86. package/dist/3314.index.js +0 -263
  87. package/dist/3480.index.js +0 -1822
  88. package/dist/3481.index.js +0 -24
  89. package/dist/3506.index.js +0 -268
  90. package/dist/3533.index.js +0 -591
  91. package/dist/3653.index.js +0 -450
  92. package/dist/3740.index.js +0 -722
  93. package/dist/3822.index.js +0 -131
  94. package/dist/3868.index.js +0 -292
  95. package/dist/3918.index.js +0 -192
  96. package/dist/4090.index.js +0 -288
  97. package/dist/4113.index.js +0 -1286
  98. package/dist/4121.index.js +0 -1190
  99. package/dist/4142.index.js +0 -690
  100. package/dist/4168.index.js +0 -509
  101. package/dist/4281.index.js +0 -993
  102. package/dist/4336.index.js +0 -436
  103. package/dist/4387.index.js +0 -532
  104. package/dist/4413.index.js +0 -302
  105. package/dist/4476.index.js +0 -4510
  106. package/dist/4491.index.js +0 -133
  107. package/dist/4538.index.js +0 -185
  108. package/dist/4684.index.js +0 -319
  109. package/dist/4740.index.js +0 -165
  110. package/dist/4780.index.js +0 -209
  111. package/dist/4802.index.js +0 -225
  112. package/dist/4812.index.js +0 -379
  113. package/dist/4835.index.js +0 -126
  114. package/dist/494.index.js +0 -226
  115. package/dist/4991.index.js +0 -549
  116. package/dist/5199.index.js +0 -305
  117. package/dist/5216.index.js +0 -109
  118. package/dist/5439.index.js +0 -301
  119. package/dist/5443.index.js +0 -97
  120. package/dist/5496.index.js +0 -377
  121. package/dist/5738.index.js +0 -240
  122. package/dist/5801.index.js +0 -588
  123. package/dist/5858.index.js +0 -223
  124. package/dist/5933.index.js +0 -143
  125. package/dist/601.index.js +0 -23
  126. package/dist/6173.index.js +0 -273
  127. package/dist/6291.index.js +0 -1871
  128. package/dist/6312.index.js +0 -666
  129. package/dist/634.index.js +0 -16182
  130. package/dist/644.index.js +0 -87
  131. package/dist/6508.index.js +0 -283
  132. package/dist/6560.index.js +0 -645
  133. package/dist/6576.index.js +0 -422
  134. package/dist/6579.index.js +0 -271
  135. package/dist/6655.index.js +0 -3221
  136. package/dist/6745.index.js +0 -305
  137. package/dist/6818.index.js +0 -21642
  138. package/dist/6932.index.js +0 -1190
  139. package/dist/6972.index.js +0 -167
  140. package/dist/6995.index.js +0 -163
  141. package/dist/7249.index.js +0 -191
  142. package/dist/7372.index.js +0 -1197
  143. package/dist/7546.index.js +0 -541
  144. package/dist/76.index.js +0 -448
  145. package/dist/7879.index.js +0 -163
  146. package/dist/8025.index.js +0 -130
  147. package/dist/8054.index.js +0 -248
  148. package/dist/808.index.js +0 -1330
  149. package/dist/8097.index.js +0 -201
  150. package/dist/8126.index.js +0 -191
  151. package/dist/8178.index.js +0 -78
  152. package/dist/8382.index.js +0 -93
  153. package/dist/8408.index.js +0 -261
  154. package/dist/8540.index.js +0 -174
  155. package/dist/8635.index.js +0 -802
  156. package/dist/8688.index.js +0 -410
  157. package/dist/8699.index.js +0 -779
  158. package/dist/8891.index.js +0 -457
  159. package/dist/8916.index.js +0 -885
  160. package/dist/9146.index.js +0 -170
  161. package/dist/9168.index.js +0 -841
  162. package/dist/9292.index.js +0 -369
  163. package/dist/9422.index.js +0 -866
  164. package/dist/9440.index.js +0 -453
  165. package/dist/9479.index.js +0 -152
  166. package/dist/9481.index.js +0 -220
  167. package/dist/9539.index.js +0 -100
  168. package/dist/9547.index.js +0 -103
  169. package/dist/9692.index.js +0 -90
  170. package/dist/9800.index.js +0 -462
  171. package/dist/9899.index.js +0 -138
  172. package/dist/9981.index.js +0 -206
  173. package/dist/999.index.js +0 -117
  174. package/dist/9999.index.js +0 -1698
@@ -1,645 +0,0 @@
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
- };