@dataparade/cli 0.0.26 → 0.0.28
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 +52 -12
- package/dist/package.json +7 -7
- package/dist/src/ai-enrichment/providers/platform-proxy-provider.js +0 -1
- package/dist/src/cli.js +37 -37
- package/dist/src/discoveries/contract/ocsf-discovery-record.d.ts +1 -1
- package/dist/src/discoveries/load-ocsf-discoveries.d.ts +0 -8
- package/dist/src/discoveries/load-ocsf-discoveries.js +0 -31
- package/dist/src/discoveries/write-ocsf-discoveries.d.ts +0 -8
- package/dist/src/discoveries/write-ocsf-discoveries.js +0 -38
- package/dist/src/evals/run-model-matrix.js +0 -1
- package/dist/src/export/export-ocsf.d.ts +18 -0
- package/dist/src/export/export-ocsf.js +104 -0
- package/dist/src/export/register-export-commands.d.ts +2 -0
- package/dist/src/export/register-export-commands.js +30 -0
- package/dist/src/facts/apply-answers.d.ts +29 -0
- package/dist/src/facts/apply-answers.js +202 -0
- package/dist/src/facts/build-facts.d.ts +24 -0
- package/dist/src/facts/build-facts.js +198 -0
- package/dist/src/facts/io.d.ts +17 -0
- package/dist/src/facts/io.js +67 -0
- package/dist/src/facts/layout.d.ts +29 -0
- package/dist/src/facts/layout.js +38 -0
- package/dist/src/facts/schema.d.ts +265 -0
- package/dist/src/facts/schema.js +122 -0
- package/dist/src/facts/slug.d.ts +7 -0
- package/dist/src/facts/slug.js +47 -0
- package/dist/src/kb/brief.d.ts +1 -2
- package/dist/src/kb/brief.js +2 -4
- package/dist/src/kb/interview-record.d.ts +18 -0
- package/dist/src/kb/interview-record.js +70 -0
- package/dist/src/kb/kb-store.d.ts +24 -18
- package/dist/src/kb/kb-store.js +89 -28
- package/dist/src/kb/land.d.ts +32 -12
- package/dist/src/kb/land.js +97 -90
- package/dist/src/kb/migrate.d.ts +23 -0
- package/dist/src/kb/migrate.js +91 -0
- package/dist/src/kb/project-diagram.js +4 -4
- package/dist/src/kb/register-kb-commands.js +71 -20
- package/dist/src/observability/scan-sentry.js +0 -1
- package/dist/src/output/scan-output-excludes.d.ts +1 -1
- package/dist/src/output/scan-output-excludes.js +14 -5
- package/dist/src/output/write-scan-knowledge.d.ts +33 -0
- package/dist/src/output/write-scan-knowledge.js +115 -0
- package/dist/src/platform-api/estimate-scan-footprint.d.ts +31 -0
- package/dist/src/platform-api/estimate-scan-footprint.js +75 -2
- package/dist/src/ui/scan-progress-renderer.d.ts +2 -0
- package/dist/src/ui/scan-progress-renderer.js +10 -0
- package/dist/src/ui/teaching-lines.js +18 -6
- package/dist/src/upload/collect-scan-sidecars.d.ts +2 -27
- package/dist/src/upload/collect-scan-sidecars.js +25 -121
- package/dist/src/upload/run-upload.js +0 -3
- package/dist/tests/cli/cli.spec.js +30 -13
- package/dist/tests/helpers/facts-fixture.d.ts +9 -0
- package/dist/tests/helpers/facts-fixture.js +72 -0
- package/dist/tests/unit/export/export-ocsf.spec.js +72 -0
- package/dist/tests/unit/facts/apply-answers.spec.js +128 -0
- package/dist/tests/unit/facts/build-facts.spec.d.ts +1 -0
- package/dist/tests/unit/facts/build-facts.spec.js +161 -0
- package/dist/tests/unit/facts/slug.spec.d.ts +1 -0
- package/dist/tests/unit/facts/slug.spec.js +30 -0
- package/dist/tests/unit/kb/kb-interview-loop.spec.js +83 -35
- package/dist/tests/unit/kb/migrate.spec.d.ts +1 -0
- package/dist/tests/unit/kb/migrate.spec.js +108 -0
- package/dist/tests/unit/output/graphify-cache-dir.spec.d.ts +1 -0
- package/dist/tests/unit/output/graphify-cache-dir.spec.js +20 -0
- package/dist/tests/unit/output/scan-output-excludes.spec.js +4 -2
- package/dist/tests/unit/platform-api/estimate-scan-footprint.spec.js +77 -0
- package/dist/tests/unit/platform-api/upload-client.spec.js +2 -2
- package/dist/tests/unit/ui/teaching-lines.spec.js +16 -0
- package/dist/tests/unit/upload/collect-scan-sidecars.spec.js +46 -46
- package/dist/tests/unit/upload/pack-scan-upload.spec.js +6 -6
- package/dist/vendor/scanner/dist/src/classifier/component-factory.js +6 -14
- package/dist/vendor/scanner/dist/src/classifier/external-url-third-party.d.ts +1 -0
- package/dist/vendor/scanner/dist/src/classifier/external-url-third-party.js +32 -1
- package/dist/vendor/scanner/dist/src/classifier/naming.d.ts +5 -0
- package/dist/vendor/scanner/dist/src/classifier/naming.js +8 -4
- package/dist/vendor/scanner/dist/src/core/pipeline/build-scan-personal-data-layers.js +26 -14
- package/dist/vendor/scanner/dist/src/core/pipeline/enrich-personal-data-layers.js +3 -1
- package/dist/vendor/scanner/dist/src/data-flow/intra-component-lineage.d.ts +18 -0
- package/dist/vendor/scanner/dist/src/data-flow/intra-component-lineage.js +125 -66
- package/dist/vendor/scanner/dist/src/index.d.ts +2 -0
- package/dist/vendor/scanner/dist/src/index.js +7 -2
- package/dist/vendor/scanner/dist/src/ingest/file-system.d.ts +5 -0
- package/dist/vendor/scanner/dist/src/ingest/file-system.js +5 -0
- package/dist/vendor/scanner/dist/src/ingest/gitignore.d.ts +17 -0
- package/dist/vendor/scanner/dist/src/ingest/gitignore.js +47 -9
- package/dist/vendor/scanner/dist/src/ingest/schema-files.d.ts +10 -2
- package/dist/vendor/scanner/dist/src/ingest/schema-files.js +24 -7
- package/dist/vendor/scanner/dist/src/patterns/frontend-frameworks.d.ts +3 -0
- package/dist/vendor/scanner/dist/src/patterns/frontend-frameworks.js +45 -0
- package/dist/vendor/scanner/dist/src/patterns/scan-exclusions.js +7 -0
- package/dist/vendor/scanner/patterns/classifier/third-party.classifier.yaml +8 -0
- package/dist/vendor/scanner/patterns/third-party.patterns.yaml +9 -0
- package/package.json +7 -7
- package/dist/src/discoveries/project-collected-diagram.d.ts +0 -7
- package/dist/src/discoveries/project-collected-diagram.js +0 -182
- package/dist/src/discoveries/project-ocsf-to-discoveries-document.d.ts +0 -16
- package/dist/src/discoveries/project-ocsf-to-discoveries-document.js +0 -269
- package/dist/src/discoveries/scan-result-to-discovery-input.d.ts +0 -13
- package/dist/src/discoveries/scan-result-to-discovery-input.js +0 -60
- package/dist/src/output/write-knowledge-graph.d.ts +0 -20
- package/dist/src/output/write-knowledge-graph.js +0 -53
- package/dist/src/output/write-scan-discoveries.d.ts +0 -17
- package/dist/src/output/write-scan-discoveries.js +0 -61
- package/dist/tests/unit/discoveries/project-collected-diagram.spec.js +0 -97
- package/dist/tests/unit/discoveries/rescan-replaces-scan-records.spec.js +0 -89
- /package/dist/tests/unit/{discoveries/project-collected-diagram.spec.d.ts → export/export-ocsf.spec.d.ts} +0 -0
- /package/dist/tests/unit/{discoveries/rescan-replaces-scan-records.spec.d.ts → facts/apply-answers.spec.d.ts} +0 -0
|
@@ -59,4 +59,20 @@ describe('buildTeachingLineGroups', () => {
|
|
|
59
59
|
const groups = (0, teaching_lines_1.buildTeachingLineGroups)([], []);
|
|
60
60
|
expect((0, teaching_lines_1.flattenTeachingLines)(groups)).toEqual([]);
|
|
61
61
|
});
|
|
62
|
+
it('counts every Next.js spelling as one framework and skips manifest hints', () => {
|
|
63
|
+
const groups = (0, teaching_lines_1.buildTeachingLineGroups)([
|
|
64
|
+
finding('express_route', { framework: 'next_or_react_route' }),
|
|
65
|
+
finding('express_route', { framework: 'nextjs' }),
|
|
66
|
+
finding('express_route', { framework: 'next' }),
|
|
67
|
+
finding('express_route', {
|
|
68
|
+
framework: 'nextjs',
|
|
69
|
+
sourceContext: 'dependency_manifest',
|
|
70
|
+
}),
|
|
71
|
+
], []);
|
|
72
|
+
expect(groups.routes).toEqual(['Found 3 Next.js routes']);
|
|
73
|
+
});
|
|
74
|
+
it('turns underscores in vendor names into title-cased words', () => {
|
|
75
|
+
const groups = (0, teaching_lines_1.buildTeachingLineGroups)([], [thirdParty('Google_identity'), thirdParty('stripe')]);
|
|
76
|
+
expect(groups.outbound).toEqual(['Calls out to Google Identity and Stripe']);
|
|
77
|
+
});
|
|
62
78
|
});
|
|
@@ -7,60 +7,60 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
7
7
|
const os_1 = __importDefault(require("os"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const collect_scan_sidecars_1 = require("../../../src/upload/collect-scan-sidecars");
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
dataparade: {
|
|
13
|
-
asserts: `dp:scan/entity/${entityId}`,
|
|
14
|
-
...(slot ? { asserted_slot: slot, asserted_value: value } : {}),
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
describe('collectScanSidecars', () => {
|
|
10
|
+
const pack_scan_upload_1 = require("../../../src/upload/pack-scan-upload");
|
|
11
|
+
describe('collectScanUploadFiles', () => {
|
|
19
12
|
let dir;
|
|
20
13
|
beforeEach(() => {
|
|
21
|
-
dir = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), 'scan-
|
|
14
|
+
dir = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), 'scan-upload-files-'));
|
|
22
15
|
fs_1.default.writeFileSync(path_1.default.join(dir, 'dataflow.json'), '{}\n');
|
|
23
16
|
});
|
|
24
17
|
afterEach(() => {
|
|
25
18
|
fs_1.default.rmSync(dir, { recursive: true, force: true });
|
|
26
19
|
});
|
|
27
|
-
it('sends
|
|
28
|
-
fs_1.default.
|
|
29
|
-
fs_1.default.
|
|
30
|
-
fs_1.default.writeFileSync(path_1.default.join(dir, '
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
fs_1.default.writeFileSync(path_1.default.join(discoveries, 'occurrence.json'), JSON.stringify(fact('occurrence:email:src/api.ts:4', 'file_path', 'src/api.ts')));
|
|
44
|
-
fs_1.default.writeFileSync(path_1.default.join(discoveries, 'data-item.json'), JSON.stringify(fact('data_item:email', 'occurrence_ids', '["occurrence:email:src/api.ts:4"]')));
|
|
45
|
-
const sidecars = (0, collect_scan_sidecars_1.collectScanSidecars)(path_1.default.join(dir, 'dataflow.json'));
|
|
46
|
-
expect(sidecars.graphifyGraph).toEqual({ nodes: [{ id: 'src/api.ts' }] });
|
|
47
|
-
expect(sidecars.dataparadeGraph).toMatchObject({
|
|
48
|
-
links: [
|
|
49
|
-
expect.objectContaining({
|
|
50
|
-
relation: 'occurs_in',
|
|
51
|
-
target: 'src/api.ts',
|
|
52
|
-
}),
|
|
53
|
-
],
|
|
54
|
-
});
|
|
55
|
-
expect(sidecars.facts).toHaveLength(2);
|
|
56
|
-
expect(JSON.stringify(sidecars.facts)).toContain('occurrence:email');
|
|
57
|
-
expect(JSON.stringify(sidecars.facts)).toContain('data_item:email');
|
|
58
|
-
expect(JSON.stringify(sidecars.facts)).not.toContain('cmp_orders');
|
|
20
|
+
it('sends facts.json, the data item files, graphify.json and answers.json, in that order', () => {
|
|
21
|
+
fs_1.default.writeFileSync(path_1.default.join(dir, 'facts.json'), '{"schemaVersion":1}');
|
|
22
|
+
fs_1.default.mkdirSync(path_1.default.join(dir, 'data-items'));
|
|
23
|
+
fs_1.default.writeFileSync(path_1.default.join(dir, 'data-items', 'phone.json'), '{"id":"data_item:phone"}');
|
|
24
|
+
fs_1.default.writeFileSync(path_1.default.join(dir, 'data-items', 'email.json'), '{"id":"data_item:email"}');
|
|
25
|
+
fs_1.default.writeFileSync(path_1.default.join(dir, 'graphify.json'), '{"nodes":[]}');
|
|
26
|
+
fs_1.default.writeFileSync(path_1.default.join(dir, 'answers.json'), '{"schemaVersion":1,"answers":[]}');
|
|
27
|
+
const files = (0, collect_scan_sidecars_1.collectScanUploadFiles)(path_1.default.join(dir, 'dataflow.json'));
|
|
28
|
+
expect(files.map((file) => file.relativePath)).toEqual([
|
|
29
|
+
'facts.json',
|
|
30
|
+
'data-items/email.json',
|
|
31
|
+
'data-items/phone.json',
|
|
32
|
+
'graphify.json',
|
|
33
|
+
'answers.json',
|
|
34
|
+
]);
|
|
35
|
+
expect(files[0].content).toBe('{"schemaVersion":1}');
|
|
59
36
|
});
|
|
60
|
-
it('
|
|
37
|
+
it('leaves out answers.json and graphify.json when they do not exist', () => {
|
|
38
|
+
fs_1.default.writeFileSync(path_1.default.join(dir, 'facts.json'), '{"schemaVersion":1}');
|
|
39
|
+
const files = (0, collect_scan_sidecars_1.collectScanUploadFiles)(path_1.default.join(dir, 'dataflow.json'));
|
|
40
|
+
expect(files.map((file) => file.relativePath)).toEqual(['facts.json']);
|
|
41
|
+
});
|
|
42
|
+
it('skips a file that is not a JSON object, and ignores the old layout', () => {
|
|
43
|
+
fs_1.default.writeFileSync(path_1.default.join(dir, 'facts.json'), 'not json');
|
|
61
44
|
fs_1.default.mkdirSync(path_1.default.join(dir, 'ocsf-discoveries'));
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
expect(
|
|
45
|
+
fs_1.default.writeFileSync(path_1.default.join(dir, 'ocsf-discoveries', 'a.json'), '{}');
|
|
46
|
+
fs_1.default.writeFileSync(path_1.default.join(dir, 'dataparade-graph.json'), '{}');
|
|
47
|
+
expect((0, collect_scan_sidecars_1.collectScanUploadFiles)(path_1.default.join(dir, 'dataflow.json'))).toEqual([]);
|
|
48
|
+
});
|
|
49
|
+
it('packs many small data item files into few requests and splits a large graphify.json', () => {
|
|
50
|
+
fs_1.default.writeFileSync(path_1.default.join(dir, 'facts.json'), '{"schemaVersion":1}');
|
|
51
|
+
fs_1.default.mkdirSync(path_1.default.join(dir, 'data-items'));
|
|
52
|
+
for (let index = 0; index < 5; index += 1) {
|
|
53
|
+
fs_1.default.writeFileSync(path_1.default.join(dir, 'data-items', `item-${index}.json`), `{"n":${index}}`);
|
|
54
|
+
}
|
|
55
|
+
const big = JSON.stringify({ nodes: [{ id: 'x'.repeat(pack_scan_upload_1.SCAN_UPLOAD_MAX_JSON_BYTES * 2) }] });
|
|
56
|
+
fs_1.default.writeFileSync(path_1.default.join(dir, 'graphify.json'), big);
|
|
57
|
+
const requests = (0, pack_scan_upload_1.packScanUploadRequests)((0, collect_scan_sidecars_1.collectScanUploadFiles)(path_1.default.join(dir, 'dataflow.json')));
|
|
58
|
+
const batches = requests.filter((request) => 'files' in request);
|
|
59
|
+
const parts = requests.filter((request) => 'part' in request);
|
|
60
|
+
expect(batches[0].files.map((file) => file.relativePath)).toEqual(expect.arrayContaining(['facts.json', 'data-items/item-0.json', 'data-items/item-4.json']));
|
|
61
|
+
expect(parts.length).toBeGreaterThanOrEqual(3);
|
|
62
|
+
for (const request of requests) {
|
|
63
|
+
expect(Buffer.byteLength(JSON.stringify(request), 'utf8')).toBeLessThanOrEqual(pack_scan_upload_1.SCAN_UPLOAD_MAX_JSON_BYTES);
|
|
64
|
+
}
|
|
65
65
|
});
|
|
66
66
|
});
|
|
@@ -4,14 +4,14 @@ const pack_scan_upload_1 = require("../../../src/upload/pack-scan-upload");
|
|
|
4
4
|
describe('packScanUploadRequests', () => {
|
|
5
5
|
it('keeps small files together and splits a file that does not fit', () => {
|
|
6
6
|
const requests = (0, pack_scan_upload_1.packScanUploadRequests)([
|
|
7
|
-
{ relativePath: '
|
|
8
|
-
{ relativePath: '
|
|
9
|
-
{ relativePath: 'graphify
|
|
7
|
+
{ relativePath: 'data-items/a.json', content: 'aa' },
|
|
8
|
+
{ relativePath: 'data-items/b.json', content: 'bb' },
|
|
9
|
+
{ relativePath: 'graphify.json', content: 'x'.repeat(200) },
|
|
10
10
|
], 200);
|
|
11
11
|
expect(requests[0]).toEqual({
|
|
12
12
|
files: [
|
|
13
|
-
{ relativePath: '
|
|
14
|
-
{ relativePath: '
|
|
13
|
+
{ relativePath: 'data-items/a.json', content: 'aa' },
|
|
14
|
+
{ relativePath: 'data-items/b.json', content: 'bb' },
|
|
15
15
|
],
|
|
16
16
|
});
|
|
17
17
|
const parts = requests.slice(1);
|
|
@@ -29,7 +29,7 @@ describe('packScanUploadRequests', () => {
|
|
|
29
29
|
expect(pack_scan_upload_1.SCAN_UPLOAD_MAX_JSON_BYTES).toBeLessThanOrEqual(4_000_000);
|
|
30
30
|
const requests = (0, pack_scan_upload_1.packScanUploadRequests)([
|
|
31
31
|
{
|
|
32
|
-
relativePath: 'graphify
|
|
32
|
+
relativePath: 'graphify.json',
|
|
33
33
|
content: 'x'.repeat(pack_scan_upload_1.SCAN_UPLOAD_MAX_JSON_BYTES),
|
|
34
34
|
},
|
|
35
35
|
]);
|
|
@@ -7,6 +7,7 @@ const flow_source_patterns_1 = require("../patterns/flow-source-patterns");
|
|
|
7
7
|
const terraform_utility_resource_1 = require("../analyzers/terraform/terraform-utility-resource");
|
|
8
8
|
const property_evidence_1 = require("./property-evidence");
|
|
9
9
|
const frontend_frameworks_1 = require("../patterns/frontend-frameworks");
|
|
10
|
+
const naming_1 = require("./naming");
|
|
10
11
|
const MERGED_HTTP_ROUTE_GROUP_KEY_PREFIX = "__cli_http_api_routes__";
|
|
11
12
|
const FRONTEND_FRAMEWORK_GROUP_KEY_PREFIX = "__cli_frontend_framework__";
|
|
12
13
|
const MERGED_HTTP_ROUTE_DISPLAY_NAME = "HTTP API";
|
|
@@ -48,15 +49,6 @@ function getSectionIdFromProperties(properties) {
|
|
|
48
49
|
return raw.trim();
|
|
49
50
|
return "<unsectioned>";
|
|
50
51
|
}
|
|
51
|
-
function toDisplayName(normalized, fallback) {
|
|
52
|
-
const base = normalized || fallback.trim();
|
|
53
|
-
if (!base)
|
|
54
|
-
return "<unknown>";
|
|
55
|
-
return base
|
|
56
|
-
.split(/\s+/)
|
|
57
|
-
.map((part) => part.length === 0 ? part : part.charAt(0).toUpperCase() + part.slice(1))
|
|
58
|
-
.join(" ");
|
|
59
|
-
}
|
|
60
52
|
function normalizeApiDisplayName(rawName, properties) {
|
|
61
53
|
const name = (rawName || "").trim();
|
|
62
54
|
if (!name)
|
|
@@ -120,7 +112,7 @@ function terraformInfrastructureDisplayName(finding, config) {
|
|
|
120
112
|
return `${bn.trim()} (${rt.trim()})`;
|
|
121
113
|
}
|
|
122
114
|
const normalized = normalizeComponentName(finding.name, config.nameNormalization);
|
|
123
|
-
return toDisplayName(normalized, finding.name);
|
|
115
|
+
return (0, naming_1.toDisplayName)(normalized, finding.name);
|
|
124
116
|
}
|
|
125
117
|
function groupFindings(findings, config) {
|
|
126
118
|
const groups = new Map();
|
|
@@ -137,10 +129,10 @@ function groupFindings(findings, config) {
|
|
|
137
129
|
: "frontend";
|
|
138
130
|
const packageNameRaw = finding.properties?.packageName;
|
|
139
131
|
const packageDisplayName = typeof packageNameRaw === "string" && packageNameRaw.trim()
|
|
140
|
-
? toDisplayName(normalizeComponentName(packageNameRaw, config.nameNormalization), packageNameRaw)
|
|
132
|
+
? (0, naming_1.toDisplayName)(normalizeComponentName(packageNameRaw, config.nameNormalization), packageNameRaw)
|
|
141
133
|
: undefined;
|
|
142
134
|
key = `${FRONTEND_FRAMEWORK_GROUP_KEY_PREFIX}:${sectionId}:${framework}`;
|
|
143
|
-
displayName = packageDisplayName ?? toDisplayName(framework, framework);
|
|
135
|
+
displayName = packageDisplayName ?? (0, naming_1.toDisplayName)(framework, framework);
|
|
144
136
|
}
|
|
145
137
|
else {
|
|
146
138
|
const sectionId = getSectionIdFromProperties(finding.properties);
|
|
@@ -192,7 +184,7 @@ function groupFindings(findings, config) {
|
|
|
192
184
|
.replace(/\\/g, "/")
|
|
193
185
|
.toLowerCase();
|
|
194
186
|
key = `${sectionId}::${keyBase}::${filePath}`;
|
|
195
|
-
displayName = toDisplayName(keyBase, keyBase);
|
|
187
|
+
displayName = (0, naming_1.toDisplayName)(keyBase, keyBase);
|
|
196
188
|
}
|
|
197
189
|
let group = groups.get(key);
|
|
198
190
|
if (!group) {
|
|
@@ -527,7 +519,7 @@ function classifyRawFindings(rawFindings, options) {
|
|
|
527
519
|
const svc = mergedProperties.serviceName;
|
|
528
520
|
if (typeof svc === "string" && svc.trim()) {
|
|
529
521
|
const normalizedService = normalizeComponentName(svc, config.nameNormalization);
|
|
530
|
-
component.name = toDisplayName(normalizedService, svc);
|
|
522
|
+
component.name = (0, naming_1.toDisplayName)(normalizedService, svc);
|
|
531
523
|
}
|
|
532
524
|
}
|
|
533
525
|
if (component.type === "asset" && component.subType === "api") {
|
|
@@ -8,6 +8,7 @@ export declare function hostMatchesOrganizationDomains(hostname: string, organiz
|
|
|
8
8
|
export declare function urlMatchesOrganizationDomains(url: string, organizationDomains: readonly string[]): boolean;
|
|
9
9
|
export declare function externalApiCallFindingUrl(finding: RawFinding): string | undefined;
|
|
10
10
|
export declare function isOrganizationOwnedExternalApiFinding(finding: RawFinding, organizationDomains: readonly string[]): boolean;
|
|
11
|
+
export declare function isReservedPlaceholderHost(hostname: string): boolean;
|
|
11
12
|
export declare function shouldIgnoreExternalHttpUrl(url: string | undefined, options?: ExternalHttpUrlOptions): boolean;
|
|
12
13
|
/**
|
|
13
14
|
* Stable third-party key: registrable-style host (last two DNS labels), e.g.
|
|
@@ -5,6 +5,7 @@ exports.hostMatchesOrganizationDomains = hostMatchesOrganizationDomains;
|
|
|
5
5
|
exports.urlMatchesOrganizationDomains = urlMatchesOrganizationDomains;
|
|
6
6
|
exports.externalApiCallFindingUrl = externalApiCallFindingUrl;
|
|
7
7
|
exports.isOrganizationOwnedExternalApiFinding = isOrganizationOwnedExternalApiFinding;
|
|
8
|
+
exports.isReservedPlaceholderHost = isReservedPlaceholderHost;
|
|
8
9
|
exports.shouldIgnoreExternalHttpUrl = shouldIgnoreExternalHttpUrl;
|
|
9
10
|
exports.deriveServiceKeyFromHostname = deriveServiceKeyFromHostname;
|
|
10
11
|
exports.urlHostMatchKeys = urlHostMatchKeys;
|
|
@@ -123,6 +124,34 @@ function isLocalOrPrivateHost(hostname) {
|
|
|
123
124
|
}
|
|
124
125
|
return false;
|
|
125
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* RFC 2606 / RFC 6761 reserved names: example.com/.org/.net (and subdomains) plus
|
|
129
|
+
* the .test, .example, .invalid and .localhost TLDs. These are documentation
|
|
130
|
+
* placeholders, never real vendors.
|
|
131
|
+
*/
|
|
132
|
+
const RESERVED_PLACEHOLDER_DOMAINS = [
|
|
133
|
+
"example.com",
|
|
134
|
+
"example.org",
|
|
135
|
+
"example.net",
|
|
136
|
+
];
|
|
137
|
+
const RESERVED_PLACEHOLDER_TLDS = [
|
|
138
|
+
"test",
|
|
139
|
+
"example",
|
|
140
|
+
"invalid",
|
|
141
|
+
"localhost",
|
|
142
|
+
];
|
|
143
|
+
function isReservedPlaceholderHost(hostname) {
|
|
144
|
+
const h = hostname.toLowerCase().replace(/\.$/, "");
|
|
145
|
+
if (!h)
|
|
146
|
+
return false;
|
|
147
|
+
for (const d of RESERVED_PLACEHOLDER_DOMAINS) {
|
|
148
|
+
if (h === d || h.endsWith(`.${d}`))
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
const labels = h.split(".");
|
|
152
|
+
const tld = labels[labels.length - 1] ?? "";
|
|
153
|
+
return RESERVED_PLACEHOLDER_TLDS.includes(tld);
|
|
154
|
+
}
|
|
126
155
|
function shouldIgnoreExternalHttpUrl(url, options) {
|
|
127
156
|
if (typeof url !== "string")
|
|
128
157
|
return true;
|
|
@@ -144,6 +173,8 @@ function shouldIgnoreExternalHttpUrl(url, options) {
|
|
|
144
173
|
}
|
|
145
174
|
if (isLocalOrPrivateHost(hostname))
|
|
146
175
|
return true;
|
|
176
|
+
if (isReservedPlaceholderHost(hostname))
|
|
177
|
+
return true;
|
|
147
178
|
const organizationDomains = resolveOrganizationDomains(options);
|
|
148
179
|
if (hostMatchesOrganizationDomains(hostname, organizationDomains)) {
|
|
149
180
|
return true;
|
|
@@ -260,7 +291,7 @@ function inferThirdPartyFromLiteralHttpUrl(finding, options) {
|
|
|
260
291
|
catch {
|
|
261
292
|
return undefined;
|
|
262
293
|
}
|
|
263
|
-
if (isLocalOrPrivateHost(hostname)) {
|
|
294
|
+
if (isLocalOrPrivateHost(hostname) || isReservedPlaceholderHost(hostname)) {
|
|
264
295
|
return undefined;
|
|
265
296
|
}
|
|
266
297
|
const serviceName = deriveServiceKeyFromHostname(hostname);
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { NameNormalizationConfig } from "./config";
|
|
2
2
|
export declare function normalizeComponentName(rawName: string, rules: NameNormalizationConfig): string;
|
|
3
|
+
/**
|
|
4
|
+
* Human-readable display name: underscores (snake_case ids such as
|
|
5
|
+
* `google_identity`) and whitespace separate words, and each word is capitalized.
|
|
6
|
+
* Dots and hyphens inside a word are preserved (`notion.so`, `next-auth`).
|
|
7
|
+
*/
|
|
3
8
|
export declare function toDisplayName(normalized: string, fallback: string): string;
|
|
4
9
|
export declare function normalizeApiDisplayName(rawName: string, properties: Record<string, unknown> | undefined): string;
|
|
@@ -41,15 +41,19 @@ function normalizeComponentName(rawName, rules) {
|
|
|
41
41
|
}
|
|
42
42
|
return lower;
|
|
43
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Human-readable display name: underscores (snake_case ids such as
|
|
46
|
+
* `google_identity`) and whitespace separate words, and each word is capitalized.
|
|
47
|
+
* Dots and hyphens inside a word are preserved (`notion.so`, `next-auth`).
|
|
48
|
+
*/
|
|
44
49
|
function toDisplayName(normalized, fallback) {
|
|
45
50
|
const base = normalized || fallback.trim();
|
|
46
51
|
if (!base)
|
|
47
52
|
return "<unknown>";
|
|
48
53
|
return base
|
|
49
|
-
.split(
|
|
50
|
-
.
|
|
51
|
-
|
|
52
|
-
: part.charAt(0).toUpperCase() + part.slice(1))
|
|
54
|
+
.split(/[\s_]+/)
|
|
55
|
+
.filter((part) => part.length > 0)
|
|
56
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
53
57
|
.join(" ");
|
|
54
58
|
}
|
|
55
59
|
function normalizeApiDisplayName(rawName, properties) {
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildScanPersonalDataLayers = buildScanPersonalDataLayers;
|
|
4
4
|
const identities_1 = require("../../eval-layers/identities");
|
|
5
|
-
function lineSnippet(
|
|
6
|
-
const lines = content.split(/\r?\n/);
|
|
5
|
+
function lineSnippet(lines, startLine, endLine) {
|
|
7
6
|
const slice = lines.slice(startLine - 1, endLine);
|
|
8
7
|
if (slice.length === 0) {
|
|
9
8
|
return undefined;
|
|
@@ -13,10 +12,25 @@ function lineSnippet(content, startLine, endLine) {
|
|
|
13
12
|
}
|
|
14
13
|
function buildScanPersonalDataLayers(inventory) {
|
|
15
14
|
const contentByPath = new Map(inventory.files.map((file) => [file.path, file.content]));
|
|
15
|
+
// Split each file into lines once, not once per occurrence: a file with thousands of
|
|
16
|
+
// occurrences (i18n catalogs, generated clients) otherwise re-splits its whole text for
|
|
17
|
+
// every one of them.
|
|
18
|
+
const linesByPath = new Map();
|
|
19
|
+
const linesOf = (filePath) => {
|
|
20
|
+
let lines = linesByPath.get(filePath);
|
|
21
|
+
if (lines)
|
|
22
|
+
return lines;
|
|
23
|
+
const content = contentByPath.get(filePath);
|
|
24
|
+
if (content === undefined)
|
|
25
|
+
return undefined;
|
|
26
|
+
lines = content.split(/\r?\n/);
|
|
27
|
+
linesByPath.set(filePath, lines);
|
|
28
|
+
return lines;
|
|
29
|
+
};
|
|
16
30
|
const occurrences = inventory.hits.map((hit) => {
|
|
17
|
-
const
|
|
18
|
-
const code =
|
|
19
|
-
? lineSnippet(
|
|
31
|
+
const lines = linesOf(hit.evidence.filePath);
|
|
32
|
+
const code = lines !== undefined
|
|
33
|
+
? lineSnippet(lines, hit.evidence.startLine, hit.evidence.endLine)
|
|
20
34
|
: undefined;
|
|
21
35
|
return {
|
|
22
36
|
id: (0, identities_1.occurrenceIdentity)(hit.id, hit.evidence.filePath, hit.evidence.startLine),
|
|
@@ -46,7 +60,7 @@ function buildScanPersonalDataLayers(inventory) {
|
|
|
46
60
|
const occurrenceId = (0, identities_1.occurrenceIdentity)(hit.id, hit.evidence.filePath, hit.evidence.startLine);
|
|
47
61
|
let entry = dataItemsById.get(id);
|
|
48
62
|
if (!entry) {
|
|
49
|
-
entry = { labels: new Set(hit.labels), occurrenceIds:
|
|
63
|
+
entry = { labels: new Set(hit.labels), occurrenceIds: new Set(), groups: new Map() };
|
|
50
64
|
dataItemsById.set(id, entry);
|
|
51
65
|
}
|
|
52
66
|
else {
|
|
@@ -54,16 +68,14 @@ function buildScanPersonalDataLayers(inventory) {
|
|
|
54
68
|
entry.labels.add(label);
|
|
55
69
|
}
|
|
56
70
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
71
|
+
// Sets keep first-seen order, as the arrays with an `includes` check did, without the
|
|
72
|
+
// quadratic scan.
|
|
73
|
+
entry.occurrenceIds.add(occurrenceId);
|
|
60
74
|
// A location-named singleton (`email~file:line`) is a occurrence no evidence grouped; it
|
|
61
75
|
// stays on the occurrence for external labels but is not listed as a data item group.
|
|
62
76
|
if (hit.group && !hit.group.startsWith(`${hit.id}~`)) {
|
|
63
|
-
const groupOccurrences = entry.groups.get(hit.group) ??
|
|
64
|
-
|
|
65
|
-
groupOccurrences.push(occurrenceId);
|
|
66
|
-
}
|
|
77
|
+
const groupOccurrences = entry.groups.get(hit.group) ?? new Set();
|
|
78
|
+
groupOccurrences.add(occurrenceId);
|
|
67
79
|
entry.groups.set(hit.group, groupOccurrences);
|
|
68
80
|
}
|
|
69
81
|
}
|
|
@@ -75,7 +87,7 @@ function buildScanPersonalDataLayers(inventory) {
|
|
|
75
87
|
...(entry.groups.size > 0
|
|
76
88
|
? {
|
|
77
89
|
groups: [...entry.groups.entries()]
|
|
78
|
-
.map(([groupId, occurrenceIds]) => ({ id: groupId, occurrenceIds }))
|
|
90
|
+
.map(([groupId, occurrenceIds]) => ({ id: groupId, occurrenceIds: [...occurrenceIds] }))
|
|
79
91
|
.sort((left, right) => left.id.localeCompare(right.id)),
|
|
80
92
|
}
|
|
81
93
|
: {}),
|
|
@@ -7,7 +7,9 @@ const build_scan_personal_data_layers_1 = require("./build-scan-personal-data-la
|
|
|
7
7
|
async function enrichOrchestratorResultWithPersonalDataLayers(rootPath, result) {
|
|
8
8
|
await (0, personal_data_inventory_1.ensureDeclarationEngine)();
|
|
9
9
|
const inventory = result.ledgerContext
|
|
10
|
-
? (0, personal_data_inventory_1.buildPersonalDataInventoryFromIngest)(result.ledgerContext.allIngestedFiles, result.ledgerContext.ingestOutcomes, await (0, schema_files_1.readSchemaFiles)(rootPath
|
|
10
|
+
? (0, personal_data_inventory_1.buildPersonalDataInventoryFromIngest)(result.ledgerContext.allIngestedFiles, result.ledgerContext.ingestOutcomes, await (0, schema_files_1.readSchemaFiles)(rootPath, {
|
|
11
|
+
excludePaths: result.ledgerContext.config.excludePaths,
|
|
12
|
+
}))
|
|
11
13
|
: await (0, personal_data_inventory_1.buildPersonalDataInventory)(rootPath);
|
|
12
14
|
const { occurrences, dataItems } = (0, build_scan_personal_data_layers_1.buildScanPersonalDataLayers)(inventory);
|
|
13
15
|
return { ...result, occurrences, dataItems };
|
|
@@ -1,7 +1,25 @@
|
|
|
1
1
|
import type { DetectedComponent } from "../core/types/component";
|
|
2
2
|
import type { DetectedDataFlow } from "../core/types/data-flow";
|
|
3
3
|
import type { FileInfo } from "../core/types/file";
|
|
4
|
+
type EnclosingScope = {
|
|
5
|
+
startLine: number;
|
|
6
|
+
endLine: number;
|
|
7
|
+
readonly text: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* The enclosing scope of each line of one file, in O(n log n) per file.
|
|
11
|
+
*
|
|
12
|
+
* A line with no scope header above it is its own scope start, so a file without
|
|
13
|
+
* function or class headers (a generated PHP baseline, a config array) has one scope
|
|
14
|
+
* per line, each running to the end of the file. Caching the joined text of those
|
|
15
|
+
* scopes kept O(lines^2) bytes alive and exhausted the heap on a 1.7 MB file. Only scope
|
|
16
|
+
* end lines are cached; `text` is joined on read and only for lines that need it. Scope
|
|
17
|
+
* ends come from a min segment tree over brace depth and a per-indent index of Ruby
|
|
18
|
+
* `end` lines, so no lookup scans forward through the file.
|
|
19
|
+
*/
|
|
20
|
+
export declare function enclosingScopeFinder(lines: string[]): (lineIndex: number) => EnclosingScope;
|
|
4
21
|
export declare function detectIntraComponentLineage(files: FileInfo[], components: DetectedComponent[], startIndex: number): {
|
|
5
22
|
flows: DetectedDataFlow[];
|
|
6
23
|
nextIndex: number;
|
|
7
24
|
};
|
|
25
|
+
export {};
|