@exodus/stasis 1.0.0-beta.14 → 1.0.0-beta.16

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 (67) hide show
  1. package/README.md +2 -1
  2. package/bin/stasis.js +99 -16
  3. package/package.json +22 -9
  4. package/src/audit-corrections.js +11 -42
  5. package/src/audit.js +241 -190
  6. package/src/babel.js +39 -122
  7. package/src/bundle-from-lockfile.js +9 -21
  8. package/src/bundle-reader.js +5 -9
  9. package/src/bundle.js +0 -3
  10. package/src/cmd/build.js +82 -174
  11. package/src/cmd/bundle-options.js +113 -167
  12. package/src/cmd/bundle.js +942 -1294
  13. package/src/cmd/diff.js +1 -4
  14. package/src/cmd/github-bundle.js +21 -26
  15. package/src/cmd/output.js +15 -12
  16. package/src/cmd/sbom.js +3 -8
  17. package/src/cmd/tokens.js +16 -23
  18. package/src/define.js +36 -94
  19. package/src/diff.js +72 -128
  20. package/src/esbuild.js +0 -4
  21. package/src/flow.js +18 -13
  22. package/src/installed.js +265 -0
  23. package/src/json-stream.js +4 -9
  24. package/src/loader-mock.js +3 -8
  25. package/src/loader.js +1 -5
  26. package/src/loaders/bash.js +41 -93
  27. package/src/loaders/cargo.js +298 -805
  28. package/src/loaders/foundry.js +109 -285
  29. package/src/loaders/paths.js +13 -13
  30. package/src/loaders/php.js +210 -489
  31. package/src/loaders/rust.js +507 -1430
  32. package/src/loaders/solidity-ownership.js +48 -128
  33. package/src/loaders/solidity.js +39 -122
  34. package/src/loaders/toml.js +7 -17
  35. package/src/lockfile.js +0 -3
  36. package/src/metro-assets.js +10 -384
  37. package/src/metro-resolver.js +58 -134
  38. package/src/metro-transformer.js +0 -5
  39. package/src/metro.js +0 -4
  40. package/src/mock.js +32 -80
  41. package/src/parse.js +4 -4
  42. package/src/prune.js +0 -3
  43. package/src/resolve-fields.js +137 -532
  44. package/src/resolve-node.js +27 -45
  45. package/src/resolve-typescript.js +166 -298
  46. package/src/rollup.js +0 -4
  47. package/src/run-installed.js +10 -0
  48. package/src/sbom.js +52 -128
  49. package/src/scan.js +142 -284
  50. package/src/sixel.js +310 -0
  51. package/src/table.js +63 -31
  52. package/src/validate-notes.d.ts +19 -0
  53. package/src/validate-notes.js +72 -0
  54. package/src/validate.d.ts +159 -0
  55. package/src/validate.js +596 -522
  56. package/src/vfs-bundle/entries.js +40 -57
  57. package/src/vfs-bundle/github.js +80 -122
  58. package/src/vfs-bundle/glob.js +4 -45
  59. package/src/vfs-bundle/lazy.js +27 -56
  60. package/src/vfs-bundle/prisma.js +235 -105
  61. package/src/vfs-bundle/soldeer.js +28 -49
  62. package/src/vfs-bundle/tree.js +295 -318
  63. package/src/vfs-bundle/yarnclean.js +10 -31
  64. package/src/vfs-bundle.js +23 -64
  65. package/src/webpack.js +0 -4
  66. package/src/why.js +78 -232
  67. package/src/installed-commits.js +0 -184
package/README.md CHANGED
@@ -75,6 +75,7 @@ _Lockfiles (npm/pnpm/etc) not mentioned: they are like the "tarball" column, but
75
75
  | `stasis prune` | trim `node_modules` to the lockfile, verifying the rest |
76
76
  | `stasis audit stasis.lock.json` | report advisories for a lockfile's or bundle's dependencies |
77
77
  | `stasis audit --why app.stasis.code.br` | same, with the import chains that pull each flagged package in |
