@dataparade/cli 0.0.35 → 0.1.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/README.md +1 -0
- package/dist/package.json +4 -4
- package/dist/src/ai-enrichment/pii-signal-rules.d.ts +5 -0
- package/dist/src/ai-enrichment/pii-signal-rules.js +2 -3
- package/dist/src/ai-enrichment/third-party-data-flow.js +5 -4
- package/dist/src/cli.js +9 -3
- package/dist/src/facts/build-facts.d.ts +2 -0
- package/dist/src/facts/build-facts.js +14 -0
- package/dist/src/facts/layout.d.ts +4 -0
- package/dist/src/facts/layout.js +5 -1
- package/dist/src/facts/scan-stamps.d.ts +7 -0
- package/dist/src/facts/scan-stamps.js +30 -0
- package/dist/src/facts/schema.d.ts +74 -0
- package/dist/src/facts/schema.js +32 -1
- package/dist/src/output/scan-output-excludes.js +2 -0
- package/dist/src/output/write-scan-knowledge.d.ts +5 -1
- package/dist/src/output/write-scan-knowledge.js +21 -0
- package/dist/src/threat-model/build-threat-model.d.ts +3 -0
- package/dist/src/threat-model/build-threat-model.js +71 -0
- package/dist/src/threat-model/carry-forward-person-set-statuses.d.ts +8 -0
- package/dist/src/threat-model/carry-forward-person-set-statuses.js +87 -0
- package/dist/src/threat-model/io.d.ts +19 -0
- package/dist/src/threat-model/io.js +63 -0
- package/dist/src/threat-model/schema.d.ts +214 -0
- package/dist/src/threat-model/schema.js +75 -0
- package/dist/src/ui/scan-progress-renderer.d.ts +8 -1
- package/dist/src/ui/scan-progress-renderer.js +20 -1
- package/dist/src/upload/collect-scan-sidecars.d.ts +2 -1
- package/dist/src/upload/collect-scan-sidecars.js +3 -1
- package/dist/tests/cli/cli.spec.js +10 -1
- package/dist/tests/helpers/facts-fixture.js +16 -16
- package/dist/tests/schema/scan-result.schema.spec.js +1 -1
- package/dist/tests/unit/ai-enrichment/third-party-data-flow.spec.js +5 -5
- package/dist/tests/unit/core/graph-mapping.spec.js +4 -3
- package/dist/tests/unit/discoveries/write-ocsf-discoveries-long-ids.spec.js +3 -3
- package/dist/tests/unit/export/export-ocsf.spec.js +4 -4
- package/dist/tests/unit/facts/apply-answers.spec.js +20 -20
- package/dist/tests/unit/facts/build-facts.spec.js +126 -45
- package/dist/tests/unit/facts/identity.spec.js +13 -0
- package/dist/tests/unit/facts/scan-stamps.spec.js +32 -0
- package/dist/tests/unit/facts/slug.spec.js +2 -0
- package/dist/tests/unit/kb/answer-fingerprint.spec.js +9 -9
- package/dist/tests/unit/kb/kb-interview-loop.spec.js +3 -3
- package/dist/tests/unit/output/scan-output-excludes.spec.js +1 -1
- package/dist/tests/unit/threat-model/build-threat-model.spec.d.ts +1 -0
- package/dist/tests/unit/threat-model/build-threat-model.spec.js +184 -0
- package/dist/tests/unit/threat-model/carry-forward-person-set-statuses.spec.d.ts +1 -0
- package/dist/tests/unit/threat-model/carry-forward-person-set-statuses.spec.js +163 -0
- package/dist/tests/unit/threat-model/io.spec.d.ts +1 -0
- package/dist/tests/unit/threat-model/io.spec.js +103 -0
- package/dist/tests/unit/threat-model/schema.spec.d.ts +1 -0
- package/dist/tests/unit/threat-model/schema.spec.js +42 -0
- package/dist/tests/unit/ui/scan-progress-renderer.spec.js +58 -0
- package/dist/tests/unit/upload/collect-scan-sidecars.spec.js +8 -5
- package/dist/vendor/scanner/dist/src/analyze/code-navigator.d.ts +1 -1
- package/dist/vendor/scanner/dist/src/analyze/code-navigator.js +4 -0
- package/dist/vendor/scanner/dist/src/analyze/column-catalog.d.ts +1 -1
- package/dist/vendor/scanner/dist/src/analyze/column-catalog.js +2 -2
- package/dist/vendor/scanner/dist/src/analyze/concept-profile.d.ts +2 -2
- package/dist/vendor/scanner/dist/src/analyze/concept-profile.js +5 -3
- package/dist/vendor/scanner/dist/src/core/pipeline/build-scan-personal-data-layers.js +1 -1
- package/dist/vendor/scanner/dist/src/core/pipeline/deterministic-scan.js +43 -0
- package/dist/vendor/scanner/dist/src/core/pipeline/graph-mapping.js +23 -2
- package/dist/vendor/scanner/dist/src/core/pipeline/mixed-app-terraform-scan.js +1 -0
- package/dist/vendor/scanner/dist/src/core/pipeline/orchestrator-result.d.ts +2 -2
- package/dist/vendor/scanner/dist/src/core/pipeline/terraform-minimal-services.js +1 -0
- package/dist/vendor/scanner/dist/src/core/schema/scan-result.schema.d.ts +160 -2
- package/dist/vendor/scanner/dist/src/core/schema/scan-result.schema.js +24 -0
- package/dist/vendor/scanner/dist/src/core/types/data-flow.d.ts +48 -0
- package/dist/vendor/scanner/dist/src/core/types/data-flow.js +53 -0
- package/dist/vendor/scanner/dist/src/data-flow/detect.js +1 -0
- package/dist/vendor/scanner/dist/src/data-flow/ensure-hub-linked-assets.js +1 -0
- package/dist/vendor/scanner/dist/src/data-flow/ensure-manifest-declared-flows.js +1 -0
- package/dist/vendor/scanner/dist/src/data-flow/flow-authentication.d.ts +30 -0
- package/dist/vendor/scanner/dist/src/data-flow/flow-authentication.js +277 -0
- package/dist/vendor/scanner/dist/src/data-flow/flow-builder.js +6 -0
- package/dist/vendor/scanner/dist/src/data-flow/flow-controls.d.ts +24 -0
- package/dist/vendor/scanner/dist/src/data-flow/flow-controls.js +238 -0
- package/dist/vendor/scanner/dist/src/data-flow/flow-data-categories.d.ts +22 -0
- package/dist/vendor/scanner/dist/src/data-flow/flow-data-categories.js +69 -0
- package/dist/vendor/scanner/dist/src/data-flow/flow-interaction-description.d.ts +13 -0
- package/dist/vendor/scanner/dist/src/data-flow/flow-interaction-description.js +263 -0
- package/dist/vendor/scanner/dist/src/data-flow/hub-link-policy.d.ts +2 -1
- package/dist/vendor/scanner/dist/src/data-flow/hub-link-policy.js +3 -0
- package/dist/vendor/scanner/dist/src/data-flow/human-interaction-channels.d.ts +37 -0
- package/dist/vendor/scanner/dist/src/data-flow/human-interaction-channels.js +483 -0
- package/dist/vendor/scanner/dist/src/data-flow/intra-component-lineage.d.ts +3 -0
- package/dist/vendor/scanner/dist/src/data-flow/intra-component-lineage.js +12 -17
- package/dist/vendor/scanner/dist/src/data-flow/terraform-flows.js +5 -1
- package/dist/vendor/scanner/dist/src/data-flow/transformation-patterns.d.ts +5 -1
- package/dist/vendor/scanner/dist/src/data-flow/transformation-patterns.js +17 -37
- package/dist/vendor/scanner/dist/src/eval/canonical/concept-map.d.ts +36 -5
- package/dist/vendor/scanner/dist/src/eval/canonical/concept-map.js +53 -60
- package/dist/vendor/scanner/dist/src/eval/canonical/graph/endpoints.js +2 -9
- package/dist/vendor/scanner/dist/src/eval/canonical/scanner/personal-data.js +10 -7
- package/dist/vendor/scanner/dist/src/graph/build-dataparade-graph.js +3 -1
- package/dist/vendor/scanner/dist/src/index.d.ts +6 -0
- package/dist/vendor/scanner/dist/src/index.js +16 -1
- package/dist/vendor/scanner/dist/src/patterns/engine.js +1 -0
- package/dist/vendor/scanner/dist/src/pii-signals/match-pii-signals.d.ts +1 -1
- package/dist/vendor/scanner/dist/src/pii-signals/match-pii-signals.js +2 -2
- package/dist/vendor/scanner/dist/src/pii-signals/occurrence-group.d.ts +3 -3
- package/dist/vendor/scanner/dist/src/pii-signals/occurrence-group.js +12 -11
- package/dist/vendor/scanner/dist/src/pii-signals/personal-data-taxonomy.d.ts +44 -0
- package/dist/vendor/scanner/dist/src/pii-signals/personal-data-taxonomy.js +167 -0
- package/dist/vendor/scanner/dist/src/pii-signals/pii-signal-aliases.js +43 -43
- package/dist/vendor/scanner/dist/src/pii-signals/pii-signal-rules.d.ts +12 -1
- package/dist/vendor/scanner/dist/src/pii-signals/pii-signal-rules.js +28 -7
- package/dist/vendor/scanner/dist/src/pii-signals/signal-token.js +1 -1
- package/dist/vendor/scanner/dist/src/threats/stride.d.ts +98 -0
- package/dist/vendor/scanner/dist/src/threats/stride.js +179 -0
- package/dist/vendor/scanner/package.json +2 -2
- package/dist/vendor/scanner/patterns/concept-profiles.yaml +2 -2
- package/dist/vendor/scanner/patterns/flow-authentication.rules.yaml +75 -0
- package/dist/vendor/scanner/patterns/flow-controls.rules.yaml +68 -0
- package/dist/vendor/scanner/patterns/personal-data-taxonomy.yaml +155 -0
- package/dist/vendor/scanner/patterns/pii-signals.rules.yaml +38 -49
- package/dist/vendor/scanner/patterns/stride.rules.yaml +86 -0
- package/package.json +4 -4
- package/dist/vendor/scanner/dist/src/eval/canonical/concept-map.validate.d.ts +0 -17
- package/dist/vendor/scanner/dist/src/eval/canonical/concept-map.validate.js +0 -108
- package/dist/vendor/scanner/patterns/personal-data-concept-map.yaml +0 -76
package/README.md
CHANGED
|
@@ -126,6 +126,7 @@ By default, a scan writes these files to `./.dataparade/`:
|
|
|
126
126
|
| --- | --- |
|
|
127
127
|
| `dataflow.json` | The diagram the web app imports: a wrapper with `schemaVersion`, `graph` (`DiagramGraphJson`: nodes, edges, viewport) and `metadata` (files scanned, duration, C4 `hierarchy`, etc.). |
|
|
128
128
|
| `facts.json` | What the latest scan found: components, data flows, data items (with groups) and the links between them. Replaced on every scan. |
|
|
129
|
+
| `threat-model.json` | STRIDE threat categories for each component and data flow, with the status the scan's rules give and a separate status a person can set. A rescan keeps the person-set status. |
|
|
129
130
|
| `data-items/<name>.json` | One file per data item, with every place it occurs in the code. |
|
|
130
131
|
| `graphify.json` | The code-structure graph from [Graphify](https://github.com/Graphify-Labs/graphify), when it is installed. |
|
|
131
132
|
| `answers.json` | People's decisions (interview answers, reviews). A scan never writes or changes it. |
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dataparade/cli",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "dataPARADE CLI — scan codebases for privacy and security data flows",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"eval:models": "pnpm exec node dist/src/evals/run-model-matrix.js"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@clack/prompts": "^1.
|
|
58
|
+
"@clack/prompts": "^1.9.0",
|
|
59
59
|
"@sentry/node": "^10.75.2",
|
|
60
60
|
"commander": "^14.0.3",
|
|
61
61
|
"dotenv": "^16.4.7",
|
|
@@ -67,14 +67,14 @@
|
|
|
67
67
|
"zod": "^4.3.5"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"@dataparade/scanner": "github:DataParade-io/scanner#
|
|
70
|
+
"@dataparade/scanner": "github:DataParade-io/scanner#798ba353eff174ae0210df166c55ea6aef351b97",
|
|
71
71
|
"@eslint/js": "^9.18.0",
|
|
72
72
|
"@types/jest": "^30.0.0",
|
|
73
73
|
"@types/node": "^22.0.0",
|
|
74
74
|
"eslint": "^9.18.0",
|
|
75
75
|
"globals": "^15.14.0",
|
|
76
76
|
"jest": "^30.5.2",
|
|
77
|
-
"ts-jest": "^29.4.
|
|
77
|
+
"ts-jest": "^29.4.15",
|
|
78
78
|
"typescript-eslint": "^8.20.0"
|
|
79
79
|
},
|
|
80
80
|
"files": [
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A scanner detector rule. Its `id` is the personal-data type it detects, a W3C DPV concept
|
|
3
|
+
* CURIE from the scanner's patterns/personal-data-taxonomy.yaml (`pd:EmailAddress`,
|
|
4
|
+
* `dpx:FirstName`; DATAP-947). `labels` is that type, which `dataShared` reports.
|
|
5
|
+
*/
|
|
1
6
|
export interface PiiSignalRule {
|
|
2
7
|
id: string;
|
|
3
8
|
category: "identifiers" | "profile_data" | "credentials";
|
|
@@ -13,7 +13,6 @@ const scanner_package_root_1 = require("../scanner-package-root");
|
|
|
13
13
|
const piiSignalRuleSchema = zod_1.z.object({
|
|
14
14
|
id: zod_1.z.string().min(1),
|
|
15
15
|
category: zod_1.z.enum(["identifiers", "profile_data", "credentials"]),
|
|
16
|
-
labels: zod_1.z.array(zod_1.z.string().min(1)).default([]),
|
|
17
16
|
patterns: zod_1.z.array(zod_1.z.string().min(1)).default([]),
|
|
18
17
|
});
|
|
19
18
|
const piiSignalCatalogSchema = zod_1.z.object({
|
|
@@ -55,9 +54,9 @@ function loadPiiSignalRules() {
|
|
|
55
54
|
throw new Error(`PII signal rules at '${configPath}' failed schema validation: ${message}`);
|
|
56
55
|
}
|
|
57
56
|
cachedRules = normalized.pii_signal_rules.map((rule) => ({
|
|
58
|
-
id: rule.id.trim()
|
|
57
|
+
id: rule.id.trim(),
|
|
59
58
|
category: rule.category,
|
|
60
|
-
labels: rule.
|
|
59
|
+
labels: [rule.id.trim()],
|
|
61
60
|
patterns: rule.patterns.map((pattern) => new RegExp(pattern, "i")),
|
|
62
61
|
}));
|
|
63
62
|
return cachedRules;
|
|
@@ -34,22 +34,23 @@ function resolveComponentId(id, remap) {
|
|
|
34
34
|
}
|
|
35
35
|
const OPERATION_RE = /\b(fetch|axios|request|invoke|send|post|get|put|patch|delete|upload|download|signIn|signOut|auth|token|storage|bucket|client|generateContent|chat|completions|models)\b/i;
|
|
36
36
|
const AI_VENDOR_TOKEN_RE = /\b(openai|googleai|gemini|anthropic|claude|mistral|cohere|vertex|vertexai|generativeai|generativelanguage|genai)\b/i;
|
|
37
|
+
/** Personal-data labels are W3C DPV concepts from the scanner taxonomy (DATAP-947). */
|
|
37
38
|
const PATTERN_RULES = [
|
|
38
39
|
{
|
|
39
40
|
re: /\b(card|payment|invoice|iban|bank[_-]?account|checkout)\b/i,
|
|
40
41
|
category: "financial",
|
|
41
|
-
labels: ["
|
|
42
|
+
labels: ["pd:Financial"],
|
|
42
43
|
capabilities: ["payments"],
|
|
43
44
|
},
|
|
44
45
|
{
|
|
45
46
|
re: /\b(patient|diagnosis|medical|health|phi)\b/i,
|
|
46
47
|
category: "health",
|
|
47
|
-
labels: ["
|
|
48
|
+
labels: ["pd:MedicalHealth"],
|
|
48
49
|
},
|
|
49
50
|
{
|
|
50
51
|
re: /\b(user[_-]?id|customer[_-]?id|ip[_-]?address|ip)\b/i,
|
|
51
52
|
category: "identifiers",
|
|
52
|
-
labels: ["
|
|
53
|
+
labels: ["pd:UID"],
|
|
53
54
|
},
|
|
54
55
|
];
|
|
55
56
|
function toBand(score) {
|
|
@@ -357,7 +358,7 @@ function inferDataSharedFromEvidenceReasons(evidence) {
|
|
|
357
358
|
}
|
|
358
359
|
if (/\b(db_password|password)\b/.test(text)) {
|
|
359
360
|
const labels = labelsByCategory.get("credentials") ?? new Set();
|
|
360
|
-
labels.add("
|
|
361
|
+
labels.add("pd:Password");
|
|
361
362
|
labelsByCategory.set("credentials", labels);
|
|
362
363
|
capabilities.add("auth");
|
|
363
364
|
directionHints.add("outbound_to_third_party");
|
package/dist/src/cli.js
CHANGED
|
@@ -322,6 +322,7 @@ function createProgram() {
|
|
|
322
322
|
(0, git_context_1.detectGitContext)(scanEntry.scanRootDir) ?? undefined;
|
|
323
323
|
// Read before the scan writes anything, so its own output never counts as a change (DATAP-876).
|
|
324
324
|
const gitStamps = (0, scan_stamps_1.readGitStamps)(scanEntry.scanRootDir, path_1.default.dirname(path_1.default.resolve(process.cwd(), options.output ?? layout_1.DEFAULT_DATAFLOW_OUTPUT)), parsedGitContext?.commitSha);
|
|
325
|
+
const gitBranch = (0, scan_stamps_1.readGitBranch)(scanEntry.scanRootDir);
|
|
325
326
|
const [{ createDefaultScanConfiguration }, { runScanPipeline }, { buildDiagramGraphFromScanResult },] = await Promise.all([
|
|
326
327
|
Promise.resolve().then(() => __importStar(require('./core/pipeline/orchestrator'))),
|
|
327
328
|
Promise.resolve().then(() => __importStar(require('./core/pipeline/scan-pipeline'))),
|
|
@@ -646,7 +647,7 @@ function createProgram() {
|
|
|
646
647
|
gitContext: parsedGitContext,
|
|
647
648
|
hierarchy,
|
|
648
649
|
});
|
|
649
|
-
(0, write_scan_knowledge_1.writeScanFacts)(layout, {
|
|
650
|
+
const builtScanFacts = (0, write_scan_knowledge_1.writeScanFacts)(layout, {
|
|
650
651
|
knowledge,
|
|
651
652
|
scanRoot: scanEntry.scanRootDir,
|
|
652
653
|
projectName: resolvedProjectName,
|
|
@@ -661,7 +662,12 @@ function createProgram() {
|
|
|
661
662
|
structureGraph: Boolean(knowledge.result.structureGraph),
|
|
662
663
|
git: gitStamps,
|
|
663
664
|
}),
|
|
665
|
+
gitBranch,
|
|
664
666
|
});
|
|
667
|
+
const threatModelCarryForward = (0, write_scan_knowledge_1.writeScanThreatModel)(layout, builtScanFacts.facts);
|
|
668
|
+
if (threatModelCarryForward.unmatchedCount > 0) {
|
|
669
|
+
ui.warn(`${threatModelCarryForward.unmatchedCount} person-set threat status(es) no longer match a threat; they are kept under unmatchedPersonSetStatuses in threat-model.json.`);
|
|
670
|
+
}
|
|
665
671
|
if (options.sensitiveScan !== false) {
|
|
666
672
|
ui.sensitiveScanMessage('Scanning for sensitive information with LeftBlock');
|
|
667
673
|
}
|
|
@@ -682,7 +688,7 @@ function createProgram() {
|
|
|
682
688
|
if (!friendlyTty) {
|
|
683
689
|
console.log(`[scan] dataflow.json written to ${dataflowOutputPath}`);
|
|
684
690
|
}
|
|
685
|
-
console.log(`[scan] facts.json and data-items/ written to ${layout.dir}`);
|
|
691
|
+
console.log(`[scan] facts.json, threat-model.json and data-items/ written to ${layout.dir}`);
|
|
686
692
|
const skipAutoUpload = Boolean(options.skipAutoUpload) ||
|
|
687
693
|
(0, upload_env_1.resolveSkipAutoUpload)(process.env);
|
|
688
694
|
if (!skipAutoUpload) {
|
|
@@ -726,7 +732,7 @@ function createProgram() {
|
|
|
726
732
|
progressUi.onUploadFailed(describeAutoUploadFailure(uploadError, dataflowOutputPath, Boolean(workspaceApiKey)));
|
|
727
733
|
}
|
|
728
734
|
}
|
|
729
|
-
ui.finish();
|
|
735
|
+
ui.finish({ scanDurationMs: scanResult.scanDurationMs });
|
|
730
736
|
}
|
|
731
737
|
catch (dataflowError) {
|
|
732
738
|
reportedFailure = {
|
|
@@ -13,6 +13,8 @@ export interface BuildFactsInput {
|
|
|
13
13
|
scannedAt?: string;
|
|
14
14
|
/** Scan stamps (DATAP-876); left out of facts.json when not given. */
|
|
15
15
|
stamps?: ScanStamps;
|
|
16
|
+
/** The checked-out Git branch (DATAP-925); left out of facts.json when not given. */
|
|
17
|
+
gitBranch?: string | null;
|
|
16
18
|
}
|
|
17
19
|
export interface BuiltFacts {
|
|
18
20
|
facts: FactsFile;
|
|
@@ -115,9 +115,22 @@ function buildFacts(input) {
|
|
|
115
115
|
targetComponentId: scrub(f.targetComponentId),
|
|
116
116
|
type: f.type,
|
|
117
117
|
...(f.targetScope !== undefined ? { targetScope: f.targetScope } : {}),
|
|
118
|
+
...(f.dataCategories !== undefined ? { dataCategories: [...f.dataCategories].sort() } : {}),
|
|
118
119
|
confidence: f.confidence,
|
|
119
120
|
sourceLocations: locations(f.sourceLocations ?? (f.sourceLocation ? [f.sourceLocation] : [])),
|
|
120
121
|
codeRefs: refsFor(scrub(f.id)),
|
|
122
|
+
...(f.authentication
|
|
123
|
+
? {
|
|
124
|
+
authentication: {
|
|
125
|
+
status: f.authentication.status,
|
|
126
|
+
kinds: [...f.authentication.kinds],
|
|
127
|
+
evidence: f.authentication.evidence.map((e) => ({ kind: e.kind, filePath: scrub(e.filePath), line: e.line })),
|
|
128
|
+
},
|
|
129
|
+
}
|
|
130
|
+
: {}),
|
|
131
|
+
...(f.controls
|
|
132
|
+
? { controls: f.controls.map((e) => ({ control: e.control, effect: e.effect, filePath: scrub(e.filePath), line: e.line })) }
|
|
133
|
+
: {}),
|
|
121
134
|
}));
|
|
122
135
|
// Data items.
|
|
123
136
|
const occurrenceById = new Map(result.occurrences.map((o) => [o.id, o]));
|
|
@@ -196,6 +209,7 @@ function buildFacts(input) {
|
|
|
196
209
|
cliVersion: input.cliVersion,
|
|
197
210
|
scannerVersion: input.scannerVersion,
|
|
198
211
|
...(input.stamps ? { stamps: input.stamps } : {}),
|
|
212
|
+
...(input.gitBranch !== undefined ? { gitBranch: input.gitBranch } : {}),
|
|
199
213
|
},
|
|
200
214
|
components: byId(components),
|
|
201
215
|
dataFlows: byId(dataFlows),
|
|
@@ -7,6 +7,8 @@ export declare const FACTS_BASENAME = "facts.json";
|
|
|
7
7
|
export declare const DATA_ITEMS_DIRNAME = "data-items";
|
|
8
8
|
export declare const GRAPHIFY_BASENAME = "graphify.json";
|
|
9
9
|
export declare const ANSWERS_BASENAME = "answers.json";
|
|
10
|
+
export declare const THREAT_MODEL_BASENAME = "threat-model.json";
|
|
11
|
+
export declare const THREAT_MODEL_UNREADABLE_COPY_BASENAME = "threat-model.unreadable.json";
|
|
10
12
|
/** Every file and folder a scan or `dataparade kb` keeps in the output folder. */
|
|
11
13
|
export interface OutputLayout {
|
|
12
14
|
/** The output folder, i.e. the folder that holds dataflow.json. */
|
|
@@ -16,6 +18,8 @@ export interface OutputLayout {
|
|
|
16
18
|
dataItemsDir: string;
|
|
17
19
|
graphifyPath: string;
|
|
18
20
|
answersPath: string;
|
|
21
|
+
threatModelPath: string;
|
|
22
|
+
threatModelUnreadableCopyPath: string;
|
|
19
23
|
/** Interview briefs (`dataparade kb brief`). */
|
|
20
24
|
briefsDir: string;
|
|
21
25
|
/** Unedited interview transcripts. */
|
package/dist/src/facts/layout.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ANSWERS_BASENAME = exports.GRAPHIFY_BASENAME = exports.DATA_ITEMS_DIRNAME = exports.FACTS_BASENAME = exports.DATAFLOW_BASENAME = exports.DEFAULT_DATAFLOW_OUTPUT = exports.DEFAULT_OUTPUT_DIRNAME = void 0;
|
|
6
|
+
exports.THREAT_MODEL_UNREADABLE_COPY_BASENAME = exports.THREAT_MODEL_BASENAME = exports.ANSWERS_BASENAME = exports.GRAPHIFY_BASENAME = exports.DATA_ITEMS_DIRNAME = exports.FACTS_BASENAME = exports.DATAFLOW_BASENAME = exports.DEFAULT_DATAFLOW_OUTPUT = exports.DEFAULT_OUTPUT_DIRNAME = void 0;
|
|
7
7
|
exports.resolveOutputLayout = resolveOutputLayout;
|
|
8
8
|
exports.layoutForDir = layoutForDir;
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
@@ -16,6 +16,8 @@ exports.FACTS_BASENAME = "facts.json";
|
|
|
16
16
|
exports.DATA_ITEMS_DIRNAME = "data-items";
|
|
17
17
|
exports.GRAPHIFY_BASENAME = "graphify.json";
|
|
18
18
|
exports.ANSWERS_BASENAME = "answers.json";
|
|
19
|
+
exports.THREAT_MODEL_BASENAME = "threat-model.json";
|
|
20
|
+
exports.THREAT_MODEL_UNREADABLE_COPY_BASENAME = "threat-model.unreadable.json";
|
|
19
21
|
/** `-o/--output` names dataflow.json; every other file sits next to it. */
|
|
20
22
|
function resolveOutputLayout(dataflowOutputPath) {
|
|
21
23
|
const dataflowPath = path_1.default.resolve(dataflowOutputPath);
|
|
@@ -31,6 +33,8 @@ function layoutForDir(dir, dataflowPath) {
|
|
|
31
33
|
dataItemsDir: path_1.default.join(root, exports.DATA_ITEMS_DIRNAME),
|
|
32
34
|
graphifyPath: path_1.default.join(root, exports.GRAPHIFY_BASENAME),
|
|
33
35
|
answersPath: path_1.default.join(root, exports.ANSWERS_BASENAME),
|
|
36
|
+
threatModelPath: path_1.default.join(root, exports.THREAT_MODEL_BASENAME),
|
|
37
|
+
threatModelUnreadableCopyPath: path_1.default.join(root, exports.THREAT_MODEL_UNREADABLE_COPY_BASENAME),
|
|
34
38
|
briefsDir: path_1.default.join(root, "briefs"),
|
|
35
39
|
evidenceDir: path_1.default.join(root, "evidence"),
|
|
36
40
|
diagramPath: path_1.default.join(root, "diagram.json"),
|
|
@@ -42,6 +42,13 @@ export interface GitStamps {
|
|
|
42
42
|
* `fallbackCommitSha` comes from --git-context, for scans of archives that have no .git.
|
|
43
43
|
*/
|
|
44
44
|
export declare function readGitStamps(scanRoot: string, outputDir: string | null, fallbackCommitSha?: string): GitStamps;
|
|
45
|
+
/**
|
|
46
|
+
* The checked-out branch of the repository containing `scanRoot` (DATAP-925). A detached HEAD,
|
|
47
|
+
* as in most CI checkouts, falls back to the CI's branch variable (`GITHUB_HEAD_REF` for a pull
|
|
48
|
+
* request, then `GITHUB_REF_NAME` when `GITHUB_REF_TYPE` is `branch`, then `CI_COMMIT_REF_NAME`
|
|
49
|
+
* on GitLab). Null outside Git and when no branch is known.
|
|
50
|
+
*/
|
|
51
|
+
export declare function readGitBranch(scanRoot: string, environment?: NodeJS.ProcessEnv): string | null;
|
|
45
52
|
export declare function buildScanStamps(input: {
|
|
46
53
|
cliVersion: string;
|
|
47
54
|
scanner: {
|
|
@@ -8,6 +8,7 @@ exports.catalogHash = catalogHash;
|
|
|
8
8
|
exports.scannerBuildInfo = scannerBuildInfo;
|
|
9
9
|
exports.findCliPackageRoot = findCliPackageRoot;
|
|
10
10
|
exports.readGitStamps = readGitStamps;
|
|
11
|
+
exports.readGitBranch = readGitBranch;
|
|
11
12
|
exports.buildScanStamps = buildScanStamps;
|
|
12
13
|
const child_process_1 = require("child_process");
|
|
13
14
|
const crypto_1 = require("crypto");
|
|
@@ -152,6 +153,35 @@ function readGitStamps(scanRoot, outputDir, fallbackCommitSha) {
|
|
|
152
153
|
return { commitSha: fallbackCommitSha ?? null, dirty: fallbackCommitSha ? false : null, rootCommitSha: null, scanRoot: null };
|
|
153
154
|
}
|
|
154
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* The checked-out branch of the repository containing `scanRoot` (DATAP-925). A detached HEAD,
|
|
158
|
+
* as in most CI checkouts, falls back to the CI's branch variable (`GITHUB_HEAD_REF` for a pull
|
|
159
|
+
* request, then `GITHUB_REF_NAME` when `GITHUB_REF_TYPE` is `branch`, then `CI_COMMIT_REF_NAME`
|
|
160
|
+
* on GitLab). Null outside Git and when no branch is known.
|
|
161
|
+
*/
|
|
162
|
+
function readGitBranch(scanRoot, environment = process.env) {
|
|
163
|
+
const branchFromContinuousIntegration = () => {
|
|
164
|
+
const pullRequestHeadBranch = environment.GITHUB_HEAD_REF?.trim();
|
|
165
|
+
if (pullRequestHeadBranch)
|
|
166
|
+
return pullRequestHeadBranch;
|
|
167
|
+
const githubRefName = environment.GITHUB_REF_NAME?.trim();
|
|
168
|
+
if (githubRefName && environment.GITHUB_REF_TYPE === "branch")
|
|
169
|
+
return githubRefName;
|
|
170
|
+
const gitlabRefName = environment.CI_COMMIT_REF_NAME?.trim();
|
|
171
|
+
if (gitlabRefName && !environment.CI_COMMIT_TAG)
|
|
172
|
+
return gitlabRefName;
|
|
173
|
+
return null;
|
|
174
|
+
};
|
|
175
|
+
try {
|
|
176
|
+
const checkedOutBranch = git(scanRoot, ["rev-parse", "--abbrev-ref", "HEAD"]);
|
|
177
|
+
if (checkedOutBranch && checkedOutBranch !== "HEAD")
|
|
178
|
+
return checkedOutBranch;
|
|
179
|
+
return branchFromContinuousIntegration();
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
155
185
|
function buildScanStamps(input) {
|
|
156
186
|
return {
|
|
157
187
|
scannerCommit: input.scanner.scannerCommit,
|
|
@@ -47,6 +47,33 @@ export declare const identitySchema: z.ZodObject<{
|
|
|
47
47
|
parts: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
48
48
|
duplicateIndex: z.ZodOptional<z.ZodNumber>;
|
|
49
49
|
}, z.core.$strip>;
|
|
50
|
+
/** Control evidence on a flow (DATAP-915). "weakens" means the line removes a control. */
|
|
51
|
+
export declare const flowControlSchema: z.ZodObject<{
|
|
52
|
+
control: z.ZodString;
|
|
53
|
+
effect: z.ZodEnum<{
|
|
54
|
+
mitigates: "mitigates";
|
|
55
|
+
weakens: "weakens";
|
|
56
|
+
}>;
|
|
57
|
+
filePath: z.ZodString;
|
|
58
|
+
line: z.ZodNumber;
|
|
59
|
+
}, z.core.$strip>;
|
|
60
|
+
/**
|
|
61
|
+
* Authentication evidence on a flow (DATAP-912). `none_seen` means no evidence was found
|
|
62
|
+
* in the code read, not that the flow has no authentication. Absent for flow types the
|
|
63
|
+
* scanner does not check (database queries).
|
|
64
|
+
*/
|
|
65
|
+
export declare const flowAuthenticationSchema: z.ZodObject<{
|
|
66
|
+
status: z.ZodEnum<{
|
|
67
|
+
seen: "seen";
|
|
68
|
+
none_seen: "none_seen";
|
|
69
|
+
}>;
|
|
70
|
+
kinds: z.ZodArray<z.ZodString>;
|
|
71
|
+
evidence: z.ZodArray<z.ZodObject<{
|
|
72
|
+
kind: z.ZodString;
|
|
73
|
+
filePath: z.ZodString;
|
|
74
|
+
line: z.ZodNumber;
|
|
75
|
+
}, z.core.$strip>>;
|
|
76
|
+
}, z.core.$strip>;
|
|
50
77
|
export declare const componentFactSchema: z.ZodObject<{
|
|
51
78
|
id: z.ZodString;
|
|
52
79
|
identity: z.ZodOptional<z.ZodObject<{
|
|
@@ -93,6 +120,7 @@ export declare const dataFlowFactSchema: z.ZodObject<{
|
|
|
93
120
|
targetComponentId: z.ZodString;
|
|
94
121
|
type: z.ZodString;
|
|
95
122
|
targetScope: z.ZodOptional<z.ZodString>;
|
|
123
|
+
dataCategories: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
96
124
|
confidence: z.ZodNumber;
|
|
97
125
|
sourceLocations: z.ZodArray<z.ZodObject<{
|
|
98
126
|
filePath: z.ZodString;
|
|
@@ -105,6 +133,27 @@ export declare const dataFlowFactSchema: z.ZodObject<{
|
|
|
105
133
|
filePath: z.ZodOptional<z.ZodString>;
|
|
106
134
|
line: z.ZodOptional<z.ZodNumber>;
|
|
107
135
|
}, z.core.$strip>>;
|
|
136
|
+
authentication: z.ZodOptional<z.ZodObject<{
|
|
137
|
+
status: z.ZodEnum<{
|
|
138
|
+
seen: "seen";
|
|
139
|
+
none_seen: "none_seen";
|
|
140
|
+
}>;
|
|
141
|
+
kinds: z.ZodArray<z.ZodString>;
|
|
142
|
+
evidence: z.ZodArray<z.ZodObject<{
|
|
143
|
+
kind: z.ZodString;
|
|
144
|
+
filePath: z.ZodString;
|
|
145
|
+
line: z.ZodNumber;
|
|
146
|
+
}, z.core.$strip>>;
|
|
147
|
+
}, z.core.$strip>>;
|
|
148
|
+
controls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
149
|
+
control: z.ZodString;
|
|
150
|
+
effect: z.ZodEnum<{
|
|
151
|
+
mitigates: "mitigates";
|
|
152
|
+
weakens: "weakens";
|
|
153
|
+
}>;
|
|
154
|
+
filePath: z.ZodString;
|
|
155
|
+
line: z.ZodNumber;
|
|
156
|
+
}, z.core.$strip>>>;
|
|
108
157
|
}, z.core.$strip>;
|
|
109
158
|
export declare const dataItemGroupSchema: z.ZodObject<{
|
|
110
159
|
id: z.ZodString;
|
|
@@ -209,6 +258,7 @@ export declare const factsFileSchema: z.ZodObject<{
|
|
|
209
258
|
rootCommitSha: z.ZodNullable<z.ZodString>;
|
|
210
259
|
scanRoot: z.ZodNullable<z.ZodString>;
|
|
211
260
|
}, z.core.$strip>>;
|
|
261
|
+
gitBranch: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
212
262
|
}, z.core.$strip>;
|
|
213
263
|
components: z.ZodArray<z.ZodObject<{
|
|
214
264
|
id: z.ZodString;
|
|
@@ -256,6 +306,7 @@ export declare const factsFileSchema: z.ZodObject<{
|
|
|
256
306
|
targetComponentId: z.ZodString;
|
|
257
307
|
type: z.ZodString;
|
|
258
308
|
targetScope: z.ZodOptional<z.ZodString>;
|
|
309
|
+
dataCategories: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
259
310
|
confidence: z.ZodNumber;
|
|
260
311
|
sourceLocations: z.ZodArray<z.ZodObject<{
|
|
261
312
|
filePath: z.ZodString;
|
|
@@ -268,6 +319,27 @@ export declare const factsFileSchema: z.ZodObject<{
|
|
|
268
319
|
filePath: z.ZodOptional<z.ZodString>;
|
|
269
320
|
line: z.ZodOptional<z.ZodNumber>;
|
|
270
321
|
}, z.core.$strip>>;
|
|
322
|
+
authentication: z.ZodOptional<z.ZodObject<{
|
|
323
|
+
status: z.ZodEnum<{
|
|
324
|
+
seen: "seen";
|
|
325
|
+
none_seen: "none_seen";
|
|
326
|
+
}>;
|
|
327
|
+
kinds: z.ZodArray<z.ZodString>;
|
|
328
|
+
evidence: z.ZodArray<z.ZodObject<{
|
|
329
|
+
kind: z.ZodString;
|
|
330
|
+
filePath: z.ZodString;
|
|
331
|
+
line: z.ZodNumber;
|
|
332
|
+
}, z.core.$strip>>;
|
|
333
|
+
}, z.core.$strip>>;
|
|
334
|
+
controls: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
335
|
+
control: z.ZodString;
|
|
336
|
+
effect: z.ZodEnum<{
|
|
337
|
+
mitigates: "mitigates";
|
|
338
|
+
weakens: "weakens";
|
|
339
|
+
}>;
|
|
340
|
+
filePath: z.ZodString;
|
|
341
|
+
line: z.ZodNumber;
|
|
342
|
+
}, z.core.$strip>>>;
|
|
271
343
|
}, z.core.$strip>>;
|
|
272
344
|
dataItems: z.ZodArray<z.ZodObject<{
|
|
273
345
|
id: z.ZodString;
|
|
@@ -491,6 +563,8 @@ export type SourceLocation = z.infer<typeof sourceLocationSchema>;
|
|
|
491
563
|
export type CodeRef = z.infer<typeof codeRefSchema>;
|
|
492
564
|
export type ComponentFact = z.infer<typeof componentFactSchema>;
|
|
493
565
|
export type DataFlowFact = z.infer<typeof dataFlowFactSchema>;
|
|
566
|
+
export type FlowAuthentication = z.infer<typeof flowAuthenticationSchema>;
|
|
567
|
+
export type FlowControl = z.infer<typeof flowControlSchema>;
|
|
494
568
|
export type DataItemGroup = z.infer<typeof dataItemGroupSchema>;
|
|
495
569
|
export type DataItemSummary = z.infer<typeof dataItemSummarySchema>;
|
|
496
570
|
export type Relation = z.infer<typeof relationSchema>;
|
package/dist/src/facts/schema.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.answersFileSchema = exports.answerSchema = exports.dataItemFileSchema = exports.occurrenceFactSchema = exports.factsFileSchema = exports.scanStampsSchema = exports.relationSchema = exports.dataItemSummarySchema = exports.dataItemGroupSchema = exports.dataFlowFactSchema = exports.componentFactSchema = exports.identitySchema = exports.codeRefSchema = exports.sourceLocationSchema = exports.SCHEMA_VERSION = void 0;
|
|
3
|
+
exports.answersFileSchema = exports.answerSchema = exports.dataItemFileSchema = exports.occurrenceFactSchema = exports.factsFileSchema = exports.scanStampsSchema = exports.relationSchema = exports.dataItemSummarySchema = exports.dataItemGroupSchema = exports.dataFlowFactSchema = exports.componentFactSchema = exports.flowAuthenticationSchema = exports.flowControlSchema = exports.identitySchema = exports.codeRefSchema = exports.sourceLocationSchema = exports.SCHEMA_VERSION = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* The DataParade knowledge base format, schema v1.
|
|
6
6
|
*
|
|
@@ -53,6 +53,23 @@ exports.identitySchema = zod_1.z.object({
|
|
|
53
53
|
parts: zod_1.z.record(zod_1.z.string(), zod_1.z.string()),
|
|
54
54
|
duplicateIndex: zod_1.z.number().int().min(2).optional(),
|
|
55
55
|
});
|
|
56
|
+
/** Control evidence on a flow (DATAP-915). "weakens" means the line removes a control. */
|
|
57
|
+
exports.flowControlSchema = zod_1.z.object({
|
|
58
|
+
control: zod_1.z.string(),
|
|
59
|
+
effect: zod_1.z.enum(["mitigates", "weakens"]),
|
|
60
|
+
filePath: zod_1.z.string(),
|
|
61
|
+
line: zod_1.z.number(),
|
|
62
|
+
});
|
|
63
|
+
/**
|
|
64
|
+
* Authentication evidence on a flow (DATAP-912). `none_seen` means no evidence was found
|
|
65
|
+
* in the code read, not that the flow has no authentication. Absent for flow types the
|
|
66
|
+
* scanner does not check (database queries).
|
|
67
|
+
*/
|
|
68
|
+
exports.flowAuthenticationSchema = zod_1.z.object({
|
|
69
|
+
status: zod_1.z.enum(["seen", "none_seen"]),
|
|
70
|
+
kinds: zod_1.z.array(zod_1.z.string()),
|
|
71
|
+
evidence: zod_1.z.array(zod_1.z.object({ kind: zod_1.z.string(), filePath: zod_1.z.string(), line: zod_1.z.number() })),
|
|
72
|
+
});
|
|
56
73
|
exports.componentFactSchema = zod_1.z.object({
|
|
57
74
|
id: zod_1.z.string(),
|
|
58
75
|
identity: exports.identitySchema.optional(),
|
|
@@ -70,9 +87,17 @@ exports.dataFlowFactSchema = zod_1.z.object({
|
|
|
70
87
|
targetComponentId: zod_1.z.string(),
|
|
71
88
|
type: zod_1.z.string(),
|
|
72
89
|
targetScope: zod_1.z.string().optional(),
|
|
90
|
+
/**
|
|
91
|
+
* Data categories the scanner observed in the code that sends the flow (DATAP-856). An empty
|
|
92
|
+
* list means none was seen; absent when the scanner did not check the flow. Not the
|
|
93
|
+
* `data_categories` interview answer, which `answers.json` holds.
|
|
94
|
+
*/
|
|
95
|
+
dataCategories: zod_1.z.array(zod_1.z.string()).optional(),
|
|
73
96
|
confidence: zod_1.z.number(),
|
|
74
97
|
sourceLocations: zod_1.z.array(exports.sourceLocationSchema),
|
|
75
98
|
codeRefs: zod_1.z.array(exports.codeRefSchema),
|
|
99
|
+
authentication: exports.flowAuthenticationSchema.optional(),
|
|
100
|
+
controls: zod_1.z.array(exports.flowControlSchema).optional(),
|
|
76
101
|
});
|
|
77
102
|
exports.dataItemGroupSchema = zod_1.z.object({
|
|
78
103
|
id: zod_1.z.string(),
|
|
@@ -132,6 +157,12 @@ exports.factsFileSchema = zod_1.z.object({
|
|
|
132
157
|
scannerVersion: zod_1.z.string(),
|
|
133
158
|
/** Absent in scans from CLI 0.0.32 and earlier; such scans cannot be compared. */
|
|
134
159
|
stamps: exports.scanStampsSchema.optional(),
|
|
160
|
+
/**
|
|
161
|
+
* The checked-out Git branch (DATAP-925). Information only: it is not a stamp, so two scans
|
|
162
|
+
* of one commit on different branches stay comparable. Null outside Git or on a detached
|
|
163
|
+
* HEAD without a CI branch variable; absent in scans from CLI 0.0.35 and earlier.
|
|
164
|
+
*/
|
|
165
|
+
gitBranch: zod_1.z.string().nullable().optional(),
|
|
135
166
|
}),
|
|
136
167
|
components: zod_1.z.array(exports.componentFactSchema),
|
|
137
168
|
dataFlows: zod_1.z.array(exports.dataFlowFactSchema),
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type DataParadeGraph, type OrchestratorScanResult } from '../../vendor/scanner/dist/src/index.js';
|
|
2
2
|
import type { OutputLayout } from '../facts/layout';
|
|
3
3
|
import { type DataflowHierarchy } from './c4-hierarchy';
|
|
4
|
-
import type { ScanStamps } from "../facts/schema";
|
|
4
|
+
import type { FactsFile, ScanStamps } from "../facts/schema";
|
|
5
|
+
import { type PersonSetStatusCarryForwardResult } from '../threat-model/carry-forward-person-set-statuses';
|
|
5
6
|
/**
|
|
6
7
|
* Where Graphify keeps its working files and cache between scans, outside the output
|
|
7
8
|
* folder: `~/.cache/dataparade/graphify/<hash of the scan root>`.
|
|
@@ -30,6 +31,9 @@ export interface WriteScanFactsOptions {
|
|
|
30
31
|
scannerVersion: string;
|
|
31
32
|
scannedAt?: string;
|
|
32
33
|
stamps?: ScanStamps;
|
|
34
|
+
gitBranch?: string | null;
|
|
33
35
|
}
|
|
34
36
|
/** Write facts.json and data-items/. answers.json is not touched. */
|
|
35
37
|
export declare function writeScanFacts(layout: OutputLayout, options: WriteScanFactsOptions): import("../facts/build-facts").BuiltFacts;
|
|
38
|
+
/** Write threat-model.json from the Facts, keeping the statuses people set in the previous file. */
|
|
39
|
+
export declare function writeScanThreatModel(layout: OutputLayout, facts: FactsFile): PersonSetStatusCarryForwardResult;
|
|
@@ -7,12 +7,14 @@ exports.graphifyCacheDir = graphifyCacheDir;
|
|
|
7
7
|
exports.prepareScanKnowledge = prepareScanKnowledge;
|
|
8
8
|
exports.buildScanHierarchy = buildScanHierarchy;
|
|
9
9
|
exports.writeScanFacts = writeScanFacts;
|
|
10
|
+
exports.writeScanThreatModel = writeScanThreatModel;
|
|
10
11
|
/**
|
|
11
12
|
* What a scan writes besides dataflow.json (DATAP-735):
|
|
12
13
|
*
|
|
13
14
|
* facts.json Facts from this scan, replaced on every scan
|
|
14
15
|
* data-items/*.json one file per data item, with its occurrences
|
|
15
16
|
* graphify.json Graphify's code-structure graph (graph.json, renamed)
|
|
17
|
+
* threat-model.json STRIDE threats per element; person-set statuses are carried forward
|
|
16
18
|
*
|
|
17
19
|
* Graphify (https://github.com/Graphify-Labs/graphify) maps the code; the scanner's
|
|
18
20
|
* knowledge graph links Facts to those code nodes. The graph is built in memory and only
|
|
@@ -27,6 +29,9 @@ const scanner_1 = require("../../vendor/scanner/dist/src/index.js");
|
|
|
27
29
|
const build_facts_1 = require("../facts/build-facts");
|
|
28
30
|
const io_1 = require("../facts/io");
|
|
29
31
|
const c4_hierarchy_1 = require("./c4-hierarchy");
|
|
32
|
+
const build_threat_model_1 = require("../threat-model/build-threat-model");
|
|
33
|
+
const carry_forward_person_set_statuses_1 = require("../threat-model/carry-forward-person-set-statuses");
|
|
34
|
+
const io_2 = require("../threat-model/io");
|
|
30
35
|
function warn(message) {
|
|
31
36
|
console.warn(`[scan] ${message}`);
|
|
32
37
|
}
|
|
@@ -110,7 +115,23 @@ function writeScanFacts(layout, options) {
|
|
|
110
115
|
scannerVersion: options.scannerVersion,
|
|
111
116
|
scannedAt: options.scannedAt,
|
|
112
117
|
stamps: options.stamps,
|
|
118
|
+
gitBranch: options.gitBranch,
|
|
113
119
|
});
|
|
114
120
|
(0, io_1.writeFactsOutput)(layout, built.facts, built.dataItemFiles);
|
|
115
121
|
return built;
|
|
116
122
|
}
|
|
123
|
+
/** Write threat-model.json from the Facts, keeping the statuses people set in the previous file. */
|
|
124
|
+
function writeScanThreatModel(layout, facts) {
|
|
125
|
+
const previousThreatModelRead = (0, io_2.readPreviousThreatModelForCarryForward)(layout);
|
|
126
|
+
if (previousThreatModelRead.outcome === 'unreadable') {
|
|
127
|
+
const whereThePreviousFileWasKept = previousThreatModelRead.unreadableCopyPath
|
|
128
|
+
? ` The previous file was kept at ${previousThreatModelRead.unreadableCopyPath}.`
|
|
129
|
+
: '';
|
|
130
|
+
warn(`warning: the previous threat-model.json could not be read (${previousThreatModelRead.reason}); person-set statuses were not carried forward.${whereThePreviousFileWasKept}`);
|
|
131
|
+
}
|
|
132
|
+
const carryForwardResult = (0, carry_forward_person_set_statuses_1.carryForwardPersonSetStatuses)((0, build_threat_model_1.buildThreatModel)(facts), previousThreatModelRead.outcome === 'read'
|
|
133
|
+
? previousThreatModelRead.threatModel
|
|
134
|
+
: undefined);
|
|
135
|
+
(0, io_2.writeThreatModel)(layout, carryForwardResult.threatModel);
|
|
136
|
+
return carryForwardResult;
|
|
137
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildThreatModel = buildThreatModel;
|
|
4
|
+
/**
|
|
5
|
+
* Builds the threat model file (DATAP-920) from Facts with the scanner's STRIDE rules.
|
|
6
|
+
* It reads only Facts, so every evidence path is already relative to the scan root.
|
|
7
|
+
*/
|
|
8
|
+
const scanner_1 = require("../../vendor/scanner/dist/src/index.js");
|
|
9
|
+
const schema_1 = require("./schema");
|
|
10
|
+
function groupDataFlowsByComponentId(dataFlows) {
|
|
11
|
+
const dataFlowsByComponentId = new Map();
|
|
12
|
+
const addDataFlowToComponent = (componentId, dataFlow) => {
|
|
13
|
+
const existingDataFlows = dataFlowsByComponentId.get(componentId) ?? [];
|
|
14
|
+
existingDataFlows.push(dataFlow);
|
|
15
|
+
dataFlowsByComponentId.set(componentId, existingDataFlows);
|
|
16
|
+
};
|
|
17
|
+
for (const dataFlow of dataFlows) {
|
|
18
|
+
addDataFlowToComponent(dataFlow.sourceComponentId, dataFlow);
|
|
19
|
+
if (dataFlow.targetComponentId !== dataFlow.sourceComponentId) {
|
|
20
|
+
addDataFlowToComponent(dataFlow.targetComponentId, dataFlow);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return dataFlowsByComponentId;
|
|
24
|
+
}
|
|
25
|
+
function toThreatModelThreat(scannerThreat, element, elementKind, frameworkElementKind) {
|
|
26
|
+
return {
|
|
27
|
+
id: (0, schema_1.threatIdForElementAndCategory)({
|
|
28
|
+
elementId: element.id,
|
|
29
|
+
framework: scannerThreat.framework,
|
|
30
|
+
category: scannerThreat.category,
|
|
31
|
+
}),
|
|
32
|
+
elementId: element.id,
|
|
33
|
+
elementKind,
|
|
34
|
+
frameworkElementKind,
|
|
35
|
+
...(element.identity ? { elementIdentityKey: element.identity.key } : {}),
|
|
36
|
+
framework: scannerThreat.framework,
|
|
37
|
+
category: scannerThreat.category,
|
|
38
|
+
ruleStatus: scannerThreat.status,
|
|
39
|
+
ruleId: scannerThreat.ruleId,
|
|
40
|
+
...(scannerThreat.statusRuleId !== undefined ? { statusRuleId: scannerThreat.statusRuleId } : {}),
|
|
41
|
+
evidence: scannerThreat.evidence ?? [],
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function buildComponentThreats(component, dataFlowsOfComponent) {
|
|
45
|
+
const componentForRules = { type: component.type, subType: component.subType || undefined };
|
|
46
|
+
const frameworkElementKind = (0, scanner_1.strideComponentKind)(componentForRules);
|
|
47
|
+
if (frameworkElementKind === undefined)
|
|
48
|
+
return [];
|
|
49
|
+
return (0, scanner_1.strideThreatsForComponent)(componentForRules, dataFlowsOfComponent).map((scannerThreat) => toThreatModelThreat(scannerThreat, component, "component", frameworkElementKind));
|
|
50
|
+
}
|
|
51
|
+
function buildDataFlowThreats(dataFlow) {
|
|
52
|
+
return (0, scanner_1.strideThreatsForFlow)(dataFlow).map((scannerThreat) => toThreatModelThreat(scannerThreat, dataFlow, "dataFlow", "data_flow"));
|
|
53
|
+
}
|
|
54
|
+
function buildThreatModel(facts) {
|
|
55
|
+
const strideRules = (0, scanner_1.loadStrideRules)();
|
|
56
|
+
const dataFlowsByComponentId = groupDataFlowsByComponentId(facts.dataFlows);
|
|
57
|
+
const componentThreats = facts.components.flatMap((component) => buildComponentThreats(component, dataFlowsByComponentId.get(component.id) ?? []));
|
|
58
|
+
const dataFlowThreats = facts.dataFlows.flatMap(buildDataFlowThreats);
|
|
59
|
+
const strideFramework = {
|
|
60
|
+
id: strideRules.framework,
|
|
61
|
+
rulesVersion: strideRules.version,
|
|
62
|
+
categories: strideRules.categories.map(({ id, name }) => ({ id, name })),
|
|
63
|
+
};
|
|
64
|
+
return {
|
|
65
|
+
schemaVersion: schema_1.THREAT_MODEL_SCHEMA_VERSION,
|
|
66
|
+
scan: facts.scan,
|
|
67
|
+
frameworks: [strideFramework],
|
|
68
|
+
threats: [...componentThreats, ...dataFlowThreats],
|
|
69
|
+
unmatchedPersonSetStatuses: [],
|
|
70
|
+
};
|
|
71
|
+
}
|