@clear-capabilities/agentic-security-scanner 0.168.0 → 0.170.0
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/CHANGELOG.md +74 -0
- package/bin/agentic-security.js +567 -0
- package/dist/2199.index.js +1 -1
- package/dist/2675.index.js +174 -0
- package/dist/2923.index.js +369 -1
- package/dist/4142.index.js +6 -6
- package/dist/4700.index.js +151 -0
- package/dist/5014.index.js +2 -2
- package/dist/5086.index.js +645 -0
- package/dist/5144.index.js +2 -2
- package/dist/5206.index.js +32 -0
- package/dist/642.index.js +197 -0
- package/dist/6447.index.js +131 -0
- package/dist/6645.index.js +87 -0
- package/dist/6730.index.js +2 -2
- package/dist/6932.index.js +2 -2
- package/dist/7055.index.js +369 -0
- package/dist/7232.index.js +24 -0
- package/dist/7552.index.js +2 -2
- package/dist/7952.index.js +301 -0
- package/dist/8714.index.js +2 -2
- package/dist/9102.index.js +110 -0
- package/dist/9800.index.js +1 -1
- package/dist/agentic-security.mjs +2 -2
- package/dist/agentic-security.mjs.sha256 +1 -1
- package/package.json +3 -3
- package/src/artifact/CLAUDE.md +100 -0
- package/src/artifact/filesystem.js +100 -0
- package/src/artifact/image-archive.js +159 -0
- package/src/artifact/inventory.js +69 -0
- package/src/artifact/layer-secrets.js +92 -0
- package/src/artifact/mismatch.js +72 -0
- package/src/artifact/provenance-graph.js +115 -0
- package/src/artifact/safe-tar.js +175 -0
- package/src/artifact/signature.js +156 -0
- package/src/artifact/vex.js +94 -0
- package/src/artifact/vuln-correlate.js +17 -0
- package/src/lineage/CLAUDE.md +19 -0
- package/src/lineage/observation-adapters.js +368 -0
- package/src/lineage/runtime-assurance.js +135 -0
- package/src/lineage/runtime-observation.js +37 -4
- package/src/posture/artifact-registry.js +8 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// PRD 5 P0 §7 — Source vs Artifact Mismatch. This is the PRD's own "Killer
|
|
2
|
+
// Demonstration": a developer fixes a vulnerability in source on Monday, but
|
|
3
|
+
// production is still serving Friday's image.
|
|
4
|
+
//
|
|
5
|
+
// Scenario A — "Git: fixed / Production image: vulnerable": an OSV advisory
|
|
6
|
+
// the DEPLOYED ARTIFACT's own vuln-correlate.js result reports against the
|
|
7
|
+
// version it actually has installed, that the CURRENT source scan does NOT
|
|
8
|
+
// report against the version source has installed/declared — i.e. source
|
|
9
|
+
// has moved past this specific advisory (patched, upgraded) but the
|
|
10
|
+
// artifact's installed version has not.
|
|
11
|
+
//
|
|
12
|
+
// Scenario B — "Git: vulnerable / Built artifact: affected component
|
|
13
|
+
// absent": the current source scan flags an advisory against some package,
|
|
14
|
+
// but that PACKAGE (by ecosystem+name, independent of version) is not
|
|
15
|
+
// present anywhere in the artifact's own component inventory at all — a
|
|
16
|
+
// dev-only/optional dependency that never actually shipped in this build.
|
|
17
|
+
//
|
|
18
|
+
// The matching key for a scenario-A/B pair is the OSV advisory id ALONE
|
|
19
|
+
// (`osvId`) — never the purl, which bakes the VERSION into the key. Keying
|
|
20
|
+
// on purl was tried first and is wrong: source and artifact are, by this
|
|
21
|
+
// comparison's entire premise, usually running DIFFERENT versions of the
|
|
22
|
+
// same package, so a purl-based key would make every version difference
|
|
23
|
+
// look like two independent mismatches instead of comparing "does this
|
|
24
|
+
// specific advisory affect each side's own installed version". An OSV
|
|
25
|
+
// advisory id already uniquely identifies one vulnerability against one
|
|
26
|
+
// package, so comparing by id alone correctly asks "is THIS advisory
|
|
27
|
+
// present on one side and absent on the other", regardless of which exact
|
|
28
|
+
// version is installed on either side.
|
|
29
|
+
//
|
|
30
|
+
// Pure comparison only — no new detection. `sourceVulnerabilities` is the
|
|
31
|
+
// output of a normal source-tree SCA scan (queryOSV-shaped `vulnerable_dep`
|
|
32
|
+
// entries); `artifactVulnerabilities`/`artifactComponents` are
|
|
33
|
+
// vuln-correlate.js's/inventory.js's output for one specific image.
|
|
34
|
+
function advisoryKey(v) {
|
|
35
|
+
return v.osvId || `no-osv-id:${v.ecosystem}:${v.name}`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function packageIdentity(c) {
|
|
39
|
+
return `${c.ecosystem}:${c.name}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function detectSourceArtifactMismatch({ sourceVulnerabilities, artifactVulnerabilities, artifactComponents }) {
|
|
43
|
+
if (!Array.isArray(sourceVulnerabilities) || !Array.isArray(artifactVulnerabilities) || !Array.isArray(artifactComponents)) {
|
|
44
|
+
throw new TypeError('detectSourceArtifactMismatch requires sourceVulnerabilities/artifactVulnerabilities/artifactComponents arrays');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const sourceKeyed = new Map();
|
|
48
|
+
for (const v of sourceVulnerabilities) {
|
|
49
|
+
if (v.type && v.type !== 'vulnerable_dep') continue;
|
|
50
|
+
sourceKeyed.set(advisoryKey(v), v);
|
|
51
|
+
}
|
|
52
|
+
const artifactKeyed = new Map();
|
|
53
|
+
for (const v of artifactVulnerabilities) {
|
|
54
|
+
if (v.type && v.type !== 'vulnerable_dep') continue;
|
|
55
|
+
artifactKeyed.set(advisoryKey(v), v);
|
|
56
|
+
}
|
|
57
|
+
const artifactPackageIdentities = new Set(artifactComponents.map(packageIdentity));
|
|
58
|
+
|
|
59
|
+
const scenarioA = [...artifactKeyed.entries()]
|
|
60
|
+
.filter(([key]) => !sourceKeyed.has(key))
|
|
61
|
+
.map(([, v]) => v);
|
|
62
|
+
|
|
63
|
+
const scenarioB = [...sourceKeyed.entries()]
|
|
64
|
+
.filter(([, v]) => !artifactPackageIdentities.has(packageIdentity(v)))
|
|
65
|
+
.map(([, v]) => v);
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
scenarioA,
|
|
69
|
+
scenarioB,
|
|
70
|
+
hasMismatch: scenarioA.length > 0 || scenarioB.length > 0,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// PRD 5 P0 §6 — Provenance Graph: Git Commit -> Build -> OCI Digest -> SBOM
|
|
2
|
+
// Component -> Finding -> Deployment.
|
|
3
|
+
//
|
|
4
|
+
// Naming: the exported field is `artifactProvenanceGraph` and the builder is
|
|
5
|
+
// `buildArtifactProvenanceGraph` — never a bare `.provenance`/`*Provenance`,
|
|
6
|
+
// per this repo's own naming discipline (5 unrelated existing uses of
|
|
7
|
+
// "provenance"; see docs/implementation-status/source-to-artifact-provenance.md).
|
|
8
|
+
//
|
|
9
|
+
// This function does no new detection — every node/edge is assembled from
|
|
10
|
+
// evidence `inventory.js`/`vuln-correlate.js` already computed. The one
|
|
11
|
+
// exception is the Git-Commit edge, whose only evidence source is the
|
|
12
|
+
// standard `org.opencontainers.image.revision` build label; when absent the
|
|
13
|
+
// commit node is explicitly `known: false`, never inferred from git history
|
|
14
|
+
// (an image's build label is the only trustworthy claim of "which commit
|
|
15
|
+
// built this" — matching it against local git history by heuristic would be
|
|
16
|
+
// a confident-looking guess, the exact failure mode PRD 5's signature-state
|
|
17
|
+
// discipline exists to prevent elsewhere in this same PRD).
|
|
18
|
+
const REVISION_LABEL = 'org.opencontainers.image.revision';
|
|
19
|
+
|
|
20
|
+
function componentId(c) {
|
|
21
|
+
return c.purl || `${c.ecosystem}:${c.name}@${c.version}`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* `inventory` is `inventory.js#buildImageInventory`'s `inventory`.
|
|
26
|
+
* `vulnerabilities` is `vuln-correlate.js`'s `queryOSVFn` result (only
|
|
27
|
+
* `type: 'vulnerable_dep'` entries become Finding nodes — the no_lockfile",
|
|
28
|
+
* "unpinned_dep" structural checks don't bind to a specific component and
|
|
29
|
+
* are not part of this graph). `deployment`, if supplied, is an
|
|
30
|
+
* OPERATOR-DECLARED record (`{ id, environment, evidence }`) — this codebase
|
|
31
|
+
* has no mechanism anywhere that discovers "which digest is running where"
|
|
32
|
+
* on its own (`lineage/deployment/` models topology, not running digests),
|
|
33
|
+
* so a missing `deployment` argument means the graph simply stops at the
|
|
34
|
+
* OCI Digest / SBOM Component / Finding nodes, never a fabricated edge.
|
|
35
|
+
*/
|
|
36
|
+
export function buildArtifactProvenanceGraph({ inventory, vulnerabilities = [], deployment = null }) {
|
|
37
|
+
if (!inventory || typeof inventory.digest !== 'string') {
|
|
38
|
+
throw new TypeError('buildArtifactProvenanceGraph requires an inventory with a digest');
|
|
39
|
+
}
|
|
40
|
+
const nodes = [];
|
|
41
|
+
const edges = [];
|
|
42
|
+
|
|
43
|
+
const commitSha = inventory.buildLabels ? inventory.buildLabels[REVISION_LABEL] || null : null;
|
|
44
|
+
const commitId = `commit:${commitSha || 'unknown'}`;
|
|
45
|
+
const buildId = `build:${inventory.digest}`;
|
|
46
|
+
const digestId = `digest:${inventory.digest}`;
|
|
47
|
+
|
|
48
|
+
nodes.push({ id: commitId, kind: 'gitCommit', sha: commitSha, known: !!commitSha });
|
|
49
|
+
nodes.push({ id: buildId, kind: 'build', digest: inventory.digest, labels: inventory.buildLabels || {} });
|
|
50
|
+
nodes.push({ id: digestId, kind: 'ociDigest', digest: inventory.digest, digestKind: inventory.digestKind, repoTags: inventory.repoTags || [] });
|
|
51
|
+
|
|
52
|
+
edges.push({
|
|
53
|
+
from: commitId, to: buildId,
|
|
54
|
+
evidence: commitSha ? `label:${REVISION_LABEL}` : 'none',
|
|
55
|
+
});
|
|
56
|
+
edges.push({ from: buildId, to: digestId, evidence: 'same-archive' });
|
|
57
|
+
|
|
58
|
+
const components = [...(inventory.osPackages || []), ...(inventory.appPackages || [])];
|
|
59
|
+
for (const c of components) {
|
|
60
|
+
const compId = `component:${componentId(c)}`;
|
|
61
|
+
nodes.push({ id: compId, kind: 'sbomComponent', purl: c.purl || null, name: c.name, version: c.version, ecosystem: c.ecosystem });
|
|
62
|
+
edges.push({ from: digestId, to: compId, evidence: 'inventory' });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const vulnDeps = (vulnerabilities || []).filter((v) => v.type === 'vulnerable_dep');
|
|
66
|
+
for (const v of vulnDeps) {
|
|
67
|
+
const compId = `component:${v.purl || `${v.ecosystem}:${v.name}@${v.version}`}`;
|
|
68
|
+
const findingId = `finding:${v.osvId}:${v.purl || `${v.ecosystem}:${v.name}@${v.version}`}`;
|
|
69
|
+
nodes.push({ id: findingId, kind: 'finding', osvId: v.osvId, cveAliases: v.cveAliases || [], severity: v.severity });
|
|
70
|
+
edges.push({ from: compId, to: findingId, evidence: 'osv' });
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (deployment) {
|
|
74
|
+
if (typeof deployment.id !== 'string') throw new TypeError('a supplied deployment record requires an "id"');
|
|
75
|
+
const deploymentId = `deployment:${deployment.id}`;
|
|
76
|
+
nodes.push({ id: deploymentId, kind: 'deployment', environment: deployment.environment || null, declaredDigest: deployment.digest || null });
|
|
77
|
+
edges.push({
|
|
78
|
+
from: digestId, to: deploymentId,
|
|
79
|
+
evidence: deployment.evidence || 'operator-declared',
|
|
80
|
+
digestMatches: deployment.digest ? deployment.digest === inventory.digest : null,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return { nodes, edges };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Walks the graph from a commit or digest to every reachable Finding/Deployment
|
|
89
|
+
* node — the `provenance trace` CLI command's query surface.
|
|
90
|
+
*/
|
|
91
|
+
export function traceArtifactProvenanceGraph(graph, fromId) {
|
|
92
|
+
if (!graph || !Array.isArray(graph.nodes) || !Array.isArray(graph.edges)) {
|
|
93
|
+
throw new TypeError('traceArtifactProvenanceGraph requires a graph with nodes/edges arrays');
|
|
94
|
+
}
|
|
95
|
+
const byId = new Map(graph.nodes.map((n) => [n.id, n]));
|
|
96
|
+
if (!byId.has(fromId)) return { found: false, path: [] };
|
|
97
|
+
const adjacency = new Map();
|
|
98
|
+
for (const e of graph.edges) {
|
|
99
|
+
if (!adjacency.has(e.from)) adjacency.set(e.from, []);
|
|
100
|
+
adjacency.get(e.from).push(e);
|
|
101
|
+
}
|
|
102
|
+
const visited = new Set([fromId]);
|
|
103
|
+
const queue = [fromId];
|
|
104
|
+
const reached = [];
|
|
105
|
+
while (queue.length) {
|
|
106
|
+
const cur = queue.shift();
|
|
107
|
+
for (const e of adjacency.get(cur) || []) {
|
|
108
|
+
if (visited.has(e.to)) continue;
|
|
109
|
+
visited.add(e.to);
|
|
110
|
+
reached.push({ node: byId.get(e.to), via: e });
|
|
111
|
+
queue.push(e.to);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return { found: true, root: byId.get(fromId), reached };
|
|
115
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// Hand-rolled, hardened POSIX/GNU tar reader for OCI/Docker image archives.
|
|
2
|
+
//
|
|
3
|
+
// Why hand-rolled instead of a dependency: this repo has no tar library (see
|
|
4
|
+
// `src/artifact/CLAUDE.md`), and PRD 5's own Safety Requirements ask for exact
|
|
5
|
+
// control over the failure modes a generic tar library treats as implementation
|
|
6
|
+
// detail: malicious entry paths, decompression bombs, giant layers, oversized
|
|
7
|
+
// archives. Rolling it ourselves means every one of those limits is a named,
|
|
8
|
+
// tested constant in this file rather than a library default we'd have to audit.
|
|
9
|
+
//
|
|
10
|
+
// Scope: ustar + GNU longname ('L' typeflag) + base-256 size fields. PAX extended
|
|
11
|
+
// headers ('x'/'g') and GNU longlink ('K') are structurally skipped (their data
|
|
12
|
+
// block is consumed so offsets stay correct, but their content is not applied) —
|
|
13
|
+
// a disclosed limitation, not a silent one. Real docker-save/oci-archive output
|
|
14
|
+
// from Go's archive/tar for images in this size/complexity class essentially
|
|
15
|
+
// never needs them; synthetic fixtures in this codebase never emit them either.
|
|
16
|
+
import zlib from 'node:zlib';
|
|
17
|
+
|
|
18
|
+
const BLOCK = 512;
|
|
19
|
+
|
|
20
|
+
export const DEFAULT_LIMITS = Object.freeze({
|
|
21
|
+
maxEntries: 200_000,
|
|
22
|
+
maxEntrySize: 512 * 1024 * 1024, // 512MB per tar entry
|
|
23
|
+
maxTotalSize: 4 * 1024 * 1024 * 1024, // 4GB per archive (sum of entry sizes)
|
|
24
|
+
maxGunzipOutput: 4 * 1024 * 1024 * 1024, // decompression-bomb guard
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export class TarSafetyError extends Error {
|
|
28
|
+
constructor(message, code) {
|
|
29
|
+
super(message);
|
|
30
|
+
this.name = 'TarSafetyError';
|
|
31
|
+
this.code = code;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function parseSizeField(buf) {
|
|
36
|
+
if (buf[0] & 0x80) {
|
|
37
|
+
// GNU base-256 extension for sizes that don't fit in octal-ASCII.
|
|
38
|
+
let n = 0n;
|
|
39
|
+
for (let i = 1; i < buf.length; i++) n = (n << 8n) | BigInt(buf[i]);
|
|
40
|
+
return Number(n);
|
|
41
|
+
}
|
|
42
|
+
const s = buf.toString('ascii').replace(/\0.*$/, '').trim();
|
|
43
|
+
if (!s) return 0;
|
|
44
|
+
const n = parseInt(s, 8);
|
|
45
|
+
return Number.isFinite(n) ? n : 0;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function cstr(buf) {
|
|
49
|
+
return buf.toString('utf8').replace(/\0.*$/, '');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// A tar entry name is unsafe when it would escape a virtual extraction root:
|
|
53
|
+
// absolute paths, `..` segments, embedded NULs, or an unreasonable length.
|
|
54
|
+
// Because this module never writes to a real filesystem path (every caller
|
|
55
|
+
// keeps extracted content in an in-memory Map keyed by this string), the
|
|
56
|
+
// classic zip-slip *write* vulnerability cannot occur here — but a hostile
|
|
57
|
+
// name must still never be silently treated as an ordinary path by downstream
|
|
58
|
+
// manifest/package-DB matching, so unsafe entries are flagged, never dropped
|
|
59
|
+
// silently and never accepted as-is.
|
|
60
|
+
export function isSafeEntryName(name) {
|
|
61
|
+
if (typeof name !== 'string' || name.length === 0 || name.length > 4096) return false;
|
|
62
|
+
if (name.includes('\0')) return false;
|
|
63
|
+
const norm = name.replace(/\\/g, '/');
|
|
64
|
+
if (norm.startsWith('/')) return false;
|
|
65
|
+
if (norm.split('/').some((p) => p === '..')) return false;
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function isWhiteoutName(name) {
|
|
70
|
+
return (name.split('/').pop() || '').startsWith('.wh.');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Resolves a whiteout entry name to what it deletes. `.wh..wh..opq` marks a
|
|
74
|
+
// directory as "opaque" (everything from earlier layers under it is hidden,
|
|
75
|
+
// not individually deleted) — reported distinctly so callers don't conflate
|
|
76
|
+
// it with a single-file deletion.
|
|
77
|
+
export function whiteoutTarget(name) {
|
|
78
|
+
const parts = name.split('/');
|
|
79
|
+
const base = parts.pop();
|
|
80
|
+
if (base === '.wh..wh..opq') return { opaque: true, dir: parts.join('/') };
|
|
81
|
+
return { opaque: false, path: [...parts, base.slice(4)].join('/') };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Decompresses a gzip member with a hard output-size cap (Node's native
|
|
85
|
+
// ERR_BUFFER_TOO_LARGE on overflow — no custom streaming counter needed).
|
|
86
|
+
// Returns the input unchanged when it isn't gzip-magic (plain tar).
|
|
87
|
+
export function decompressIfGzip(buf, limits = DEFAULT_LIMITS) {
|
|
88
|
+
if (buf.length >= 2 && buf[0] === 0x1f && buf[1] === 0x8b) {
|
|
89
|
+
try {
|
|
90
|
+
return zlib.gunzipSync(buf, { maxOutputLength: limits.maxGunzipOutput });
|
|
91
|
+
} catch (err) {
|
|
92
|
+
if (err && err.code === 'ERR_BUFFER_TOO_LARGE') {
|
|
93
|
+
throw new TarSafetyError('decompressed layer exceeds the decompression-bomb guard', 'gunzip_too_large');
|
|
94
|
+
}
|
|
95
|
+
throw new TarSafetyError(`gzip stream is malformed: ${err.message}`, 'gunzip_malformed');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return buf;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Reads a decompressed tar buffer and yields one record per entry:
|
|
103
|
+
* { name, size, typeflag, linkname, data, unsafe }
|
|
104
|
+
* `data` is a Buffer view into `buf` (never copied) for safe entries, `null`
|
|
105
|
+
* for unsafe ones. Throws TarSafetyError (never returns a partial result) the
|
|
106
|
+
* moment any configured limit is exceeded.
|
|
107
|
+
*/
|
|
108
|
+
export function* readTarEntries(buf, limits = DEFAULT_LIMITS) {
|
|
109
|
+
if (!Buffer.isBuffer(buf)) throw new TarSafetyError('tar input must be a Buffer', 'bad_input');
|
|
110
|
+
let offset = 0;
|
|
111
|
+
let count = 0;
|
|
112
|
+
let totalSize = 0;
|
|
113
|
+
let pendingLongName = null;
|
|
114
|
+
|
|
115
|
+
while (offset + BLOCK <= buf.length) {
|
|
116
|
+
const header = buf.subarray(offset, offset + BLOCK);
|
|
117
|
+
if (header.every((b) => b === 0)) {
|
|
118
|
+
offset += BLOCK;
|
|
119
|
+
continue; // end-of-archive zero-fill padding
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
count += 1;
|
|
123
|
+
if (count > limits.maxEntries) {
|
|
124
|
+
throw new TarSafetyError(`tar archive has more than ${limits.maxEntries} entries`, 'too_many_entries');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
let name = cstr(header.subarray(0, 100));
|
|
128
|
+
const typeflag = String.fromCharCode(header[156] || 0);
|
|
129
|
+
const linkname = cstr(header.subarray(157, 257));
|
|
130
|
+
const magic = header.subarray(257, 263).toString('ascii');
|
|
131
|
+
const prefix = magic.startsWith('ustar') ? cstr(header.subarray(345, 500)) : '';
|
|
132
|
+
if (prefix) name = `${prefix}/${name}`;
|
|
133
|
+
const size = parseSizeField(header.subarray(124, 136));
|
|
134
|
+
|
|
135
|
+
offset += BLOCK;
|
|
136
|
+
|
|
137
|
+
if (size < 0 || !Number.isFinite(size)) {
|
|
138
|
+
throw new TarSafetyError(`tar entry "${name}" has an invalid size field`, 'bad_size');
|
|
139
|
+
}
|
|
140
|
+
if (size > limits.maxEntrySize) {
|
|
141
|
+
throw new TarSafetyError(`tar entry "${name}" (${size} bytes) exceeds the per-entry size limit`, 'entry_too_large');
|
|
142
|
+
}
|
|
143
|
+
totalSize += size;
|
|
144
|
+
if (totalSize > limits.maxTotalSize) {
|
|
145
|
+
throw new TarSafetyError('tar archive exceeds the total-size limit', 'archive_too_large');
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const dataBlocks = Math.ceil(size / BLOCK);
|
|
149
|
+
if (offset + size > buf.length) {
|
|
150
|
+
throw new TarSafetyError(`tar entry "${name}" claims more data than the archive contains`, 'truncated');
|
|
151
|
+
}
|
|
152
|
+
const data = size > 0 ? buf.subarray(offset, offset + size) : Buffer.alloc(0);
|
|
153
|
+
offset += dataBlocks * BLOCK;
|
|
154
|
+
|
|
155
|
+
const resolvedName = pendingLongName ? pendingLongName : name;
|
|
156
|
+
pendingLongName = null;
|
|
157
|
+
|
|
158
|
+
if (typeflag === 'L') {
|
|
159
|
+
// GNU longname: this entry's data IS the next entry's real name.
|
|
160
|
+
pendingLongName = cstr(data);
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
if (typeflag === 'K' || typeflag === 'x' || typeflag === 'g') {
|
|
164
|
+
// GNU longlink / PAX extended header — structurally skipped (see header comment).
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (!isSafeEntryName(resolvedName)) {
|
|
169
|
+
yield { name: resolvedName, size, typeflag, linkname, data: null, unsafe: true };
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
yield { name: resolvedName.replace(/\\/g, '/'), size, typeflag, linkname, data, unsafe: false };
|
|
174
|
+
}
|
|
175
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// PRD 5 P0 §5 — Signature Verification. States are exactly the PRD's own
|
|
2
|
+
// four, deliberately different from `sca/sigstore-verify.js`'s own vocabulary
|
|
3
|
+
// (`verified/unverified/tampered/unknown`) so the two are never confused by
|
|
4
|
+
// shared words — see docs/implementation-status/source-to-artifact-provenance.md's
|
|
5
|
+
// naming-discipline section:
|
|
6
|
+
//
|
|
7
|
+
// verified — a real cryptographic check ran and the signature matches.
|
|
8
|
+
// invalid — a real cryptographic check ran and the signature does NOT match.
|
|
9
|
+
// missing — no signature/attestation material was supplied at all.
|
|
10
|
+
// unavailable — material was supplied but could not be cryptographically
|
|
11
|
+
// checked (no public key given, or the check itself could
|
|
12
|
+
// not run) — the PRD's "never treat missing tooling as
|
|
13
|
+
// verified" clause means this state, not `verified`, is what
|
|
14
|
+
// an incomplete check must report.
|
|
15
|
+
//
|
|
16
|
+
// Two real, independent mechanisms are implemented:
|
|
17
|
+
// 1. A plain detached signature over the image digest string, verified
|
|
18
|
+
// with an operator-supplied public key. This is this tool's OWN local
|
|
19
|
+
// convention, not cosign's "simple signing" JSON format — disclosed in
|
|
20
|
+
// the implementation-status doc, not silently passed off as cosign-
|
|
21
|
+
// compatible.
|
|
22
|
+
// 2. Real DSSE (Dead Simple Signing Envelope) verification for in-toto/SLSA
|
|
23
|
+
// provenance attestations — the actual encoding cosign/Sigstore use for
|
|
24
|
+
// attestations, so a real cosign-keyed attestation bundle DOES verify
|
|
25
|
+
// here given the matching public key. `dssePae` is the exact PAE
|
|
26
|
+
// (Pre-Authentication Encoding) from the DSSE spec.
|
|
27
|
+
//
|
|
28
|
+
// Keyless/Rekor-transparency-log verification is NOT implemented — disclosed
|
|
29
|
+
// as a gap, never faked. `sca/sigstore-verify.js`'s Rekor-query pattern is
|
|
30
|
+
// the template a future increment could extend this module with.
|
|
31
|
+
import crypto from 'node:crypto';
|
|
32
|
+
|
|
33
|
+
export const SIGNATURE_STATES = Object.freeze(['verified', 'invalid', 'missing', 'unavailable']);
|
|
34
|
+
|
|
35
|
+
function verifyRaw(payload, signature, publicKeyPem) {
|
|
36
|
+
let publicKey;
|
|
37
|
+
try {
|
|
38
|
+
publicKey = crypto.createPublicKey(publicKeyPem);
|
|
39
|
+
} catch (err) {
|
|
40
|
+
return { ok: false, error: `public key is not parseable: ${err.message}` };
|
|
41
|
+
}
|
|
42
|
+
const keyType = publicKey.asymmetricKeyType;
|
|
43
|
+
const algorithm = (keyType === 'ed25519' || keyType === 'ed448') ? null : 'sha256';
|
|
44
|
+
try {
|
|
45
|
+
const ok = crypto.verify(algorithm, payload, publicKey, signature);
|
|
46
|
+
return { ok, keyType };
|
|
47
|
+
} catch (err) {
|
|
48
|
+
return { ok: false, error: `signature verification failed to run: ${err.message}` };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Verifies a detached signature over an image's digest string.
|
|
54
|
+
* `signature`/`publicKeyPem` are Buffer/PEM-string; either missing means
|
|
55
|
+
* `missing` (nothing was supplied to check).
|
|
56
|
+
*/
|
|
57
|
+
export function verifyImageSignature({ digest, signature, publicKeyPem }) {
|
|
58
|
+
if (typeof digest !== 'string' || !digest.startsWith('sha256:')) {
|
|
59
|
+
return { state: 'unavailable', reason: 'no image digest available to verify a signature against' };
|
|
60
|
+
}
|
|
61
|
+
if (!signature || !publicKeyPem) {
|
|
62
|
+
return { state: 'missing', reason: 'no detached signature and public key were supplied for this image' };
|
|
63
|
+
}
|
|
64
|
+
const { ok, error, keyType } = verifyRaw(Buffer.from(digest, 'utf8'), signature, publicKeyPem);
|
|
65
|
+
if (error) return { state: 'invalid', reason: error };
|
|
66
|
+
return ok
|
|
67
|
+
? { state: 'verified', keyType }
|
|
68
|
+
: { state: 'invalid', reason: 'signature does not match the image digest under the supplied public key' };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// DSSE Pre-Authentication Encoding: "DSSEv1" SP LEN(type) SP type SP LEN(body) SP body.
|
|
72
|
+
function dssePae(payloadType, payloadBytes) {
|
|
73
|
+
const typeBytes = Buffer.from(payloadType, 'utf8');
|
|
74
|
+
return Buffer.concat([
|
|
75
|
+
Buffer.from('DSSEv1 ', 'ascii'),
|
|
76
|
+
Buffer.from(String(typeBytes.length), 'ascii'),
|
|
77
|
+
Buffer.from(' ', 'ascii'),
|
|
78
|
+
typeBytes,
|
|
79
|
+
Buffer.from(' ', 'ascii'),
|
|
80
|
+
Buffer.from(String(payloadBytes.length), 'ascii'),
|
|
81
|
+
Buffer.from(' ', 'ascii'),
|
|
82
|
+
payloadBytes,
|
|
83
|
+
]);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const SLSA_PREDICATE_PREFIX = 'https://slsa.dev/provenance/';
|
|
87
|
+
const INTOTO_STATEMENT_TYPES = new Set(['https://in-toto.io/Statement/v0.1', 'https://in-toto.io/Statement/v1']);
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Verifies an in-toto/SLSA provenance attestation for an image.
|
|
91
|
+
* `envelope` is a DSSE envelope: `{ payloadType, payload (base64 in-toto
|
|
92
|
+
* Statement JSON), signatures: [{ sig (base64) }] }` — the real shape
|
|
93
|
+
* cosign/Sigstore attestations use. `publicKeyPem` verifies one of
|
|
94
|
+
* `signatures` against `dssePae(payloadType, payload)`.
|
|
95
|
+
*
|
|
96
|
+
* The subject-digest match is checked FIRST and independently of signature
|
|
97
|
+
* verification, so a mismatched subject is always `invalid` (never
|
|
98
|
+
* "unavailable", which would understate a real, checkable problem).
|
|
99
|
+
*/
|
|
100
|
+
export function verifyProvenanceAttestation({ digest, envelope, publicKeyPem }) {
|
|
101
|
+
if (!envelope) return { state: 'missing', reason: 'no in-toto/SLSA provenance attestation was supplied for this image' };
|
|
102
|
+
|
|
103
|
+
let env;
|
|
104
|
+
try {
|
|
105
|
+
env = typeof envelope === 'string' ? JSON.parse(envelope) : envelope;
|
|
106
|
+
} catch (err) {
|
|
107
|
+
return { state: 'invalid', reason: `attestation envelope is not valid JSON: ${err.message}` };
|
|
108
|
+
}
|
|
109
|
+
if (typeof env.payload !== 'string' || typeof env.payloadType !== 'string' || !Array.isArray(env.signatures)) {
|
|
110
|
+
return { state: 'invalid', reason: 'not a recognized DSSE envelope (missing payload, payloadType, or signatures)' };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
let payloadBytes;
|
|
114
|
+
let stmt;
|
|
115
|
+
try {
|
|
116
|
+
payloadBytes = Buffer.from(env.payload, 'base64');
|
|
117
|
+
stmt = JSON.parse(payloadBytes.toString('utf8'));
|
|
118
|
+
} catch (err) {
|
|
119
|
+
return { state: 'invalid', reason: `attestation payload is not a valid base64-encoded JSON statement: ${err.message}` };
|
|
120
|
+
}
|
|
121
|
+
if (!INTOTO_STATEMENT_TYPES.has(stmt._type)) {
|
|
122
|
+
return { state: 'invalid', reason: 'statement is missing a recognized in-toto "_type"' };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const digestHex = typeof digest === 'string' && digest.startsWith('sha256:') ? digest.slice('sha256:'.length) : digest;
|
|
126
|
+
const subjects = Array.isArray(stmt.subject) ? stmt.subject : [];
|
|
127
|
+
const subjectMatches = subjects.some((s) => s && s.digest && s.digest.sha256 === digestHex);
|
|
128
|
+
if (!subjectMatches) {
|
|
129
|
+
return { state: 'invalid', reason: 'attestation subject digest does not match this image', predicateType: stmt.predicateType || null };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const predicateType = stmt.predicateType || null;
|
|
133
|
+
const isSlsa = typeof predicateType === 'string' && predicateType.startsWith(SLSA_PREDICATE_PREFIX);
|
|
134
|
+
|
|
135
|
+
if (!publicKeyPem || env.signatures.length === 0) {
|
|
136
|
+
return {
|
|
137
|
+
state: 'unavailable',
|
|
138
|
+
reason: 'attestation subject matches this image, but no public key was supplied to verify its signature',
|
|
139
|
+
predicateType, isSlsa,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const pae = dssePae(env.payloadType, payloadBytes);
|
|
144
|
+
for (const sigEntry of env.signatures) {
|
|
145
|
+
if (!sigEntry || typeof sigEntry.sig !== 'string') continue;
|
|
146
|
+
let sigBytes;
|
|
147
|
+
try {
|
|
148
|
+
sigBytes = Buffer.from(sigEntry.sig, 'base64');
|
|
149
|
+
} catch {
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
const { ok } = verifyRaw(pae, sigBytes, publicKeyPem);
|
|
153
|
+
if (ok) return { state: 'verified', predicateType, isSlsa };
|
|
154
|
+
}
|
|
155
|
+
return { state: 'invalid', reason: 'no signature in the attestation envelope verifies under the supplied public key', predicateType, isSlsa };
|
|
156
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// PRD 5 P0 §8 — VEX (Vulnerability Exploitability eXchange). Statuses are the
|
|
2
|
+
// PRD's own four. The PRD's one explicit rule — "`not affected` requires
|
|
3
|
+
// positive evidence" — is enforced structurally: `not_affected` is only ever
|
|
4
|
+
// returned from one of two named, checked evidence paths below; there is no
|
|
5
|
+
// code path that reaches it by default or by absence of information.
|
|
6
|
+
// Justification strings follow the CISA VEX vocabulary this repo's other VEX
|
|
7
|
+
// output (`toVex` in `src/posture/sbom.js`'s neighborhood) already uses,
|
|
8
|
+
// where applicable.
|
|
9
|
+
//
|
|
10
|
+
// `affected` likewise requires positive evidence (confirmed reachability),
|
|
11
|
+
// not just "OSV lists this version as vulnerable" — a scanner result alone
|
|
12
|
+
// only tells you the CVE/version pair matches; it doesn't tell you the
|
|
13
|
+
// vulnerable code path is reachable in THIS artifact. Absent that
|
|
14
|
+
// confirmation, the honest status is `under_investigation`, never a
|
|
15
|
+
// confident `affected` the evidence doesn't support.
|
|
16
|
+
export const VEX_STATUSES = Object.freeze(['affected', 'not_affected', 'fixed', 'under_investigation']);
|
|
17
|
+
|
|
18
|
+
// Loose dotted-numeric version comparison. Returns -1/0/1, or null when
|
|
19
|
+
// either side isn't a clean dotted-numeric form — a "fixed" verdict is only
|
|
20
|
+
// ever returned when this does NOT return null; an unparseable version
|
|
21
|
+
// means that evidence path is skipped, never guessed through.
|
|
22
|
+
function compareVersions(a, b) {
|
|
23
|
+
const pa = String(a).split(/[.-]/).map((s) => (/^\d+$/.test(s) ? parseInt(s, 10) : null));
|
|
24
|
+
const pb = String(b).split(/[.-]/).map((s) => (/^\d+$/.test(s) ? parseInt(s, 10) : null));
|
|
25
|
+
if (pa.some((n) => n === null) || pb.some((n) => n === null)) return null;
|
|
26
|
+
const len = Math.max(pa.length, pb.length);
|
|
27
|
+
for (let i = 0; i < len; i++) {
|
|
28
|
+
const x = pa[i] ?? 0;
|
|
29
|
+
const y = pb[i] ?? 0;
|
|
30
|
+
if (x !== y) return x < y ? -1 : 1;
|
|
31
|
+
}
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function componentKeyOf(c) {
|
|
36
|
+
return c.purl || (c.ecosystem && c.name && c.version ? `${c.ecosystem}:${c.name}@${c.version}` : null);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* `vulnerability` is one `vulnerable_dep`-shaped entry already confirmed
|
|
41
|
+
* present via `vuln-correlate.js` against THIS artifact. `artifactComponents`
|
|
42
|
+
* is the artifact's own inventory (`osPackages`/`appPackages` concatenated).
|
|
43
|
+
* `reachability`, if supplied, is `{ reachable: true|false, reason }` from
|
|
44
|
+
* this codebase's existing dataflow/reachability evidence (never computed
|
|
45
|
+
* here — this module does no new analysis, only statuses the evidence it's
|
|
46
|
+
* handed).
|
|
47
|
+
*/
|
|
48
|
+
export function deriveVexStatus({ vulnerability, artifactComponents, reachability = null }) {
|
|
49
|
+
if (!vulnerability || typeof vulnerability !== 'object') {
|
|
50
|
+
throw new TypeError('deriveVexStatus requires a vulnerability object');
|
|
51
|
+
}
|
|
52
|
+
if (!Array.isArray(artifactComponents)) {
|
|
53
|
+
throw new TypeError('deriveVexStatus requires an artifactComponents array');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const vulnKey = vulnerability.purl
|
|
57
|
+
|| (vulnerability.ecosystem && vulnerability.name && vulnerability.version ? `${vulnerability.ecosystem}:${vulnerability.name}@${vulnerability.version}` : null);
|
|
58
|
+
const present = vulnKey != null && artifactComponents.some((c) => componentKeyOf(c) === vulnKey);
|
|
59
|
+
|
|
60
|
+
if (!present) {
|
|
61
|
+
return {
|
|
62
|
+
status: 'not_affected',
|
|
63
|
+
justification: 'component_not_present',
|
|
64
|
+
evidence: 'the affected component (by purl/ecosystem+name+version) is not present in this artifact\'s inventory',
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (reachability && reachability.reachable === false) {
|
|
69
|
+
return {
|
|
70
|
+
status: 'not_affected',
|
|
71
|
+
justification: 'vulnerable_code_not_in_execute_path',
|
|
72
|
+
evidence: reachability.reason || 'static reachability analysis found no path to the vulnerable function in this artifact',
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (Array.isArray(vulnerability.fixedVersions) && vulnerability.fixedVersions.length && vulnerability.version) {
|
|
77
|
+
for (const fv of vulnerability.fixedVersions) {
|
|
78
|
+
const cmp = compareVersions(vulnerability.version, fv);
|
|
79
|
+
if (cmp !== null && cmp >= 0) {
|
|
80
|
+
return { status: 'fixed', justification: null, evidence: `installed version ${vulnerability.version} is >= the fixed version ${fv}` };
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (reachability && reachability.reachable === true) {
|
|
86
|
+
return { status: 'affected', justification: null, evidence: reachability.reason || 'static reachability analysis confirmed a path to the vulnerable function in this artifact' };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
status: 'under_investigation',
|
|
91
|
+
justification: null,
|
|
92
|
+
evidence: 'the affected component is present and not confirmed fixed, but reachability has not been established — not a confident "affected" claim',
|
|
93
|
+
};
|
|
94
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// PRD 5 P0 §4 — Container Vulnerability Analysis. "Reuse current SCA
|
|
2
|
+
// semantics where technically valid": this module does nothing but hand an
|
|
3
|
+
// image's OS + application package inventory to the engine's existing
|
|
4
|
+
// OSV/KEV/EPSS query path (`queryOSV`, imported via `src/sca/index.js`),
|
|
5
|
+
// exactly as every other SCA finding in this codebase gets its CVE data.
|
|
6
|
+
// `queryOSVFn` is injected (not imported directly) so this module's own
|
|
7
|
+
// tests never make a real network call and stay independent of engine.js's
|
|
8
|
+
// load cost; the CLI wiring passes the real `queryOSV`.
|
|
9
|
+
export async function correlateImageVulnerabilities({ inventory, fileContents, queryOSVFn }) {
|
|
10
|
+
if (typeof queryOSVFn !== 'function') throw new TypeError('correlateImageVulnerabilities requires queryOSVFn(components, allFileContents)');
|
|
11
|
+
if (!inventory || !Array.isArray(inventory.osPackages) || !Array.isArray(inventory.appPackages)) {
|
|
12
|
+
throw new TypeError('correlateImageVulnerabilities requires an inventory with osPackages/appPackages arrays');
|
|
13
|
+
}
|
|
14
|
+
const components = [...inventory.osPackages, ...inventory.appPackages];
|
|
15
|
+
const vulnerabilities = await queryOSVFn(components, fileContents || {});
|
|
16
|
+
return { components, vulnerabilities };
|
|
17
|
+
}
|
package/src/lineage/CLAUDE.md
CHANGED
|
@@ -946,6 +946,25 @@ layer, without collecting a single payload value.
|
|
|
946
946
|
| `coverage.js` / `index.js` (extended, additively) | `buildGraphWithCoverage` composes a default `correlateObservations` closure over a **pre-loaded** `opts.runtimeObservations` array (never a raw path); `index.js` performs the ONE read per `buildLineageGraph` call (`fs.existsSync(dir) ? loadObservations(scanRoot) : null` — the `null` is deliberate, see below). |
|
|
947
947
|
| `bin/agentic-security.js` (`dataflow observations import\|list`, `dataflow twin`) | The AC-29 proof surface — see `commands/dataflow.md`'s own `## Runtime observations (FR-505)` / `## Runtime Digital Twin layers (AC-29)` sections for the full CLI reference. `observations import` is dry-run-by-default and refuses the WHOLE import on any rejected record; `observations list` never prints an attribute key or value; `dataflow twin` is read-only and never writes into `.agentic-security/`. |
|
|
948
948
|
|
|
949
|
+
### PRD "Runtime-Corroborated Security Twin" addendum (2026-10-13) — closes the real telemetry-input gap
|
|
950
|
+
|
|
951
|
+
`observation-adapters.js` gained four more adapters alongside `native-jsonl`: `otel-json`
|
|
952
|
+
(OpenTelemetry JSON trace export, one draft per span), `envoy-access-log` (Envoy's default JSON
|
|
953
|
+
access log, `response_flags` → the new `network.securityDecision` attribute), `k8s-audit-log`
|
|
954
|
+
(Kubernetes `audit.k8s.io` JSONL — `objectRef`/`responseStatus.code`, deliberately never
|
|
955
|
+
`user.username`), `http-access-log` (generic JSON-lines access log). All four are pure (zero
|
|
956
|
+
imports) and follow the exact same `(text, context) -> {drafts, errors}` contract, dropping every
|
|
957
|
+
field with no safe, approved destination. `runtime-observation.js` gained exactly one new attribute
|
|
958
|
+
key, `network.securityDecision` (a closed `allowed|denied` enum, deliberately narrower than the
|
|
959
|
+
generic identifier-value grammar every other key gets) — no identity field was added; that remains
|
|
960
|
+
a deliberate, disclosed omission. `runtime-assurance.js` (new) reports `runtimeStatus:
|
|
961
|
+
complete|partial|unavailable`, read by the new top-level `runtime` CLI (`runtime ingest/status/
|
|
962
|
+
reconcile/query`, `commands/runtime.md`) — `ingest` shims the existing `dataflow observations
|
|
963
|
+
import`, the rest are new but read-only over the existing correlation/store functions. The 3-rung
|
|
964
|
+
match ladder, the 3-valued `OBSERVATION_LAYERS`, and the server/UI deferral above are ALL
|
|
965
|
+
unchanged — see `docs/implementation-status/runtime-corroborated-twin.md` for the full scope
|
|
966
|
+
decision and what was deliberately left out.
|
|
967
|
+
|
|
949
968
|
### The five AC-29 properties a future UI increment inherits, and must not break
|
|
950
969
|
|
|
951
970
|
A future UI increment (deferred here — see the out-of-scope list below) sits
|