78
+ | `stasis audit` | same, for the bundle `stasis bundle` would build of `stasis.config.json`'s entries, without writing it |
78
79
  | `stasis validate app.stasis.code.br` | check a bundle's own code against its repository and its dependencies against their published packages, held to its lockfile |
79
80
  | `stasis sbom --format=spdx stasis.lock.json` | export an SPDX SBOM for a lockfile or bundle |
80
81
  | `stasis sbom --format=cyclonedx app.stasis.code.br` | export a CycloneDX SBOM for a lockfile or bundle |
@@ -90,7 +91,7 @@ Each command's options are documented in [doc/](https://github.com/PreventiveMea
90
91
  [`audit`](https://github.com/PreventiveMeasures/stasis/blob/main/doc/audit.md),
91
92
  [`validate`](https://github.com/PreventiveMeasures/stasis/blob/main/doc/validate.md),
92
93
  [`sbom`](https://github.com/PreventiveMeasures/stasis/blob/main/doc/sbom.md).
93
- `stasis bundle` also bundles Solidity, PHP, Bash and Rust sources, see [file formats](https://github.com/PreventiveMeasures/stasis/blob/main/doc/file-formats.md#source-language-bundles-solidity--php--bash--rust).
94
+ `stasis bundle` also bundles Solidity, PHP, Bash, Rust and TEAL sources, see [file formats](https://github.com/PreventiveMeasures/stasis/blob/main/doc/file-formats.md#source-language-bundles-solidity--php--bash--rust--teal).
94
95
 
95
96
  ## Runtime
96
97
 
package/bin/stasis.js CHANGED
@@ -19,18 +19,19 @@ assert(basename(jsname) === 'stasis' || pathsEqual(jsname, fileURLToPath(import.
19
19
 
20
20
  const HELP = `Usage:
21
21
  stasis run --lock=(add|replace|frozen|ignore) [--bundle=(add|replace|load|frozen|ignore)] [--bundle-file=path/to/bundle.br] [--resources-bundle-file=path/to/resources.br] [--dependencies] [--child-process] [--package-json] [--mock] [--import=module ...] [--fs=(sync|async)] [--resources=ext,ext] [--brotli-quality=0..11] path/to/file.js ...
22
- stasis bundle [--deptree] [--scope=(node_modules|full)] [--conditions=cond1,cond2] [--mainFields=field1,field2] [--metro [--metro-resolver] [--babel|--babel-aliases=path/to/aliases.json] --platforms=ios,android] [--jsx] [--flow] [--typescript [--tsconfig=path/to/tsconfig.json]] [--resources=ext,ext] [--define=K=V ...] [--package-json] [--lockfile=path/to/stasis.lock.json] [--brotli-quality=0..11] [--add] [--output=(path|-)] path/to/file.(js|ts|jsx|tsx) ...
22
+ stasis bundle [--deptree] [--scope=(node_modules|full)] [--conditions=cond1,cond2] [--mainFields=field1,field2] [--metro [--metro-resolver] [--babel|--babel-aliases=path/to/aliases.json] --platforms=ios,android] [--jsx] [--flow] [--typescript [--tsconfig=path/to/tsconfig.json]] [--resources=ext,ext] [--define=K=V ...] [--package-json] [--lockfile=path/to/stasis.lock.json [--lockfile-only]] [--brotli-quality=0..11] [--add] [--output=(path|-)] path/to/file.(js|ts|jsx|tsx) ...
23
23
  stasis bundle [--deptree] [--mapping=path/to/remappings(.txt|.toml)] [--manifests] [--add] [--output=(path|-)] path/to/(file.sol|dir) ...
24
24
  stasis bundle [--cargo] [--cargo-features=a,b,pkg/c] [--cargo-no-default-features] [--cargo-all-features] [--cargo-target=(triple|host)] [--cargo-manifests] [--add] [--output=(path|-)] path/to/file.rs ...
25
25
  stasis bundle [--add] [--output=(path|-)] path/to/file.(php|sh|bash) ...
26
- stasis bundle [--deptree] [--babel] [--metro-resolver] [--cargo] [--cargo-target=(triple|host)] [--lockfile=path/to/stasis.lock.json] [--brotli-quality=0..11] [--add] [--output=(path|-)] [entry ...] (the entries' options from stasis.config.json's entries)
27
- stasis github-bundle (owner/name[/path]|--github=owner/name [--directory=path]) [--sha=commit|--tag=name] [--package-manager=(pnpm|yarn1|npm|soldeer) [--package-manager-version=version]] [--no-lazy] [--generate=prisma] [--lockfile=path/to/stasis.lock.json] [--output=(path|-)] [stasis bundle's options for the entries] [path/in/repo/to/(file.(js|ts|jsx|tsx)|file.sol|dir) ...]
26
+ stasis bundle [--deptree] [--babel] [--metro-resolver] [--cargo] [--cargo-target=(triple|host)] [--lockfile=path/to/stasis.lock.json [--lockfile-only]] [--brotli-quality=0..11] [--add] [--output=(path|-)] [entry ...] (the entries' options from stasis.config.json's entries)
27
+ stasis github-bundle (owner/name[/path]|--github=owner/name [--directory=path]) [--sha=commit|--tag=name] [--package-manager=(pnpm|yarn1|npm|soldeer) [--package-manager-version=version]] [--no-lazy] [--generate=prisma|--no-generate] [--lockfile=path/to/stasis.lock.json [--lockfile-only]] [--output=(path|-)] [stasis bundle's options for the entries] [path/in/repo/to/(file.(js|ts|jsx|tsx)|file.sol|dir) ...]
28
28
  stasis add path/to/(file|dir) ...
29
29
  stasis build --output=(dir|file.js) [--format=(esm|cjs|iife)] [--platform=(node|browser|neutral|hermes)] [--babel|--flow] [--minify] [--sourcemap] [--define=K=V ...] [--external=pkg ...] [--loader=.ext:name ...] [--metro=(ios|android|...) [--assets-dest=dir]] path/to/(stasis.code.br|stasis.lock.json) [entry]
30
30
  stasis extract [--output=path/to/dir] [--lock=(frozen|add|replace|ignore|none)] path/to/bundle.stasis.code.br
31
31
  stasis diff --stat [--imports] path/to/(lockfile|bundle) path/to/(lockfile|bundle)
32
32
  stasis prune [path/to/project]
33
- stasis audit [--why|--why-deep] [--why-full] [--reason=consumer] [--repo-advisories] path/to/(lockfile|bundle) ...
33
+ stasis audit [--why|--why-deep] [--why-full] [--reason=consumer] [--repo-advisories|--no-repo-advisories] path/to/(lockfile|bundle) ...
34
+ stasis audit [--why|--why-deep] [--why-full] [--reason=consumer] [--repo-advisories|--no-repo-advisories] (the bundle stasis bundle builds of stasis.config.json's entries, not written)
34
35
  stasis validate [--github=owner/name] [--sha=commit] [--directory=path] [--only-deps] [--lockfile=path | --no-lockfile] [--allow-unverified] [--show-valid] path/to/bundle
35
36
  stasis sbom --format=(spdx|cyclonedx) [--output=(path|-)] path/to/(lockfile|bundle) ...
36
37
  stasis --version
@@ -50,6 +51,23 @@ function fail(message) {
50
51
  process.exit(1)
51
52
  }
52
53
 
54
+ // `build()`'s result, what it warns (console.warn's) held meanwhile: dropped where it succeeds, said
55
+ // where it fails, before its error is.
56
+ async function warningsOnFailure(build) {
57
+ const warn = console.warn
58
+ const held = []
59
+ console.warn = (...args) => held.push(args)
60
+ try {
61
+ return await build()
62
+ } catch (error) {
63
+ console.warn = warn
64
+ for (const args of held) console.warn(...args)
65
+ throw error
66
+ } finally {
67
+ console.warn = warn
68
+ }
69
+ }
70
+
53
71
  // The per-user cache directory, as each platform names it (XDG ignores a relative path).
54
72
  function userCacheDir() {
55
73
  if (isAbsolute(process.env.XDG_CACHE_HOME ?? '')) return join(process.env.XDG_CACHE_HOME, 'stasis')
@@ -108,6 +126,8 @@ if (command === '-v' || command === '--version') {
108
126
  // import map matches a non-mock run; native addons still can't load (--allow-addons off).
109
127
  nodeArgs.push('--conditions=node-addons')
110
128
  }
129
+ // Before the loader, whose State reads the install through it.
130
+ nodeArgs.push('--import', import.meta.resolve('../src/run-installed.js'))
111
131
  // --mock uses stasis's loader-mock entry (composes the mock before installing the hooks), whose
112
132
  // denials the --import preloads then run under.
113
133
  const loader = import.meta.resolve(values.mock ? '../src/loader-mock.js' : '@exodus/stasis-core/loader')
@@ -143,6 +163,7 @@ if (command === '-v' || command === '--version') {
143
163
  output: { type: 'string', short: 'o' },
144
164
  scope: { type: 'string' },
145
165
  lockfile: { type: 'string' },
166
+ 'lockfile-only': { type: 'boolean' },
146
167
  conditions: { type: 'string' },
147
168
  mainFields: { type: 'string' },
148
169
  metro: { type: 'boolean' },
@@ -156,6 +177,7 @@ if (command === '-v' || command === '--version') {
156
177
  'package-json': { type: 'boolean' },
157
178
  'brotli-quality': { type: 'string' },
158
179
  generate: { type: 'string', multiple: true },
180
+ 'no-generate': { type: 'boolean' },
159
181
  }
160
182
  const parse = (args) => parseLeadingOptions(args, options, { valueFlags: valueFlagsOf(options), onError: fail })
161
183
  // The repo as `owner/name[/path]`, for --github=owner/name [--directory=path]: the first argument
@@ -175,6 +197,14 @@ if (command === '-v' || command === '--version') {
175
197
  }
176
198
  if (github === undefined) fail('Error: github-bundle requires the repo to bundle: owner/name[/path], or --github=owner/name')
177
199
  if (values.sha !== undefined && values.tag !== undefined) fail('Error: github-bundle takes --sha or --tag, not both')
200
+ if (values.generate !== undefined && values['no-generate']) fail('Error: github-bundle takes --generate or --no-generate, not both')
201
+ const lockfileOnly = Boolean(values['lockfile-only'])
202
+ if (lockfileOnly) {
203
+ // Before anything is fetched.
204
+ const { lockfileOnlyError } = await import('../src/cmd/output.js')
205
+ const refused = lockfileOnlyError({ lockfile: values.lockfile, output: values.output, brotliQuality: values['brotli-quality'] })
206
+ if (refused !== null) fail(`Error: github-bundle: ${refused}`)
207
+ }
178
208
  // Whether each option applies to the entries is buildGitHubBundle's to say.
179
209
  const list = (value) => [value ?? []].flat().flatMap((v) => v.split(',')).map((s) => s.trim()).filter(Boolean)
180
210
  const brotliQuality = brotliQualityOption(values['brotli-quality'], fail)
@@ -206,6 +236,7 @@ if (command === '-v' || command === '--version') {
206
236
  manifests: Boolean(values.manifests),
207
237
  output: values.output,
208
238
  lockfile: values.lockfile,
239
+ lockfileOnly,
209
240
  scope: values.scope,
210
241
  conditions: list(values.conditions),
211
242
  mainFields: values.mainFields === undefined ? undefined : list(values.mainFields),
@@ -218,10 +249,12 @@ if (command === '-v' || command === '--version') {
218
249
  resources: values.resources === undefined ? undefined : list(values.resources),
219
250
  define,
220
251
  packageJSON: Boolean(values['package-json']),
221
- generate: list(values.generate),
252
+ // Detected without either, unless stasis.config.json's generatePrisma says not.
253
+ generate: values['no-generate'] ? [] : values.generate === undefined ? undefined : list(values.generate),
222
254
  brotliQuality,
223
255
  })
224
256
  } else if (command === 'add') {
257
+ await import('../src/run-installed.js')
225
258
  await addCli(argv, { label: 'stasis', fail })
226
259
  } else if (command === 'build') {
227
260
  const options = {
@@ -313,23 +346,73 @@ if (command === '-v' || command === '--version') {
313
346
  } else if (command === 'prune') {
314
347
  await pruneCli(argv, { label: 'stasis', fail })
315
348
  } else if (command === 'audit') {
316
- const options = { why: { type: 'boolean' }, 'why-deep': { type: 'boolean' }, 'why-full': { type: 'boolean' }, reason: { type: 'string' }, 'repo-advisories': { type: 'boolean' } }
349
+ const options = { why: { type: 'boolean' }, 'why-deep': { type: 'boolean' }, 'why-full': { type: 'boolean' }, reason: { type: 'string' }, 'repo-advisories': { type: 'boolean' }, 'no-repo-advisories': { type: 'boolean' } }
317
350
  const values = parseLeadingOptions(argv, options, { valueFlags: valueFlagsOf(options), onError: fail })
318
- if (argv.length === 0) fail('Nothing to audit: no path to file given')
319
- const repoAdvisories = Boolean(values['repo-advisories'])
320
- if (repoAdvisories && !process.env.GITHUB_TOKEN) fail('Error: --repo-advisories requires a GitHub token in GITHUB_TOKEN')
351
+ if (values['repo-advisories'] && values['no-repo-advisories']) fail('Error: --repo-advisories and --no-repo-advisories: give one')
352
+ // With no file, the bundle a bare `stasis bundle` would write of the entries stasis.config.json's
353
+ // `entries` names, planned (and refused) as it plans them, and built after the checks below.
354
+ let plan
355
+ if (argv.length === 0) {
356
+ const cwd = process.cwd()
357
+ const { bundlePlan, readConfigEntries } = await import('../src/cmd/bundle-options.js')
358
+ try {
359
+ const config = readConfigEntries(cwd)
360
+ const entries = [...(config?.values() ?? [])].map(({ entry }) => entry)
361
+ if (entries.length === 0) fail('Nothing to audit: no path to file given, nor entries in stasis.config.json to bundle')
362
+ plan = { cwd, ...bundlePlan({ cwd, entries, values: {}, config }) }
363
+ } catch (cause) {
364
+ fail(`Error: ${cause.message}`)
365
+ }
366
+ }
367
+ // Each package's GitHub repository is asked for its advisories, a request a package, unless
368
+ // --no-repo-advisories: with githubToken's token, as GitHub's anonymous rate wouldn't last a project.
369
+ // Without one, they are not asked, which a line above the table says; --repo-advisories fails instead.
370
+ const token = (await import('../src/cmd/tokens.js')).githubToken()
371
+ if (values['repo-advisories'] && !token) fail('Error: --repo-advisories requires a GitHub token in GITHUB_TOKEN')
372
+ const repoAdvisories = !values['no-repo-advisories'] && Boolean(token)
373
+ const tokenless = !values['no-repo-advisories'] && !token
374
+ // Built as `stasis bundle` builds it, but neither written nor compressed, nor its warnings said
375
+ // unless it fails (its error is, as ever).
376
+ let files = argv.map((f) => resolve(f))
377
+ if (plan !== undefined) {
378
+ const { buildCommandBundle } = await import('../src/cmd/bundle.js')
379
+ files = [await warningsOnFailure(() => buildCommandBundle(plan))]
380
+ }
321
381
  // A Soldeer package's and a GitHub repo's advisories are their repository's, asked of GitHub with
322
- // GITHUB_TOKEN where it is set; the client asks nothing for any other package by itself.
323
- const github = (await import('@preventive/upstream/github.js')).createClient({ token: process.env.GITHUB_TOKEN || null })
382
+ // githubToken's token where there is one; the client asks nothing for any other package by itself.
383
+ const github = (await import('@preventive/upstream/github.js')).createClient({ token })
324
384
  // Upstream caches what it looks up (a package's GitHub repo, a month each) only where told to, and
325
385
  // answers from it without asking: a per-user directory, never one shared with less trusted jobs.
326
386
  const { setCacheDir } = await import('@preventive/upstream/npm.js')
327
387
  setCacheDir(userCacheDir())
328
- const { audit, printAuditReport } = await import('../src/audit.js')
329
- const files = argv.map((f) => resolve(f))
330
- const report = await audit(files, { why: Boolean(values.why), whyDeep: Boolean(values['why-deep']), whyFull: Boolean(values['why-full']), reason: values.reason, repoAdvisories, github })
331
- printAuditReport(report)
332
- process.exitCode = report.rows.length === 0 ? 0 : 1
388
+ const { AuditError, audit, printAuditReport } = await import('../src/audit.js')
389
+ // With no file, the package manager's lockfile installing the project too, or each JS one its
390
+ // stasis.config.json names in its `lockfiles`: their packages the bundle doesn't hold checked for
391
+ // malware (npm's registry alone), their being found or refused told, not failed.
392
+ let lockfile = null
393
+ if (plan !== undefined) {
394
+ try {
395
+ lockfile = await (await import('../src/validate.js')).lockedNpmPackages(plan.cwd)
396
+ } catch (cause) {
397
+ console.error(`Lockfile not checked for malware: ${cause.message}`)
398
+ }
399
+ }
400
+ let report
401
+ try {
402
+ // --reason audits that consumer's packages alone; one no file records is refused before any is asked about.
403
+ // OSV is asked about npm packages too, never a private one (upstream checks each name is public).
404
+ report = await audit(files, { why: Boolean(values.why), whyDeep: Boolean(values['why-deep']), whyFull: Boolean(values['why-full']), reason: values.reason, repoAdvisories, github, osv: true, lockfile })
405
+ } catch (cause) {
406
+ if (cause instanceof AuditError) fail(`Error: ${cause.message}`)
407
+ throw cause
408
+ }
409
+ // Each advisory's source as an icon, where the terminal draws sixel images, sized to its cells.
410
+ const { capabilities, logos } = await import('../src/sixel.js')
411
+ const terminal = await capabilities()
412
+ const notes = tokenless ? ['Repository advisories require GITHUB_TOKEN; continuing without them'] : []
413
+ printAuditReport(report, { icons: terminal.sixel && logos(terminal.cell, terminal.background), notes })
414
+ // Malware npm's registry tells of in any dependency fails it too, whatever --reason.
415
+ process.exitCode = report.rows.length === 0 && report.npmMalware.length === 0 ? 0 : 1
333
416
  } else if (command === 'validate') {
334
417
  // Exits 0 where the bundle is valid, 1 where it is invalid, 2 where a file it was to check went
335
418
  // unverified (unless --allow-unverified), and 3 where it refused the bundle, or failed.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/stasis",
3
- "version": "1.0.0-beta.14",
3
+ "version": "1.0.0-beta.16",
4
4
  "description": "File-level source bundles and lockfiles",
5
5
  "type": "module",
6
6
  "exports": {
@@ -20,8 +20,15 @@
20
20
  "./prune": "./src/prune.js",
21
21
  "./sbom": "./src/sbom.js",
22
22
  "./audit-corrections": "./src/audit-corrections.js",
23
- "./validate": "./src/validate.js",
23
+ "./validate": {
24
+ "types": "./src/validate.d.ts",
25
+ "default": "./src/validate.js"
26
+ },
24
27
  "./vfs-bundle": "./src/vfs-bundle.js",
28
+ "./validate-notes": {
29
+ "types": "./src/validate-notes.d.ts",
30
+ "default": "./src/validate-notes.js"
31
+ },
25
32
  "./logo.svg": "./logo.svg"
26
33
  },
27
34
  "files": [
@@ -46,7 +53,7 @@
46
53
  "src/diff.js",
47
54
  "src/esbuild.js",
48
55
  "src/flow.js",
49
- "src/installed-commits.js",
56
+ "src/installed.js",
50
57
  "src/json-stream.js",
51
58
  "src/loader.js",
52
59
  "src/loader-mock.js",
@@ -71,9 +78,14 @@
71
78
  "src/resolve-node.js",
72
79
  "src/resolve-typescript.js",
73
80
  "src/rollup.js",
81
+ "src/run-installed.js",
74
82
  "src/sbom.js",
83
+ "src/sixel.js",
75
84
  "src/table.js",
85
+ "src/validate.d.ts",
76
86
  "src/validate.js",
87
+ "src/validate-notes.d.ts",
88
+ "src/validate-notes.js",
77
89
  "src/scan.js",
78
90
  "src/vfs-bundle.js",
79
91
  "src/vfs-bundle/entries.js",
@@ -106,12 +118,13 @@
106
118
  "homepage": "https://github.com/PreventiveMeasures/stasis#readme",
107
119
  "dependencies": {
108
120
  "@exodus/bytes": "^1.16.0",
109
- "@exodus/stasis-core": "1.0.0-beta.14",
110
- "@exodus/stasis-plugins": "1.0.0-beta.14",
111
- "@preventive/archive": "^1.2.2",
112
- "@preventive/deptree": "^1.3.3",
113
- "@preventive/lockfile": "^1.2.0",
114
- "@preventive/upstream": "^1.4.0",
121
+ "@exodus/stasis-core": "1.0.0-beta.16",
122
+ "@exodus/stasis-plugins": "1.0.0-beta.16",
123
+ "@preventive/archive": "^1.4.0",
124
+ "@preventive/deptree": "^1.4.1",
125
+ "@preventive/lockfile": "^1.3.0",
126
+ "@preventive/rn": "1.0.0-alpha.6",
127
+ "@preventive/upstream": "^1.6.0",
115
128
  "@preventive/vfs": "^1.1.0",
116
129
  "flow-remove-types": "^2.322.0",
117
130
  "oxc-parser": "^0.152.0"
@@ -1,22 +1,7 @@
1
1
  import { satisfies, valid } from '@preventive/upstream/semver.js'
2
2
 
3
- // Manual corrections to audit findings: files that must NOT count as evidence
4
- // that a (potentially vulnerable) package's code is present. An import edge whose
5
- // target is one of these files is not evidence the package is really used, so a
6
- // package pulled in only through corrected files is skipped by the audit (see
7
- // collectPackagesFromFile) -- none of its real code ships, so no advisory applies.
8
- //
9
- // Exported as `@exodus/stasis/audit-corrections`, as plain data, so a tool that
10
- // lays out or reads packages without stasis -- a tree @preventive/deptree builds,
11
- // a server reading bundles -- can apply the same corrections without its own copy.
12
- // Each entry names a package of `ecosystem`, one audit-irrelevant `file` (relative
13
- // to the module dir), `range` -- the semver range VERIFIED to match the rationale --
14
- // and `integrity`, the sha512 of every distinct copy of `file` the versions in
15
- // `range` publish, as a stasis lockfile records a file: a holder of the file's bytes
16
- // can tell they are one of the copies verified. The correction never applies outside
17
- // the range: a release could change the file, so the range is widened only after
18
- // re-checking the file in the new versions, adding any new copy's integrity. Frozen,
19
- // as the audit reads these very objects.
3
+ // Files that are no evidence of a package's real code: one shipped only as these is not audited. Each `range` is
4
+ // VERIFIED, widened only after re-checking `file`; `integrity` is the sha512 of each copy of it there, as a lockfile has it.
20
5
  export const CORRECTIONS = Object.freeze([
21
6
  {
22
7
  // ws's browser build is a noop stub -- `module.exports = function () { throw
@@ -55,42 +40,26 @@ export const CORRECTIONS = Object.freeze([
55
40
  },
56
41
  ].map((correction) => Object.freeze({ ...correction, integrity: Object.freeze(correction.integrity) })))
57
42
 
58
- // Is `rel` (a file path relative to the module dir) audit-irrelevant for
59
- // `name@version` of `ecosystem`? Unknown or unparsable versions are never
60
- // corrected (fail closed: the package stays audited).
61
- function isCorrectedFile(name, version, rel, ecosystem) {
62
- for (const correction of CORRECTIONS) {
63
- if (correction.ecosystem !== ecosystem || correction.name !== name || correction.file !== rel) continue
64
- if (valid(version) && satisfies(version, correction.range)) return true
65
- }
66
- return false
67
- }
43
+ // An unknown or unparsable version is never corrected: fail closed, the package stays audited.
44
+ const isCorrectedFile = (name, version, rel, ecosystem) => CORRECTIONS.some((correction) => correction.ecosystem === ecosystem && correction.name === name
45
+ && correction.file === rel && valid(version) && satisfies(version, correction.range))
68
46
 
69
- // A manifest (top-level or nested) is never code: the resolution graph records
70
- // resolver/metadata reads of `package.json` as edges (react-native scans sibling
71
- // packages' manifests for Haste/asset resolution) and consumers record them
72
- // alongside bundled files, but no package code ships through one. So too for the
73
- // manifests the other ecosystems' bundles carry beside a dependency's code
74
- // (--cargo-manifests, --manifests): its Cargo.toml and the checksums cargo vendored
75
- // it with (a registry's copy, a git checkout's, or one whose source isn't known),
76
- // its composer.json, a Solidity dependency's foundry.toml and remappings.
47
+ // A manifest is never code, though the graph records resolver reads of `package.json` (react-native scans its siblings'
48
+ // for Haste), nor are those other ecosystems' bundles carry (--cargo-manifests, --manifests).
77
49
  const CARGO_MANIFESTS = new Set(['Cargo.toml', 'Cargo.lock', '.cargo-checksum.json'])
50
+ const FOUNDRY_MANIFESTS = new Set(['package.json', 'foundry.toml', 'remappings.txt', 'soldeer.toml'])
78
51
  const MANIFESTS = {
79
52
  npm: new Set(['package.json']),
80
53
  cargo: CARGO_MANIFESTS,
81
54
  'cargo-git': CARGO_MANIFESTS,
82
55
  'cargo-unknown': CARGO_MANIFESTS,
83
56
  composer: new Set(['composer.json', 'composer.lock']),
84
- soldeer: new Set(['package.json', 'foundry.toml', 'remappings.txt', 'soldeer.toml']),
85
- github: new Set(['package.json', 'foundry.toml', 'remappings.txt', 'soldeer.toml']),
57
+ soldeer: FOUNDRY_MANIFESTS,
58
+ github: FOUNDRY_MANIFESTS,
86
59
  }
87
60
  const isManifest = (rel, ecosystem) => MANIFESTS[ecosystem]?.has(rel.slice(rel.lastIndexOf('/') + 1)) ?? false
88
61
 
89
- // Is `rel` evidence that `name@version`'s REAL code is present, of a dependency of
90
- // `ecosystem` (npm by default)? This is the one rule every audit surface shares --
91
- // package presence, the reason column, and the --why chain graph all count a file
92
- // (or an edge targeting it) only when it passes. Manifests never do; CORRECTIONS'
93
- // files don't within their verified range.
62
+ // The one rule package presence, the reason column and the --why graph share.
94
63
  export function isEvidenceFile(name, version, rel, ecosystem = 'npm') {
95
64
  return !isManifest(rel, ecosystem) && !isCorrectedFile(name, version, rel, ecosystem)
96
65
  }