@clear-capabilities/agentic-security-scanner 0.144.0 → 0.147.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 +390 -0
- package/bin/agentic-security.js +3813 -83
- package/dist/1122.index.js +702 -0
- package/dist/{301.index.js → 1301.index.js} +2 -2
- package/dist/1379.index.js +591 -0
- package/dist/{444.index.js → 1444.index.js} +13 -4
- package/dist/{660.index.js → 1660.index.js} +2 -2
- package/dist/{700.index.js → 1700.index.js} +2 -2
- package/dist/{905.index.js → 1905.index.js} +3 -3
- package/dist/{920.index.js → 1920.index.js} +3 -3
- package/dist/{238.index.js → 2238.index.js} +3 -3
- package/dist/2271.index.js +165 -0
- package/dist/{985.index.js → 2376.index.js} +1260 -340
- package/dist/2432.index.js +793 -0
- package/dist/2659.index.js +93 -0
- package/dist/{826.index.js → 2826.index.js} +2 -2
- package/dist/{830.index.js → 2830.index.js} +2 -2
- package/dist/2923.index.js +298 -0
- package/dist/{1.index.js → 3001.index.js} +5 -5
- package/dist/{117.index.js → 3117.index.js} +3 -3
- package/dist/3180.index.js +307 -0
- package/dist/3276.index.js +117 -0
- package/dist/{415.index.js → 3415.index.js} +2 -2
- package/dist/{499.index.js → 3499.index.js} +2 -2
- package/dist/3518.index.js +450 -0
- package/dist/{526.index.js → 3526.index.js} +14 -6
- package/dist/{736.index.js → 3736.index.js} +4 -4
- package/dist/{839.index.js → 3839.index.js} +4 -4
- package/dist/{113.index.js → 4113.index.js} +14 -6
- package/dist/{265.index.js → 4265.index.js} +2 -2
- package/dist/{384.index.js → 4384.index.js} +3 -3
- package/dist/4547.index.js +268 -0
- package/dist/4863.index.js +422 -0
- package/dist/{970.index.js → 4970.index.js} +67 -3
- package/dist/5051.index.js +770 -0
- package/dist/{144.index.js → 5144.index.js} +5 -5
- package/dist/{333.index.js → 5333.index.js} +3 -3
- package/dist/5343.index.js +185 -0
- package/dist/5350.index.js +866 -0
- package/dist/5561.index.js +436 -0
- package/dist/{637.index.js → 5637.index.js} +29 -7
- package/dist/{449.index.js → 5830.index.js} +78 -14
- package/dist/6626.index.js +532 -0
- package/dist/6662.index.js +297 -0
- package/dist/{675.index.js → 6675.index.js} +5 -5
- package/dist/{730.index.js → 6730.index.js} +6 -6
- package/dist/6829.index.js +225 -0
- package/dist/6944.index.js +130 -0
- package/dist/{178.index.js → 7178.index.js} +26 -8
- package/dist/{227.index.js → 7227.index.js} +2 -2
- package/dist/7310.index.js +520 -0
- package/dist/{552.index.js → 7552.index.js} +4 -4
- package/dist/7709.index.js +78 -0
- package/dist/8218.index.js +160 -0
- package/dist/{476.index.js → 8476.index.js} +4 -4
- package/dist/{513.index.js → 8513.index.js} +5 -5
- package/dist/{520.index.js → 8520.index.js} +2 -2
- package/dist/{718.index.js → 8718.index.js} +2 -2
- package/dist/{752.index.js → 8752.index.js} +2 -2
- package/dist/8846.index.js +100 -0
- package/dist/{435.index.js → 9091.index.js} +580 -187
- package/dist/{207.index.js → 9207.index.js} +2 -2
- package/dist/{220.index.js → 9220.index.js} +2 -2
- package/dist/9390.index.js +163 -0
- package/dist/{503.index.js → 9503.index.js} +2 -2
- package/dist/{801.index.js → 9801.index.js} +2 -2
- package/dist/{824.index.js → 9824.index.js} +2 -2
- package/dist/agentic-security.mjs +16 -16
- package/dist/agentic-security.mjs.sha256 +1 -1
- package/dist/compliance-frameworks/hipaa-security-rule.json +3 -2
- package/package.json +23 -10
- package/src/compare.js +6 -1
- package/src/dataflow/CLAUDE.md +2 -2
- package/src/dataflow/catalog.js +42 -0
- package/src/dataflow/orm-write-catalog.js +175 -0
- package/src/engine.js +580 -30
- package/src/fix/apply-fix-service.js +1 -0
- package/src/history-scan.js +22 -5
- package/src/ir/CLAUDE.md +2 -1
- package/src/ir/chrome-probe.mjs +150 -0
- package/src/ir/parser-js.js +94 -7
- package/src/lineage/CLAUDE.md +1203 -0
- package/src/lineage/DESIGN_DESTINATION_RESOLVER.md +156 -0
- package/src/lineage/DESIGN_GRAPH_BUILDER.md +938 -0
- package/src/lineage/DESIGN_HANDLING_ANALYZER.md +355 -0
- package/src/lineage/DESIGN_INTRAPROCEDURAL.md +628 -0
- package/src/lineage/DESIGN_PATH_PROVENANCE.md +3451 -0
- package/src/lineage/DESIGN_QUEUE_DETAIL.md +120 -0
- package/src/lineage/DESIGN_REGISTRIES.md +880 -0
- package/src/lineage/DESIGN_STORE_DETAIL.md +143 -0
- package/src/lineage/DESIGN_TRANSIT_PROTECTION.md +245 -0
- package/src/lineage/classification.js +56 -0
- package/src/lineage/coverage.js +658 -0
- package/src/lineage/cross-repo-link.js +107 -0
- package/src/lineage/dataflow-graph.schema.json +184 -0
- package/src/lineage/decision-story.js +206 -0
- package/src/lineage/drift-policy.js +279 -0
- package/src/lineage/driver.js +135 -0
- package/src/lineage/engine.js +992 -0
- package/src/lineage/export-briefing.js +628 -0
- package/src/lineage/export-csv.js +62 -0
- package/src/lineage/export-json.js +238 -0
- package/src/lineage/export-privacy.js +258 -0
- package/src/lineage/federation-loader.js +111 -0
- package/src/lineage/field-identity.js +78 -0
- package/src/lineage/fixtures/build-flagship-fixture.mjs +272 -0
- package/src/lineage/fixtures/flagship-graph.json +1453 -0
- package/src/lineage/flow-grade.js +221 -0
- package/src/lineage/governance-edit.js +169 -0
- package/src/lineage/graph-builder.js +1114 -0
- package/src/lineage/graph-diff.js +431 -0
- package/src/lineage/graph-snapshot.js +180 -0
- package/src/lineage/handling-analyzer.js +168 -0
- package/src/lineage/ids.js +349 -0
- package/src/lineage/impact-assessment.js +76 -0
- package/src/lineage/impact-engine.js +268 -0
- package/src/lineage/index.js +281 -0
- package/src/lineage/language-coverage-tiers.js +58 -0
- package/src/lineage/obligation-mapping.js +126 -0
- package/src/lineage/obligation-predicates.js +235 -0
- package/src/lineage/observation-adapters.js +282 -0
- package/src/lineage/observation-correlation.js +622 -0
- package/src/lineage/observation-store.js +497 -0
- package/src/lineage/path-query.js +410 -0
- package/src/lineage/path-store.js +400 -0
- package/src/lineage/protection.js +53 -0
- package/src/lineage/recipient-profile.js +192 -0
- package/src/lineage/recipient-registry.js +394 -0
- package/src/lineage/redact-graph.js +224 -0
- package/src/lineage/remediation.js +417 -0
- package/src/lineage/resolve-destination.js +91 -0
- package/src/lineage/runtime-observation.js +464 -0
- package/src/lineage/scenario-diff.js +84 -0
- package/src/lineage/scenario-engine.js +251 -0
- package/src/lineage/scenario.js +101 -0
- package/src/lineage/schema.js +167 -0
- package/src/lineage/sink-registry.js +427 -0
- package/src/lineage/source-registry.js +357 -0
- package/src/lineage/source-seeding.js +212 -0
- package/src/lineage/summaries.js +590 -0
- package/src/lineage/transform-catalog.js +397 -0
- package/src/lineage/transit-protection.js +150 -0
- package/src/lineage/validate.js +285 -0
- package/src/lsp/server.js +49 -2
- package/src/mcp/CLAUDE.md +7 -1
- package/src/mcp/dataflow-tools.js +160 -0
- package/src/mcp/server.js +1 -1
- package/src/mcp/tools.js +22 -1
- package/src/pipeline/assurance-mode.js +64 -1
- package/src/pipeline/finding-schema.js +8 -1
- package/src/pipeline/scan-health.js +19 -1
- package/src/posture/CLAUDE.md +140 -0
- package/src/posture/accuracy-scorecard.js +60 -0
- package/src/posture/artifact-registry.js +76 -0
- package/src/posture/auditor-walkthrough.js +192 -13
- package/src/posture/compliance-frameworks/hipaa-security-rule.json +3 -2
- package/src/posture/compliance-policy.js +12 -2
- package/src/posture/cross-repo-memory.js +7 -2
- package/src/posture/fix-history.js +25 -2
- package/src/posture/fix-verify.js +9 -1
- package/src/posture/fleet.js +0 -0
- package/src/posture/git-history.js +13 -5
- package/src/posture/material-change.js +21 -2
- package/src/posture/mttr.js +75 -12
- package/src/posture/obligation-evidence-pack.js +202 -0
- package/src/posture/pre-incident-archaeology.js +39 -7
- package/src/posture/privacy-framework.js +14 -0
- package/src/posture/provenance/ai-authorship.js +68 -0
- package/src/posture/provenance/branch-entry.js +80 -0
- package/src/posture/provenance/cache.js +143 -0
- package/src/posture/provenance/confidence.js +36 -0
- package/src/posture/provenance/coordinator.js +786 -0
- package/src/posture/provenance/dag-walk.js +249 -0
- package/src/posture/provenance/evidence-attribution.js +59 -0
- package/src/posture/provenance/git-evidence.js +310 -0
- package/src/posture/provenance/lifecycle.js +208 -0
- package/src/posture/provenance/missing-control-resolver.js +137 -0
- package/src/posture/provenance/origin-resolver.js +342 -0
- package/src/posture/provenance/predicate-replay.js +133 -0
- package/src/posture/provenance/providers/config.js +39 -0
- package/src/posture/provenance/providers/github.js +62 -0
- package/src/posture/provenance/providers/gitlab.js +58 -0
- package/src/posture/provenance/repo-lineage.js +74 -0
- package/src/posture/provenance/sca-origin.js +139 -0
- package/src/posture/provenance/schema.js +255 -0
- package/src/posture/provenance/transitive-sca.js +147 -0
- package/src/posture/provenance/validate.js +30 -0
- package/src/posture/provenance-evidence-bundle.js +144 -0
- package/src/posture/remediation-ledger.js +337 -0
- package/src/posture/sbom-diff.js +15 -2
- package/src/posture/secret-history.js +10 -2
- package/src/posture/state-dir.js +38 -14
- package/src/posture/vuln-archaeology.js +8 -2
- package/src/pr-delta.js +25 -4
- package/src/report/index.js +197 -3
- package/src/runScan.js +34 -5
- package/src/sast/rate-limit.js +33 -3
- package/src/server/CLAUDE.md +47 -0
- package/src/server/graph-loader.js +141 -0
- package/src/server/http-server.js +325 -0
- package/src/server/routes.js +129 -0
- package/src/server/security.js +111 -0
- package/src/server/static-assets.js +139 -0
- package/src/util/git-hardening.js +128 -0
- package/dist/11.index.js +0 -353
- package/dist/259.index.js +0 -975
- package/dist/317.index.js +0 -300
- package/dist/609.index.js +0 -741
- package/dist/838.index.js +0 -152
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Structural validator for DataFlowGraph v1 (PRD section 10). Hand-rolled
|
|
3
|
+
// rather than a generic JSON-Schema interpreter + a new `ajv`-style
|
|
4
|
+
// dependency, matching this codebase's existing preference for
|
|
5
|
+
// hand-rolled implementations over new runtime deps (see every parser in
|
|
6
|
+
// scanner/src/ir/). scanner/src/lineage/dataflow-graph.schema.json (Task
|
|
7
|
+
// 6) is the authoritative JSON Schema document for external interop /
|
|
8
|
+
// documentation; this file is what the engine actually calls at graph-
|
|
9
|
+
// build phase 12 (PRD 18.3: "Validate the graph contract and freeze it
|
|
10
|
+
// before rendering").
|
|
11
|
+
//
|
|
12
|
+
// Never throws. A malformed top-level input produces one error and
|
|
13
|
+
// returns early; a malformed nested entity is skipped for further
|
|
14
|
+
// structural checks on ITSELF but does not stop validation of siblings.
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
SCHEMA_VERSION, NODE_KINDS, MAPPING_TYPES, COVERAGE_STATUS_VALUES, EXTERNALITY_VALUES,
|
|
18
|
+
TRANSFORM_KINDS, REVERSIBILITY_VALUES, DESTINATION_RESOLUTION_VALUES, EDGE_PROVENANCE_VALUES, POLICY_STATES,
|
|
19
|
+
FLOW_SUMMARY_VALUES, EVIDENCE_TYPES, GRAPH_SCOPE_SOURCES, HANDLING_VALUES, STORE_OPERATION_VALUES,
|
|
20
|
+
QUEUE_OPERATION_VALUES,
|
|
21
|
+
} from './schema.js';
|
|
22
|
+
import { isValidProtectionDimension, PROTECTION_DIMENSIONS } from './protection.js';
|
|
23
|
+
import { LINEAGE_DATA_CLASSES, isAiContext } from './classification.js';
|
|
24
|
+
|
|
25
|
+
function _err(errors, path, message) {
|
|
26
|
+
errors.push({ path, message });
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function _requireArray(graph, key, errors) {
|
|
30
|
+
if (!Array.isArray(graph[key])) _err(errors, `$.${key}`, `${key} must be an array`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function _requireObject(graph, key, errors) {
|
|
34
|
+
if (typeof graph[key] !== 'object' || graph[key] === null || Array.isArray(graph[key])) {
|
|
35
|
+
_err(errors, `$.${key}`, `${key} must be an object`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const ID_PREFIXES = {
|
|
40
|
+
node: /^node:/,
|
|
41
|
+
edge: /^edge:/,
|
|
42
|
+
data: /^data:/,
|
|
43
|
+
flow: /^flow:/,
|
|
44
|
+
transform: /^transform:/,
|
|
45
|
+
evidence: /^evidence:/,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
function _validateNode(node, idx, errors, seenIds) {
|
|
49
|
+
const path = (suffix) => `$.nodes[${idx}]${suffix}`;
|
|
50
|
+
if (!node || typeof node !== 'object') { _err(errors, path(''), 'node must be an object'); return; }
|
|
51
|
+
if (typeof node.id !== 'string' || !node.id) _err(errors, path('.id'), 'node.id is required');
|
|
52
|
+
else {
|
|
53
|
+
if (!ID_PREFIXES.node.test(node.id)) _err(errors, path('.id'), `node.id must start with "node:"`);
|
|
54
|
+
seenIds.add(node.id);
|
|
55
|
+
}
|
|
56
|
+
if (!NODE_KINDS.includes(node.kind)) _err(errors, path('.kind'), `unrecognized node kind "${node.kind}"`);
|
|
57
|
+
// node.subtype is optional and may be `null` — an `unsupported`-coverage
|
|
58
|
+
// node (e.g. a sink registry decision with `category: null`, PRD 6.4/
|
|
59
|
+
// DESIGN_REGISTRIES.md §9.0) legitimately carries no subtype at all,
|
|
60
|
+
// either as an absent field or an explicit `null`; only a present,
|
|
61
|
+
// non-null, non-string value (a number, object, array, etc.) is invalid.
|
|
62
|
+
if (Object.prototype.hasOwnProperty.call(node, 'subtype') && node.subtype !== null && typeof node.subtype !== 'string') {
|
|
63
|
+
_err(errors, path('.subtype'), 'node.subtype must be a string or null');
|
|
64
|
+
}
|
|
65
|
+
if (typeof node.label !== 'string' || !node.label) _err(errors, path('.label'), 'node.label is required');
|
|
66
|
+
if (!Array.isArray(node.aliases)) _err(errors, path('.aliases'), 'node.aliases must be an array');
|
|
67
|
+
if (!Array.isArray(node.dataElementIds)) _err(errors, path('.dataElementIds'), 'node.dataElementIds must be an array');
|
|
68
|
+
if (!Array.isArray(node.evidenceRefs)) _err(errors, path('.evidenceRefs'), 'node.evidenceRefs must be an array');
|
|
69
|
+
if (!COVERAGE_STATUS_VALUES.includes(node.coverageStatus)) _err(errors, path('.coverageStatus'), `unrecognized coverageStatus "${node.coverageStatus}"`);
|
|
70
|
+
if (node.externality && !EXTERNALITY_VALUES.includes(node.externality.value)) {
|
|
71
|
+
_err(errors, path('.externality.value'), `unrecognized externality "${node.externality.value}"`);
|
|
72
|
+
}
|
|
73
|
+
// Milestone 2, Sub-project A, increment 1: `node.destination` is `null`
|
|
74
|
+
// on every node this increment doesn't resolve — only checked when
|
|
75
|
+
// non-null, mirroring `_validateEdge`'s own `edge.protocol` pattern below.
|
|
76
|
+
if (node.destination && typeof node.destination === 'object') {
|
|
77
|
+
if (!DESTINATION_RESOLUTION_VALUES.includes(node.destination.resolutionStatus)) {
|
|
78
|
+
_err(errors, path('.destination.resolutionStatus'), `unrecognized destination.resolutionStatus "${node.destination.resolutionStatus}"`);
|
|
79
|
+
}
|
|
80
|
+
if (node.destination.resolutionStatus !== 'literal' && node.destination.literalValue !== null) {
|
|
81
|
+
_err(errors, path('.destination.literalValue'), 'destination.literalValue must be null unless resolutionStatus is "literal"');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// Milestone 2, Sub-project E, increment 2: `node.storeDetail` is `null`
|
|
85
|
+
// on every node this increment doesn't populate — only checked when
|
|
86
|
+
// non-null, mirroring `node.destination`'s own "only checked when the
|
|
87
|
+
// parent object is present" shape immediately above.
|
|
88
|
+
if (node.storeDetail && typeof node.storeDetail === 'object') {
|
|
89
|
+
if (node.storeDetail.operation !== null && !STORE_OPERATION_VALUES.includes(node.storeDetail.operation)) {
|
|
90
|
+
_err(errors, path('.storeDetail.operation'), `unrecognized storeDetail.operation "${node.storeDetail.operation}"`);
|
|
91
|
+
}
|
|
92
|
+
if (Object.prototype.hasOwnProperty.call(node.storeDetail, 'columns') && !Array.isArray(node.storeDetail.columns)) {
|
|
93
|
+
_err(errors, path('.storeDetail.columns'), 'storeDetail.columns must be an array');
|
|
94
|
+
} else if (Array.isArray(node.storeDetail.columns)) {
|
|
95
|
+
node.storeDetail.columns.forEach((c, i) => {
|
|
96
|
+
if (typeof c !== 'string') _err(errors, path(`.storeDetail.columns[${i}]`), 'storeDetail.columns entries must be strings');
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// Milestone 2, Sub-project E, increment 3: `node.queueDetail` is `null`
|
|
101
|
+
// on every node this increment doesn't populate — only checked when
|
|
102
|
+
// non-null, mirroring `node.storeDetail`'s own "only checked when the
|
|
103
|
+
// parent object is present" shape immediately above.
|
|
104
|
+
if (node.queueDetail && typeof node.queueDetail === 'object') {
|
|
105
|
+
if (node.queueDetail.operation !== null && !QUEUE_OPERATION_VALUES.includes(node.queueDetail.operation)) {
|
|
106
|
+
_err(errors, path('.queueDetail.operation'), `unrecognized queueDetail.operation "${node.queueDetail.operation}"`);
|
|
107
|
+
}
|
|
108
|
+
if (node.queueDetail.topic !== null && typeof node.queueDetail.topic !== 'string') {
|
|
109
|
+
_err(errors, path('.queueDetail.topic'), 'queueDetail.topic must be a string or null');
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function _validateDataElement(de, idx, errors, seenIds) {
|
|
115
|
+
const path = (suffix) => `$.dataElements[${idx}]${suffix}`;
|
|
116
|
+
if (!de || typeof de !== 'object') { _err(errors, path(''), 'dataElement must be an object'); return; }
|
|
117
|
+
if (typeof de.id !== 'string' || !de.id) _err(errors, path('.id'), 'dataElement.id is required');
|
|
118
|
+
else {
|
|
119
|
+
if (!ID_PREFIXES.data.test(de.id)) _err(errors, path('.id'), `dataElement.id must start with "data:"`);
|
|
120
|
+
seenIds.add(de.id);
|
|
121
|
+
}
|
|
122
|
+
if (typeof de.name !== 'string' || !de.name) _err(errors, path('.name'), 'dataElement.name is required');
|
|
123
|
+
if (!Array.isArray(de.dataClasses)) _err(errors, path('.dataClasses'), 'dataElement.dataClasses must be an array');
|
|
124
|
+
else {
|
|
125
|
+
for (let i = 0; i < de.dataClasses.length; i++) {
|
|
126
|
+
const cls = de.dataClasses[i];
|
|
127
|
+
if (!LINEAGE_DATA_CLASSES.includes(cls)) {
|
|
128
|
+
_err(errors, path(`.dataClasses[${i}]`), `unrecognized data class "${cls}"`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (!Array.isArray(de.aiContexts)) _err(errors, path('.aiContexts'), 'dataElement.aiContexts must be an array');
|
|
133
|
+
else {
|
|
134
|
+
for (let i = 0; i < de.aiContexts.length; i++) {
|
|
135
|
+
const ctx = de.aiContexts[i];
|
|
136
|
+
if (!isAiContext(ctx)) {
|
|
137
|
+
_err(errors, path(`.aiContexts[${i}]`), `unrecognized AI processing context "${ctx}"`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function _validateEdge(edge, idx, errors, nodeIds, dataElementIds) {
|
|
144
|
+
const path = (suffix) => `$.edges[${idx}]${suffix}`;
|
|
145
|
+
if (!edge || typeof edge !== 'object') { _err(errors, path(''), 'edge must be an object'); return; }
|
|
146
|
+
if (typeof edge.id !== 'string' || !edge.id) _err(errors, path('.id'), 'edge.id is required');
|
|
147
|
+
else if (!ID_PREFIXES.edge.test(edge.id)) _err(errors, path('.id'), `edge.id must start with "edge:"`);
|
|
148
|
+
if (!nodeIds.has(edge.from)) _err(errors, path('.from'), `unknown node id "${edge.from}"`);
|
|
149
|
+
if (!nodeIds.has(edge.to)) _err(errors, path('.to'), `unknown node id "${edge.to}"`);
|
|
150
|
+
if (edge.relationship !== 'data_flow') _err(errors, path('.relationship'), `unrecognized relationship "${edge.relationship}"`);
|
|
151
|
+
if (!Array.isArray(edge.fieldMappings)) _err(errors, path('.fieldMappings'), 'edge.fieldMappings must be an array');
|
|
152
|
+
else {
|
|
153
|
+
edge.fieldMappings.forEach((fm, i) => {
|
|
154
|
+
if (!MAPPING_TYPES.includes(fm?.mappingType)) _err(errors, path(`.fieldMappings[${i}].mappingType`), `unrecognized mappingType "${fm?.mappingType}"`);
|
|
155
|
+
for (const deId of fm?.dataElementIds || []) {
|
|
156
|
+
if (!dataElementIds.has(deId)) _err(errors, path(`.fieldMappings[${i}].dataElementIds`), `unknown dataElement id "${deId}"`);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
if (!edge.protection || typeof edge.protection !== 'object') {
|
|
161
|
+
_err(errors, path('.protection'), 'edge.protection is required');
|
|
162
|
+
} else {
|
|
163
|
+
for (const dim of PROTECTION_DIMENSIONS) {
|
|
164
|
+
if (!isValidProtectionDimension(edge.protection[dim])) _err(errors, path(`.protection.${dim}`), `invalid protection dimension`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (edge.protocol && typeof edge.protocol === 'object') {
|
|
168
|
+
if (!DESTINATION_RESOLUTION_VALUES.includes(edge.protocol.destinationResolution)) {
|
|
169
|
+
_err(errors, path('.protocol.destinationResolution'), `unrecognized destinationResolution "${edge.protocol.destinationResolution}"`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (!EDGE_PROVENANCE_VALUES.includes(edge.provenance)) {
|
|
173
|
+
_err(errors, path('.provenance'), `unrecognized provenance "${edge.provenance}"`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function _validateFlow(flow, idx, errors, nodeIds, dataElementIds, edgeIds) {
|
|
178
|
+
const path = (suffix) => `$.flows[${idx}]${suffix}`;
|
|
179
|
+
if (!flow || typeof flow !== 'object') { _err(errors, path(''), 'flow must be an object'); return; }
|
|
180
|
+
if (typeof flow.id !== 'string' || !flow.id) _err(errors, path('.id'), 'flow.id is required');
|
|
181
|
+
else if (!ID_PREFIXES.flow.test(flow.id)) _err(errors, path('.id'), `flow.id must start with "flow:"`);
|
|
182
|
+
if (!nodeIds.has(flow.source)) _err(errors, path('.source'), `unknown node id "${flow.source}"`);
|
|
183
|
+
if (!nodeIds.has(flow.sink)) _err(errors, path('.sink'), `unknown node id "${flow.sink}"`);
|
|
184
|
+
for (const deId of flow.dataElementIds || []) {
|
|
185
|
+
if (!dataElementIds.has(deId)) _err(errors, path('.dataElementIds'), `unknown dataElement id "${deId}"`);
|
|
186
|
+
}
|
|
187
|
+
for (const eId of flow.edgeIds || []) {
|
|
188
|
+
if (!edgeIds.has(eId)) _err(errors, path('.edgeIds'), `unknown edge id "${eId}"`);
|
|
189
|
+
}
|
|
190
|
+
if (!POLICY_STATES.includes(flow.policyVerdict)) _err(errors, path('.policyVerdict'), `unrecognized policyVerdict "${flow.policyVerdict}"`);
|
|
191
|
+
if (!FLOW_SUMMARY_VALUES.includes(flow.protectionSummary)) _err(errors, path('.protectionSummary'), `unrecognized protectionSummary "${flow.protectionSummary}"`);
|
|
192
|
+
// Milestone 2, Sub-project D, increment 1: `flow.handling` is `null` on
|
|
193
|
+
// every flow this increment's own caller chose not to populate — only
|
|
194
|
+
// checked when non-null, mirroring `_validateNode`'s own `node.destination`
|
|
195
|
+
// pattern above.
|
|
196
|
+
if (flow.handling != null && !HANDLING_VALUES.includes(flow.handling)) {
|
|
197
|
+
_err(errors, path('.handling'), `unrecognized handling "${flow.handling}"`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function _validateTransformation(t, idx, errors) {
|
|
202
|
+
const path = (suffix) => `$.transformations[${idx}]${suffix}`;
|
|
203
|
+
if (!t || typeof t !== 'object') { _err(errors, path(''), 'transformation must be an object'); return; }
|
|
204
|
+
if (typeof t.id !== 'string' || !t.id) _err(errors, path('.id'), 'transformation.id is required');
|
|
205
|
+
else if (!ID_PREFIXES.transform.test(t.id)) _err(errors, path('.id'), `transformation.id must start with "transform:"`);
|
|
206
|
+
if (!TRANSFORM_KINDS.includes(t.kind)) _err(errors, path('.kind'), `unrecognized transformation kind "${t.kind}"`);
|
|
207
|
+
if (!REVERSIBILITY_VALUES.includes(t.reversibility)) _err(errors, path('.reversibility'), `unrecognized reversibility "${t.reversibility}"`);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function _validateEvidence(e, idx, errors) {
|
|
211
|
+
const path = (suffix) => `$.evidence[${idx}]${suffix}`;
|
|
212
|
+
if (!e || typeof e !== 'object') { _err(errors, path(''), 'evidence must be an object'); return; }
|
|
213
|
+
if (typeof e.id !== 'string' || !e.id) _err(errors, path('.id'), 'evidence.id is required');
|
|
214
|
+
else if (!ID_PREFIXES.evidence.test(e.id)) _err(errors, path('.id'), `evidence.id must start with "evidence:"`);
|
|
215
|
+
if (!EVIDENCE_TYPES.includes(e.evidenceType)) _err(errors, path('.evidenceType'), `unrecognized evidenceType "${e.evidenceType}"`);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Report a validation error for every duplicate id beyond the first
|
|
220
|
+
* occurrence in a top-level entity array. Entities with a missing/invalid
|
|
221
|
+
* id are skipped here — that is already reported by the per-entity
|
|
222
|
+
* structural check, and treating `undefined` as a colliding "id" would be
|
|
223
|
+
* noise, not signal.
|
|
224
|
+
*/
|
|
225
|
+
function _checkDuplicateIds(items, key, errors) {
|
|
226
|
+
const seenAt = new Map();
|
|
227
|
+
items.forEach((item, idx) => {
|
|
228
|
+
if (!item || typeof item.id !== 'string' || !item.id) return;
|
|
229
|
+
if (seenAt.has(item.id)) {
|
|
230
|
+
_err(errors, `$.${key}[${idx}].id`, `duplicate id "${item.id}" (also used at $.${key}[${seenAt.get(item.id)}])`);
|
|
231
|
+
} else {
|
|
232
|
+
seenAt.set(item.id, idx);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Structurally validate a DataFlowGraph v1 envelope. Returns
|
|
239
|
+
* `{valid, errors}` and never throws.
|
|
240
|
+
*/
|
|
241
|
+
export function validateGraph(graph) {
|
|
242
|
+
const errors = [];
|
|
243
|
+
if (!graph || typeof graph !== 'object' || Array.isArray(graph)) {
|
|
244
|
+
return { valid: false, errors: [{ path: '$', message: 'graph must be an object' }] };
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (graph.schemaVersion !== SCHEMA_VERSION) {
|
|
248
|
+
_err(errors, '$.schemaVersion', `expected "${SCHEMA_VERSION}", got "${graph.schemaVersion}"`);
|
|
249
|
+
}
|
|
250
|
+
if (typeof graph.graphId !== 'string' || !graph.graphId.startsWith('dfg:')) {
|
|
251
|
+
_err(errors, '$.graphId', 'graphId must be a string starting with "dfg:"');
|
|
252
|
+
}
|
|
253
|
+
for (const key of ['nodes', 'edges', 'dataElements', 'transformations', 'flows', 'controls', 'policies', 'evidence', 'limitations']) {
|
|
254
|
+
_requireArray(graph, key, errors);
|
|
255
|
+
}
|
|
256
|
+
for (const key of ['scope', 'scanHealth', 'taxonomy', 'coverage', 'extensions']) {
|
|
257
|
+
_requireObject(graph, key, errors);
|
|
258
|
+
}
|
|
259
|
+
if (graph.scope && typeof graph.scope === 'object' && !Array.isArray(graph.scope)) {
|
|
260
|
+
if (!GRAPH_SCOPE_SOURCES.includes(graph.scope.source)) {
|
|
261
|
+
_err(errors, '$.scope.source', `unrecognized scope.source "${graph.scope.source}"`);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const nodeIds = new Set();
|
|
266
|
+
const dataElementIds = new Set();
|
|
267
|
+
const edgeIds = new Set();
|
|
268
|
+
|
|
269
|
+
(Array.isArray(graph.nodes) ? graph.nodes : []).forEach((n, i) => _validateNode(n, i, errors, nodeIds));
|
|
270
|
+
(Array.isArray(graph.dataElements) ? graph.dataElements : []).forEach((d, i) => _validateDataElement(d, i, errors, dataElementIds));
|
|
271
|
+
(Array.isArray(graph.edges) ? graph.edges : []).forEach((e, i) => {
|
|
272
|
+
_validateEdge(e, i, errors, nodeIds, dataElementIds);
|
|
273
|
+
if (e && typeof e.id === 'string') edgeIds.add(e.id);
|
|
274
|
+
});
|
|
275
|
+
(Array.isArray(graph.flows) ? graph.flows : []).forEach((f, i) => _validateFlow(f, i, errors, nodeIds, dataElementIds, edgeIds));
|
|
276
|
+
(Array.isArray(graph.transformations) ? graph.transformations : []).forEach((t, i) => _validateTransformation(t, i, errors));
|
|
277
|
+
(Array.isArray(graph.evidence) ? graph.evidence : []).forEach((e, i) => _validateEvidence(e, i, errors));
|
|
278
|
+
|
|
279
|
+
_checkDuplicateIds(Array.isArray(graph.nodes) ? graph.nodes : [], 'nodes', errors);
|
|
280
|
+
_checkDuplicateIds(Array.isArray(graph.edges) ? graph.edges : [], 'edges', errors);
|
|
281
|
+
_checkDuplicateIds(Array.isArray(graph.dataElements) ? graph.dataElements : [], 'dataElements', errors);
|
|
282
|
+
_checkDuplicateIds(Array.isArray(graph.flows) ? graph.flows : [], 'flows', errors);
|
|
283
|
+
|
|
284
|
+
return { valid: errors.length === 0, errors };
|
|
285
|
+
}
|
package/src/lsp/server.js
CHANGED
|
@@ -18,6 +18,7 @@ import * as path from 'node:path';
|
|
|
18
18
|
import * as readline from 'node:readline';
|
|
19
19
|
import { runScan } from '../runScan.js';
|
|
20
20
|
import { resetCustomRulesBudget } from '../posture/custom-rules.js';
|
|
21
|
+
import { withStateWritesDisabled } from '../posture/state-dir.js';
|
|
21
22
|
import { redactFinding } from '../mcp/redact.js';
|
|
22
23
|
import { _remediationOf } from '../report/index.js';
|
|
23
24
|
|
|
@@ -156,7 +157,34 @@ async function scanFile(uri) {
|
|
|
156
157
|
// whose source and sink are connected only through a call. Scoped to
|
|
157
158
|
// exactly the saved file (fileContents has one entry), so this does not
|
|
158
159
|
// turn every keystroke's save into a full-project deep scan.
|
|
159
|
-
|
|
160
|
+
// withStateWritesDisabled, for the same reason mcp/tools.js's scan_diff
|
|
161
|
+
// wraps its own partial-set scan (FR-704). This is a DIAGNOSTIC surface: it
|
|
162
|
+
// runs on every file save, against the user's real project root, with a
|
|
163
|
+
// fileContents map holding exactly one file. Without the wrapper,
|
|
164
|
+
// runFullScan's state writers fire on every keystroke-save — dpia.md,
|
|
165
|
+
// ropa.md, privacy-framework.json, threat-model.json and the rest, written
|
|
166
|
+
// into the user's tree by an editor plugin they never asked to mutate
|
|
167
|
+
// anything.
|
|
168
|
+
//
|
|
169
|
+
// The provenance lifecycle store makes that actively destructive rather
|
|
170
|
+
// than merely noisy: updateLifecycle marks every open stableId ABSENT from
|
|
171
|
+
// the finding set it is handed as `remediated`, and this set is one file's
|
|
172
|
+
// worth of findings. Every save would remediate the whole project, and the
|
|
173
|
+
// next real scan would reintroduce it.
|
|
174
|
+
//
|
|
175
|
+
// Chosen over forwarding `provenance:false` through runScan because that
|
|
176
|
+
// would fix only the lifecycle half and leave the other state writers
|
|
177
|
+
// firing. The flag is process-global (see its KNOWN LIMITATION), which is
|
|
178
|
+
// harmless here: this server is a read-only surface whose every scan wants
|
|
179
|
+
// writes off, so overlapping saves can only ever agree, and the `finally`
|
|
180
|
+
// restores the prior value either way. exceptCategories:['provenance-cache']
|
|
181
|
+
// (M2 §2.4) is the one deliberate exception — every OTHER write this scan
|
|
182
|
+
// would make stays suppressed, but the provenance disk cache stays live so
|
|
183
|
+
// repeated saves of the same file are not each paying the full uncached
|
|
184
|
+
// resolution cost.
|
|
185
|
+
const { scan } = await withStateWritesDisabled(() =>
|
|
186
|
+
runScan(_rootDir, { fileContents, depFileContents, deep: true, deepInCi: true }),
|
|
187
|
+
{ exceptCategories: ['provenance-cache'] });
|
|
160
188
|
// Stage 6 correctness audit: this only ever read scan.findings (the SAST
|
|
161
189
|
// channel). scan.secrets and scan.logicVulns are separate arrays on the
|
|
162
190
|
// raw runScan() result — normalizeFindings is what merges all four
|
|
@@ -298,7 +326,26 @@ export function startLspServer() {
|
|
|
298
326
|
}
|
|
299
327
|
|
|
300
328
|
// Allow direct invocation as a bin entry: `node lsp/server.js`.
|
|
301
|
-
|
|
329
|
+
//
|
|
330
|
+
// `import.meta.url === file://${process.argv[1]}` looks equivalent but is
|
|
331
|
+
// NOT: when this script is invoked through a symlink (exactly what
|
|
332
|
+
// `npm install -g`, `npx`, and `node_modules/.bin/<name>` all do for a
|
|
333
|
+
// package's `bin` entries — and `agentic-security-lsp` IS one of this
|
|
334
|
+
// package's bin entries), Node resolves `import.meta.url` to the symlink's
|
|
335
|
+
// realpath while `process.argv[1]` stays the symlink path as invoked, so the
|
|
336
|
+
// two never match, the guard is always false, and the server silently exits
|
|
337
|
+
// with no output — an editor would see the language server start and
|
|
338
|
+
// immediately die with nothing on stderr to explain it. `import.meta.main` is
|
|
339
|
+
// resolved correctly through a symlink. It was added in Node v24.2.0
|
|
340
|
+
// (backported to v22.18.0) and is currently Stability 1.0 (early development)
|
|
341
|
+
// per Node's own docs — NOT stable, and NOT available on v20.11. Concretely:
|
|
342
|
+
// it is `undefined` on Node 24.0.0/24.1.x, which satisfy this repo's declared
|
|
343
|
+
// `engines.node: ">=24.0.0"` floor, so `import.meta.main` alone would
|
|
344
|
+
// reproduce this exact bug on a plain non-symlinked invocation under those two
|
|
345
|
+
// point releases. The `??` fallback covers that gap without bumping the
|
|
346
|
+
// engines floor. Identical to bin/agentic-security.js's guard, deliberately —
|
|
347
|
+
// see the long-form note there.
|
|
348
|
+
if (import.meta.main ?? (import.meta.url === `file://${process.argv[1]}`)) {
|
|
302
349
|
startLspServer();
|
|
303
350
|
}
|
|
304
351
|
|
package/src/mcp/CLAUDE.md
CHANGED
|
@@ -23,8 +23,14 @@ MCP server. JSON-RPC 2.0 over NDJSON on stdin/stdout. Bin entry `../../bin/agent
|
|
|
23
23
|
| `query_triage_memory` | ✓ | reads past triage decisions (wont-fix/false-positive) by natural-language query |
|
|
24
24
|
| `query_findings_memory` | ✓ | reads accumulated scan memory (findings + triage history + AGENTS.md) by natural-language query |
|
|
25
25
|
| `query_cache_telemetry` | ✓ | reads prompt-cache economics from the current session transcript; no network |
|
|
26
|
+
| `dataflow_get_graph` | ✓ | reads the signed `lineage-graph.json` (via `server/graph-loader.js`, reused unmodified); returns the DataFlowGraph v1 artifact. Milestone 5: an optional `filter: {nodeIds, edgeIds}` input narrows the returned nodes/edges/flows/dataElements via the exact same `validateFilterShape`/`_filterGraph` pair the CLI's `--filter` and the `explore` server's `POST /api/v1/query` endpoint use — closes the large-graph gap FOR A CALLER THAT SUPPLIES A FILTER. **Known gap, still real**: an OMITTED filter still returns the whole graph inline with no pagination/offload — a very large, unfiltered graph can still exceed the stdio transport line cap — see `dataflow-tools.js`'s own header comment |
|
|
27
|
+
| `dataflow_get_node` | ✓ | as above, ID-scoped node lookup (via `server/routes.js`'s `handleNode`, reused unmodified) |
|
|
28
|
+
| `dataflow_get_edge` | ✓ | as above, ID-scoped edge lookup (`handleEdge`) |
|
|
29
|
+
| `dataflow_get_flow` | ✓ | as above, ID-scoped flow lookup (`handleFlow`), includes contributing node/edge canonical ids |
|
|
26
30
|
|
|
27
|
-
**
|
|
31
|
+
**Dataflow-tools redaction scope (found by a post-Task-2 whole-branch security review, fixed same day):** the initial cut only redacted `evidence[].location.note`, which turned out to be fixture-only — the real graph-builder emitter never populates `.note` (it uses `{file,line}`). The real source-derived surfaces are `node.destination.raw`/`.literalValue` (lifted verbatim from a scanned call-site argument by `lineage/resolve-destination.js`) and `evidence[].claim`/`.snippet`. `dataflow-tools.js`'s `_redactNode`/`_redactEvidence`/`_redactGraph` now cover all of them, applied on `dataflow_get_graph` (full graph) and `dataflow_get_node` (single node); edges and flows carry only `evidenceRefs` (id strings), never embedded evidence or destination-shaped fields, so they need no redaction pass. `dataflow-tools.js` was also missing from `server.js`'s `CODE_FINGERPRINT` file list (OWASP MCP04/MCP09) — added.
|
|
32
|
+
|
|
33
|
+
**21 tools, not 12** — this table previously stopped at 12 and the count quoted elsewhere (root `CLAUDE.md`, the non-Claude plugin manifests) said "Six." Re-derive with `grep -c "name: '" scanner/src/mcp/tools.js scanner/src/mcp/dataflow-tools.js | awk -F: '{s+=$2} END{print s}'` — **not** `tools.js` alone, which now undercounts by 4: the 4 `dataflow_*` tools are defined in `dataflow-tools.js` and only imported into `tools.js`'s `ALL_TOOLS`. If a future tool file follows this same reused-adapter-module pattern, extend the file list rather than trusting a single-file grep again.
|
|
28
34
|
|
|
29
35
|
**Two write tools, not one.** `apply_fix` and `apply_sca_upgrade` both write; `verify_fix` also writes (see its row above) though not to the target project's own files. `apply_fix` additionally requires `confirm:true` AND the last-scan HMAC to verify AND the target path not on the reserved-write list; `apply_sca_upgrade` requires `confirm:true` and gates on its own test-restore cycle.
|
|
30
36
|
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// dataflow-tools.js — Milestone 4, sub-project MCP tools.
|
|
2
|
+
//
|
|
3
|
+
// Thin, read-only MCP adapter over the DataFlowGraph v1 artifact. Every
|
|
4
|
+
// piece of actual graph-loading and graph-query logic here is REUSED,
|
|
5
|
+
// unmodified, from scanner/src/server/ (built for the `explore` HTTP
|
|
6
|
+
// server, Milestone 3): loadSignedGraph does the signed-artifact
|
|
7
|
+
// load+verify, the four handleX functions do the lookups. This module
|
|
8
|
+
// adds nothing but MCP tool shape (name/description/inputSchema/handler)
|
|
9
|
+
// and MCP-appropriate error handling — no new graph-query logic is
|
|
10
|
+
// written here, on purpose (see this sub-project's own scoping doc).
|
|
11
|
+
|
|
12
|
+
import { loadSignedGraph } from '../server/graph-loader.js';
|
|
13
|
+
import { handleGraph, handleNode, handleEdge, handleFlow } from '../server/routes.js';
|
|
14
|
+
import { _redactNode, _redactEvidence, _redactGraph } from '../lineage/redact-graph.js';
|
|
15
|
+
import { _filterGraph, validateFilterShape } from '../lineage/export-json.js';
|
|
16
|
+
|
|
17
|
+
const META = { source: 'agentic-security-mcp', untrusted_excerpts: true };
|
|
18
|
+
|
|
19
|
+
function _loadOrFailure(sessionRoot) {
|
|
20
|
+
const loaded = loadSignedGraph(sessionRoot);
|
|
21
|
+
if (loaded.ok) return { graph: loaded.graph };
|
|
22
|
+
return {
|
|
23
|
+
failure: {
|
|
24
|
+
_meta: META,
|
|
25
|
+
hasResult: false,
|
|
26
|
+
reason: loaded.reason,
|
|
27
|
+
message: loaded.message,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Milestone 5, large-graph pagination: an optional `filter` input narrows the
|
|
33
|
+
// returned graph via the exact same `validateFilterShape`/`_filterGraph`
|
|
34
|
+
// pair the CLI's own `--filter` and the `explore` server's new
|
|
35
|
+
// `POST /api/v1/query` endpoint both already use — one real, shared
|
|
36
|
+
// primitive, not a third drifting copy. KNOWN, DISCLOSED GAP (still open):
|
|
37
|
+
// an OMITTED filter still returns the whole graph inline, with the same
|
|
38
|
+
// stdio.js MAX_LINE_BYTES (4MB) risk on a very large, unfiltered scan as
|
|
39
|
+
// before this change — this increment adds an opt-in capability for a
|
|
40
|
+
// caller that supplies a filter, it does not add a forced fallback/offload
|
|
41
|
+
// for a caller that doesn't. That remains a follow-up increment.
|
|
42
|
+
// Final whole-branch review finding: `filter: {}` is NOT the same as
|
|
43
|
+
// omitting `filter` — `_filterGraph` treats an empty (but well-formed)
|
|
44
|
+
// filter object as "narrow to nothing" (empty nodeIds/edgeIds Sets), so
|
|
45
|
+
// `filter: {}` returns an EMPTY graph (zero nodes/edges/flows), not the
|
|
46
|
+
// whole one. Called out explicitly in this tool's own `description` below
|
|
47
|
+
// so an agent reaching for "no restriction" reaches for OMITTING the
|
|
48
|
+
// argument, never for `{}`.
|
|
49
|
+
export const dataflow_get_graph = {
|
|
50
|
+
name: 'dataflow_get_graph',
|
|
51
|
+
description: 'Return the DataFlowGraph v1 artifact from the last signed, verified deep-mode scan: nodes, edges, flows, scope, coverage, and limitations. Requires a prior `AGENTIC_SECURITY_LINEAGE_DEEP=1 agentic-security scan`. Optional `filter: {nodeIds, edgeIds}` narrows the returned nodes/edges/flows/dataElements (same primitive as the CLI\'s `--filter` and the `explore` server\'s `POST /api/v1/query`). IMPORTANT: omit `filter` entirely for the whole graph — passing `filter: {}` returns an EMPTY graph (zero nodes/edges/flows), not the whole one, since an empty filter narrows to nothing rather than meaning "no restriction". KNOWN GAP: an OMITTED filter still returns the whole graph inline with no pagination/offload — may exceed the stdio transport line cap on a very large, unfiltered graph; supply a real, non-empty filter to narrow the response.',
|
|
52
|
+
inputSchema: {
|
|
53
|
+
type: 'object',
|
|
54
|
+
additionalProperties: false,
|
|
55
|
+
properties: {
|
|
56
|
+
filter: {
|
|
57
|
+
type: 'object',
|
|
58
|
+
additionalProperties: false,
|
|
59
|
+
properties: {
|
|
60
|
+
nodeIds: { type: 'array', items: { type: 'string' } },
|
|
61
|
+
edgeIds: { type: 'array', items: { type: 'string' } },
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
async handler(args, ctx) {
|
|
67
|
+
const { graph, failure } = _loadOrFailure(ctx.sessionRoot);
|
|
68
|
+
if (failure) return failure;
|
|
69
|
+
// Milestone 5, large-graph pagination: reuses the exact same
|
|
70
|
+
// validateFilterShape/_filterGraph pair the new POST /api/v1/query
|
|
71
|
+
// server endpoint and the CLI's own --filter both use — one real,
|
|
72
|
+
// shared primitive, not a third drifting copy.
|
|
73
|
+
const filterCheck = validateFilterShape(args?.filter);
|
|
74
|
+
if (!filterCheck.valid) {
|
|
75
|
+
return { _meta: META, hasResult: false, reason: 'invalid-filter', message: filterCheck.error };
|
|
76
|
+
}
|
|
77
|
+
const { status, body } = handleGraph(graph);
|
|
78
|
+
return {
|
|
79
|
+
_meta: META,
|
|
80
|
+
hasResult: true,
|
|
81
|
+
status,
|
|
82
|
+
data: _redactGraph(args?.filter ? _filterGraph(body.data, args.filter) : body.data),
|
|
83
|
+
digest: body.digest,
|
|
84
|
+
schemaVersion: body.schemaVersion,
|
|
85
|
+
extensions: body.extensions,
|
|
86
|
+
scope: body.scope,
|
|
87
|
+
coverage: body.coverage,
|
|
88
|
+
limitations: body.limitations,
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export const dataflow_get_node = {
|
|
94
|
+
name: 'dataflow_get_node',
|
|
95
|
+
description: 'Look up one node by canonical id in the DataFlowGraph v1 artifact.',
|
|
96
|
+
inputSchema: {
|
|
97
|
+
type: 'object',
|
|
98
|
+
additionalProperties: false,
|
|
99
|
+
properties: { id: { type: 'string', minLength: 1, maxLength: 512 } },
|
|
100
|
+
required: ['id'],
|
|
101
|
+
},
|
|
102
|
+
async handler({ id }, ctx) {
|
|
103
|
+
const { graph, failure } = _loadOrFailure(ctx.sessionRoot);
|
|
104
|
+
if (failure) return failure;
|
|
105
|
+
const { status, body } = handleNode(graph, id);
|
|
106
|
+
return {
|
|
107
|
+
_meta: META,
|
|
108
|
+
hasResult: true,
|
|
109
|
+
notFound: status === 404,
|
|
110
|
+
data: _redactNode(body.data),
|
|
111
|
+
canonicalIds: body.canonicalIds,
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export const dataflow_get_edge = {
|
|
117
|
+
name: 'dataflow_get_edge',
|
|
118
|
+
description: 'Look up one edge by canonical id in the DataFlowGraph v1 artifact.',
|
|
119
|
+
inputSchema: {
|
|
120
|
+
type: 'object',
|
|
121
|
+
additionalProperties: false,
|
|
122
|
+
properties: { id: { type: 'string', minLength: 1, maxLength: 512 } },
|
|
123
|
+
required: ['id'],
|
|
124
|
+
},
|
|
125
|
+
async handler({ id }, ctx) {
|
|
126
|
+
const { graph, failure } = _loadOrFailure(ctx.sessionRoot);
|
|
127
|
+
if (failure) return failure;
|
|
128
|
+
const { status, body } = handleEdge(graph, id);
|
|
129
|
+
return {
|
|
130
|
+
_meta: META,
|
|
131
|
+
hasResult: true,
|
|
132
|
+
notFound: status === 404,
|
|
133
|
+
data: body.data,
|
|
134
|
+
canonicalIds: body.canonicalIds,
|
|
135
|
+
};
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
export const dataflow_get_flow = {
|
|
140
|
+
name: 'dataflow_get_flow',
|
|
141
|
+
description: 'Look up one flow by canonical id in the DataFlowGraph v1 artifact, including its contributing node/edge canonical ids.',
|
|
142
|
+
inputSchema: {
|
|
143
|
+
type: 'object',
|
|
144
|
+
additionalProperties: false,
|
|
145
|
+
properties: { id: { type: 'string', minLength: 1, maxLength: 512 } },
|
|
146
|
+
required: ['id'],
|
|
147
|
+
},
|
|
148
|
+
async handler({ id }, ctx) {
|
|
149
|
+
const { graph, failure } = _loadOrFailure(ctx.sessionRoot);
|
|
150
|
+
if (failure) return failure;
|
|
151
|
+
const { status, body } = handleFlow(graph, id);
|
|
152
|
+
return {
|
|
153
|
+
_meta: META,
|
|
154
|
+
hasResult: true,
|
|
155
|
+
notFound: status === 404,
|
|
156
|
+
data: body.data,
|
|
157
|
+
canonicalIds: body.canonicalIds,
|
|
158
|
+
};
|
|
159
|
+
},
|
|
160
|
+
};
|
package/src/mcp/server.js
CHANGED
|
@@ -43,7 +43,7 @@ const TOOLS_BY_NAME = Object.fromEntries(ALL_TOOLS.map(t => [t.name, t]));
|
|
|
43
43
|
function _codeFingerprint() {
|
|
44
44
|
try {
|
|
45
45
|
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
46
|
-
const files = ['server.js', 'tools.js', 'stdio.js', 'audit.js', 'validate.js', 'redact.js'];
|
|
46
|
+
const files = ['server.js', 'tools.js', 'dataflow-tools.js', 'stdio.js', 'audit.js', 'validate.js', 'redact.js'];
|
|
47
47
|
const h = crypto.createHash('sha256');
|
|
48
48
|
for (const f of files) {
|
|
49
49
|
try { h.update(f); h.update(fs.readFileSync(path.join(here, f))); } catch {}
|
package/src/mcp/tools.js
CHANGED
|
@@ -26,6 +26,11 @@ import { withStateWritesDisabled } from '../posture/state-dir.js';
|
|
|
26
26
|
import { analyzeTranscript, formatCacheReport, renderCacheStatusLine } from '../posture/cache-economics.js';
|
|
27
27
|
import { redactString, redactFinding } from './redact.js';
|
|
28
28
|
import { _remediationOf, normalizeFindings } from '../report/index.js';
|
|
29
|
+
// Git-origin provenance (Finding Provenance M0/M1). Distinct from
|
|
30
|
+
// `finding.provenance` (AI-authorship) and from an SCA entry's `provenance`
|
|
31
|
+
// (Sigstore/SLSA attestation) — see report/index.js's import comment.
|
|
32
|
+
import { redactFindingProvenance } from '../posture/provenance/schema.js';
|
|
33
|
+
import { dataflow_get_graph, dataflow_get_node, dataflow_get_edge, dataflow_get_flow } from './dataflow-tools.js';
|
|
29
34
|
|
|
30
35
|
// Lazy-loaded: these transitively pull in npm packages (@babel/core and
|
|
31
36
|
// friends) that aren't available in the plugin-cache install path
|
|
@@ -571,6 +576,21 @@ export const explain_finding = {
|
|
|
571
576
|
epssScore: typeof f.epssScore === 'number' ? f.epssScore : null,
|
|
572
577
|
epssPercentile: typeof f.epssPercentile === 'number' ? f.epssPercentile : null,
|
|
573
578
|
exploitedNow: !!f.exploitedNow,
|
|
579
|
+
// Which commit introduced this finding. `includeEmail` stays at its
|
|
580
|
+
// DEFAULT (false) unconditionally — unlike the JSON report there is no
|
|
581
|
+
// operator-set env escape for it here, because the consumer is an
|
|
582
|
+
// agent that has no business receiving a committer's email address.
|
|
583
|
+
// `pseudonymize`, by contrast, IS read back from the same env var
|
|
584
|
+
// report/index.js's `_normalizedProvenance` reads
|
|
585
|
+
// (AGENTIC_SECURITY_PSEUDONYMIZE_AUTHORS=1 / --pseudonymize-authors) —
|
|
586
|
+
// fix-round item 4: an operator who set that policy was still getting
|
|
587
|
+
// raw committer names (and, via providerEnrichment, raw reviewer
|
|
588
|
+
// logins/CODEOWNERS lines) through this MCP surface because this call
|
|
589
|
+
// passed no options object at all, silently defeating their policy at
|
|
590
|
+
// this one output boundary while report/index.js honoured it.
|
|
591
|
+
findingProvenance: f.findingProvenance ? redactFindingProvenance(f.findingProvenance, {
|
|
592
|
+
pseudonymize: process.env.AGENTIC_SECURITY_PSEUDONYMIZE_AUTHORS === '1',
|
|
593
|
+
}) : null,
|
|
574
594
|
};
|
|
575
595
|
},
|
|
576
596
|
};
|
|
@@ -775,6 +795,7 @@ export const apply_fix = {
|
|
|
775
795
|
const entry = await applyFixHistory({
|
|
776
796
|
scanRoot: ctx.sessionRoot, file: rel, originalContent, newContent: v.content, fileExisted,
|
|
777
797
|
findingId: f.id, stableId: f.stableId, ruleId: f.ruleId || f.cwe || f.family || null, vuln: f.vuln || f.title || null,
|
|
798
|
+
findingProvenance: f.findingProvenance || null,
|
|
778
799
|
});
|
|
779
800
|
written.push({ file: rel, historyId: entry.id, backupPath: entry.backupPath });
|
|
780
801
|
}
|
|
@@ -1524,4 +1545,4 @@ export const apply_sca_upgrade = {
|
|
|
1524
1545
|
},
|
|
1525
1546
|
};
|
|
1526
1547
|
|
|
1527
|
-
export const ALL_TOOLS = [scan_diff, query_taint, explain_finding, apply_fix, verify_fix, synthesize_fix, find_rule_module, append_scratchpad, read_scratchpad, append_agents_memory, read_agents_memory, lookup_cve, synthesize_sca_upgrade, apply_sca_upgrade, query_triage_memory, query_findings_memory, query_cache_telemetry];
|
|
1548
|
+
export const ALL_TOOLS = [scan_diff, query_taint, explain_finding, apply_fix, verify_fix, synthesize_fix, find_rule_module, append_scratchpad, read_scratchpad, append_agents_memory, read_agents_memory, lookup_cve, synthesize_sca_upgrade, apply_sca_upgrade, query_triage_memory, query_findings_memory, query_cache_telemetry, dataflow_get_graph, dataflow_get_node, dataflow_get_edge, dataflow_get_flow];
|