repometry 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/package.json +1 -1
  2. package/target/main/resources/report/json/report-v2.schema.json +12 -1
  3. package/target/main/resources/viewer/files.css +3 -0
  4. package/target/main/ts/api/git/git.d.ts +1 -1
  5. package/target/main/ts/api/git/git.js +21 -5
  6. package/target/main/ts/api/git/inspection-source.d.ts +1 -1
  7. package/target/main/ts/api/git/inspection-source.js +10 -4
  8. package/target/main/ts/api/git/local.d.ts +1 -1
  9. package/target/main/ts/api/git/local.js +29 -10
  10. package/target/main/ts/api/worker/worker-protocol.js +34 -9
  11. package/target/main/ts/compose/analyze-snapshot.d.ts +1 -0
  12. package/target/main/ts/compose/analyze-snapshot.js +50 -17
  13. package/target/main/ts/compose/inspect.js +2 -2
  14. package/target/main/ts/compose/plugin-list.js +2 -1
  15. package/target/main/ts/compose/security-plugins.d.ts +1 -0
  16. package/target/main/ts/compose/security-plugins.js +7 -0
  17. package/target/main/ts/core/engine/manifest.js +3 -2
  18. package/target/main/ts/core/engine/plugin.d.ts +2 -0
  19. package/target/main/ts/core/model/line-coverage.d.ts +2 -0
  20. package/target/main/ts/core/model/line-coverage.js +19 -1
  21. package/target/main/ts/core/model/source.d.ts +3 -0
  22. package/target/main/ts/core/model/source.js +4 -1
  23. package/target/main/ts/core/usecases/inspect.js +2 -2
  24. package/target/main/ts/plugins/coverage/coverage.d.ts +4 -3
  25. package/target/main/ts/plugins/coverage/coverage.js +46 -17
  26. package/target/main/ts/plugins/language-js/js-security.d.ts +4 -0
  27. package/target/main/ts/plugins/language-js/js-security.js +508 -0
  28. package/target/main/ts/plugins/security/actions-security.d.ts +2 -0
  29. package/target/main/ts/plugins/security/actions-security.js +581 -0
  30. package/target/main/ts/plugins/security/dockerfile.d.ts +2 -0
  31. package/target/main/ts/plugins/security/dockerfile.js +488 -0
  32. package/target/main/ts/plugins/security/npm-supply-chain.d.ts +4 -0
  33. package/target/main/ts/plugins/security/npm-supply-chain.js +368 -0
  34. package/target/main/ts/plugins/security/secrets.d.ts +12 -0
  35. package/target/main/ts/plugins/security/secrets.js +254 -0
  36. package/target/main/ts/report/html/app/viewer-files.d.ts +7 -0
  37. package/target/main/ts/report/html/app/viewer-files.js +17 -3
  38. package/target/main/ts/report/html/app/viewer-filter.js +8 -0
  39. package/target/main/ts/report/html/app/viewer-source.d.ts +5 -0
  40. package/target/main/ts/report/html/app/viewer-source.js +33 -7
  41. package/target/main/ts/report/html/site/badges.d.ts +1 -4
  42. package/target/main/ts/report/html/site/badges.js +28 -19
  43. package/target/main/ts/report/json/projections/commit-summary.js +2 -11
  44. package/target/main/ts/report/json/projections/inspection-context.js +6 -12
  45. package/target/main/ts/report/json/projections/security-summary.d.ts +11 -0
  46. package/target/main/ts/report/json/projections/security-summary.js +22 -0
