@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/server-managed/http.ts
CHANGED
|
@@ -68,11 +68,16 @@
|
|
|
68
68
|
// POST /api/admin/repositories/remove → admin permanently removes a repo
|
|
69
69
|
// GET /api/admin/repositories/risk[?team=|?repo=] → admin: each connected repo's npm lockfiles, or a team's or one repo's,
|
|
70
70
|
// their packages and what risk tells of each, Brotli-encoded ndjson as each is found; the reader leaving stops it | 400/401/403/404
|
|
71
|
+
// GET /api/admin/repositories/risk/stasis?repoId=&commit=&path=… → admin: what Stasis reaches of a repo's stasis.config.json
|
|
72
|
+
// files at a commit, each built as its dependency review builds it, a build still to be made asked for again | 400/401/403/404
|
|
73
|
+
// GET /api/admin/repositories/risk/lockfile?repoId=&commit=&path= → admin: an npm lockfile of a repo at a commit, as a scan
|
|
74
|
+
// read it, and the package.json beside a yarn.lock, for what depends on a package it locks | 400/401/403/404/429/502
|
|
71
75
|
// GET /api/admin/reports → admin|manage list of uploaded reports | 401/403
|
|
72
76
|
// POST /api/admin/reports → admin|manage uploads a report (raw body) | 401/403/413
|
|
73
77
|
// GET /api/admin/reports/<id> → admin|manage downloads a stored report | 401/403/404
|
|
74
78
|
// DELETE /api/admin/reports/<id> → admin|manage deletes a report | 401/403/404
|
|
75
79
|
// POST /api/admin/reports/set-repo → admin|manage attaches/detaches a report's repo | 401/403/404
|
|
80
|
+
// POST /api/admin/reports/set-opening → admin|manage switches a report to open on Confirmed, where it offers that | 401/403/404/409/503
|
|
76
81
|
// GET /api/admin/reports/<id>/location → admin|manage live location suggestion | 401/403/404/503
|
|
77
82
|
// GET /api/bundles/<id>/{metadata,contents} → authorized encoded bytes | 401/404/422
|
|
78
83
|
// GET /api/bundles/<id>/advisories → published dependency advisories (security access), of one ?reason= or ?entry= point where given | 400/401/403/404
|
|
@@ -169,7 +174,7 @@ import { createHash, randomUUID } from 'node:crypto'
|
|
|
169
174
|
import type { AvatarStore, CachedAvatar } from './avatar-store.ts'
|
|
170
175
|
import type { BlobStore, OpenedBlob } from './blob-store.ts'
|
|
171
176
|
import { bundleFilePrefix, bundleIntegrity, bundleKind, bundleRepo, reportBundleHashes } from './bundle.ts'
|
|
172
|
-
import { resolveRepositoryImportLocation } from './repository-aliases.ts'
|
|
177
|
+
import { ourRepositoryNames, resolveRepositoryImportLocation } from './repository-aliases.ts'
|
|
173
178
|
import type { ManagedConfig } from './config.ts'
|
|
174
179
|
import type { BundleBuildConditions, BundleProvenance, BundleReuse, ManagedBundle, ManagedDb, ManagedSession, ReportRecord, SelectedRepo, StoredUser, TriageEventRow } from './db.ts'
|
|
175
180
|
import type { OriginGate } from '../server-common/origin.ts'
|
|
@@ -192,11 +197,13 @@ import { collectRepos, fetchPublicRepository, installUrl, publicRepositoryName,
|
|
|
192
197
|
import { type TaggedRead, keepTaggedReadsIn } from './github-requests.ts'
|
|
193
198
|
import { SHA, timeOf } from './github-values.ts'
|
|
194
199
|
import { GithubApiError, upstreamGithub } from './github-errors.ts'
|
|
200
|
+
import { STASIS_CONFIG } from './stasis-config.ts'
|
|
195
201
|
import { createClient } from '@preventive/upstream/github.js'
|
|
196
202
|
import type { ConnectedRepo } from './github-app.ts'
|
|
197
203
|
import { canAddAnyPublicRepository, canAddRepositories, passesPublicRepositorySafeguard } from './repository-policy.ts'
|
|
198
204
|
import { RepositoryDiscovery } from './repository-discovery.ts'
|
|
199
205
|
import { RISK_KEPT_MS, SCAN_READ_KEPT_MS, type ScanProgress, repositoryRiskLines } from './repository-risk.ts'
|
|
206
|
+
import { stasisConfigRow } from './repository-risk-read.ts'
|
|
200
207
|
import { WORKFLOWS_DIR } from './repository-actions.ts'
|
|
201
208
|
import { githubActionsSource } from './github-actions.ts'
|
|
202
209
|
import { type RepositoryEntry, createRepositoryBrowser, repositoryTreeFiles, scopedDirectory } from './repository-browser.ts'
|
|
@@ -227,6 +234,7 @@ import { teamAppKey, teamAppStates, withWorkspaceSummary } from './team-app.ts'
|
|
|
227
234
|
import { hashToken, randomToken, safeEqual } from './crypto.ts'
|
|
228
235
|
import { canDeleteComment, parseCommentBody } from '../common/managed/comments.ts'
|
|
229
236
|
import { ManagedMutationError, reportReferenceSnapshot } from './management.ts'
|
|
237
|
+
import { confirmedDefaultOffered, readConfirmedOffered, withConfirmedOffered } from './report-opening.ts'
|
|
230
238
|
import { BundleBuildError, buildRepositoryBundle, buildRepositoryLockfile, parseBundleBuild, withBundleBuildLease } from './bundle-build.ts'
|
|
231
239
|
import { NpmPackageError, type NpmReader, type NpmVersionDocument, type NpmVersionStore, VERSION_KEPT_MS, canReadPrivateNpm, npmFileRows, npmPublishTime, npmScopesCount, npmTarballFilename, readNpmVersion, readNpmVersions, readTogether } from './npm-packages.ts'
|
|
232
240
|
import { loadNpmFiles, loadNpmPackageBody, loadNpmTarball } from './npm-loads.ts'
|
|
@@ -246,7 +254,7 @@ import { eachOf } from './queue.ts'
|
|
|
246
254
|
import { lockedAt, lockedIn, lockfilesAt } from './commit-lockfiles.ts'
|
|
247
255
|
import { MAX_REQUIRED_REVIEWS, type PublishedReview, type RepoDependencyReview } from './repository-dependency-reviews.ts'
|
|
248
256
|
import { EVERY_LOCKFILE, type LockfileScope, heldTo, isStasisConfig, reviewedIn, scopeOf, stasisConfigs } from './lockfile-scope.ts'
|
|
249
|
-
import { type StasisDependencyReader, type StasisWant, stasisDependencyReader, stasisDirectory, wantingBeside, withReach } from './stasis-dependencies.ts'
|
|
257
|
+
import { type StasisDependencyReader, type StasisRead, type StasisWant, stasisDependencyReader, stasisDirectory, wantingBeside, withReach } from './stasis-dependencies.ts'
|
|
250
258
|
import { type BundledVersion, bundleDependencies, installsBundle } from './bundle-dependency-reviews.ts'
|
|
251
259
|
import { type CommentReviews, type ReviewBaselineStore, baselineFor, heldDependencies, reviewedDependencies, reviewedPackages } from './pull-dependency-reviews.ts'
|
|
252
260
|
import { formattedPull, withFormatted } from './dependency-review-comments.ts'
|
|
@@ -305,9 +313,12 @@ const CONNECT_REPO_APP_PATH = '/api/admin/repositories/connect-app'
|
|
|
305
313
|
const REPO_IMPACT_PATH = '/api/admin/repositories/impact'
|
|
306
314
|
const REMOVE_REPO_PATH = '/api/admin/repositories/remove'
|
|
307
315
|
const REPO_RISK_PATH = '/api/admin/repositories/risk'
|
|
316
|
+
const REPO_RISK_STASIS_PATH = '/api/admin/repositories/risk/stasis'
|
|
317
|
+
const REPO_RISK_LOCKFILE_PATH = '/api/admin/repositories/risk/lockfile'
|
|
308
318
|
const ADMIN_REPORTS_PATH = '/api/admin/reports'
|
|
309
319
|
const REPORT_SET_REPO_PATH = '/api/admin/reports/set-repo'
|
|
310
320
|
const REPORT_SET_VISIBLE_PATH = '/api/admin/reports/set-visible'
|
|
321
|
+
const REPORT_SET_OPENING_PATH = '/api/admin/reports/set-opening'
|
|
311
322
|
const REPORT_PREFIX = '/api/admin/reports/'
|
|
312
323
|
const ADMIN_BUNDLES_PATH = '/api/admin/bundles'
|
|
313
324
|
const BUNDLE_CREATE_PATH = '/api/admin/bundles/create'
|
|
@@ -344,9 +355,10 @@ const NPM_RISK_PATH = '/api/npm/risk'
|
|
|
344
355
|
const NPM_DELTA_PATH = '/api/npm/delta'
|
|
345
356
|
const NPM_DELTAS_PATH = '/api/npm/deltas'
|
|
346
357
|
// What risk's errors (risk/npm/registry.js NpmRiskError) are answered as: npm
|
|
347
|
-
// having no such package or version,
|
|
348
|
-
//
|
|
349
|
-
|
|
358
|
+
// having no such package or version, a tarball unpacking past risk's bounds,
|
|
359
|
+
// or one installers would install other than one set of files from, as the
|
|
360
|
+
// viewer refuses it (npm-packages.ts readNpmTar); npm failing otherwise a 502.
|
|
361
|
+
const NPM_RISK_STATUS: Partial<Record<string, number>> = { 'package-not-found': 404, 'version-not-found': 404, 'package-too-large': 413, 'tarball-conflict': 422 }
|
|
350
362
|
// A risk failure answered with its code alone, as risk's status for it (NPM_RISK_STATUS, else 502), its cause
|
|
351
363
|
// logged where it is the server's or npm's, not the reader's (a 5xx), for the logs to say why.
|
|
352
364
|
function sendRiskError(res: ServerResponse, err: NpmRiskError) {
|
|
@@ -699,8 +711,10 @@ function sendViewOnly(res: ServerResponse): void {
|
|
|
699
711
|
// would link it to the viewed user.
|
|
700
712
|
function viewAllows(method: string, path: string): boolean {
|
|
701
713
|
if (method === 'GET' || method === 'HEAD') return path !== ISSUE_LOGIN_PATH && path !== LINK_LOGIN_PATH
|
|
702
|
-
return (method === 'DELETE' && path === VIEW_AS_PATH) || (method === 'POST' && (path === LOGOUT_PATH || path === REPORT_QUERY_PATH))
|
|
714
|
+
return (method === 'DELETE' && path === VIEW_AS_PATH) || (method === 'POST' && (path === LOGOUT_PATH || path === REPORT_QUERY_PATH || TEAM_REVIEW_CHANGES.test(path)))
|
|
703
715
|
}
|
|
716
|
+
// Where a team's Dependencies tab asks which versions' reviews changed (handleTeamReviewChanges).
|
|
717
|
+
const TEAM_REVIEW_CHANGES = /^\/api\/teams\/([^/]+)\/dependency-reviews\/changed$/u
|
|
704
718
|
|
|
705
719
|
// POST /api/auth/logout — drop the session (same-origin + CSRF), which also
|
|
706
720
|
// ends a view opened from it.
|
|
@@ -1306,6 +1320,31 @@ async function handleSetReportVisible(req: IncomingMessage, res: ServerResponse,
|
|
|
1306
1320
|
sendJson(res, 200, { ok: true, visible })
|
|
1307
1321
|
}
|
|
1308
1322
|
|
|
1323
|
+
// POST /api/admin/reports/set-opening — switch a stored report to open on
|
|
1324
|
+
// Confirmed whatever Confirmed hides, or back to the outcome its view works
|
|
1325
|
+
// out (report-opening.ts). Body { reportId, confirmedDefault }. On only where
|
|
1326
|
+
// the report offers it (409 `not-offered`): one not read for that yet is read
|
|
1327
|
+
// first, 503 where its bytes cannot be. Off is always allowed.
|
|
1328
|
+
async function handleSetReportOpening(req: IncomingMessage, res: ServerResponse, deps: ManagedHttpDeps, cookie: string | undefined): Promise<void> {
|
|
1329
|
+
const s = await manageMutation(req, res, deps, cookie, { handed: true })
|
|
1330
|
+
if (s == null) return
|
|
1331
|
+
const body = await readBodyFields(req, res)
|
|
1332
|
+
if (!body) return
|
|
1333
|
+
const { reportId, confirmedDefault } = body
|
|
1334
|
+
if (typeof reportId !== 'string' || typeof confirmedDefault !== 'boolean') { sendJson(res, 400, { error: 'bad-request' }); return }
|
|
1335
|
+
if (confirmedDefault) {
|
|
1336
|
+
// The mutation checks access again as it writes; this read only for one
|
|
1337
|
+
// the manager may read, so it tells nothing of any other.
|
|
1338
|
+
const stored = await canViewReport(deps, s.user, reportId) ? await deps.db.getReport(reportId) : null
|
|
1339
|
+
if (stored?.confirmedOffered === null && await readConfirmedOffered(deps.db, deps.reportStore, stored) === null) { sendJson(res, 503, { error: 'unavailable' }); return }
|
|
1340
|
+
}
|
|
1341
|
+
const { report, user } = await deps.db.mutateReport(s.session.id, reportId, { type: 'opening', confirmedDefault })
|
|
1342
|
+
if (report.confirmedDefault !== confirmedDefault) {
|
|
1343
|
+
await activity(deps, user, 'visibility', confirmedDefault ? 'set a report to open on Confirmed' : 'set a report to open on its detected outcome', { reportId, report: report.filename, repo: await repositoryName(deps, report.repoId) })
|
|
1344
|
+
}
|
|
1345
|
+
sendJson(res, 200, { ok: true, confirmedDefault })
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1309
1348
|
async function handleSetBundleVisible(req: IncomingMessage, res: ServerResponse, deps: ManagedHttpDeps, cookie: string | undefined): Promise<void> {
|
|
1310
1349
|
const s = await manageMutation(req, res, deps, cookie, { handed: true })
|
|
1311
1350
|
if (s == null) return
|
|
@@ -1340,10 +1379,13 @@ async function handleSetBundleRepo(req: IncomingMessage, res: ServerResponse, de
|
|
|
1340
1379
|
// GET /api/admin/reports — the uploaded reports for the "Manage reports" page.
|
|
1341
1380
|
// Visible to admin|manage. Read-only, so no CSRF (like /api/admin/users).
|
|
1342
1381
|
// `maxBytes` lets the page show / pre-check the upload size cap; `repos` feeds
|
|
1343
|
-
// the upload repo picker.
|
|
1382
|
+
// the upload repo picker. Reports uploaded before their opening was read are
|
|
1383
|
+
// read for it as they list, a bounded share each time (report-opening.ts).
|
|
1344
1384
|
async function handleListReports(res: ServerResponse, deps: ManagedHttpDeps, session: ManagedSession): Promise<void> {
|
|
1385
|
+
const catalog = await deps.db.getReportCatalog(session.id, Date.now())
|
|
1345
1386
|
sendJson(res, 200, {
|
|
1346
|
-
...
|
|
1387
|
+
...catalog,
|
|
1388
|
+
reports: await withConfirmedOffered(deps.db, deps.reportStore, catalog.reports),
|
|
1347
1389
|
maxBytes: deps.config.maxReportBytes,
|
|
1348
1390
|
})
|
|
1349
1391
|
}
|
|
@@ -1458,13 +1500,15 @@ async function handleUploadReport(req: IncomingMessage, res: ServerResponse, dep
|
|
|
1458
1500
|
const contentType = (firstHeader(req.headers['content-type']) ?? '').split(';', 1)[0]!.trim() || 'application/json'
|
|
1459
1501
|
// A JSON report's parse already in hand, not parsed again for its hashes.
|
|
1460
1502
|
const { bundleId, integrity } = await resolveReportBundle(deps, s.user, parsed.format === 'json' ? parsed.data : null)
|
|
1503
|
+
// Last, as it backfills the parse's finding IDs.
|
|
1504
|
+
const confirmedOffered = await confirmedDefaultOffered(filename, parsed.data)
|
|
1461
1505
|
const dataKey = await deps.reportStore.put(id, bytes)
|
|
1462
1506
|
let report: ReportRecord
|
|
1463
1507
|
try {
|
|
1464
1508
|
report = await deps.db.insertOrReuseReport({
|
|
1465
1509
|
id, filename, contentType, byteSize: bytes.length, sha256, dataKey,
|
|
1466
1510
|
uploadedBy: s.user.id, uploadedByLogin: s.user.login, repoId,
|
|
1467
|
-
repoDirectory: directory, repoEmbedded, analyzer, visible: false, bundleId, bundleIntegrity: integrity,
|
|
1511
|
+
repoDirectory: directory, repoEmbedded, analyzer, visible: false, bundleId, bundleIntegrity: integrity, confirmedOffered,
|
|
1468
1512
|
}, Date.now(), s.session.id)
|
|
1469
1513
|
} catch (err) {
|
|
1470
1514
|
// A successful COMMIT can lose its acknowledgement. Never delete a file
|
|
@@ -1542,10 +1586,18 @@ async function repositoryBrowserUser(deps: ManagedHttpDeps, userId: string) {
|
|
|
1542
1586
|
return { githubUserId, token }
|
|
1543
1587
|
}
|
|
1544
1588
|
|
|
1545
|
-
// The repository browser
|
|
1546
|
-
//
|
|
1589
|
+
// The repository browser of `user` (repository-browser.ts), with their own
|
|
1590
|
+
// GitHub access. A repository GitHub renamed or transferred since it was
|
|
1591
|
+
// connected is renamed here as it reads it, its old name an alias of it
|
|
1592
|
+
// where that names nothing else (renameRepository).
|
|
1593
|
+
function repositoryBrowser(deps: ManagedHttpDeps, user: Awaited<ReturnType<typeof repositoryBrowserUser>>) {
|
|
1594
|
+
return createRepositoryBrowser(deps.config, user, undefined, async (repo, from, redirected) => { await deps.db.renameRepository(repo, from, redirected) })
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
// The repository browser's reader of `repo`, with user `userId`'s own GitHub
|
|
1598
|
+
// access.
|
|
1547
1599
|
async function repositoryReader(deps: ManagedHttpDeps, userId: string, repo: SelectedRepo) {
|
|
1548
|
-
return
|
|
1600
|
+
return repositoryBrowser(deps, await repositoryBrowserUser(deps, userId)).reader(repo)
|
|
1549
1601
|
}
|
|
1550
1602
|
|
|
1551
1603
|
// After a catalog response: read the commit details it lacked with this
|
|
@@ -1557,7 +1609,7 @@ async function backfillCatalogCommits(deps: ManagedHttpDeps, userId: string, mis
|
|
|
1557
1609
|
// Read once for the repositories the backfill reaches, not once each.
|
|
1558
1610
|
const repo = (await (repos ??= deps.db.listAllRepos())).find(item => item.repoId === repoId)
|
|
1559
1611
|
if (!repo) return null
|
|
1560
|
-
browser ??=
|
|
1612
|
+
browser ??= repositoryBrowser(deps, await repositoryBrowserUser(deps, userId))
|
|
1561
1613
|
return browser.reader(repo)
|
|
1562
1614
|
}).catch(err => { console.warn('managed: commit backfill failed:', err) })
|
|
1563
1615
|
}
|
|
@@ -1606,6 +1658,35 @@ async function readRepositoryRefs(db: ManagedDb, reader: RepositoryReader, repo:
|
|
|
1606
1658
|
return { ...refs.value, defaultContents: contents.value }
|
|
1607
1659
|
}
|
|
1608
1660
|
|
|
1661
|
+
// Whether `user`'s grants reach all of repository `repoId`'s directory `path`.
|
|
1662
|
+
async function reachesDirectory(deps: ManagedHttpDeps, user: StoredUser, repoId: number, path: string) {
|
|
1663
|
+
return repositoryAccessIn(await repositoryGrants(deps, user), repoId, path)?.virtualEntries === null
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
|
+
const holdsConfig = (contents: { entries: RepositoryEntry[] }) => contents.entries.some(entry => entry.name === STASIS_CONFIG && entry.type === 'file')
|
|
1667
|
+
|
|
1668
|
+
// The directory Create a bundle opens at in place of the default branch's
|
|
1669
|
+
// root, `root`, as if browsed to from there: where the root, as the reader is
|
|
1670
|
+
// shown it, holds no stasis.config.json, that of the one stasis.config.json
|
|
1671
|
+
// the repository's dependency review names, where it names one alone, the
|
|
1672
|
+
// reader's grants reach all of it, and it holds that file at the root's
|
|
1673
|
+
// commit. Null otherwise, as where GitHub fails reading it.
|
|
1674
|
+
async function reviewedConfigContents(deps: ManagedHttpDeps, reader: RepositoryReader, user: StoredUser, repoId: number,
|
|
1675
|
+
root: RepositoryContents | null, listed: ListedAt): Promise<RepositoryContents | null> {
|
|
1676
|
+
if (!root || holdsConfig(root)) return null
|
|
1677
|
+
const configs = stasisConfigs((await deps.db.repoDependencyReview(repoId))?.lockfiles ?? EVERY_LOCKFILE)
|
|
1678
|
+
if (configs.length !== 1) return null
|
|
1679
|
+
const path = configs[0]!.includes('/') ? configs[0]!.slice(0, configs[0]!.lastIndexOf('/')) : ''
|
|
1680
|
+
if (!path || !await reachesDirectory(deps, user, repoId, path)) return null
|
|
1681
|
+
try {
|
|
1682
|
+
const contents = { ...await listed(root.commit, path, () => reader.directory(path, root.commit)), path, commit: root.commit }
|
|
1683
|
+
return holdsConfig(contents) ? contents : null
|
|
1684
|
+
} catch (err) {
|
|
1685
|
+
if (err instanceof GithubApiError) return null
|
|
1686
|
+
throw err
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1689
|
+
|
|
1609
1690
|
function scopeRepositoryContents(contents: RepositoryContents | null, virtualEntries: RepositoryEntry[] | null) {
|
|
1610
1691
|
return contents && { ...contents, ...(virtualEntries ? {
|
|
1611
1692
|
entries: virtualEntries, limited: false, configEntryPoints: [], packageEntryPoints: [], solidityEntryPoints: [], soliditySuggestionsLimited: false,
|
|
@@ -1691,6 +1772,9 @@ function answerGithubFailure(res: ServerResponse, err: unknown): void {
|
|
|
1691
1772
|
}
|
|
1692
1773
|
|
|
1693
1774
|
// Recheck repository/path grants after upstream reads, before returning names.
|
|
1775
|
+
// Refs read `withDefault`, as Create a bundle opens a repository, carry its
|
|
1776
|
+
// default branch's root (`defaultContents`) and, where it opens elsewhere,
|
|
1777
|
+
// that directory too (`configContents`, reviewedConfigContents).
|
|
1694
1778
|
async function handleRepositoryBrowser(res: ServerResponse, deps: ManagedHttpDeps, cookie: string | undefined, query: URLSearchParams, refs: boolean): Promise<void> {
|
|
1695
1779
|
const asked = repositoryQuery(res, query)
|
|
1696
1780
|
if (!asked) return
|
|
@@ -1714,6 +1798,7 @@ async function handleRepositoryBrowser(res: ServerResponse, deps: ManagedHttpDep
|
|
|
1714
1798
|
const trees = repositoryTreesOf(deps)
|
|
1715
1799
|
const listedAt: ListedAt = (commit, at, read) => trees.listing(`${repoId}\0${LISTING_READ}\0${commit}\0${at}`, read)
|
|
1716
1800
|
const revisions = refs ? await readRepositoryRefs(deps.db, reader, access.repo, withDefault, access.virtualEntries, listedAt) : null
|
|
1801
|
+
const configContents = withDefault ? await reviewedConfigContents(deps, reader, access.user, repoId, revisions?.defaultContents ?? null, listedAt) : null
|
|
1717
1802
|
const contents = refs ? null : commitOnly ? { path, commit: await reader.commit(ref) } : await readRepositoryContents(reader, ref, path, access.virtualEntries, listedAt)
|
|
1718
1803
|
const { tagCommits, tagsComplete, ...listed } = revisions ?? { tagCommits: [], tagsComplete: false }
|
|
1719
1804
|
// Every refs read (Create a bundle's, and the code viewer's) refreshes the
|
|
@@ -1727,8 +1812,10 @@ async function handleRepositoryBrowser(res: ServerResponse, deps: ManagedHttpDep
|
|
|
1727
1812
|
// This request (or another reader) may have refreshed the shared hint.
|
|
1728
1813
|
const current = await stillAuthorized(res, reader, authorize, access.repo)
|
|
1729
1814
|
if (!current) return
|
|
1815
|
+
// The directory opened in the root's place, where the grants checked again still reach all of it.
|
|
1816
|
+
const opened = configContents && await reachesDirectory(deps, current.user, repoId, configContents.path) ? configContents : null
|
|
1730
1817
|
sendJson(res, 200, refs ? { ...listed, tagCommits, ...(withDefault ? {
|
|
1731
|
-
defaultContents: scopeRepositoryContents(revisions?.defaultContents ?? null, current.virtualEntries),
|
|
1818
|
+
defaultContents: scopeRepositoryContents(revisions?.defaultContents ?? null, current.virtualEntries), ...(opened && { configContents: opened }),
|
|
1732
1819
|
} : {}) } : commitOnly ? contents : scopeRepositoryContents(contents as RepositoryContents, current.virtualEntries))
|
|
1733
1820
|
} catch (err) {
|
|
1734
1821
|
answerGithubFailure(res, err)
|
|
@@ -2901,6 +2988,36 @@ async function handleTeamDependencies(res: ServerResponse, deps: ManagedHttpDeps
|
|
|
2901
2988
|
await out.end()
|
|
2902
2989
|
}
|
|
2903
2990
|
|
|
2991
|
+
// POST /api/teams/:id/dependency-reviews/changed, `{ since, versions:
|
|
2992
|
+
// [[name, version], …] }`: those of `versions`, the npm versions its
|
|
2993
|
+
// Dependencies tab shows, whose reviews, published to a team counting for
|
|
2994
|
+
// any of the team's repositories, were published (to it or to one more
|
|
2995
|
+
// team) or revoked at `since` or after (the `now` an earlier answer told,
|
|
2996
|
+
// the server's time), for the tab to ask again of the pull requests listing
|
|
2997
|
+
// them: `{ now, versions: [[name, version], …] }`; with no `since`, `{ now }`
|
|
2998
|
+
// alone. Only those asked of are told, as many as MAX_CHANGED_ASKED, so it
|
|
2999
|
+
// lists no other team's reviews of packages the team's pull requests lock
|
|
3000
|
+
// none of. A POST of no effect, allowed while viewing as another user.
|
|
3001
|
+
const MAX_CHANGED_ASKED = 5000
|
|
3002
|
+
const MAX_CHANGED_BODY_BYTES = 512 * 1024
|
|
3003
|
+
async function handleTeamReviewChanges(req: IncomingMessage, res: ServerResponse, deps: ManagedHttpDeps, cookie: string | undefined, teamId: string): Promise<void> {
|
|
3004
|
+
const s = await checkMutation(req, res, deps, cookie, { view: true })
|
|
3005
|
+
if (!s) return
|
|
3006
|
+
const body = await readBodyObject(req, res, MAX_CHANGED_BODY_BYTES)
|
|
3007
|
+
if (!body) return
|
|
3008
|
+
const { since = null, versions = [] } = body
|
|
3009
|
+
if ((since !== null && (!Number.isSafeInteger(since) || (since as number) < 0)) || !Array.isArray(versions) || versions.length > MAX_CHANGED_ASKED
|
|
3010
|
+
|| !versions.every(one => Array.isArray(one) && one.length === 2 && isNpmPackageName(one[0]) && isNpmPackageSpec(one[1]))) {
|
|
3011
|
+
sendJson(res, 400, { error: 'bad-request' }); return
|
|
3012
|
+
}
|
|
3013
|
+
const snapshot = await teamSnapshot(deps.db, s.session.id, teamId)
|
|
3014
|
+
const now = Date.now()
|
|
3015
|
+
if (since === null) { sendJson(res, 200, { now }); return }
|
|
3016
|
+
const changed = await deps.db.changedReviewVersions([...new Set(snapshot.repositories.map(repo => repo.repoId))], since as number,
|
|
3017
|
+
(versions as [string, string][]).map(([name, version]) => ({ name, version })))
|
|
3018
|
+
sendJson(res, 200, { now, versions: changed.map(({ name, version }) => [name, version]) })
|
|
3019
|
+
}
|
|
3020
|
+
|
|
2904
3021
|
// A repository's lines of its team's Dependencies, as handleTeamDependencies
|
|
2905
3022
|
// tells them; whether all were written, none left for its time.
|
|
2906
3023
|
async function teamRepositoryDependencies(deps: ManagedHttpDeps, access: WholeAccess, setting: RepoDependencyReview, deadline: number,
|
|
@@ -3443,6 +3560,82 @@ async function riskRepositories(db: ManagedDb, query: URLSearchParams): Promise<
|
|
|
3443
3560
|
})
|
|
3444
3561
|
}
|
|
3445
3562
|
|
|
3563
|
+
// What Stasis reaches of the stasis.config.json at `config` of `repo` at
|
|
3564
|
+
// `commit`, as its dependency review's reader has it (stasisReader): the
|
|
3565
|
+
// same builds, in the same worker, kept the same way. One not kept yet is
|
|
3566
|
+
// asked for with `token`, the reader's own, at no priority over a review's,
|
|
3567
|
+
// told the branch `branch` (none where `''`), whose history holds the
|
|
3568
|
+
// commit; none is waited for. One with no token to build it with fails, as
|
|
3569
|
+
// a review refuses it (readWholeRepositoryOf).
|
|
3570
|
+
async function riskStasis(deps: ManagedHttpDeps, repo: { repoId: number; fullName: string }, token: string | null, commit: string, branch: string,
|
|
3571
|
+
config: string): Promise<StasisRead> {
|
|
3572
|
+
const reader = stasisReader(deps)
|
|
3573
|
+
const read = await reader.read(repo.repoId, commit, config)
|
|
3574
|
+
if (read.status !== 'pending') return read
|
|
3575
|
+
if (!token) return { status: 'failed', error: 'github-token-required', transient: false }
|
|
3576
|
+
reader.build([{ repo: { repoId: repo.repoId, fullName: repo.fullName }, token, commit, config, ...branch ? { branch } : {}, priority: 0 }])
|
|
3577
|
+
return read
|
|
3578
|
+
}
|
|
3579
|
+
|
|
3580
|
+
// GET /api/admin/repositories/risk/stasis?repoId=&commit=&path=…: what
|
|
3581
|
+
// Stasis reaches of the stasis.config.json files at `path`, up to
|
|
3582
|
+
// MAX_RISK_STASIS, of repository `repoId` at `commit`, as a risk scan tells
|
|
3583
|
+
// them (repository-risk-read.ts StasisConfigRow), for its page to ask again
|
|
3584
|
+
// while builds of them are still to be made, every 30 seconds as a dependency
|
|
3585
|
+
// review's page asks: each asked for again (riskStasis), lest it lapse
|
|
3586
|
+
// (stasis-dependencies.ts). For admins, with their own GitHub access, as the
|
|
3587
|
+
// scan reads the repository; a path naming no stasis.config.json in the
|
|
3588
|
+
// commit's tree told so (`no-config`).
|
|
3589
|
+
const MAX_RISK_STASIS = 50
|
|
3590
|
+
async function handleRepositoryRiskStasis(res: ServerResponse, deps: ManagedHttpDeps, cookie: string | undefined, query: URLSearchParams): Promise<void> {
|
|
3591
|
+
const s = await readAdminSession(res, deps, cookie)
|
|
3592
|
+
if (!s) return
|
|
3593
|
+
const commit = query.get('commit') ?? '', paths = query.getAll('path'), repoId = askedRepoId(query)
|
|
3594
|
+
if (repoId === null || !/^[\da-f]{40}$/u.test(commit) || paths.length === 0 || paths.length > MAX_RISK_STASIS || new Set(paths).size < paths.length
|
|
3595
|
+
|| !paths.every(isStasisConfig)) { sendJson(res, 400, { error: 'bad-request' }); return }
|
|
3596
|
+
const repo = (await deps.db.listSelectedRepos()).find(item => item.repoId === repoId)
|
|
3597
|
+
if (!repo) { sendJson(res, 404, { error: 'no-repository' }); return }
|
|
3598
|
+
try {
|
|
3599
|
+
const reader = await repositoryReader(deps, s.user.id, repo)
|
|
3600
|
+
const token = reader.readToken()
|
|
3601
|
+
const tree = await repositoryTree(repo.fullName, token, commit, commitTreeKept(deps, repoId))
|
|
3602
|
+
if (!tree) { sendJson(res, 404, { error: 'no-commit' }); return }
|
|
3603
|
+
const files = new Set(tree.files)
|
|
3604
|
+
sendJson(res, 200, { configs: await Promise.all(paths.map(async path => (files.has(path)
|
|
3605
|
+
? stasisConfigRow(path, await riskStasis(deps, repo, token, commit, reader.defaultBranch, path)) : { path, error: 'no-config' }))) })
|
|
3606
|
+
} catch (err) {
|
|
3607
|
+
if (err instanceof GithubApiError) { sendRefusal(res, githubRefusal(err)); return }
|
|
3608
|
+
throw err
|
|
3609
|
+
}
|
|
3610
|
+
}
|
|
3611
|
+
|
|
3612
|
+
// GET /api/admin/repositories/risk/lockfile?repoId=&commit=&path=: a lockfile
|
|
3613
|
+
// a risk scan reads (locked-packages.ts) at `commit`, for its page to show
|
|
3614
|
+
// what depends on a package in it: its text, and the package.json beside a
|
|
3615
|
+
// yarn.lock, which its reader there takes (null for none). For admins, with
|
|
3616
|
+
// their own GitHub access, as the scan reads the repository.
|
|
3617
|
+
const RISK_LOCKFILE = /^(?:(?!\.\.?\/)[^/]+\/)*(?:package-lock\.json|npm-shrinkwrap\.json|pnpm-lock\.yaml|yarn\.lock)$/u
|
|
3618
|
+
async function handleRepositoryRiskLockfile(res: ServerResponse, deps: ManagedHttpDeps, cookie: string | undefined, query: URLSearchParams): Promise<void> {
|
|
3619
|
+
const s = await readAdminSession(res, deps, cookie)
|
|
3620
|
+
if (!s) return
|
|
3621
|
+
const commit = query.get('commit') ?? '', path = query.get('path') ?? '', repoId = askedRepoId(query)
|
|
3622
|
+
if (repoId === null || !/^[\da-f]{40}$/u.test(commit) || !RISK_LOCKFILE.test(path)) { sendJson(res, 400, { error: 'bad-request' }); return }
|
|
3623
|
+
const repo = (await deps.db.listSelectedRepos()).find(item => item.repoId === repoId)
|
|
3624
|
+
if (!repo) { sendJson(res, 404, { error: 'no-repository' }); return }
|
|
3625
|
+
try {
|
|
3626
|
+
const client = createClient({ token: (await repositoryReader(deps, s.user.id, repo)).readToken() })
|
|
3627
|
+
const file = (at: string) => upstreamGithub(() => client.getRepoFile({ repo: repo.fullName, path: at, ref: commit }))
|
|
3628
|
+
const [text, manifest] = await Promise.all([file(path), path.endsWith('yarn.lock') ? file(path.replace(/yarn\.lock$/u, 'package.json')).catch((err: unknown) => {
|
|
3629
|
+
if (err instanceof GithubApiError && err.status === 404) return null
|
|
3630
|
+
throw err
|
|
3631
|
+
}) : null])
|
|
3632
|
+
sendJson(res, 200, { text, manifest })
|
|
3633
|
+
} catch (err) {
|
|
3634
|
+
if (err instanceof GithubApiError) { sendRefusal(res, githubRefusal(err)); return }
|
|
3635
|
+
throw err
|
|
3636
|
+
}
|
|
3637
|
+
}
|
|
3638
|
+
|
|
3446
3639
|
// Where a scan in parts keeps its progress (repository-risk.ts
|
|
3447
3640
|
// ScanProgress) under `key`, for a day; none where the page gave no scan id.
|
|
3448
3641
|
function scanProgress(deps: ManagedHttpDeps, key: string, scan: string | null) {
|
|
@@ -3463,7 +3656,9 @@ function scanProgress(deps: ManagedHttpDeps, key: string, scan: string | null) {
|
|
|
3463
3656
|
// repository's Dependabot alerts, open or dismissed, read with the App's
|
|
3464
3657
|
// installation token where the admin's own access to it lets them see them on
|
|
3465
3658
|
// GitHub (dependabot-access.ts); and its GitHub Actions, the references they
|
|
3466
|
-
// make resolved with the admin's own GitHub token (github-actions.ts)
|
|
3659
|
+
// make resolved with the admin's own GitHub token (github-actions.ts); and
|
|
3660
|
+
// what Stasis reaches of each of its stasis.config.json files, as its
|
|
3661
|
+
// dependency review has them built (riskStasis). The
|
|
3467
3662
|
// reader leaving, losing their admin role or
|
|
3468
3663
|
// the server shutting down stops it.
|
|
3469
3664
|
async function handleRepositoryRisk(res: ServerResponse, deps: ManagedHttpDeps, cookie: string | undefined, query: URLSearchParams): Promise<void> {
|
|
@@ -3479,7 +3674,7 @@ async function handleRepositoryRisk(res: ServerResponse, deps: ManagedHttpDeps,
|
|
|
3479
3674
|
res.on('close', () => { controller.abort() })
|
|
3480
3675
|
res.setTimeout(REPO_RISK_IDLE_MS, () => res.destroy())
|
|
3481
3676
|
const user = await repositoryBrowserUser(deps, s.user.id)
|
|
3482
|
-
const browser =
|
|
3677
|
+
const browser = repositoryBrowser(deps, user)
|
|
3483
3678
|
const scopes = new Map<string, Promise<boolean>>()
|
|
3484
3679
|
const teamScoped = (name: string) => {
|
|
3485
3680
|
const scope = npmPackageScope(name)
|
|
@@ -3498,7 +3693,8 @@ async function handleRepositoryRisk(res: ServerResponse, deps: ManagedHttpDeps,
|
|
|
3498
3693
|
async open(repo) {
|
|
3499
3694
|
const reader = await browser.reader(repo)
|
|
3500
3695
|
const commit = await reader.commit('')
|
|
3501
|
-
const
|
|
3696
|
+
const token = reader.readToken()
|
|
3697
|
+
const client = createClient({ token })
|
|
3502
3698
|
return {
|
|
3503
3699
|
commit,
|
|
3504
3700
|
lockfiles: async () => (await upstreamGithub(() => client.findRepoLockfiles({ repo: repo.fullName, sha: commit }))).lockfiles,
|
|
@@ -3508,6 +3704,10 @@ async function handleRepositoryRisk(res: ServerResponse, deps: ManagedHttpDeps,
|
|
|
3508
3704
|
dependabot: () => reader.dependabotAlerts(),
|
|
3509
3705
|
workflows: () => reader.directory(WORKFLOWS_DIR, commit).then(({ entries }) => entries.filter(entry => entry.type === 'file' && /\.ya?ml$/iu.test(entry.name)).map(entry => entry.path),
|
|
3510
3706
|
(error: unknown) => { if (error instanceof GithubApiError && error.status === 404) return []; throw error }),
|
|
3707
|
+
// Its files as its tree lists them at the commit, kept by it, as its
|
|
3708
|
+
// dependency review's settings read them (handleRepositoryLockfiles).
|
|
3709
|
+
files: async () => (await repositoryTree(repo.fullName, token, commit, commitTreeKept(deps, repo.repoId)))?.files ?? [],
|
|
3710
|
+
stasis: config => riskStasis(deps, repo, token, commit, reader.defaultBranch, config),
|
|
3511
3711
|
}
|
|
3512
3712
|
},
|
|
3513
3713
|
// References resolved with the admin's token, and each one's advisories
|
|
@@ -3989,14 +4189,14 @@ async function handleUploadBundle(req: IncomingMessage, res: ServerResponse, dep
|
|
|
3989
4189
|
try { rawDirectory = decodeURIComponent(firstHeader(req.headers['x-repo-directory']) ?? '') }
|
|
3990
4190
|
catch { sendJson(res, 400, { error: 'bad-directory' }); return }
|
|
3991
4191
|
if (!existing && repo.repoId == null && kind === 'stasis') {
|
|
3992
|
-
const embedded = await bundleRepo(bytes)
|
|
4192
|
+
const embedded = await bundleRepo(bytes, filename)
|
|
3993
4193
|
const github = reportRepoGithub({ repo: embedded })
|
|
3994
4194
|
const embeddedDirectory = normalizeTeamPath(embedded?.directory)
|
|
3995
4195
|
// Invalid optional metadata must not reject an otherwise unattached bundle.
|
|
3996
4196
|
// Only repository-wide aliases/direct connections can resolve without a
|
|
3997
4197
|
// valid directory; do not decode file paths or match directory aliases.
|
|
3998
4198
|
const location = github == null ? null : embeddedDirectory.ok
|
|
3999
|
-
? await resolveRepositoryImportLocation(deps.db, github, embeddedDirectory.path ?? '', () => bundleFilePrefix(bytes))
|
|
4199
|
+
? await resolveRepositoryImportLocation(deps.db, github, embeddedDirectory.path ?? '', () => bundleFilePrefix(bytes, filename))
|
|
4000
4200
|
: await deps.db.getRepositoryImportLocation(github, '')
|
|
4001
4201
|
if (location?.repoId != null) {
|
|
4002
4202
|
repo.repoId = location.repoId
|
|
@@ -4344,7 +4544,7 @@ async function handleViewReport(req: IncomingMessage, res: ServerResponse, deps:
|
|
|
4344
4544
|
if (data == null) { sendJson(res, 422, { error: 'unreadable-report' }); return }
|
|
4345
4545
|
const links = mergeLinkGroups(snapshot.linkRevision ? await deps.db.getEnabledLinkGroups(snapshot.linkRevision) : [], await reportIds(data))
|
|
4346
4546
|
// Without a finding's `repo` none of ours (common/finding-repo.js isStrayRepo).
|
|
4347
|
-
const ours = ourRepoSlugs([...
|
|
4547
|
+
const ours = ourRepoSlugs([...await ourRepositoryNames(deps.db), access.repo.github])
|
|
4348
4548
|
envelope = { data: withoutStrayRepos(data, ours), repo: access.repo, ...(links.length > 0 ? { links } : {}) }
|
|
4349
4549
|
}
|
|
4350
4550
|
// Link decryption and finding-ID backfill can outlast access or link changes.
|
|
@@ -4385,7 +4585,7 @@ async function handleQueryReports(req: IncomingMessage, res: ServerResponse, dep
|
|
|
4385
4585
|
const reports = new Map(snapshot.reports.map(report => [report.id, report]))
|
|
4386
4586
|
// The repositories that are ours, for a finding's `repo` none of them
|
|
4387
4587
|
// (common/finding-repo.js isStrayRepo), which every report sent leaves out.
|
|
4388
|
-
const selected =
|
|
4588
|
+
const selected = await ourRepositoryNames(deps.db)
|
|
4389
4589
|
if (reports.size !== ids.length) { sendJson(res, 404, { error: 'no-report' }); return }
|
|
4390
4590
|
const storedBytes = snapshot.reports.reduce((total, report) => total + report.byteSize, 0)
|
|
4391
4591
|
if (storedBytes > MAX_REPORT_QUERY_BYTES) { sendJson(res, 413, { error: 'batch-too-large' }); return }
|
|
@@ -5573,7 +5773,7 @@ async function handleWorkspaceShare(req: IncomingMessage, res: ServerResponse, d
|
|
|
5573
5773
|
|
|
5574
5774
|
// The repositories' reads that are GETs of their query alone, by their paths.
|
|
5575
5775
|
const REPOSITORY_QUERY_READS = new Map<string, (res: ServerResponse, deps: ManagedHttpDeps, cookie: string | undefined, query: URLSearchParams) => Promise<void>>([
|
|
5576
|
-
[REPO_RISK_PATH, handleRepositoryRisk], [REPO_CODE_PATH, handleRepositoryCode], [REPO_HISTORY_PATH, handleRepositoryHistory],
|
|
5776
|
+
[REPO_RISK_PATH, handleRepositoryRisk], [REPO_RISK_STASIS_PATH, handleRepositoryRiskStasis], [REPO_RISK_LOCKFILE_PATH, handleRepositoryRiskLockfile], [REPO_CODE_PATH, handleRepositoryCode], [REPO_HISTORY_PATH, handleRepositoryHistory],
|
|
5577
5777
|
[REPO_CHANGES_PATH, handleRepositoryChanges], [REPO_TREE_PATH, handleRepositoryTree], [REPO_ISSUES_PATH, handleRepositoryIssues],
|
|
5578
5778
|
[REPO_AGENTS_PATH, handleRepositoryAgents], [REPO_ITEM_PATH, handleRepositoryItem], [REPO_PULL_DEPENDENCIES_PATH, handleRepositoryPullDependencies],
|
|
5579
5779
|
[REPO_BRANCH_DEPENDENCIES_PATH, handleRepositoryBranchDependencies], [REPO_LOCKFILES_PATH, handleRepositoryLockfiles],
|
|
@@ -5772,6 +5972,10 @@ export function createManagedRequestHandler(deps: ManagedHttpDeps): Handler {
|
|
|
5772
5972
|
if (method !== 'POST') { send405(res, 'POST'); return }
|
|
5773
5973
|
await handleSetReportVisible(req, res, deps, cookie); return
|
|
5774
5974
|
}
|
|
5975
|
+
if (path === REPORT_SET_OPENING_PATH) {
|
|
5976
|
+
if (method !== 'POST') { send405(res, 'POST'); return }
|
|
5977
|
+
await handleSetReportOpening(req, res, deps, cookie); return
|
|
5978
|
+
}
|
|
5775
5979
|
if (path === '/api/admin/reports/finding-ids') {
|
|
5776
5980
|
if (method !== 'GET') { send405(res, 'GET'); return }
|
|
5777
5981
|
await handleImportFindingIds(res, deps, cookie, url.searchParams); return
|
|
@@ -5874,6 +6078,11 @@ export function createManagedRequestHandler(deps: ManagedHttpDeps): Handler {
|
|
|
5874
6078
|
if (method !== 'GET') { send405(res, 'GET'); return }
|
|
5875
6079
|
await handleTeamDependencies(res, deps, cookie, workspaceSession!, teamDependencies[1]!, url.searchParams); return
|
|
5876
6080
|
}
|
|
6081
|
+
const teamReviewChanges = TEAM_REVIEW_CHANGES.exec(path)
|
|
6082
|
+
if (teamReviewChanges) {
|
|
6083
|
+
if (method !== 'POST') { send405(res, 'POST'); return }
|
|
6084
|
+
await handleTeamReviewChanges(req, res, deps, cookie, teamReviewChanges[1]!); return
|
|
6085
|
+
}
|
|
5877
6086
|
const teamFixes = /^\/api\/teams\/([^/]+)\/fixes$/u.exec(path)
|
|
5878
6087
|
if (teamFixes) {
|
|
5879
6088
|
if (method !== 'GET') { send405(res, 'GET'); return }
|
|
@@ -19,10 +19,13 @@ export async function sessionAdmin(db: ManagedSql, sessionId: string): Promise<{
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export type ContentMutation = { type: 'delete' } | { type: 'repo'; repoId: number | null; directory: string } | { type: 'visibility'; visible: boolean }
|
|
22
|
+
// A report's alone: whether it opens on Confirmed whatever Confirmed hides,
|
|
23
|
+
// switched on only where its content offers it (report-opening.ts).
|
|
24
|
+
export type ReportMutation = ContentMutation | { type: 'opening'; confirmedDefault: boolean }
|
|
22
25
|
type RemovalRepo = Pick<ManagedRepo, 'repoId' | 'fullName' | 'addedAt'>
|
|
23
26
|
type RemovalAnnotations = { reports: string; ids: string[] }
|
|
24
27
|
export interface ManagementStore {
|
|
25
|
-
mutateReport(sessionId: string, id: string, change:
|
|
28
|
+
mutateReport(sessionId: string, id: string, change: ReportMutation): Promise<{ report: ReportRecord; user: StoredUser }>
|
|
26
29
|
mutateBundle(sessionId: string, id: string, change: ContentMutation): Promise<{ bundle: ManagedBundle; user: StoredUser }>
|
|
27
30
|
// A repeated upload/build of stored bytes (see reuseBundle). Renames need the
|
|
28
31
|
// access other bundle mutations need; a server build labels the row anyway.
|
|
@@ -33,7 +36,7 @@ export interface ManagementStore {
|
|
|
33
36
|
}
|
|
34
37
|
type ManagementDb = Pick<ManagedDb, 'sessionWithUser' | 'getReport' | 'getBundle' | 'listReports' | 'listReportsForRepo'
|
|
35
38
|
| 'listBundlesForRepo' | 'listAllRepos' | 'listSelectedRepos' | 'userCanReadReport' | 'userCanReadBundle' | 'userCanReadRepoPath'
|
|
36
|
-
| 'deleteReport' | 'setReportRepo' | 'setReportVisible' | 'deleteBundle' | 'setBundleRepo' | 'setBundleVisible' | 'reuseBundle'
|
|
39
|
+
| 'deleteReport' | 'setReportRepo' | 'setReportVisible' | 'setReportConfirmedDefault' | 'deleteBundle' | 'setBundleRepo' | 'setBundleVisible' | 'reuseBundle'
|
|
37
40
|
| 'deleteReportsForRepo' | 'deleteBundlesForRepo' | 'deleteRepo' | 'deleteTriage' | 'recordActivity'>
|
|
38
41
|
|
|
39
42
|
// Only immutable bytes/format and repository membership affect the overlap
|
|
@@ -52,21 +55,24 @@ export function managementMethods(db: ManagementDb): ManagementStore {
|
|
|
52
55
|
if (!roleAtLeast(s.user.role, role)) throw new ManagedMutationError(403, 'forbidden')
|
|
53
56
|
return s.user
|
|
54
57
|
}
|
|
55
|
-
async function destination(user: { id: string; role: string }, change:
|
|
58
|
+
async function destination(user: { id: string; role: string }, change: ReportMutation) {
|
|
56
59
|
if (change.type !== 'repo' || change.repoId === null) return
|
|
57
60
|
if (!(await db.listSelectedRepos()).some(repo => repo.repoId === change.repoId)) throw new ManagedMutationError(400, 'bad-repo')
|
|
58
61
|
if (user.role !== 'admin' && !await db.userCanReadRepoPath(user.id, change.repoId, change.directory)) throw new ManagedMutationError(403, 'repo-forbidden')
|
|
59
62
|
}
|
|
60
63
|
return {
|
|
61
|
-
async mutateReport(sessionId: string, id: string, change:
|
|
64
|
+
async mutateReport(sessionId: string, id: string, change: ReportMutation) {
|
|
62
65
|
const user = await authorize(sessionId, 'manage')
|
|
63
66
|
const report = await db.getReport(id)
|
|
64
67
|
if (!report || (user.role !== 'admin' && report.uploadedBy !== user.id && !await db.userCanReadReport(user.id, id))) throw new ManagedMutationError(404, 'no-report')
|
|
65
68
|
if (user.role !== 'admin' && report.repoId !== null && !await db.userCanReadReport(user.id, id)) throw new ManagedMutationError(403, 'repo-forbidden')
|
|
66
69
|
if (change.type === 'repo' && report.repoEmbedded) throw new ManagedMutationError(409, 'repo-in-report')
|
|
70
|
+
// Off is always allowed, even of one whose content no longer offers it.
|
|
71
|
+
if (change.type === 'opening' && change.confirmedDefault && report.confirmedOffered !== true) throw new ManagedMutationError(409, 'not-offered')
|
|
67
72
|
if (change.type !== 'visibility') await destination(user, change)
|
|
68
73
|
if (change.type === 'delete') await db.deleteReport(id)
|
|
69
74
|
else if (change.type === 'visibility') await db.setReportVisible(id, change.visible)
|
|
75
|
+
else if (change.type === 'opening') await db.setReportConfirmedDefault(id, change.confirmedDefault)
|
|
70
76
|
else await db.setReportRepo(id, change.repoId, change.directory)
|
|
71
77
|
return { report, user }
|
|
72
78
|
},
|
|
@@ -62,7 +62,7 @@ function texts(files: NpmPackageFile[] | null) {
|
|
|
62
62
|
let length = 0
|
|
63
63
|
const binaries: NpmPackageFile[] = []
|
|
64
64
|
const read = (files ?? []).flatMap(file => {
|
|
65
|
-
const text = npmFileText(file.bytes)
|
|
65
|
+
const text = file.link === undefined ? npmFileText(file.bytes) : null
|
|
66
66
|
if (text === null) { binaries.push(file); return [] }
|
|
67
67
|
length += text.length
|
|
68
68
|
return [[file.path, text] as [string, string]]
|