@preventive/triage 1.0.0-alpha.72 → 1.0.0-alpha.73
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/common/bundle-sources.d.ts +2 -0
- package/common/bundle-sources.js +19 -2
- package/common/finding-duplicates.js +5 -0
- package/common/finding-filters.js +45 -4
- package/common/line-diff.d.ts +2 -2
- package/common/line-diff.js +20 -8
- package/common/managed/finding-detail.js +1 -1
- package/common/managed/review-view-routes.js +23 -0
- package/common/managed/risk-routes.js +30 -0
- package/common/managed/routes.js +11 -6
- package/common/managed/team-app.d.ts +8 -6
- package/common/managed/team-app.js +15 -3
- package/common/stasis-files.d.ts +5 -0
- package/common/stasis-files.js +20 -0
- package/common/stasis-tgz.d.ts +6 -0
- package/common/stasis-tgz.js +27 -0
- package/common/workspace-app.js +20 -0
- package/out/activity.js +2 -4
- package/out/{chunk-2F3CYNPZ.js → chunk-2IHCVA3Y.js} +1 -1
- package/out/{chunk-HAZKDK4M.js → chunk-2V6Q4ZOZ.js} +1 -1
- package/out/{chunk-RRBIJL2B.js → chunk-4IW3VD3H.js} +1 -1
- package/out/chunk-4YZOXAXR.js +2 -0
- package/out/chunk-5NUDNLJA.js +6 -0
- package/out/chunk-5YP7P5KA.js +1 -0
- package/out/chunk-6VOB5WXX.js +2 -0
- package/out/chunk-A4BBBHQU.js +1 -0
- package/out/{chunk-4ISO5F7Y.js → chunk-ADMVRLNP.js} +1 -1
- package/out/chunk-BIWPZT4E.js +52 -0
- package/out/{chunk-HETCVNO4.js → chunk-BLPHP4U3.js} +1 -1
- package/out/{chunk-Y5ZHFNBD.js → chunk-BXQCCW7F.js} +1 -1
- package/out/{chunk-JFL7WLRV.js → chunk-CU3FPB3P.js} +1 -1
- package/out/chunk-CXVBTUK3.js +4 -0
- package/out/{chunk-M37X4LCF.js → chunk-EXQQ5VQJ.js} +1 -1
- package/out/{chunk-NXATZJQ2.js → chunk-GSNSP3EF.js} +1 -1
- package/out/chunk-GV5U7OLP.js +40 -0
- package/out/{chunk-JOXLZXMI.js → chunk-GX5UXWT4.js} +1 -1
- package/out/{chunk-YF4M5OCI.js → chunk-I6UQQKAH.js} +1 -1
- package/out/{chunk-UCP3JRE2.js → chunk-LVW7WWV4.js} +1 -1
- package/out/chunk-NEFCZAIY.js +11 -0
- package/out/{chunk-TOXMUOIW.js → chunk-OQS2USZM.js} +1 -1
- package/out/chunk-PX5DLFSD.js +1 -0
- package/out/chunk-QBFT2DDR.js +1 -0
- package/out/{chunk-WKFBZYJX.js → chunk-RGNF4OH6.js} +1 -1
- package/out/chunk-RLLA4GHZ.js +1 -0
- package/out/chunk-ROHACH7V.js +3 -0
- package/out/chunk-ROWUGPID.js +1 -0
- package/out/{chunk-QMVOEBWC.js → chunk-S2ZIKK45.js} +1 -1
- package/out/chunk-SSPDMA6D.js +1 -0
- package/out/chunk-TD7RVUTT.js +2 -0
- package/out/{chunk-4XIH7YTX.js → chunk-UH6NZBSU.js} +1 -1
- package/out/{chunk-M3Y6SLC4.js → chunk-UJP4PQJA.js} +1 -1
- package/out/{chunk-PAD2JHZT.js → chunk-UJSJMXEG.js} +1 -1
- package/out/{chunk-E3LFSUDJ.js → chunk-VYYUMYVW.js} +1 -1
- package/out/{chunk-VRX2APNA.js → chunk-XVKDPU4D.js} +1 -1
- package/out/chunk-Y2XGV3RC.js +8 -0
- package/out/chunk-YCEMQETS.js +255 -0
- package/out/client-managed-import.js +3 -3
- package/out/client-managed.js +30 -28
- package/out/compare.js +16 -23
- package/out/dialogs.js +38 -38
- package/out/graph.js +14 -14
- package/out/index.html +31 -51
- package/out/scan.js +2 -2
- package/out/terminal.js +239 -240
- package/out/view.css +1 -1
- package/out/view.js +15 -15
- package/package.json +20 -13
- package/risk/actions/resolve.js +47 -16
- package/risk/actions/uses.js +27 -9
- package/risk/actions/workflow.js +75 -2
- package/risk/files/hosts.js +4 -4
- package/risk/files/readability.js +5 -2
- package/risk/files/runs-code.js +12 -25
- package/risk/files/script.js +141 -19
- package/risk/index.d.ts +24 -7
- package/risk/index.js +1 -0
- package/risk/npm/assess.js +1 -1
- package/risk/npm/compare.js +5 -4
- package/risk/npm/diff.js +1 -1
- package/risk/npm/held.js +6 -2
- package/risk/npm/registry.js +5 -2
- package/risk/npm/tarball.js +79 -22
- package/server-managed/bundle-advisories.ts +12 -36
- package/server-managed/bundle-build-worker.js +29 -11
- package/server-managed/bundle-build.ts +4 -3
- package/server-managed/bundle-cache.ts +53 -13
- package/server-managed/bundle.ts +45 -13
- package/server-managed/comparison.ts +3 -3
- package/server-managed/db-methods.ts +54 -17
- package/server-managed/db-neon.ts +9 -2
- package/server-managed/db-schema.ts +12 -2
- package/server-managed/db.ts +4 -1
- package/server-managed/dependency-reviews.ts +8 -5
- package/server-managed/github-errors.ts +22 -0
- package/server-managed/github-requests.ts +4 -2
- package/server-managed/http.ts +231 -22
- package/server-managed/management.ts +10 -4
- package/server-managed/npm-delta.ts +1 -1
- package/server-managed/npm-packages.ts +30 -29
- package/server-managed/npm-patch.ts +9 -9
- package/server-managed/package-entry-points.ts +54 -6
- package/server-managed/rename-diff-worker.js +11 -7
- package/server-managed/rename-diff.ts +5 -4
- package/server-managed/report-opening.ts +77 -0
- package/server-managed/report-sources.ts +2 -1
- package/server-managed/repository-aliases.ts +34 -0
- package/server-managed/repository-browser.ts +87 -32
- package/server-managed/repository-code.ts +6 -3
- package/server-managed/repository-dependency-reviews.ts +21 -0
- package/server-managed/repository-risk-read.ts +50 -4
- package/server-managed/repository-risk.ts +9 -2
- package/server-managed/stasis-config.ts +97 -5
- package/server-managed/team-reports.ts +5 -3
- package/server-managed/type-only-proof.js +26 -4
- package/server-managed/upstream-cache.ts +18 -12
- package/server-managed/workspace-shares.ts +4 -4
- package/out/chunk-27Y75UQR.js +0 -4
- package/out/chunk-4RS3NDOG.js +0 -1
- package/out/chunk-4XSH6ZLT.js +0 -1
- package/out/chunk-7CHIFYQW.js +0 -42
- package/out/chunk-CZ3U2LI4.js +0 -2
- package/out/chunk-ETL5ZPPR.js +0 -259
- package/out/chunk-L6VIWL2Y.js +0 -1
- package/out/chunk-OSHR3N4S.js +0 -3
- package/out/chunk-UD33S2MG.js +0 -52
- package/out/chunk-VG5RH6KN.js +0 -2
- package/out/chunk-WFDXHPT2.js +0 -12
- package/out/chunk-WMFDQS2L.js +0 -11
- package/out/chunk-WREU7JAG.js +0 -1
- /package/out/{chunk-4LZK6C6N.js → chunk-74JZTGTO.js} +0 -0
- /package/out/{chunk-JMG5DXII.js → chunk-7HP2VYIC.js} +0 -0
- /package/out/{chunk-HOB3YPS5.js → chunk-K4XJHM2T.js} +0 -0
- /package/out/{chunk-4EMM6UCD.js → chunk-QI66YA4F.js} +0 -0
- /package/out/{chunk-G3LY2FV4.js → chunk-WCDYSIKG.js} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@preventive/triage",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.73",
|
|
4
4
|
"description": "Client & relay server for triaging of automated reports",
|
|
5
5
|
"license": "MIT OR Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -184,6 +184,7 @@
|
|
|
184
184
|
"server-managed/queue.ts",
|
|
185
185
|
"server-managed/repo-path.ts",
|
|
186
186
|
"server-managed/report-migration.ts",
|
|
187
|
+
"server-managed/report-opening.ts",
|
|
187
188
|
"server-managed/report-query.ts",
|
|
188
189
|
"server-managed/report-response.ts",
|
|
189
190
|
"server-managed/report-store.ts",
|
|
@@ -311,6 +312,8 @@
|
|
|
311
312
|
"common/managed/report-content.ts",
|
|
312
313
|
"common/managed/repository-alias.ts",
|
|
313
314
|
"common/managed/report-filter.ts",
|
|
315
|
+
"common/managed/review-view-routes.js",
|
|
316
|
+
"common/managed/risk-routes.js",
|
|
314
317
|
"common/managed/roles.ts",
|
|
315
318
|
"common/managed/routes.d.ts",
|
|
316
319
|
"common/managed/routes.js",
|
|
@@ -330,6 +333,10 @@
|
|
|
330
333
|
"common/scan-server.ts",
|
|
331
334
|
"common/security-links.d.ts",
|
|
332
335
|
"common/security-links.js",
|
|
336
|
+
"common/stasis-files.d.ts",
|
|
337
|
+
"common/stasis-files.js",
|
|
338
|
+
"common/stasis-tgz.d.ts",
|
|
339
|
+
"common/stasis-tgz.js",
|
|
333
340
|
"common/utf8.d.ts",
|
|
334
341
|
"common/utf8.js",
|
|
335
342
|
"common/workspace-app.js",
|
|
@@ -413,41 +420,41 @@
|
|
|
413
420
|
"test": "node --js-base-64 --require=./tests/_resource-loader.js --experimental-test-module-mocks --test-timeout=120000 --test-concurrency=$(node -p 'Math.ceil(os.availableParallelism() * 1.5)') --test ./tests/*.test.js"
|
|
414
421
|
},
|
|
415
422
|
"devDependencies": {
|
|
416
|
-
"@electric-sql/pglite": "^0.5.
|
|
423
|
+
"@electric-sql/pglite": "^0.5.16",
|
|
417
424
|
"@noble/ciphers": "^2.4.0",
|
|
418
425
|
"@preventive/terminal": "2.0.0-beta.3",
|
|
419
426
|
"@rray/frontend": "^1.0.0",
|
|
420
427
|
"@stylistic/stylelint-plugin": "^6.0.1",
|
|
421
428
|
"@types/node": "^26.6.6",
|
|
422
429
|
"@types/ws": "^8.18.2",
|
|
423
|
-
"@vercel/functions": "^3.11.
|
|
430
|
+
"@vercel/functions": "^3.11.3",
|
|
424
431
|
"brotli": "^1.3.3",
|
|
425
432
|
"esbuild": "^0.28.2",
|
|
426
433
|
"lit": "^3.3.3",
|
|
427
434
|
"minify-html-literals": "^1.3.5",
|
|
428
|
-
"oxlint": "^1.
|
|
435
|
+
"oxlint": "^1.93.0",
|
|
429
436
|
"prismjs": "^1.30.0",
|
|
430
437
|
"stylelint": "^18.0.0",
|
|
431
438
|
"stylelint-config-recommended": "^19.0.0",
|
|
432
439
|
"typescript": "^7.0.2"
|
|
433
440
|
},
|
|
434
441
|
"dependencies": {
|
|
435
|
-
"@exodus/stasis": "1.0.0-rc.
|
|
436
|
-
"@exodus/stasis-core": "1.0.0-rc.
|
|
442
|
+
"@exodus/stasis": "1.0.0-rc.9",
|
|
443
|
+
"@exodus/stasis-core": "1.0.0-rc.9",
|
|
437
444
|
"@preventive/archive": "^1.4.1",
|
|
438
|
-
"@preventive/compare": "^1.2.
|
|
445
|
+
"@preventive/compare": "^1.2.14",
|
|
439
446
|
"@preventive/diff": "^1.1.1",
|
|
440
|
-
"@preventive/lockfile": "^1.3.
|
|
447
|
+
"@preventive/lockfile": "^1.3.1",
|
|
441
448
|
"@preventive/publishers": "^1.1.0",
|
|
442
449
|
"@preventive/report": "^1.0.1",
|
|
443
450
|
"@preventive/sourcemap": "1.0.0-alpha.1",
|
|
444
|
-
"@preventive/upstream": "^1.
|
|
451
|
+
"@preventive/upstream": "^1.9.1",
|
|
445
452
|
"css-tree": "^3.2.1",
|
|
446
|
-
"oxc-minify": "^0.
|
|
453
|
+
"oxc-minify": "^0.158.0",
|
|
447
454
|
"oxc-parser": "^0.152.0",
|
|
448
|
-
"oxfmt": "^0.
|
|
455
|
+
"oxfmt": "^0.78.0",
|
|
449
456
|
"semver": "^7.8.6",
|
|
450
|
-
"ws": "^8.
|
|
457
|
+
"ws": "^8.23.0"
|
|
451
458
|
},
|
|
452
459
|
"peerDependencies": {
|
|
453
460
|
"@neondatabase/serverless": "^1.0.2",
|
|
@@ -465,5 +472,5 @@
|
|
|
465
472
|
"optional": true
|
|
466
473
|
}
|
|
467
474
|
},
|
|
468
|
-
"packageManager": "pnpm@12.
|
|
475
|
+
"packageManager": "pnpm@12.21.0+sha512.66fd8278ee28935ce951792d34367ff3af5c432a2756445823029533835b8da529bbe0be5130afd56ed0713fb8789e47bad82d93bd5ae2fe54b15562d6276ef0"
|
|
469
476
|
}
|
package/risk/actions/resolve.js
CHANGED
|
@@ -5,7 +5,7 @@ import { YamlError } from '@preventive/lockfile/yaml.js'
|
|
|
5
5
|
import { readWorkflow } from './workflow.js'
|
|
6
6
|
import { workflowFindings, workflowUses } from './findings.js'
|
|
7
7
|
import { imageFinding, scriptFindings } from './scripts/grade.js'
|
|
8
|
-
import { isWorkflowPath, ownerKind, readImage, readUses, usesKey } from './uses.js'
|
|
8
|
+
import { isVersion, isWorkflowPath, ownerKind, readImage, readUses, usesKey } from './uses.js'
|
|
9
9
|
|
|
10
10
|
// An action's tags as versions: a release's (`v4.2.1`), and a major (`v4`) or
|
|
11
11
|
// minor one (`v4.2`) moved to its line's latest. `[major, minor, patch]`,
|
|
@@ -136,30 +136,55 @@ function tagFindings(ref, commit, tags) {
|
|
|
136
136
|
return findings
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
//
|
|
139
|
+
// The ref a reference names, and whether a branch or a tag alone (`only`):
|
|
140
|
+
// HEAD, as a checkout with no ref names one, its default branch; a
|
|
141
|
+
// checkout's `refs/heads/…` and `refs/tags/…`.
|
|
142
|
+
function refNamed(uses, info) {
|
|
143
|
+
if (uses.ref === 'HEAD') return { ref: info.defaultBranch, only: 'branch' }
|
|
144
|
+
const qualified = /^refs\/(heads|tags)\/(.+)$/u.exec(uses.ref)
|
|
145
|
+
return qualified ? { ref: qualified[2], only: qualified[1] === 'heads' ? 'branch' : 'tag' } : { ref: uses.ref, only: null }
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// A ref not a commit, resolved as GitHub resolves it, a tag before a branch,
|
|
149
|
+
// or as a checkout does (`checkout`), a branch before a tag; one named a
|
|
150
|
+
// branch or a tag alone as that alone.
|
|
140
151
|
async function refOf(uses, info, source, tags) {
|
|
141
|
-
const name = info.fullName
|
|
142
|
-
const [tagged, branched] = await Promise.all([tags ? tags.find(
|
|
152
|
+
const name = info.fullName, { ref, only } = refNamed(uses, info)
|
|
153
|
+
const [tagged, branched] = await Promise.all([only === 'branch' ? null : tags ? tags.find(each => each.tag === ref)?.oid ?? null : source.tag(name, ref),
|
|
154
|
+
only === 'tag' ? null : source.branch(name, ref)])
|
|
143
155
|
if (!tagged && !branched) return { commit: null, at: null, findings: [{ id: 'ref-missing', severity: 'moderate' }] }
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
findings
|
|
156
|
+
const ambiguous = tagged && branched ? [{ id: 'ambiguous-ref', severity: 'high', branch: branched }] : []
|
|
157
|
+
if (!tagged || (branched && uses.checkout)) return { commit: branched, at: 'branch', findings: [...ambiguous, { id: 'branch-ref', severity: 'high' }] }
|
|
158
|
+
const findings = [...ambiguous, ...tagFindings(ref, tagged, tags)]
|
|
147
159
|
const where = await reachable(source, info, tagged, tags)
|
|
148
160
|
if (where === 'none') findings.push({ id: 'tag-off-branch', severity: 'low' })
|
|
149
161
|
return { commit: tagged, at: 'tag', findings }
|
|
150
162
|
}
|
|
151
163
|
|
|
152
|
-
// Whether
|
|
164
|
+
// Whether the version or ref a comment names is a tag on the commit, a
|
|
165
|
+
// version with or without its `v`, or a major or minor tag's line.
|
|
153
166
|
function commentHolds(comment, named) {
|
|
154
|
-
const version = tagVersion(comment)
|
|
155
|
-
return named.some(tag => tag === comment ||
|
|
167
|
+
const unprefixed = text => text.replace(/^v/u, ''), version = tagVersion(comment)
|
|
168
|
+
return named.some(tag => tag === comment || (isVersion(comment) && isVersion(tag) && unprefixed(tag) === unprefixed(comment))
|
|
169
|
+
|| (version && version[2] === null && ofLine(version, tagVersion(tag))))
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Whether the branch a comment names has the commit in its history; null
|
|
173
|
+
// where it has no such branch, or GitHub no such commit.
|
|
174
|
+
async function onBranch(source, name, branch, commit) {
|
|
175
|
+
const head = await source.branch(name, branch)
|
|
176
|
+
return head === null ? null : head === commit || await source.contains(name, head, commit)
|
|
156
177
|
}
|
|
157
178
|
|
|
158
|
-
// A commit, looked for in the history where no tag names it, held to its
|
|
179
|
+
// A commit, looked for in the history where no tag names it, held to its
|
|
180
|
+
// comment: by a tag on it of the version or ref the comment names, else by
|
|
181
|
+
// a branch so named with it in its history (`# main`, or a `# v4` that is
|
|
182
|
+
// a branch). A ref named alone that no tag nor branch is named is a note,
|
|
183
|
+
// held to nothing.
|
|
159
184
|
async function pinnedOf(uses, info, source, tags) {
|
|
160
|
-
const commit = uses.ref
|
|
161
|
-
|
|
162
|
-
|
|
185
|
+
const commit = uses.ref, { comment } = uses
|
|
186
|
+
const commented = !tags && comment ? await source.tag(info.fullName, comment) : null
|
|
187
|
+
const named = commented === commit ? [comment] : tagsOn(tags, commit)
|
|
163
188
|
const findings = []
|
|
164
189
|
if (named.length === 0) {
|
|
165
190
|
const where = await reachable(source, info, commit, tags)
|
|
@@ -168,7 +193,13 @@ async function pinnedOf(uses, info, source, tags) {
|
|
|
168
193
|
else if (where === 'unknown') findings.push({ id: 'unverified-commit', severity: 'high' })
|
|
169
194
|
else if (tags) findings.push({ id: 'untagged-commit', severity: 'moderate', on: where })
|
|
170
195
|
}
|
|
171
|
-
if (
|
|
196
|
+
if (comment && !commentHolds(comment, named)) {
|
|
197
|
+
const branch = await onBranch(source, info.fullName, comment, commit)
|
|
198
|
+
const tagged = commented !== null || Boolean(tags?.some(({ tag }) => tag === comment))
|
|
199
|
+
if (branch === false || (branch === null && (isVersion(comment) || tagged))) {
|
|
200
|
+
findings.push({ id: 'comment-mismatch', severity: 'high', comment, tags: named, ...branch === false && { branch: comment } })
|
|
201
|
+
}
|
|
202
|
+
}
|
|
172
203
|
return { commit, at: 'sha', named, findings }
|
|
173
204
|
}
|
|
174
205
|
|
|
@@ -239,7 +270,7 @@ export async function resolveAction(uses, source, { owner = null } = {}) {
|
|
|
239
270
|
const runs = ref.commit && !ref.findings.some(({ id }) => id === 'commit-missing')
|
|
240
271
|
// What it runs, and its advisories at the versions that is.
|
|
241
272
|
const [code, advised] = runs ? await Promise.all([codeOf(uses, info, ref.commit, source),
|
|
242
|
-
advisoryFindings(source, info, advisedVersions(ref.at, uses.ref, ref.commit, ref.named ?? tagsOn(tags, ref.commit)))]) : [null, []]
|
|
273
|
+
advisoryFindings(source, info, advisedVersions(ref.at, refNamed(uses, info).ref, ref.commit, ref.named ?? tagsOn(tags, ref.commit)))]) : [null, []]
|
|
243
274
|
return { ...at, repository: { fullName: info.fullName, private: Boolean(info.private) }, commit: ref.commit, at: ref.at, tags: tagsOn(tags, ref.commit),
|
|
244
275
|
findings: [...findings, ...ref.findings, ...advised, ...code?.findings ?? []], uses: code?.uses ?? [] }
|
|
245
276
|
}
|
package/risk/actions/uses.js
CHANGED
|
@@ -9,7 +9,15 @@ const SHA = /^[\da-f]{40}$/u
|
|
|
9
9
|
const SHORT_SHA = /^[\da-f]{7,39}$/u
|
|
10
10
|
// A version a comment beside a pin names, as Dependabot, Renovate, pinact
|
|
11
11
|
// and ratchet write one (`# v4.1.1`, `# tag=v4.1.1`, `# ratchet:x@v4`).
|
|
12
|
-
const
|
|
12
|
+
const VERSION = String.raw`v?\d+(?:\.\d+){0,3}(?:[-+][\w.-]+)?`
|
|
13
|
+
const VERSION_COMMENT = new RegExp(String.raw`^#\s*(?:tag\s*[=:]\s*|pin@|ratchet:[^\s@]+@)?(${VERSION})(?![\w.])`, 'iu')
|
|
14
|
+
// Whether what a comment names is a version, not a ref named alone.
|
|
15
|
+
const VERSION_ALONE = new RegExp(`^${VERSION}$`, 'iu')
|
|
16
|
+
export const isVersion = text => VERSION_ALONE.test(text)
|
|
17
|
+
// Else a branch or a tag a comment names alone (`# main`, `# ratchet:x@main`),
|
|
18
|
+
// one git can name so.
|
|
19
|
+
const REF_COMMENT = /^#\s*(?:ratchet:[^\s@]+@)?([\w./-]{1,255})$/u
|
|
20
|
+
const BAD_REF = /\.\.|\/\/|^-|(?:^|\/)\.|\.lock(?:\/|$)|[./]$|^\//u
|
|
13
21
|
|
|
14
22
|
// `sha`, `short-sha`, `ref` (a tag or a branch), or `expression`, which GitHub refuses.
|
|
15
23
|
function pinOf(ref) {
|
|
@@ -31,14 +39,21 @@ export function readImage(text) {
|
|
|
31
39
|
return { image: tagged ? named.slice(0, colon) : named, tag: tagged ? named.slice(colon + 1) : null, digest }
|
|
32
40
|
}
|
|
33
41
|
|
|
34
|
-
|
|
42
|
+
// The ref a comment names alone, whole (`# v1/maintenance`), else the
|
|
43
|
+
// version it begins with (`# v4 is fine`); null for neither.
|
|
44
|
+
function commentNamed(comment) {
|
|
45
|
+
const text = typeof comment === 'string' ? comment.trim() : ''
|
|
46
|
+
const ref = REF_COMMENT.exec(text)?.[1]
|
|
47
|
+
return ref && !BAD_REF.test(ref) ? ref : VERSION_COMMENT.exec(text)?.[1] ?? null
|
|
48
|
+
}
|
|
35
49
|
|
|
36
50
|
export const isWorkflowPath = path => /^\.github\/workflows\/[^/]+\.ya?ml$/u.test(path)
|
|
37
51
|
|
|
38
52
|
// `{ kind, uses, … }`: `action`, or `workflow` at a job's level (`job`), with
|
|
39
|
-
// its `repo`, `path`, `ref`, `pin` and
|
|
40
|
-
// at the commit running, `job` a reusable workflow's,
|
|
41
|
-
// workflow's commit; `docker`; or `invalid`, which GitHub
|
|
53
|
+
// its `repo`, `path`, `ref`, `pin` and the version or ref its `comment`
|
|
54
|
+
// names; `local`, `self` at the commit running, `job` a reusable workflow's,
|
|
55
|
+
// at the calling workflow's commit; `docker`; or `invalid`, which GitHub
|
|
56
|
+
// won't run.
|
|
42
57
|
export function readUses(text, { job = false, comment = null } = {}) {
|
|
43
58
|
const uses = typeof text === 'string' ? text.trim() : ''
|
|
44
59
|
if (uses.startsWith('./') || uses.startsWith('$/')) {
|
|
@@ -54,18 +69,21 @@ export function readUses(text, { job = false, comment = null } = {}) {
|
|
|
54
69
|
if (!OWNER.test(owner) || !NAME.test(name) || ref === '' || path.some(part => !NAME.test(part)) || (job && !isWorkflowPath(path.join('/')))) {
|
|
55
70
|
return { kind: 'invalid', uses }
|
|
56
71
|
}
|
|
57
|
-
return { kind: job ? 'workflow' : 'action', uses, repo: `${owner}/${name}`, path: path.join('/'), ref, pin: pinOf(ref), comment:
|
|
72
|
+
return { kind: job ? 'workflow' : 'action', uses, repo: `${owner}/${name}`, path: path.join('/'), ref, pin: pinOf(ref), comment: commentNamed(comment) }
|
|
58
73
|
}
|
|
59
74
|
|
|
60
|
-
// The key a reference is resolved once by, a commit's with its comment
|
|
61
|
-
|
|
75
|
+
// The key a reference is resolved once by, a commit's with what its comment
|
|
76
|
+
// names, and one a checkout resolves a branch first by (`checkout`) so.
|
|
77
|
+
export const usesKey = ({ repo, path, ref, pin, comment, checkout }) => `${repo.toLowerCase()}${path ? `/${path}` : ''}@${ref}${
|
|
78
|
+
pin === 'sha' ? comment ? ` # ${comment}` : '' : checkout ? ' # checkout' : ''}`
|
|
62
79
|
|
|
63
80
|
// A reference from its key, a reusable workflow's by its path's.
|
|
64
81
|
export function usesOfKey(key) {
|
|
65
82
|
const m = typeof key === 'string' ? /^([^@\s]+@\S+)(?: # (\S+))?$/u.exec(key) : null
|
|
66
83
|
const job = Boolean(m && /^[^/]+\/[^/]+\/\.github\/workflows\/[^/@]+\.ya?ml@/u.test(m[1]))
|
|
67
84
|
const read = m ? readUses(m[1], { job, comment: m[2] ? `# ${m[2]}` : null }) : null
|
|
68
|
-
|
|
85
|
+
const each = read?.kind === 'action' && read.pin !== 'sha' && m[2] === 'checkout' ? { ...read, comment: null, checkout: true } : read
|
|
86
|
+
return each && (each.kind === 'action' || each.kind === 'workflow') && usesKey(each) === key ? each : null
|
|
69
87
|
}
|
|
70
88
|
|
|
71
89
|
// GitHub's own, the workflow's owner's, or another's.
|
package/risk/actions/workflow.js
CHANGED
|
@@ -13,11 +13,79 @@ function lineOf(file, container, key, fallback) {
|
|
|
13
13
|
return line === undefined ? fallback : line + 1
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
// The comment a line ends with, from 1.
|
|
17
|
+
const commentOn = (file, line) => /(?:^|[ \t])(#.*)$/u.exec(file.lines[line - 1] ?? '')?.[1] ?? null
|
|
18
|
+
|
|
16
19
|
// A step's or a job's `uses`, on its line, with the comment that line ends with.
|
|
17
20
|
function usesOf(file, owner, fallback, job = false) {
|
|
18
21
|
if (typeof owner.uses !== 'string') return null
|
|
19
22
|
const line = lineOf(file, owner, 'uses', fallback)
|
|
20
|
-
return { ...readUses(owner.uses, { job, comment:
|
|
23
|
+
return { ...readUses(owner.uses, { job, comment: commentOn(file, line) }), line }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// A path's parts from the workspace, null for one out of it.
|
|
27
|
+
function partsOf(path) {
|
|
28
|
+
const parts = path.split('/').filter(part => part !== '' && part !== '.')
|
|
29
|
+
return parts.includes('..') ? null : parts
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const hasExpression = text => /\$\{\{/u.test(text)
|
|
33
|
+
const OWN_REPOSITORY = /^\$\{\{\s*github\.repository\s*\}\}$/u
|
|
34
|
+
const inputText = value => value === undefined || value === null ? '' : String(value).trim()
|
|
35
|
+
|
|
36
|
+
// A checkout's ref as a reference names it: a commit in either case; HEAD,
|
|
37
|
+
// the default branch, for none; `refs/heads/…` and `refs/tags/…`, a branch
|
|
38
|
+
// or a tag alone; else one checkout looks for as a branch before a tag
|
|
39
|
+
// (`checkout`), not a tag first as a `uses:` is.
|
|
40
|
+
function checkoutRef(written) {
|
|
41
|
+
if (written === '') return { ref: 'HEAD' }
|
|
42
|
+
if (/^[\da-f]{40}$/iu.test(written)) return { ref: written.toLowerCase() }
|
|
43
|
+
const qualified = /^refs\/(heads|tags)\/(.+)$/iu.exec(written)
|
|
44
|
+
if (qualified) return { ref: `refs/${qualified[1].toLowerCase()}/${qualified[2]}` }
|
|
45
|
+
return /^refs\//iu.test(written) ? { ref: written } : { ref: written, branchFirst: true }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// What a step checks out (actions/checkout) and where (`at`, the path's
|
|
49
|
+
// parts): the repository's own (`own`); another's `repository` at its ref
|
|
50
|
+
// (checkoutRef), with the comment its ref's line ends with; or, where an
|
|
51
|
+
// expression names which, `unknown`. Null for no checkout, or one to a
|
|
52
|
+
// path an expression names.
|
|
53
|
+
function checkoutOf(file, step, uses) {
|
|
54
|
+
if (uses?.kind !== 'action' || uses.repo.toLowerCase() !== 'actions/checkout') return null
|
|
55
|
+
const inputs = isMap(step.with) ? step.with : {}
|
|
56
|
+
const path = inputText(inputs.path)
|
|
57
|
+
const at = hasExpression(path) ? null : partsOf(path)
|
|
58
|
+
if (!at) return null
|
|
59
|
+
const repository = inputText(inputs.repository), written = inputText(inputs.ref)
|
|
60
|
+
if (repository === '' || OWN_REPOSITORY.test(repository)) return { at, own: true }
|
|
61
|
+
if (hasExpression(repository) || hasExpression(written)) return { at, unknown: true }
|
|
62
|
+
return { at, repository, ...checkoutRef(written), comment: inputs.ref === undefined ? null : commentOn(file, lineOf(file, inputs, 'ref', null)) }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// A step's condition: null where it always runs (none, or true), false
|
|
66
|
+
// where it never does, else its expression's text.
|
|
67
|
+
function conditionOf(step) {
|
|
68
|
+
if (step.if === undefined || step.if === null || step.if === true) return null
|
|
69
|
+
const text = step.if === false ? 'false' : String(step.if).trim().replace(/^\$\{\{([^]*)\}\}$/u, '$1').trim()
|
|
70
|
+
if (text === '' || text === 'true') return null
|
|
71
|
+
return text === 'false' ? false : text
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// A step's `./` action, where a checkout before it in its job is at its
|
|
75
|
+
// path, the latest's that runs whenever the step does (none's condition,
|
|
76
|
+
// or the step's own): another repository's, as a `uses:` naming it at its
|
|
77
|
+
// ref; the repository's own, from the path it is checked out to; as
|
|
78
|
+
// written where an expression names which.
|
|
79
|
+
function checkedOut(uses, checkouts, when) {
|
|
80
|
+
if (uses?.kind !== 'local' || uses.self) return uses
|
|
81
|
+
const dir = partsOf(uses.path)
|
|
82
|
+
const checkout = dir && checkouts.findLast(({ at, ...each }) => (each.when === null || each.when === when) && at.every((part, index) => dir[index] === part))
|
|
83
|
+
if (!checkout || checkout.unknown || (checkout.own && checkout.at.length === 0)) return uses
|
|
84
|
+
const rest = dir.slice(checkout.at.length).join('/')
|
|
85
|
+
if (checkout.own) return { ...uses, path: rest }
|
|
86
|
+
const read = readUses(`${checkout.repository}${rest ? `/${rest}` : ''}@${checkout.ref}`, { comment: checkout.comment })
|
|
87
|
+
if (read.kind !== 'action') return uses
|
|
88
|
+
return { ...read, ...checkout.branchFirst && read.pin !== 'sha' && { checkout: true }, line: uses.line }
|
|
21
89
|
}
|
|
22
90
|
|
|
23
91
|
function triggersOf(on) {
|
|
@@ -48,12 +116,17 @@ function inputsOf(file, owner, line) {
|
|
|
48
116
|
return { with: inputs, withLines: inputs ? Object.fromEntries(Object.keys(inputs).map(key => [key, lineOf(file, inputs, key, line)])) : {} }
|
|
49
117
|
}
|
|
50
118
|
|
|
119
|
+
// A job's steps, each `./` action as the checkouts before it that run have it.
|
|
51
120
|
function stepsOf(file, steps, directory, env = {}) {
|
|
52
121
|
if (!Array.isArray(steps)) return []
|
|
122
|
+
const checkouts = []
|
|
53
123
|
return steps.flatMap((step, index) => {
|
|
54
124
|
if (!isMap(step)) return []
|
|
55
125
|
const line = lineOf(file, steps, index, null)
|
|
56
|
-
|
|
126
|
+
const uses = usesOf(file, step, line), when = conditionOf(step)
|
|
127
|
+
const checkout = when === false ? null : checkoutOf(file, step, uses)
|
|
128
|
+
if (checkout) checkouts.push({ ...checkout, when })
|
|
129
|
+
return [{ line, uses: checkedOut(uses, checkouts, when), run: runOf(file, step, directory, env), ...inputsOf(file, step, line) }]
|
|
57
130
|
})
|
|
58
131
|
}
|
|
59
132
|
|
package/risk/files/hosts.js
CHANGED
|
@@ -6,14 +6,14 @@
|
|
|
6
6
|
// IP lookup), as a file's stamps say (stamps.js).
|
|
7
7
|
//
|
|
8
8
|
// A quick read, not a parse, as runs-code.js reads: a host is a URL's in a
|
|
9
|
-
// script's strings, regular expressions and template literals
|
|
10
|
-
//
|
|
9
|
+
// script's strings, regular expressions and template literals (script.js
|
|
10
|
+
// jsMatchAll), its comments aside, where a link to docs is no host
|
|
11
11
|
// the code calls; an exfiltration host is told in any text but prose and a
|
|
12
12
|
// source map, wherever it is written. A host built as the code runs
|
|
13
13
|
// (`'https://' + name`, `${host}`) goes unseen, so a version without these
|
|
14
14
|
// labels is not one that sends nothing.
|
|
15
15
|
import { NPM_PROSE, SOURCE_MAP } from './readability.js'
|
|
16
|
-
import {
|
|
16
|
+
import { NPM_MAX_FOUND, jsMatchAll, lineOf, npmIsScript } from './script.js'
|
|
17
17
|
|
|
18
18
|
// How many hosts a file is told naming at most, the first it names.
|
|
19
19
|
const NPM_MAX_HOSTS = 1000
|
|
@@ -86,7 +86,7 @@ function githubNamed(url) {
|
|
|
86
86
|
export function npmHosts(path, text, script = false) {
|
|
87
87
|
if (!npmIsScript(path, text, script) || !(text.includes('://') || text.includes(':\\/\\/'))) return null
|
|
88
88
|
const hosts = new Map(), line = lineOf(text)
|
|
89
|
-
for (const { 1: token, index } of text
|
|
89
|
+
for (const { 1: token, index } of jsMatchAll(text)) {
|
|
90
90
|
if (hosts.size >= NPM_MAX_HOSTS) break
|
|
91
91
|
// Read unescaped, its offsets as near: on the same line but in a template
|
|
92
92
|
// across lines; a regular expression without its closing slash and flags,
|
|
@@ -58,8 +58,11 @@ export const npmLargeCode = (path, bytes, script = false) => typeof bytes === 'n
|
|
|
58
58
|
// no one can read it in review, yet what reads it by its byte order mark can
|
|
59
59
|
// run it, or type with it, as UTF-16 (a browser's classic script, Windows
|
|
60
60
|
// Script Host, TypeScript), and node runs it decoded as UTF-8 whatever it
|
|
61
|
-
// holds past its code (`//` and a byte no UTF-8 has).
|
|
62
|
-
|
|
61
|
+
// holds past its code (`//` and a byte no UTF-8 has). `npmCodePath`: whether
|
|
62
|
+
// a path names JavaScript or TypeScript by its extension, by which Compare
|
|
63
|
+
// tells such a file that isn't text from a binary one.
|
|
64
|
+
export const npmCodePath = path => CODE.test(path)
|
|
65
|
+
export const npmBinaryCode = (path, readability, script = false) => readability?.category === 'binary' && (script || npmCodePath(path))
|
|
63
66
|
|
|
64
67
|
// A file with a line over UNREADABLE_LINE characters, by how it reads
|
|
65
68
|
// (`now`, npmFileReadability's), `path` its path: an inline source map's line
|
package/risk/files/runs-code.js
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
// required by a name computed, a path or URL put together, the
|
|
31
31
|
// registry's host read from config), so a file without a label is not one
|
|
32
32
|
// without them.
|
|
33
|
-
import {
|
|
33
|
+
import { NPM_MAX_FOUND, jsMatchAll, lineOf, npmIsScript } from './script.js'
|
|
34
34
|
|
|
35
35
|
// What may come between a call's parts: blanks and comments
|
|
36
36
|
// (`Function/* note */(…)`), each comment ending at its first `*/`.
|
|
@@ -128,8 +128,9 @@ const TOKEN_NAME = String.raw`(?=NPM|GITHUB)(?<![\p{ID_Continue}$])(?<!\b(?:cons
|
|
|
128
128
|
// object (`const { eval: run } = globalThis`, `({ a, eval: run } = window)`).
|
|
129
129
|
const KEYED = String.raw`(?<=[{,;]${GAP}eval)\s*:(?!${GAP}(?:true|!0)(?![\p{ID_Continue}$]))`
|
|
130
130
|
+ String.raw`(?![^{};]{0,200}\}${GAP}=${GAP}(?:${GLOBAL})(?![\p{ID_Continue}$]))`
|
|
131
|
-
//
|
|
132
|
-
// tells them, each taking its own text,
|
|
131
|
+
// What a script's code does, read beside its strings, regular expressions and
|
|
132
|
+
// comments as script.js's jsMatchAll tells them, each taking its own text,
|
|
133
|
+
// and in none of them: eval,
|
|
133
134
|
// not a property TypeScript types as optional (`eval?: T`, JavaScript's `?:`
|
|
134
135
|
// none of its own) nor a key (KEYED), and Function called, but to find the
|
|
135
136
|
// global object;
|
|
@@ -138,8 +139,8 @@ const KEYED = String.raw`(?<=[{,;]${GAP}eval)\s*:(?!${GAP}(?:true|!0)(?![\p{ID_C
|
|
|
138
139
|
// = …`), not named in a type (`typeof Module.prototype._compile`); a token's
|
|
139
140
|
// name, its value read; the environment read out whole; and a PUT request's
|
|
140
141
|
// call (`axios.put(…)`).
|
|
141
|
-
const READS =
|
|
142
|
-
+ String.raw`|(?<compile>\.${GAP}_compile(?:${FUNCTION_CALLED}|${GAP}=(?![=>])))|(?<tokens>${TOKEN_NAME})|(?<env>${ENV_WHOLE})|(?<put>\.${GAP}put${GAP}\()
|
|
142
|
+
const READS = String.raw`(?<eval>${named('eval')}(?![\p{ID_Continue}$])(?!\s*\?:)(?!${KEYED}))|(?<function>${named('Function')}${FUNCTION_CALLED}${GLOBAL_FOUND})`
|
|
143
|
+
+ String.raw`|(?<compile>\.${GAP}_compile(?:${FUNCTION_CALLED}|${GAP}=(?![=>])))|(?<tokens>${TOKEN_NAME})|(?<env>${ENV_WHOLE})|(?<put>\.${GAP}put${GAP}\()`
|
|
143
144
|
// What a string holds that a kind is: a credential file's path, npm's, SSH's
|
|
144
145
|
// or AWS's (`~/.npmrc`, `.ssh/id_rsa`, `.aws/credentials`, not `x.npmrc` or
|
|
145
146
|
// `.sshd`); a token's name where it is read, the string the name alone (a
|
|
@@ -456,7 +457,7 @@ function read(code, base, at) {
|
|
|
456
457
|
// ends; whether the strings since a program's name are its arguments, an
|
|
457
458
|
// option or its value each, and whether the last is an option.
|
|
458
459
|
let before = null, command = null, end = 0, option = false, program = false
|
|
459
|
-
for (const { 0: token, 1: string, groups, index } of code
|
|
460
|
+
for (const { 0: token, 1: string, groups, index } of jsMatchAll(code, READS)) {
|
|
460
461
|
if (string === undefined) {
|
|
461
462
|
for (const kind of CODE_KINDS) if (groups[kind]) at(kind, base + index)
|
|
462
463
|
continue
|
|
@@ -552,29 +553,15 @@ function substitutions(template) {
|
|
|
552
553
|
return found
|
|
553
554
|
}
|
|
554
555
|
|
|
555
|
-
// A string, regular expression or comment where it starts, told as
|
|
556
|
-
// JS_STRING_OR_COMMENT tells them in a whole text.
|
|
557
|
-
const TOKEN = new RegExp(JS_STRING_OR_COMMENT.source, 'muy')
|
|
558
|
-
|
|
559
556
|
// Where the `}` closing code from `from` in a text is, or the text's end for
|
|
560
557
|
// none: the first its braces leave unbalanced, those in its strings, regular
|
|
561
|
-
// expressions and comments aside (`${/* } */ x}`, `${/}/.test(x)}`)
|
|
558
|
+
// expressions and comments aside (`${/* } */ x}`, `${/}/.test(x)}`), read as
|
|
559
|
+
// script.js reads them.
|
|
562
560
|
function closing(text, from) {
|
|
563
561
|
let depth = 0
|
|
564
|
-
for (
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
// comment's leading blanks taken from where they start.
|
|
568
|
-
if ('"\'`/ \t'.includes(char)) {
|
|
569
|
-
TOKEN.lastIndex = at
|
|
570
|
-
const token = TOKEN.exec(text)
|
|
571
|
-
if (token) {
|
|
572
|
-
at += token[0].length - 1
|
|
573
|
-
continue
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
if (char === '{') depth++
|
|
577
|
-
else if (char === '}' && depth-- === 0) return at
|
|
562
|
+
for (const { 0: token, index } of jsMatchAll(text, '[{}]', from)) {
|
|
563
|
+
if (token === '{') depth++
|
|
564
|
+
else if (token === '}' && depth-- === 0) return index
|
|
578
565
|
}
|
|
579
566
|
return text.length
|
|
580
567
|
}
|