@@ -0,0 +1,488 @@
1
+ import { pluginApi } from '../../core/engine/plugin.js';
2
+ import { findingResult } from '../../core/model/finding.js';
3
+ import { sourceFile } from '../../core/model/snapshot.js';
4
+ const rules = {
5
+ 'unpinned-base-image': { level: 'medium',
6
+ description: 'A FROM image has no tag or uses latest and is not pinned by digest, so rebuilds can silently change the base.' },
7
+ 'runs-as-root': { level: 'medium',
8
+ description: 'The final stage sets no USER or switches back to root, so the container runs as root.' },
9
+ 'remote-add': { level: 'medium',
10
+ description: 'ADD downloads a remote URL without checksum verification instead of curl with a checksum or COPY.' },
11
+ 'pipe-to-shell': { level: 'high',
12
+ description: 'A RUN step pipes a curl or wget download straight into a shell, executing unverified remote code.' },
13
+ 'secret-in-env': { level: 'high',
14
+ description: 'An ENV or ARG with a secret-looking name carries a literal value that is stored in the image or its history.' },
15
+ 'apt-unpinned-upgrade': { level: 'low',
16
+ description: 'A RUN step runs apt-get upgrade or dist-upgrade, so the image contents depend on the day it was built.' },
17
+ 'sudo-usage': { level: 'low',
18
+ description: 'A RUN step uses sudo, which is unnecessary during builds and behaves unpredictably in containers.' },
19
+ };
20
+ const directive = /^#[ \t]*([A-Za-z][A-Za-z0-9]*)[ \t]*=[ \t]*(.+?)[ \t]*$/;
21
+ const directives = new Set(['syntax', 'escape', 'check']);
22
+ const heredocInstructions = new Set(['ADD', 'COPY', 'RUN']);
23
+ const shells = new Set(['sh', 'bash', 'zsh', 'ksh', 'mksh', 'dash', 'ash', 'fish', 'csh', 'tcsh']);
24
+ const prefixes = new Set(['!', '{', 'command', 'do', 'elif', 'else', 'env', 'exec', 'if', 'nice', 'nohup', 'sudo', 'then', 'time', 'until', 'while']);
25
+ const prefixOptionsWithValues = new Set(['-C', '-D', '-S', '-T', '-U', '-g', '-h', '-n', '-p', '-r', '-t', '-u']);
26
+ const aptOptionsWithValues = new Set(['-c', '-o', '-t', '--config-file', '--option', '--target-release']);
27
+ const upgrades = new Set(['upgrade', 'dist-upgrade', 'full-upgrade']);
28
+ const substitutedDownload = /(?:^|[\s;&|(])(?:\S*\/)?(?:a|ba|da|k|z)?sh\s+(?:-\w+\s+)*["']?(?:\$\(|<\(|`)\s*(?:curl|wget)\b/;
29
+ const secretName = /_(?:[A-Z0-9]*PASS(?:WORD|WD)S?|[A-Z0-9]*SECRETS?|[A-Z0-9]*TOKENS?|API_?KEYS?|PRIVATE_?KEYS?|ACCESS_?KEYS?)_/;
30
+ const qualifiers = new Set(['DIR', 'ENABLED', 'ENDPOINT', 'EXPIRES', 'EXPIRY', 'FILE', 'FORMAT', 'HEADER', 'HOST', 'LEN', 'LENGTH',
31
+ 'LIFETIME', 'MODE', 'NAME', 'PATH', 'POLICY', 'PORT', 'REQUIRED', 'SIZE', 'TIMEOUT', 'TTL', 'TYPE', 'URI', 'URL', 'USER',
32
+ 'USERNAME', 'VERSION']);
33
+ export const dockerfile = {
34
+ id: 'dockerfile', version: '1.0.0', api: pluginApi,
35
+ kinds: ['security'],
36
+ claims: { globs: ['**/Dockerfile', '**/Dockerfile.*', '**/*.dockerfile', '**/Containerfile'] },
37
+ produces: [{ contract: findingResult.id, persistence: 'report' }],
38
+ rules: Object.entries(rules).map(([id, { description }]) => ({ id, category: 'infrastructure', description })),
39
+ operations: [{
40
+ id: 'scan', role: 'inspection', inputs: { source: sourceFile }, output: findingResult,
41
+ execute(inputs) {
42
+ const { path, bytes } = inputs.read('source', sourceFile);
43
+ if (bytes.includes(0))
44
+ return { measurements: [], findings: [] };
45
+ return { measurements: [], findings: scan(path, new TextDecoder().decode(bytes)) };
46
+ },
47
+ }],
48
+ };
49
+ function scan(path, text) {
50
+ const { escape, instructions } = parseDockerfile(text);
51
+ const findings = [];
52
+ const report = (rule, at, message) => {
53
+ findings.push({ tool: 'dockerfile', category: 'infrastructure', rule, level: rules[rule].level, message, path,
54
+ line: at.line, endLine: at.endLine });
55
+ };
56
+ const globals = new Map();
57
+ const stages = [];
58
+ const names = new Map();
59
+ for (const instruction of instructions) {
60
+ const { keyword } = instruction;
61
+ if (keyword === 'FROM') {
62
+ const [reference = '', as, name] = words(instruction.args, escape).filter(item => !item.startsWith('--'));
63
+ const image = expand(reference, globals);
64
+ const parent = names.get((image ?? reference).toLowerCase());
65
+ const external = parent === undefined && image !== undefined && image.toLowerCase() !== 'scratch';
66
+ if (external) {
67
+ const pinning = pinningOf(image);
68
+ if (pinning === 'none') {
69
+ report('unpinned-base-image', instruction, `Base image ${image} has no tag or digest, so every build pulls whatever latest points to; pin a version tag or a digest.`);
70
+ }
71
+ else if (pinning === 'latest') {
72
+ report('unpinned-base-image', instruction, `Base image ${image} uses the mutable latest tag; pin a version tag or a digest.`);
73
+ }
74
+ }
75
+ stages.push({ from: instruction, image: parent === undefined ? image : undefined, parent, users: [] });
76
+ if (as?.toUpperCase() === 'AS' && name)
77
+ names.set(name.toLowerCase(), stages.length - 1);
78
+ }
79
+ else if (keyword === 'USER') {
80
+ stages.at(-1)?.users.push(instruction);
81
+ }
82
+ else if (keyword === 'ENV' || keyword === 'ARG') {
83
+ for (const { name, value } of variables(instruction, escape)) {
84
+ if (keyword === 'ARG' && stages.length === 0)
85
+ globals.set(name, value);
86
+ if (!isSecretName(name) || !isLiteral(value))
87
+ continue;
88
+ report('secret-in-env', instruction, keyword === 'ENV'
89
+ ? `ENV ${name} sets a literal secret value that is stored in the image; inject it at runtime or with a build secret instead.`
90
+ : `ARG ${name} has a literal default secret value that is recorded in the image history; pass it with a build secret instead.`);
91
+ }
92
+ }
93
+ else if (keyword === 'ADD') {
94
+ if (isRemoteAdd(instruction.args, escape)) {
95
+ report('remote-add', instruction, 'ADD downloads a remote URL without checksum verification; fetch it with curl and verify a checksum, or COPY a local file.');
96
+ }
97
+ }
98
+ else if (keyword === 'RUN') {
99
+ const script = runScript(instruction);
100
+ const commands = pipelines(script);
101
+ if (substitutedDownload.test(script) || commands.some(pipesDownloadToShell)) {
102
+ report('pipe-to-shell', instruction, 'RUN pipes a curl or wget download straight into a shell; download to a file and verify its checksum before running it.');
103
+ }
104
+ if (commands.flat().some(upgradesAllPackages)) {
105
+ report('apt-unpinned-upgrade', instruction, 'RUN upgrades every installed package with apt, which makes the build unreproducible; use a newer base image or pin packages.');
106
+ }
107
+ if (commands.flat().some(item => command(item).sudo)) {
108
+ report('sudo-usage', instruction, 'RUN uses sudo, which behaves unpredictably in containers; run the step before switching USER or use gosu instead.');
109
+ }
110
+ }
111
+ }
112
+ const final = stages.length - 1;
113
+ if (final >= 0) {
114
+ const { user, image } = effectiveUser(stages, final);
115
+ if (user !== undefined) {
116
+ const account = (words(user.args, escape)[0] ?? '').split(':')[0];
117
+ if (account === 'root' || account === '0') {
118
+ report('runs-as-root', user, 'The final stage runs as root because its last USER is root; switch to an unprivileged user.');
119
+ }
120
+ }
121
+ else if (image === undefined || !/nonroot/i.test(image)) {
122
+ report('runs-as-root', stages[final].from, 'The final stage never sets USER, so the container runs as root; add a USER with an unprivileged account.');
123
+ }
124
+ }
125
+ return findings.sort((left, right) => left.line - right.line || left.endLine - right.endLine
126
+ || left.rule.localeCompare(right.rule));
127
+ }
128
+ function parseDockerfile(text) {
129
+ const lines = text.split(/\r\n|\r|\n/);
130
+ const escape = escapeOf(lines);
131
+ const continuation = new RegExp(`${escape === '`' ? '`' : '\\\\'}[ \\t]*$`);
132
+ const instructions = [];
133
+ let index = 0;
134
+ while (index < lines.length) {
135
+ if (isIgnorable(lines[index])) {
136
+ index++;
137
+ continue;
138
+ }
139
+ const start = index;
140
+ let end = index;
141
+ let logical = '';
142
+ for (;;) {
143
+ const physical = lines[end];
144
+ const match = continuation.exec(physical);
145
+ if (match === null) {
146
+ logical += physical;
147
+ break;
148
+ }
149
+ logical += physical.slice(0, match.index);
150
+ let next = end + 1;
151
+ while (next < lines.length && isIgnorable(lines[next]))
152
+ next++;
153
+ if (next >= lines.length)
154
+ break;
155
+ end = next;
156
+ }
157
+ index = end + 1;
158
+ const match = /^\s*(\S+)\s*(.*)$/s.exec(logical);
159
+ if (match === null)
160
+ continue;
161
+ const keyword = match[1].toUpperCase();
162
+ const args = match[2].trim();
163
+ const heredocs = [];
164
+ if (heredocInstructions.has(keyword)) {
165
+ for (const { name, chomp } of heredocMarkers(args)) {
166
+ const body = [];
167
+ while (index < lines.length) {
168
+ const line = chomp ? lines[index].replace(/^\t+/, '') : lines[index];
169
+ end = index++;
170
+ if (line === name)
171
+ break;
172
+ body.push(line);
173
+ }
174
+ heredocs.push(body.join('\n'));
175
+ }
176
+ }
177
+ instructions.push({ keyword, args, line: start + 1, endLine: end + 1, heredocs });
178
+ }
179
+ return { escape, instructions };
180
+ }
181
+ /** Parser directives are only read from the leading comment lines, before any blank line, comment or instruction. */
182
+ function escapeOf(lines) {
183
+ let escape = '\\';
184
+ for (const line of lines) {
185
+ const match = directive.exec(line.trim());
186
+ if (match === null || !directives.has(match[1].toLowerCase()))
187
+ break;
188
+ if (match[1].toLowerCase() === 'escape' && (match[2] === '`' || match[2] === '\\'))
189
+ escape = match[2];
190
+ }
191
+ return escape;
192
+ }
193
+ function isIgnorable(line) {
194
+ const trimmed = line.trim();
195
+ return trimmed === '' || trimmed.startsWith('#');
196
+ }
197
+ /** Heredoc markers start a word, as in BuildKit: `<<EOF`, `<<-EOF` or `<<"EOF"`, but not `<<<` or a quoted `"<<EOF"`. */
198
+ function heredocMarkers(args) {
199
+ return rawWords(args).flatMap(word => {
200
+ const match = /^\d*<<(-?)([^<]+)$/.exec(word);
201
+ const name = match?.[2].replace(/["'\\]/g, '');
202
+ return match && name ? [{ name, chomp: match[1] === '-' }] : [];
203
+ });
204
+ }
205
+ /** Split on unquoted whitespace and keep quotes and escapes as written. */
206
+ function rawWords(text) {
207
+ const result = [];
208
+ let word = '';
209
+ let quote = '';
210
+ for (let index = 0; index < text.length; index++) {
211
+ const char = text[index];
212
+ if (quote === '' && /\s/.test(char)) {
213
+ if (word !== '')
214
+ result.push(word);
215
+ word = '';
216
+ continue;
217
+ }
218
+ word += char;
219
+ if (quote === '' && (char === '"' || char === "'"))
220
+ quote = char;
221
+ else if (char === quote)
222
+ quote = '';
223
+ else if (char === '\\' && quote !== "'" && index + 1 < text.length)
224
+ word += text[++index];
225
+ }
226
+ if (word !== '')
227
+ result.push(word);
228
+ return result;
229
+ }
230
+ /** Split Dockerfile arguments into words with quotes removed and the escape character applied. */
231
+ function words(text, escape) {
232
+ const result = [];
233
+ let word = '';
234
+ let quote = '';
235
+ let started = false;
236
+ for (let index = 0; index < text.length; index++) {
237
+ const char = text[index];
238
+ if (quote === "'") {
239
+ if (char === "'")
240
+ quote = '';
241
+ else
242
+ word += char;
243
+ }
244
+ else if (quote === '"') {
245
+ if (char === '"')
246
+ quote = '';
247
+ else if (char === escape && ['"', '$', escape].includes(text[index + 1] ?? ''))
248
+ word += text[++index];
249
+ else
250
+ word += char;
251
+ }
252
+ else if (/\s/.test(char)) {
253
+ if (started)
254
+ result.push(word);
255
+ word = '';
256
+ started = false;
257
+ }
258
+ else {
259
+ started = true;
260
+ if (char === '"' || char === "'")
261
+ quote = char;
262
+ else if (char === escape && index + 1 < text.length)
263
+ word += text[++index];
264
+ else
265
+ word += char;
266
+ }
267
+ }
268
+ if (started)
269
+ result.push(word);
270
+ return result;
271
+ }
272
+ function variables(instruction, escape) {
273
+ const items = words(instruction.args, escape);
274
+ if (instruction.keyword === 'ENV' && items[0] !== undefined && !items[0].includes('=')) {
275
+ const rest = instruction.args.replace(/^\S+\s*/, '');
276
+ return [{ name: items[0], value: rest === '' ? undefined : words(rest, escape).join(' ') }];
277
+ }
278
+ return items.map(item => {
279
+ const at = item.indexOf('=');
280
+ return at < 0 ? { name: item, value: undefined } : { name: item.slice(0, at), value: item.slice(at + 1) };
281
+ });
282
+ }
283
+ function isSecretName(name) {
284
+ const normalized = name.replace(/([a-z0-9])([A-Z])/g, '$1_$2').replace(/[^A-Za-z0-9]+/g, '_').toUpperCase();
285
+ const last = normalized.slice(normalized.lastIndexOf('_') + 1);
286
+ return secretName.test(`_${normalized}_`) && !qualifiers.has(last);
287
+ }
288
+ /** A literal value is non-empty and does not merely pass a build argument or another variable through. */
289
+ function isLiteral(value) {
290
+ return value !== undefined && value.trim() !== '' && !/\$(?:\{|[A-Za-z_])/.test(value);
291
+ }
292
+ /** Expand `$NAME`, `${NAME}`, `${NAME:-word}` and `${NAME:+word}` from global ARG defaults; unresolved references yield undefined. */
293
+ function expand(text, values) {
294
+ let resolved = true;
295
+ const result = text.replace(/\$(?:\{([A-Za-z_]\w*)(?::([-+])([^}]*))?\}|([A-Za-z_]\w*))/g, (_, braced, operator, word, bare) => {
296
+ const value = values.get(braced ?? bare ?? '');
297
+ if (operator === '-')
298
+ return value || (word ?? '');
299
+ if (value === undefined)
300
+ resolved = false;
301
+ return operator === '+' ? (value ? word ?? '' : '') : value ?? '';
302
+ });
303
+ return resolved && result !== '' && !result.includes('$') ? result : undefined;
304
+ }
305
+ function pinningOf(image) {
306
+ if (/@[a-z0-9]+:[0-9a-f]+$/i.test(image))
307
+ return 'digest';
308
+ const name = image.split('@')[0];
309
+ const last = name.slice(name.lastIndexOf('/') + 1);
310
+ const colon = last.indexOf(':');
311
+ if (colon < 0)
312
+ return 'none';
313
+ return last.slice(colon + 1) === 'latest' ? 'latest' : 'tag';
314
+ }
315
+ function effectiveUser(stages, index) {
316
+ const stage = stages[index];
317
+ const user = stage.users.at(-1);
318
+ if (user !== undefined)
319
+ return { user };
320
+ if (stage.parent !== undefined)
321
+ return effectiveUser(stages, stage.parent);
322
+ return stage.image === undefined ? {} : { image: stage.image };
323
+ }
324
+ function isRemoteAdd(args, escape) {
325
+ const flags = rawWords(args);
326
+ const firstSource = flags.findIndex(word => !word.startsWith('--'));
327
+ if (flags.slice(0, firstSource < 0 ? flags.length : firstSource).some(flag => flag.startsWith('--checksum')))
328
+ return false;
329
+ const rest = args.replace(/^(?:--\S+\s+)*/, '');
330
+ const items = (rest.startsWith('[') ? jsonArray(rest) : undefined) ?? words(rest, escape);
331
+ return items.slice(0, -1).some(source => /^https?:\/\//i.test(source));
332
+ }
333
+ /** The shell script a RUN executes: the exec-form `-c` argument, or the shell form plus heredocs that feed a shell. */
334
+ function runScript({ args: raw, heredocs }) {
335
+ const args = raw.replace(/^(?:--\S+\s+)*/, '');
336
+ if (args.startsWith('[')) {
337
+ const exec = jsonArray(args);
338
+ if (exec !== undefined) {
339
+ const flag = exec.indexOf('-c');
340
+ return shells.has(basename(exec[0] ?? '')) && flag > 0 && flag + 1 < exec.length ? exec[flag + 1] : exec.join(' ');
341
+ }
342
+ }
343
+ const items = rawWords(args);
344
+ const isMarker = (word) => word !== undefined && /^\d*<<-?[^<]+$/.test(word);
345
+ const feedsShell = isMarker(items[0]) || (shells.has(basename(items[0] ?? '')) && items.some(isMarker));
346
+ return feedsShell ? [args, ...heredocs].join('\n') : args;
347
+ }
348
+ function jsonArray(text) {
349
+ try {
350
+ const value = JSON.parse(text);
351
+ return Array.isArray(value) && value.every((item) => typeof item === 'string') ? value : undefined;
352
+ }
353
+ catch {
354
+ return undefined;
355
+ }
356
+ }
357
+ /** Split a shell script into pipelines of commands, each a list of unquoted words; comments are dropped. */
358
+ function pipelines(script) {
359
+ const result = [];
360
+ let pipeline = [];
361
+ let current = [];
362
+ let word = '';
363
+ let started = false;
364
+ let quote = '';
365
+ const endWord = () => {
366
+ if (started)
367
+ current.push(word);
368
+ word = '';
369
+ started = false;
370
+ };
371
+ const endCommand = () => {
372
+ endWord();
373
+ if (current.length > 0)
374
+ pipeline.push(current);
375
+ current = [];
376
+ };
377
+ const endPipeline = () => {
378
+ endCommand();
379
+ if (pipeline.length > 0)
380
+ result.push(pipeline);
381
+ pipeline = [];
382
+ };
383
+ for (let index = 0; index < script.length; index++) {
384
+ const char = script[index];
385
+ const previous = script[index - 1];
386
+ const next = script[index + 1];
387
+ if (quote !== '') {
388
+ if (char === quote)
389
+ quote = '';
390
+ else if (char === '\\' && quote === '"' && next !== undefined)
391
+ word += script[++index];
392
+ else
393
+ word += char;
394
+ }
395
+ else if (char === '\\') {
396
+ if (next === '\n')
397
+ index++;
398
+ else if (next !== undefined) {
399
+ word += script[++index];
400
+ started = true;
401
+ }
402
+ }
403
+ else if (char === '"' || char === "'") {
404
+ quote = char;
405
+ started = true;
406
+ }
407
+ else if (char === '#' && !started) {
408
+ while (index + 1 < script.length && script[index + 1] !== '\n')
409
+ index++;
410
+ }
411
+ else if (char === '\n' || char === ';') {
412
+ endPipeline();
413
+ }
414
+ else if ((char === '&' || char === '|') && (previous === '>' || previous === '<' || next === '>')) {
415
+ word += char;
416
+ started = true;
417
+ }
418
+ else if (char === '&') {
419
+ if (next === '&')
420
+ index++;
421
+ endPipeline();
422
+ }
423
+ else if (char === '|') {
424
+ if (next === '|') {
425
+ index++;
426
+ endPipeline();
427
+ }
428
+ else {
429
+ if (next === '&')
430
+ index++;
431
+ endCommand();
432
+ }
433
+ }
434
+ else if (/\s/.test(char) || char === '(' || char === ')') {
435
+ endWord();
436
+ }
437
+ else {
438
+ word += char;
439
+ started = true;
440
+ }
441
+ }
442
+ endPipeline();
443
+ return result;
444
+ }
445
+ /** Resolve the executed program, skipping variable assignments and wrappers such as sudo or env with their options. */
446
+ function command(items) {
447
+ let sudo = false;
448
+ let index = 0;
449
+ while (index < items.length) {
450
+ const word = items[index];
451
+ if (/^[A-Za-z_]\w*=/.test(word)) {
452
+ index++;
453
+ continue;
454
+ }
455
+ const name = basename(word);
456
+ if (!prefixes.has(name))
457
+ return { name, args: items.slice(index + 1), sudo };
458
+ if (name === 'sudo')
459
+ sudo = true;
460
+ index++;
461
+ while (index < items.length && items[index].startsWith('-') && items[index] !== '-') {
462
+ index += prefixOptionsWithValues.has(items[index]) ? 2 : 1;
463
+ }
464
+ }
465
+ return { name: undefined, args: [], sudo };
466
+ }
467
+ function pipesDownloadToShell(pipeline) {
468
+ const names = pipeline.map(items => command(items).name);
469
+ const download = names.findIndex(name => name === 'curl' || name === 'wget');
470
+ return download >= 0 && names.slice(download + 1).some(name => name !== undefined && shells.has(name));
471
+ }
472
+ function upgradesAllPackages(items) {
473
+ const { name, args } = command(items);
474
+ if (name !== 'apt-get' && name !== 'apt')
475
+ return false;
476
+ for (let index = 0; index < args.length; index++) {
477
+ const arg = args[index];
478
+ if (aptOptionsWithValues.has(arg))
479
+ index++;
480
+ else if (!arg.startsWith('-'))
481
+ return upgrades.has(arg);
482
+ }
483
+ return false;
484
+ }
485
+ function basename(word) {
486
+ return word.slice(word.lastIndexOf('/') + 1);
487
+ }
488
+ //# sourceMappingURL=dockerfile.js.map
@@ -0,0 +1,4 @@
1
+ import type { Plugin } from '../../core/engine/plugin.js';
2
+ /** Above this many hits of one rule in one file, the rest collapse into a single summary finding. */
3
+ export declare const findingsPerRule = 20;
4
+ export declare const npmSupplyChain: Plugin;