@preventive/triage 1.0.0-alpha.70 → 1.0.0-alpha.72
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/managed/directory-packages.ts +28 -0
- package/out/activity.js +4 -4
- package/out/{chunk-GTMTGYPT.js → chunk-27Y75UQR.js} +1 -1
- package/out/chunk-4LZK6C6N.js +11 -0
- package/out/chunk-4XSH6ZLT.js +1 -0
- package/out/{chunk-QPGM3DTI.js → chunk-7CHIFYQW.js} +1 -1
- package/out/chunk-7YFJUT2P.js +1 -0
- package/out/chunk-CZ3U2LI4.js +2 -0
- package/out/chunk-ETL5ZPPR.js +259 -0
- package/out/{chunk-45J7357T.js → chunk-L6VIWL2Y.js} +1 -1
- package/out/{chunk-MPXVKVPF.js → chunk-OSHR3N4S.js} +1 -1
- package/out/chunk-PQPKHAI5.js +15 -0
- package/out/chunk-UD33S2MG.js +52 -0
- package/out/{chunk-GZ46SSTF.js → chunk-WKFBZYJX.js} +1 -1
- package/out/client-managed.js +28 -27
- package/out/compare.js +13 -15
- package/out/dialogs.js +28 -28
- package/out/graph.js +1 -1
- package/out/index.html +6 -6
- package/out/scan.js +2 -2
- package/out/terminal.js +1 -1
- package/out/view.css +1 -1
- package/out/view.js +11 -11
- package/package.json +3 -1
- package/risk/actions/resolve.js +9 -3
- package/risk/files/characters.js +11 -0
- package/risk/files/source-map-link.js +43 -0
- package/risk/npm/compare.js +4 -26
- package/server-managed/bundle-advisory-inventory.ts +9 -1
- package/server-managed/bundle-build-worker.js +5 -2
- package/server-managed/bundle-cache.ts +1 -1
- package/server-managed/bundle-dependency-reviews.ts +11 -4
- package/server-managed/http.ts +111 -57
- package/server-managed/locked-packages.ts +9 -4
- package/server-managed/npm-delta.ts +16 -1
- package/server-managed/npm-kept.ts +6 -0
- package/server-managed/pull-dependencies.ts +5 -2
- package/server-managed/pull-dependency-reviews.ts +22 -8
- package/server-managed/repository-issues.ts +15 -9
- package/server-managed/stasis-dependencies.ts +7 -4
- package/out/chunk-2HGKTQ5Q.js +0 -52
- package/out/chunk-7GJNLCXF.js +0 -15
- package/out/chunk-CGRIZ5M5.js +0 -1
- package/out/chunk-D6NVKGGG.js +0 -10
- package/out/chunk-MQ4HT75S.js +0 -247
- package/out/chunk-NB4JBTKK.js +0 -2
- package/out/chunk-VFWMQ3LG.js +0 -2
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.72",
|
|
4
4
|
"description": "Client & relay server for triaging of automated reports",
|
|
5
5
|
"license": "MIT OR Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -296,6 +296,7 @@
|
|
|
296
296
|
"common/linked-workspace-groups.js",
|
|
297
297
|
"common/managed/agent-tasks.ts",
|
|
298
298
|
"common/managed/comments.ts",
|
|
299
|
+
"common/managed/directory-packages.ts",
|
|
299
300
|
"common/managed/finding-detail.d.ts",
|
|
300
301
|
"common/managed/finding-detail.js",
|
|
301
302
|
"common/managed/finding-values.d.ts",
|
|
@@ -340,6 +341,7 @@
|
|
|
340
341
|
"risk/files/readability.js",
|
|
341
342
|
"risk/files/runs-code.js",
|
|
342
343
|
"risk/files/script.js",
|
|
344
|
+
"risk/files/source-map-link.js",
|
|
343
345
|
"risk/files/stamps.js",
|
|
344
346
|
"risk/npm/assess.js",
|
|
345
347
|
"risk/npm/combined.js",
|
package/risk/actions/resolve.js
CHANGED
|
@@ -189,13 +189,19 @@ const RATED = new Set(['critical', 'high', 'moderate', 'low'])
|
|
|
189
189
|
// finding: malware red, else as its source rates it, one unrated yellow. One
|
|
190
190
|
// not known public is `internal`, asked of its own advisories alone, its name
|
|
191
191
|
// sent to no other source; why not (`advisories-unavailable`) where they
|
|
192
|
-
// couldn't be had, the rest resolved all the same.
|
|
192
|
+
// couldn't be had, the rest resolved all the same. Each with what tells it
|
|
193
|
+
// apart, as its row's tooltip shows it: its source, other ids, CVSS score,
|
|
194
|
+
// CWEs, the range it affects, whether its source rates it (`unrated`) and,
|
|
195
|
+
// where it is no vulnerability as such, what it is (`informational`); not
|
|
196
|
+
// its text, which its link has.
|
|
193
197
|
async function advisoryFindings(source, info, versions) {
|
|
194
198
|
if (source.advisories === undefined) return []
|
|
195
199
|
try {
|
|
196
|
-
return (await source.advisories(info.fullName, versions, info.private ?? true)).map(({ id, title, url, severity, malware, versions: affected
|
|
200
|
+
return (await source.advisories(info.fullName, versions, info.private ?? true)).map(({ id, title, url, severity, malware, versions: affected, source: from,
|
|
201
|
+
aliases, cvss, cwe, range, informational }) => ({
|
|
197
202
|
id: 'advisory', severity: malware ? 'critical' : RATED.has(severity) ? severity : 'moderate', advisory: id, ...title && { title }, ...url && { url },
|
|
198
|
-
...malware && { malware: true }, versions: affected })
|
|
203
|
+
...malware && { malware: true }, ...!malware && !RATED.has(severity) && { unrated: true }, versions: affected, ...from && { source: from }, ...aliases?.length && { aliases }, ...Number.isFinite(cvss) && { cvss },
|
|
204
|
+
...cwe?.length && { cwe }, ...range && { range }, ...informational && { informational } }))
|
|
199
205
|
} catch { return [{ id: 'advisories-unavailable', severity: 'notice' }] }
|
|
200
206
|
}
|
|
201
207
|
|
package/risk/files/characters.js
CHANGED
|
@@ -14,6 +14,17 @@
|
|
|
14
14
|
export const CONTROLS = /(?![\t\n\r])\p{Cc}|[\u202A-\u202E\u2066-\u2069]/gu
|
|
15
15
|
const NON_ASCII = /\P{ASCII}/u
|
|
16
16
|
|
|
17
|
+
// What shows as nothing, or as another character, where a viewer draws it as
|
|
18
|
+
// text: the controls but tab and line feed (C0, DEL, C1), the format
|
|
19
|
+
// characters (Cf: zero-width ones, the bidi controls, tags), lone surrogates
|
|
20
|
+
// (Cs; `u` reads a pair as the one character it spells), private use (Co) and
|
|
21
|
+
// unassigned (Cn) code points, the line and paragraph separators, spaces other
|
|
22
|
+
// than a space, the default-ignorable characters and the Braille blank. A code
|
|
23
|
+
// viewer boxes each (ui/view/control-chars.js), and a source map's listing
|
|
24
|
+
// writes a line holding one as JSON (common/sourcemap-listing.js).
|
|
25
|
+
// eslint-disable-next-line no-control-regex
|
|
26
|
+
export const UNSEEN = /[\u0000-\u0008\u000B-\u001F\u007F-\u009F\u00A0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u2800\u3000\p{Cf}\p{Cs}\p{Co}\p{Cn}\p{Default_Ignorable_Code_Point}]/u
|
|
27
|
+
|
|
17
28
|
// A file's text: `kind` 'ascii' or 'utf8', by whether it holds anything past
|
|
18
29
|
// ASCII, else 'binary' (which the server tells by its bytes, sending no
|
|
19
30
|
// text); `controls` the control and invisible characters a text holds, how
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// How a built file names its source map, and what a source map is: read
|
|
2
|
+
// alike where a version's map is told rebuilt with its file (npm/compare.js
|
|
3
|
+
// rebuiltWithMap) and where a map's listing is of the file beside it that
|
|
4
|
+
// names it (common/pretty-sourcemap.js).
|
|
5
|
+
|
|
6
|
+
// A `sourceMappingURL` comment and no more, on a file's last line.
|
|
7
|
+
const SOURCE_MAP_FILE = /^\s*(?:\/\/[#@] sourceMappingURL=(\S+)|\/\*[#@] sourceMappingURL=(\S+?)\s*\*\/)\s*$/u
|
|
8
|
+
// A map name a build writes (`a.js.map`, `../maps/a.map`): segments of
|
|
9
|
+
// letters, digits and `._~@+-`, as a browser reads them alike. One at a URL,
|
|
10
|
+
// from a site's root, or with an escape or a backslash names none.
|
|
11
|
+
const MAP_NAME = /^(?:[\w.~@+-]+\/)*[\w.~@+-]+\.map$/u
|
|
12
|
+
|
|
13
|
+
// The map a file's text names on its last line by a plain path from the
|
|
14
|
+
// file's own (MAP_NAME), or null: none named, or one named otherwise (a data:
|
|
15
|
+
// URL, a site's).
|
|
16
|
+
export function mapNamed(text) {
|
|
17
|
+
if (typeof text !== 'string') return null
|
|
18
|
+
const trimmed = text.trimEnd()
|
|
19
|
+
const directive = SOURCE_MAP_FILE.exec(trimmed.slice(trimmed.lastIndexOf('\n') + 1))
|
|
20
|
+
const name = directive?.[1] ?? directive?.[2]
|
|
21
|
+
return name && MAP_NAME.test(name) ? name : null
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// The path `name` names from beside `file`, or null for one above the root.
|
|
25
|
+
export function besideFile(file, name) {
|
|
26
|
+
const parts = file.split('/').slice(0, -1)
|
|
27
|
+
for (const part of name.split('/')) {
|
|
28
|
+
if (part === '..' && parts.length === 0) return null
|
|
29
|
+
if (part === '..') parts.pop()
|
|
30
|
+
else if (part !== '.') parts.push(part)
|
|
31
|
+
}
|
|
32
|
+
return parts.join('/')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Whether a text is a source map: JSON with `mappings`, or each of an
|
|
36
|
+
// indexed map's `sections` with its own.
|
|
37
|
+
export function isSourceMap(text) {
|
|
38
|
+
try {
|
|
39
|
+
const json = JSON.parse(text)
|
|
40
|
+
return typeof json?.mappings === 'string'
|
|
41
|
+
|| (Array.isArray(json?.sections) && json.sections.length > 0 && json.sections.every(section => typeof section?.map?.mappings === 'string'))
|
|
42
|
+
} catch { return false }
|
|
43
|
+
}
|
package/risk/npm/compare.js
CHANGED
|
@@ -13,6 +13,7 @@ import { npmHostFinding } from './held.js'
|
|
|
13
13
|
import { HOST_TAGS, npmHostSeverity, npmHostsTagged } from '../files/hosts.js'
|
|
14
14
|
import { npmBecameUnreadable, npmBinaryCode, npmLargeCode, npmUnreadable } from '../files/readability.js'
|
|
15
15
|
import { npmIsScript } from '../files/script.js'
|
|
16
|
+
import { besideFile, isSourceMap, mapNamed } from '../files/source-map-link.js'
|
|
16
17
|
import { SEVERITIES } from '../files/stamps.js'
|
|
17
18
|
import { CREDENTIAL_TAGS, npmFoundAdded, npmRunsCodeFlags, npmRunsCodeTagged, npmRunsCodeWithout } from '../files/runs-code.js'
|
|
18
19
|
import { npmDependencySpecs } from './dependencies.js'
|
|
@@ -126,40 +127,17 @@ function npmMajorRelease(was, now) {
|
|
|
126
127
|
// Whether the open version's file at `path` (`basePath` in the one compared
|
|
127
128
|
// with) had its source map rebuilt with it: its last line, a
|
|
128
129
|
// `sourceMappingURL` comment and no more, names a map file of the package by
|
|
129
|
-
// a plain path from the file's own (
|
|
130
|
+
// a plain path from the file's own (source-map-link.js mapNamed), a source map
|
|
130
131
|
// (its `mappings`, or each of an indexed map's `sections`, told), new or
|
|
131
132
|
// changed from the one at its path, or beside the file's own before it was
|
|
132
133
|
// renamed, as a build writes them together. An attack editing a built file
|
|
133
134
|
// leaves its map as it was.
|
|
134
|
-
const SOURCE_MAP_FILE = /^\s*(?:\/\/[#@] sourceMappingURL=(\S+)|\/\*[#@] sourceMappingURL=(\S+?)\s*\*\/)\s*$/u
|
|
135
|
-
// A map name a build writes (`a.js.map`, `../maps/a.map`): segments of
|
|
136
|
-
// letters, digits and `._~@+-`, as a browser reads them alike. One at a URL,
|
|
137
|
-
// from a site's root, or with an escape or a backslash names none.
|
|
138
|
-
const MAP_NAME = /^(?:[\w.~@+-]+\/)*[\w.~@+-]+\.map$/u
|
|
139
|
-
function besideFile(file, name) {
|
|
140
|
-
const parts = file.split('/').slice(0, -1)
|
|
141
|
-
for (const part of name.split('/')) {
|
|
142
|
-
if (part === '..' && parts.length === 0) return null
|
|
143
|
-
if (part === '..') parts.pop()
|
|
144
|
-
else if (part !== '.') parts.push(part)
|
|
145
|
-
}
|
|
146
|
-
return parts.join('/')
|
|
147
|
-
}
|
|
148
135
|
function rebuiltWithMap(base, other, path, basePath) {
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
const name = directive?.[1] ?? directive?.[2]
|
|
152
|
-
if (!name || !MAP_NAME.test(name)) return false
|
|
136
|
+
const name = mapNamed(bundleFilesAsMap(other).get(path))
|
|
137
|
+
if (!name) return false
|
|
153
138
|
const [map, was] = [bundleFilesAsMap(other).get(besideFile(path, name)), bundleFilesAsMap(base)]
|
|
154
139
|
return isSourceMap(map) && map !== was.get(besideFile(path, name)) && map !== was.get(besideFile(basePath, name))
|
|
155
140
|
}
|
|
156
|
-
const isSourceMap = text => {
|
|
157
|
-
try {
|
|
158
|
-
const json = JSON.parse(text)
|
|
159
|
-
return typeof json?.mappings === 'string'
|
|
160
|
-
|| (Array.isArray(json?.sections) && json.sections.length > 0 && json.sections.every(section => typeof section?.map?.mappings === 'string'))
|
|
161
|
-
} catch { return false }
|
|
162
|
-
}
|
|
163
141
|
|
|
164
142
|
// The files become unreadable as a finding says them: red, but orange in a
|
|
165
143
|
// major release, or where each had its source map rebuilt with it.
|
|
@@ -2,6 +2,7 @@ import { isEvidenceFile } from '@exodus/stasis/audit-corrections'
|
|
|
2
2
|
import { packageRepo } from '@exodus/stasis-core/bundle-util'
|
|
3
3
|
import type { Package } from '@preventive/upstream/advisories.js'
|
|
4
4
|
import type { BundleDetails } from '../common/bundle-metadata.js'
|
|
5
|
+
import { MALFORMED_DIRECTORY_PACKAGE, isDirectoryEcosystem, malformedDirectoryPackage } from '../common/managed/directory-packages.ts'
|
|
5
6
|
|
|
6
7
|
interface SkippedAdvisoryPackage {
|
|
7
8
|
ecosystem: string
|
|
@@ -10,7 +11,7 @@ interface SkippedAdvisoryPackage {
|
|
|
10
11
|
because: string
|
|
11
12
|
}
|
|
12
13
|
export interface BundleAdvisoryInventory { packages: Package[]; skipped: SkippedAdvisoryPackage[] }
|
|
13
|
-
interface BundleModule { ecosystem?: string; name?: string; version?: string; repo?: { github?: Package['github'] }; files: Record<string, unknown> }
|
|
14
|
+
interface BundleModule { ecosystem?: string; name?: string; version?: string; integrity?: string; directory?: string; repo?: { github?: Package['github'] }; files: Record<string, unknown> }
|
|
14
15
|
|
|
15
16
|
// The GitHub repository a bundled package.json's text names, read as Stasis
|
|
16
17
|
// records a dependency's (packageRepo) and as Node reads the file, past a byte
|
|
@@ -46,6 +47,13 @@ export function bundleAdvisoryInventory(details: BundleDetails, paths: Iterable<
|
|
|
46
47
|
const { name, version } = info
|
|
47
48
|
if (ecosystem === undefined || typeof name !== 'string' || !name || typeof version !== 'string' || !version) continue
|
|
48
49
|
if (!Object.keys(info.files).some(file => (!selected || selected.has(`${dir}/${file}`)) && isEvidenceFile(name, version, file, ecosystem))) continue
|
|
50
|
+
// One installed from a directory is the repository's own code, neither
|
|
51
|
+
// audited nor reviewed as a dependency; one whose record isn't as Stasis
|
|
52
|
+
// records one is skipped, its bundle's dependency review failing.
|
|
53
|
+
if (isDirectoryEcosystem(ecosystem)) {
|
|
54
|
+
if (malformedDirectoryPackage(info)) skipped.set(JSON.stringify([ecosystem, name, version]), { ecosystem, name, version, because: MALFORMED_DIRECTORY_PACKAGE })
|
|
55
|
+
continue
|
|
56
|
+
}
|
|
49
57
|
const because = skipReason(ecosystem, version)
|
|
50
58
|
if (!supported(ecosystem) || because !== undefined) {
|
|
51
59
|
skipped.set(JSON.stringify([ecosystem, name, version]), { ecosystem, name, version, because: because ?? `No advisory source is supported for ${ecosystem}.` })
|
|
@@ -10,6 +10,7 @@ import { brotliOptions } from '@exodus/stasis-core/brotli'
|
|
|
10
10
|
import { LOCK_FILE, dependencyEcosystem, integrityHex } from '@exodus/stasis-core/util'
|
|
11
11
|
import { HttpError, createClient } from '@preventive/upstream/github.js'
|
|
12
12
|
import { githubBundleFilename } from './bundle-build.ts'
|
|
13
|
+
import { isDirectoryPackage } from '../common/managed/directory-packages.ts'
|
|
13
14
|
import { bundleBuildDiagnostic } from './bundle-build-diagnostics.js'
|
|
14
15
|
import { MAX_STASIS_CONFIG_BYTES, STASIS_CONFIG, namesLockfiles, parseStasisConfig } from './stasis-config.ts'
|
|
15
16
|
|
|
@@ -189,12 +190,14 @@ export async function buildStasisBundle({ input, github, token, maxBytes, scopes
|
|
|
189
190
|
// The npm package versions a Stasis lockfile holds code of (an evidence
|
|
190
191
|
// file, by Stasis's audit rule), each once as it was installed: with its
|
|
191
192
|
// tarball's integrity and, patched, pnpm's hash of its patch (a sha256 in
|
|
192
|
-
// hex, as pnpm's lockfile names it), where the lockfile attests them.
|
|
193
|
+
// hex, as pnpm's lockfile names it), where the lockfile attests them. One
|
|
194
|
+
// installed from a directory, the repository's own code, is none of them;
|
|
195
|
+
// one whose record tells it malformed fails the build (isDirectoryPackage).
|
|
193
196
|
export function lockfileDependencies(lockfile) {
|
|
194
197
|
const found = new Map()
|
|
195
198
|
for (const [dir, info] of lockfile.modules) {
|
|
196
199
|
const { name, version } = info
|
|
197
|
-
if (dir === '.' || dependencyEcosystem(dir, info.ecosystem) !== 'npm' || typeof name !== 'string' || !name || typeof version !== 'string' || !version) continue
|
|
200
|
+
if (dir === '.' || isDirectoryPackage(info) || dependencyEcosystem(dir, info.ecosystem) !== 'npm' || typeof name !== 'string' || !name || typeof version !== 'string' || !version) continue
|
|
198
201
|
if (!Object.keys(info.files).some(file => isEvidenceFile(name, version, file, 'npm'))) continue
|
|
199
202
|
const patch = typeof info.patch?.integrity === 'string' ? integrityHex(info.patch.integrity) : undefined
|
|
200
203
|
const one = { name, version, ...(typeof info.integrity === 'string' && { integrity: info.integrity }), ...(patch && { patch }) }
|
|
@@ -46,7 +46,7 @@ export interface BundleCacheStorage {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
const filename = `v${BUNDLE_METADATA_VERSION}-metadata.json.br`
|
|
49
|
-
const packagesFilename = '
|
|
49
|
+
const packagesFilename = 'v8-advisory-inventory.json'
|
|
50
50
|
|
|
51
51
|
// An entry point's inventory is rows of the bundle's own, a package's versions
|
|
52
52
|
// in order and then the skipped: kept as a 0 or 1 for each, since spelled out,
|
|
@@ -46,9 +46,15 @@ const lockedAsInstalled = (one: BundledVersion, pkg: LockedPackage) => one.integ
|
|
|
46
46
|
|
|
47
47
|
// The versions `bundled` as `read`'s lockfiles lock them (`locked`), each as
|
|
48
48
|
// the nearest of their directories locking it locks it; one told with how it
|
|
49
|
-
// was installed, as the nearest locking it so does, where one does.
|
|
50
|
-
//
|
|
51
|
-
//
|
|
49
|
+
// was installed, as the nearest locking it so does, where one does. One a
|
|
50
|
+
// lockfile installs from a directory of the project's own by no version, as
|
|
51
|
+
// pnpm's does, is locked by its name alone, where none there locks it by its
|
|
52
|
+
// version: a bundle holds it by its package.json's, with no integrity, as
|
|
53
|
+
// Stasis before it tagged one `npm:directory`
|
|
54
|
+
// (common/managed/directory-packages.ts) records it; one installed from an
|
|
55
|
+
// archive, told with its integrity, never so. With those none lock
|
|
56
|
+
// (`unlocked`), how many versions there are (`versions`), and the
|
|
57
|
+
// lockfiles' paths, the nearest first.
|
|
52
58
|
export function lockedVersions(bundled: BundledVersion[], read: CommitLockfiles) {
|
|
53
59
|
const byDirectory = Map.groupBy(read.lockfiles.map(({ path }) => path), directoryOf)
|
|
54
60
|
// Each directory's versions by their name and version, the nearest first.
|
|
@@ -58,7 +64,8 @@ export function lockedVersions(bundled: BundledVersion[], read: CommitLockfiles)
|
|
|
58
64
|
const unlocked = new Map<string, BundledVersion>()
|
|
59
65
|
for (const one of bundled) {
|
|
60
66
|
const key = `${one.name}@${one.version}`
|
|
61
|
-
const
|
|
67
|
+
const directory = (locked: Map<string, LockedPackage[]>) => one.integrity === undefined ? locked.get(`${one.name}@`)?.filter(pkg => pkg.source === 'file') : undefined
|
|
68
|
+
const locking = nearest.flatMap(({ locked }) => { const locks = locked.get(key) ?? directory(locked); return locks?.length ? [locks] : [] })
|
|
62
69
|
const variants = locking.map(locks => locks.filter(pkg => lockedAsInstalled(one, pkg))).find(locks => locks.length > 0) ?? locking[0]
|
|
63
70
|
if (!variants) { unlocked.set(key, { name: one.name, version: one.version }); continue }
|
|
64
71
|
for (const pkg of variants) if (!found.has(lockedWith(pkg))) found.set(lockedWith(pkg), pkg)
|