@vltpkg/audit
@vltpkg/audit
The security audit behind vlt audit: which security alerts a package
is reported for and how severe they are, the search for a version that
fixes them, the remediation lines, the audit result, its human and
JSON views, and the audit of an installed project.
Usage
Audit a project vlt installed, as vlt audit does:
import {
auditFails,
auditProject,
formatAuditSummary,
} from '@vltpkg/audit'
// `options` are the config options vlt loads: `projectRoot`,
// `packageJson`, `scurry`, `monorepo`, the registries, …
const result = await auditProject({
...options,
auditLevel: 'low',
signal: new AbortController().signal,
warn: message => console.error(message),
})
console.log(formatAuditSummary(result))
if (auditFails(result)) process.exitCode = 1auditGraph audits packages of a graph you have already loaded. With
remediation: true, either one looks fixes up in the registry and the
security feed for the remediation lines.
The building blocks work on a graph and security data of your own:
import { baseDepID } from '@vltpkg/dep-id'
import { Query } from '@vltpkg/query'
import { SecurityArchive } from '@vltpkg/security-archive'
import {
auditFails,
auditQuery,
buildAuditResult,
formatAuditSummary,
} from '@vltpkg/audit'
// `graph` is a graph loaded with @vltpkg/graph, e.g. `actual.load()`
const nodes = [...graph.nodes.values()]
const archive = await SecurityArchive.start({ nodes })
const query = new Query({
nodes: new Set(nodes),
edges: graph.edges,
importers: graph.importers,
securityArchive: archive,
})
const { nodes: matched } = await query.search(auditQuery, {
signal: new AbortController().signal,
})
const result = buildAuditResult({
auditLevel: 'low',
importers: graph.importers,
nodes,
flagged: new Set(matched.map(node => baseDepID(node.id))),
archive,
})
console.log(formatAuditSummary(result))
if (auditFails(result)) process.exitCode = 1For remediation lines there, pass
targets: await findFixTargets({ ...sameOptions, lookup }), where
lookup is a FixLookup that answers from the registry and the
security feed.