@dataparade/cli 0.0.34 → 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/classifier/component-factory.js +20 -0
- 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/detectors/python.js +11 -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/python.patterns.yaml +2 -2
- 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
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
import type { SourceLocation } from "./file";
|
|
2
2
|
export type DataFlowType = "api_call" | "database_query" | "message_queue" | "file_transfer" | "webhook" | "rpc" | "data_transfer";
|
|
3
|
+
export declare const FLOW_RELATIONSHIPS: readonly ["invokes", "queries", "publishes", "consumes", "interacts", "authenticates_via", "exposes", "uses_in_process", "depends_on", "provisions"];
|
|
4
|
+
export type FlowRelationship = (typeof FLOW_RELATIONSHIPS)[number];
|
|
5
|
+
export declare const FLOW_PROTOCOLS: readonly ["rest", "graphql", "grpc", "soap", "json_rpc", "mcp", "sql", "mongodb_wire", "redis", "kafka", "amqp", "mqtt", "smtp", "oauth_oidc", "otlp", "vendor_sdk", "unknown"];
|
|
6
|
+
export type FlowProtocol = (typeof FLOW_PROTOCOLS)[number];
|
|
7
|
+
export declare const FLOW_TRANSPORTS: readonly ["https", "http", "websocket", "http2", "tcp_tls", "tcp", "stdio", "in_process", "unknown"];
|
|
8
|
+
export type FlowTransport = (typeof FLOW_TRANSPORTS)[number];
|
|
9
|
+
export declare const HUMAN_INTERACTION_CHANNELS: readonly ["web_gui", "mobile_app", "desktop_app", "cli", "mcp", "api_direct", "email", "unknown"];
|
|
10
|
+
export type HumanInteractionChannel = (typeof HUMAN_INTERACTION_CHANNELS)[number];
|
|
11
|
+
export interface HumanInteractionChannelEvidence {
|
|
12
|
+
signal: string;
|
|
13
|
+
filePath: string;
|
|
14
|
+
line: number;
|
|
15
|
+
}
|
|
16
|
+
/** One line of authentication evidence on a flow (DATAP-912). */
|
|
17
|
+
export interface FlowAuthenticationEvidence {
|
|
18
|
+
kind: string;
|
|
19
|
+
filePath: string;
|
|
20
|
+
line: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Authentication evidence on a flow (DATAP-912). `none_seen` means no evidence was found,
|
|
24
|
+
* not that the flow is unauthenticated. Absent when the flow type is not checked.
|
|
25
|
+
*/
|
|
26
|
+
export interface FlowAuthentication {
|
|
27
|
+
status: "seen" | "none_seen";
|
|
28
|
+
kinds: string[];
|
|
29
|
+
evidence: FlowAuthenticationEvidence[];
|
|
30
|
+
}
|
|
31
|
+
export type FlowControlEffect = "mitigates" | "weakens";
|
|
32
|
+
/**
|
|
33
|
+
* One line of control evidence on a flow (DATAP-915): TLS, a timeout, plain HTTP.
|
|
34
|
+
* "weakens" means the line removes a control.
|
|
35
|
+
*/
|
|
36
|
+
export interface FlowControlEvidence {
|
|
37
|
+
control: string;
|
|
38
|
+
effect: FlowControlEffect;
|
|
39
|
+
filePath: string;
|
|
40
|
+
line: number;
|
|
41
|
+
}
|
|
3
42
|
export interface DetectedDataFlow {
|
|
4
43
|
id: string;
|
|
5
44
|
sourceComponentId: string;
|
|
@@ -21,4 +60,13 @@ export interface DetectedDataFlow {
|
|
|
21
60
|
targetScope?: "local" | "cross_section_internal" | "external" | "unknown";
|
|
22
61
|
targetScopeConfidence?: "high" | "medium" | "low";
|
|
23
62
|
targetScopeReason?: string;
|
|
63
|
+
authentication?: FlowAuthentication;
|
|
64
|
+
/** Control evidence (DATAP-915). Empty when nothing was seen; absent when not checked. */
|
|
65
|
+
controls?: FlowControlEvidence[];
|
|
66
|
+
relationship?: FlowRelationship;
|
|
67
|
+
protocol?: FlowProtocol;
|
|
68
|
+
transport?: FlowTransport;
|
|
69
|
+
client?: string;
|
|
70
|
+
channel?: HumanInteractionChannel;
|
|
71
|
+
channelEvidence?: HumanInteractionChannelEvidence[];
|
|
24
72
|
}
|
|
@@ -1,2 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HUMAN_INTERACTION_CHANNELS = exports.FLOW_TRANSPORTS = exports.FLOW_PROTOCOLS = exports.FLOW_RELATIONSHIPS = void 0;
|
|
4
|
+
exports.FLOW_RELATIONSHIPS = [
|
|
5
|
+
"invokes",
|
|
6
|
+
"queries",
|
|
7
|
+
"publishes",
|
|
8
|
+
"consumes",
|
|
9
|
+
"interacts",
|
|
10
|
+
"authenticates_via",
|
|
11
|
+
"exposes",
|
|
12
|
+
"uses_in_process",
|
|
13
|
+
"depends_on",
|
|
14
|
+
"provisions",
|
|
15
|
+
];
|
|
16
|
+
exports.FLOW_PROTOCOLS = [
|
|
17
|
+
"rest",
|
|
18
|
+
"graphql",
|
|
19
|
+
"grpc",
|
|
20
|
+
"soap",
|
|
21
|
+
"json_rpc",
|
|
22
|
+
"mcp",
|
|
23
|
+
"sql",
|
|
24
|
+
"mongodb_wire",
|
|
25
|
+
"redis",
|
|
26
|
+
"kafka",
|
|
27
|
+
"amqp",
|
|
28
|
+
"mqtt",
|
|
29
|
+
"smtp",
|
|
30
|
+
"oauth_oidc",
|
|
31
|
+
"otlp",
|
|
32
|
+
"vendor_sdk",
|
|
33
|
+
"unknown",
|
|
34
|
+
];
|
|
35
|
+
exports.FLOW_TRANSPORTS = [
|
|
36
|
+
"https",
|
|
37
|
+
"http",
|
|
38
|
+
"websocket",
|
|
39
|
+
"http2",
|
|
40
|
+
"tcp_tls",
|
|
41
|
+
"tcp",
|
|
42
|
+
"stdio",
|
|
43
|
+
"in_process",
|
|
44
|
+
"unknown",
|
|
45
|
+
];
|
|
46
|
+
exports.HUMAN_INTERACTION_CHANNELS = [
|
|
47
|
+
"web_gui",
|
|
48
|
+
"mobile_app",
|
|
49
|
+
"desktop_app",
|
|
50
|
+
"cli",
|
|
51
|
+
"mcp",
|
|
52
|
+
"api_direct",
|
|
53
|
+
"email",
|
|
54
|
+
"unknown",
|
|
55
|
+
];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { DetectedDataFlow, FlowAuthentication } from "../core/types/data-flow";
|
|
2
|
+
import type { FileInfo, SourceLocation } from "../core/types/file";
|
|
3
|
+
export interface FlowAuthenticationRules {
|
|
4
|
+
version: number;
|
|
5
|
+
maxLinesBefore: number;
|
|
6
|
+
linesAfter: number;
|
|
7
|
+
helperLines: number;
|
|
8
|
+
skipFlowTypes: Set<string>;
|
|
9
|
+
credentialArgument: RegExp;
|
|
10
|
+
kinds: Array<{
|
|
11
|
+
id: string;
|
|
12
|
+
patterns: RegExp[];
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
15
|
+
export declare function loadFlowAuthenticationRules(): FlowAuthenticationRules;
|
|
16
|
+
export declare const FUNCTION_START: RegExp;
|
|
17
|
+
export declare const IMPORT_LINE: RegExp;
|
|
18
|
+
export declare function escapeRegExp(value: string): string;
|
|
19
|
+
/** Line indexes (0-based) of the code around one request. */
|
|
20
|
+
export declare function requestWindow(lines: string[], index: number, rules: Pick<FlowAuthenticationRules, "maxLinesBefore" | "linesAfter">): number[];
|
|
21
|
+
/**
|
|
22
|
+
* Line indexes of the definition of `name` elsewhere in the file: a function, or a
|
|
23
|
+
* top-level constant. Local variables are already inside the request window.
|
|
24
|
+
*/
|
|
25
|
+
export declare function definitionLines(lines: string[], name: string, rules: Pick<FlowAuthenticationRules, "helperLines">): number[];
|
|
26
|
+
export declare function locationsOf(flow: DetectedDataFlow): SourceLocation[];
|
|
27
|
+
/** Authentication evidence for one flow, or undefined when the flow is not checked. */
|
|
28
|
+
export declare function flowAuthentication(flow: DetectedDataFlow, linesByPath: ReadonlyMap<string, string[]>, rules?: FlowAuthenticationRules): FlowAuthentication | undefined;
|
|
29
|
+
/** Sets `authentication` on each checked flow. Mutates the flows. */
|
|
30
|
+
export declare function annotateFlowAuthentication(flows: DetectedDataFlow[], files: FileInfo[]): void;
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.IMPORT_LINE = exports.FUNCTION_START = void 0;
|
|
7
|
+
exports.loadFlowAuthenticationRules = loadFlowAuthenticationRules;
|
|
8
|
+
exports.escapeRegExp = escapeRegExp;
|
|
9
|
+
exports.requestWindow = requestWindow;
|
|
10
|
+
exports.definitionLines = definitionLines;
|
|
11
|
+
exports.locationsOf = locationsOf;
|
|
12
|
+
exports.flowAuthentication = flowAuthentication;
|
|
13
|
+
exports.annotateFlowAuthentication = annotateFlowAuthentication;
|
|
14
|
+
/**
|
|
15
|
+
* Authentication evidence on data flows (DATAP-912).
|
|
16
|
+
*
|
|
17
|
+
* For each evidence location of a flow, read the code around the request (the enclosing
|
|
18
|
+
* function, up to a few lines after the call and never past the end of that function) and any helper function or constant that the
|
|
19
|
+
* call passes as `headers=`, `auth=` and similar. Apply the patterns in
|
|
20
|
+
* patterns/flow-authentication.rules.yaml. Each match records its kind and line.
|
|
21
|
+
*
|
|
22
|
+
* "none_seen" means no evidence was found. It does not mean the flow is unauthenticated.
|
|
23
|
+
*/
|
|
24
|
+
const fs_1 = __importDefault(require("fs"));
|
|
25
|
+
const path_1 = __importDefault(require("path"));
|
|
26
|
+
const yaml_1 = __importDefault(require("yaml"));
|
|
27
|
+
const zod_1 = require("zod");
|
|
28
|
+
const MAX_LOCATIONS_PER_FLOW = 12;
|
|
29
|
+
const MAX_EVIDENCE_PER_FLOW = 6;
|
|
30
|
+
const rulesSchema = zod_1.z.object({
|
|
31
|
+
version: zod_1.z.number(),
|
|
32
|
+
window: zod_1.z.object({
|
|
33
|
+
max_lines_before: zod_1.z.number().int().positive(),
|
|
34
|
+
lines_after: zod_1.z.number().int().nonnegative(),
|
|
35
|
+
helper_lines: zod_1.z.number().int().positive(),
|
|
36
|
+
}),
|
|
37
|
+
skip_flow_types: zod_1.z.array(zod_1.z.string()).default([]),
|
|
38
|
+
credential_arguments: zod_1.z.array(zod_1.z.string().min(1)),
|
|
39
|
+
kinds: zod_1.z.array(zod_1.z.object({ id: zod_1.z.string().min(1), patterns: zod_1.z.array(zod_1.z.string().min(1)).min(1) })),
|
|
40
|
+
});
|
|
41
|
+
let cached;
|
|
42
|
+
function rulesPath() {
|
|
43
|
+
const parts = __dirname.split(path_1.default.sep);
|
|
44
|
+
const distIndex = parts.lastIndexOf("dist");
|
|
45
|
+
const root = distIndex !== -1 ? parts.slice(0, distIndex).join(path_1.default.sep) : path_1.default.resolve(__dirname, "..", "..");
|
|
46
|
+
return path_1.default.join(root, "patterns", "flow-authentication.rules.yaml");
|
|
47
|
+
}
|
|
48
|
+
function loadFlowAuthenticationRules() {
|
|
49
|
+
if (cached)
|
|
50
|
+
return cached;
|
|
51
|
+
const raw = rulesSchema.parse(yaml_1.default.parse(fs_1.default.readFileSync(rulesPath(), "utf8")));
|
|
52
|
+
const args = raw.credential_arguments.map((a) => a.replace(/[^A-Za-z0-9_]/g, "")).join("|");
|
|
53
|
+
cached = {
|
|
54
|
+
version: raw.version,
|
|
55
|
+
maxLinesBefore: raw.window.max_lines_before,
|
|
56
|
+
linesAfter: raw.window.lines_after,
|
|
57
|
+
helperLines: raw.window.helper_lines,
|
|
58
|
+
skipFlowTypes: new Set(raw.skip_flow_types),
|
|
59
|
+
// `headers=_auth_headers()`, `auth=creds`, `headers: buildHeaders(token)`, `headers=self._headers`.
|
|
60
|
+
credentialArgument: new RegExp(`\\b(?:${args})\\s*[=:]\\s*(?:self\\.|this\\.)?([A-Za-z_][A-Za-z0-9_]*)\\s*(\\()?`, "g"),
|
|
61
|
+
kinds: raw.kinds.map((k) => ({ id: k.id, patterns: k.patterns.map((p) => new RegExp(p)) })),
|
|
62
|
+
};
|
|
63
|
+
return cached;
|
|
64
|
+
}
|
|
65
|
+
exports.FUNCTION_START = /^\s*(?:@\w+.*)?(?:async\s+)?def\s+\w+\s*\(|^\s*(?:export\s+)?(?:default\s+)?(?:async\s+)?function\b|^\s*(?:public|private|protected|static|async|\s)*[A-Za-z_$][\w$]*\s*\([^)]*\)\s*(?::\s*[^{=]+)?\{\s*$|=>\s*\{\s*$|^\s*func\b.*\{\s*$|^\s*(?:(?:public|private|protected|internal|static|final|abstract|override|virtual|async|synchronized)\s+)+[\w<>\[\],.?\s]+?\s+\w+\s*\([^)]*\)\s*(?:throws\s+[\w.,\s]+)?\{\s*$/;
|
|
66
|
+
exports.IMPORT_LINE = /^\s*(?:from\s+[\w.]+\s+import\b|import\s+[\w.]+|import\b.*\bfrom\s+["']|const\s+\w+\s*=\s*require\()/;
|
|
67
|
+
/** Kinds that an SDK client takes as a constructor argument. */
|
|
68
|
+
const SDK_CLIENT_KINDS = new Set(["api_key", "oauth"]);
|
|
69
|
+
function escapeRegExp(value) {
|
|
70
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
71
|
+
}
|
|
72
|
+
/** Line indexes (0-based) of the code around one request. */
|
|
73
|
+
function requestWindow(lines, index, rules) {
|
|
74
|
+
let start = index;
|
|
75
|
+
let enclosing;
|
|
76
|
+
const floor = Math.max(0, index - rules.maxLinesBefore);
|
|
77
|
+
for (let i = index; i >= floor; i -= 1) {
|
|
78
|
+
start = i;
|
|
79
|
+
// A nested function or callback that closes before the call does not enclose it.
|
|
80
|
+
if (exports.FUNCTION_START.test(lines[i] ?? "") && !closesBefore(lines, i, index)) {
|
|
81
|
+
enclosing = i;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const limit = Math.min(lines.length - 1, index + rules.linesAfter);
|
|
86
|
+
const end = enclosing === undefined ? nextFunctionBound(lines, index, limit) : functionEnd(lines, enclosing, index, limit);
|
|
87
|
+
const out = [];
|
|
88
|
+
for (let i = start; i <= end; i += 1)
|
|
89
|
+
out.push(i);
|
|
90
|
+
return out;
|
|
91
|
+
}
|
|
92
|
+
const PY_DEF = /^(\s*)(?:async\s+)?def\s/;
|
|
93
|
+
const DECORATOR = /^\s*@\w/;
|
|
94
|
+
function indentOf(line) {
|
|
95
|
+
return line.length - line.trimStart().length;
|
|
96
|
+
}
|
|
97
|
+
/** Last line before the next function definition, up to `limit`. */
|
|
98
|
+
function nextFunctionBound(lines, index, limit) {
|
|
99
|
+
for (let i = index + 1; i <= limit; i += 1) {
|
|
100
|
+
if (exports.FUNCTION_START.test(lines[i] ?? "") || DECORATOR.test(lines[i] ?? ""))
|
|
101
|
+
return i - 1;
|
|
102
|
+
}
|
|
103
|
+
return limit;
|
|
104
|
+
}
|
|
105
|
+
/** Count of `{` minus `}` on a line, ignoring string literals and line comments. */
|
|
106
|
+
function braceDelta(line) {
|
|
107
|
+
const code = line.replace(/(["'`])(?:\\.|(?!\1).)*\1/g, "").replace(/\/\/.*$/, "");
|
|
108
|
+
let delta = 0;
|
|
109
|
+
for (const ch of code) {
|
|
110
|
+
if (ch === "{")
|
|
111
|
+
delta += 1;
|
|
112
|
+
else if (ch === "}")
|
|
113
|
+
delta -= 1;
|
|
114
|
+
}
|
|
115
|
+
return delta;
|
|
116
|
+
}
|
|
117
|
+
/** True when the function that starts at `start` ends before line `index`. */
|
|
118
|
+
function closesBefore(lines, start, index) {
|
|
119
|
+
if (start === index)
|
|
120
|
+
return false;
|
|
121
|
+
const py = PY_DEF.exec(lines[start] ?? "");
|
|
122
|
+
if (py) {
|
|
123
|
+
const defIndent = py[1].length;
|
|
124
|
+
for (let i = start + 1; i < index; i += 1) {
|
|
125
|
+
const line = lines[i] ?? "";
|
|
126
|
+
if (line.trim() !== "" && indentOf(line) <= defIndent)
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
let depth = 0;
|
|
132
|
+
let opened = false;
|
|
133
|
+
for (let i = start; i < index; i += 1) {
|
|
134
|
+
depth += braceDelta(lines[i] ?? "");
|
|
135
|
+
if (depth > 0)
|
|
136
|
+
opened = true;
|
|
137
|
+
if (opened && depth <= 0)
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Last line of the function that starts at `start` and contains `index`, up to `limit`.
|
|
144
|
+
* Python functions end at the first non-blank line indented no deeper than the `def`.
|
|
145
|
+
* Brace functions end where the braces opened on the first line close.
|
|
146
|
+
*/
|
|
147
|
+
function functionEnd(lines, start, index, limit) {
|
|
148
|
+
const py = PY_DEF.exec(lines[start] ?? "");
|
|
149
|
+
if (py) {
|
|
150
|
+
const defIndent = py[1].length;
|
|
151
|
+
for (let i = index + 1; i <= limit; i += 1) {
|
|
152
|
+
const line = lines[i] ?? "";
|
|
153
|
+
if (line.trim() === "")
|
|
154
|
+
continue;
|
|
155
|
+
if (indentOf(line) <= defIndent)
|
|
156
|
+
return i - 1;
|
|
157
|
+
}
|
|
158
|
+
return limit;
|
|
159
|
+
}
|
|
160
|
+
let depth = 0;
|
|
161
|
+
let opened = false;
|
|
162
|
+
for (let i = start; i <= limit; i += 1) {
|
|
163
|
+
depth += braceDelta(lines[i] ?? "");
|
|
164
|
+
if (depth > 0)
|
|
165
|
+
opened = true;
|
|
166
|
+
if (opened && depth <= 0 && i >= index)
|
|
167
|
+
return i;
|
|
168
|
+
}
|
|
169
|
+
return nextFunctionBound(lines, index, limit);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Line indexes of the definition of `name` elsewhere in the file: a function, or a
|
|
173
|
+
* top-level constant. Local variables are already inside the request window.
|
|
174
|
+
*/
|
|
175
|
+
function definitionLines(lines, name, rules) {
|
|
176
|
+
const n = escapeRegExp(name);
|
|
177
|
+
const def = new RegExp(`^\\s*(?:async\\s+)?def\\s+${n}\\s*\\(|^\\s*(?:export\\s+)?(?:async\\s+)?function\\s+${n}\\s*\\(|^(?:export\\s+)?(?:const|let|var)\\s+${n}\\b|^${n}\\s*(?::[^=]+)?=[^=]`);
|
|
178
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
179
|
+
if (!def.test(lines[i]))
|
|
180
|
+
continue;
|
|
181
|
+
const out = [];
|
|
182
|
+
for (let j = i; j < Math.min(lines.length, i + rules.helperLines); j += 1)
|
|
183
|
+
out.push(j);
|
|
184
|
+
return out;
|
|
185
|
+
}
|
|
186
|
+
return [];
|
|
187
|
+
}
|
|
188
|
+
function evidenceForLocation(lines, location, rules) {
|
|
189
|
+
const index = location.startLine - 1;
|
|
190
|
+
if (index < 0 || index >= lines.length)
|
|
191
|
+
return [];
|
|
192
|
+
const window = requestWindow(lines, index, rules);
|
|
193
|
+
const read = new Set(window);
|
|
194
|
+
const windowText = window.map((i) => lines[i]).join("\n");
|
|
195
|
+
rules.credentialArgument.lastIndex = 0;
|
|
196
|
+
for (const match of windowText.matchAll(rules.credentialArgument)) {
|
|
197
|
+
const name = match[1];
|
|
198
|
+
// A name assigned inside the window is a local; its value is already read.
|
|
199
|
+
const local = new RegExp(`^\\s*${escapeRegExp(name)}\\s*(?::[^=]+)?=[^=]`);
|
|
200
|
+
if (window.some((i) => local.test(lines[i])))
|
|
201
|
+
continue;
|
|
202
|
+
for (const i of definitionLines(lines, name, rules))
|
|
203
|
+
read.add(i);
|
|
204
|
+
}
|
|
205
|
+
// SDK flows cite the import. The credentials go to the client built in the same file,
|
|
206
|
+
// so read the file, but keep only the kinds an SDK client takes.
|
|
207
|
+
const sdkImport = exports.IMPORT_LINE.test(lines[index]);
|
|
208
|
+
if (sdkImport)
|
|
209
|
+
for (let i = 0; i < lines.length; i += 1)
|
|
210
|
+
read.add(i);
|
|
211
|
+
const evidence = [];
|
|
212
|
+
for (const i of [...read].sort((a, b) => a - b)) {
|
|
213
|
+
const line = lines[i];
|
|
214
|
+
for (const kind of rules.kinds) {
|
|
215
|
+
if (sdkImport && !SDK_CLIENT_KINDS.has(kind.id))
|
|
216
|
+
continue;
|
|
217
|
+
if (kind.patterns.some((p) => p.test(line))) {
|
|
218
|
+
evidence.push({ kind: kind.id, filePath: location.filePath, line: i + 1 });
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return evidence;
|
|
223
|
+
}
|
|
224
|
+
function locationsOf(flow) {
|
|
225
|
+
if (flow.sourceLocations && flow.sourceLocations.length > 0)
|
|
226
|
+
return flow.sourceLocations;
|
|
227
|
+
return flow.sourceLocation ? [flow.sourceLocation] : [];
|
|
228
|
+
}
|
|
229
|
+
/** Authentication evidence for one flow, or undefined when the flow is not checked. */
|
|
230
|
+
function flowAuthentication(flow, linesByPath, rules = loadFlowAuthenticationRules()) {
|
|
231
|
+
if (rules.skipFlowTypes.has(flow.type))
|
|
232
|
+
return undefined;
|
|
233
|
+
const locations = locationsOf(flow).slice(0, MAX_LOCATIONS_PER_FLOW);
|
|
234
|
+
if (locations.length === 0)
|
|
235
|
+
return undefined;
|
|
236
|
+
const seen = new Map();
|
|
237
|
+
for (const location of locations) {
|
|
238
|
+
const lines = linesByPath.get(location.filePath);
|
|
239
|
+
if (!lines)
|
|
240
|
+
continue;
|
|
241
|
+
for (const e of evidenceForLocation(lines, location, rules)) {
|
|
242
|
+
seen.set(`${e.kind}|${e.filePath}|${e.line}`, e);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const evidence = [...seen.values()].sort((a, b) => a.kind.localeCompare(b.kind) || a.filePath.localeCompare(b.filePath) || a.line - b.line);
|
|
246
|
+
const kinds = [...new Set(evidence.map((e) => e.kind))].sort();
|
|
247
|
+
if (kinds.length === 0)
|
|
248
|
+
return { status: "none_seen", kinds: [], evidence: [] };
|
|
249
|
+
// Keep at least one line for each kind, then fill up to the cap.
|
|
250
|
+
const kept = kinds.map((k) => evidence.find((e) => e.kind === k));
|
|
251
|
+
for (const e of evidence) {
|
|
252
|
+
if (kept.length >= MAX_EVIDENCE_PER_FLOW)
|
|
253
|
+
break;
|
|
254
|
+
if (!kept.includes(e))
|
|
255
|
+
kept.push(e);
|
|
256
|
+
}
|
|
257
|
+
kept.sort((a, b) => a.kind.localeCompare(b.kind) || a.filePath.localeCompare(b.filePath) || a.line - b.line);
|
|
258
|
+
return { status: "seen", kinds, evidence: kept };
|
|
259
|
+
}
|
|
260
|
+
/** Sets `authentication` on each checked flow. Mutates the flows. */
|
|
261
|
+
function annotateFlowAuthentication(flows, files) {
|
|
262
|
+
if (flows.length === 0)
|
|
263
|
+
return;
|
|
264
|
+
const rules = loadFlowAuthenticationRules();
|
|
265
|
+
const linesByPath = new Map();
|
|
266
|
+
for (const file of files) {
|
|
267
|
+
if (typeof file.content === "string")
|
|
268
|
+
linesByPath.set(file.path, file.content.split(/\r?\n/));
|
|
269
|
+
}
|
|
270
|
+
for (const flow of flows) {
|
|
271
|
+
const auth = flowAuthentication(flow, linesByPath, rules);
|
|
272
|
+
if (auth)
|
|
273
|
+
flow.authentication = auth;
|
|
274
|
+
else
|
|
275
|
+
delete flow.authentication;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.flowTypeForExternalApi = flowTypeForExternalApi;
|
|
4
4
|
exports.buildFlow = buildFlow;
|
|
5
|
+
const flow_interaction_description_1 = require("./flow-interaction-description");
|
|
5
6
|
function getSectionIdFromMaybeUnknown(raw) {
|
|
6
7
|
if (typeof raw !== "string")
|
|
7
8
|
return undefined;
|
|
@@ -64,6 +65,7 @@ function buildFlow(sourceId, targetId, type, finding, index, sourceComponent, ta
|
|
|
64
65
|
? finding.properties.url
|
|
65
66
|
: undefined;
|
|
66
67
|
const scope = inferTargetScope(sourceComponent, targetComponent);
|
|
68
|
+
const interactionDescription = (0, flow_interaction_description_1.describeFlowFromFinding)(finding, type, sourceComponent, targetComponent);
|
|
67
69
|
return {
|
|
68
70
|
id: `flow_${index}`,
|
|
69
71
|
sourceComponentId: sourceId,
|
|
@@ -76,5 +78,9 @@ function buildFlow(sourceId, targetId, type, finding, index, sourceComponent, ta
|
|
|
76
78
|
targetScope: scope.targetScope,
|
|
77
79
|
targetScopeConfidence: scope.targetScopeConfidence,
|
|
78
80
|
targetScopeReason: scope.targetScopeReason,
|
|
81
|
+
...definedPropertiesOnly(interactionDescription),
|
|
79
82
|
};
|
|
80
83
|
}
|
|
84
|
+
function definedPropertiesOnly(value) {
|
|
85
|
+
return Object.fromEntries(Object.entries(value).filter(([, propertyValue]) => propertyValue !== undefined));
|
|
86
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { DetectedDataFlow, FlowControlEffect, FlowControlEvidence } from "../core/types/data-flow";
|
|
2
|
+
import type { FileInfo } from "../core/types/file";
|
|
3
|
+
import { type FlowAuthenticationRules } from "./flow-authentication";
|
|
4
|
+
export interface FlowControlRules {
|
|
5
|
+
version: number;
|
|
6
|
+
skipFlowTypes: Set<string>;
|
|
7
|
+
urlConstant: RegExp;
|
|
8
|
+
commentLine: RegExp;
|
|
9
|
+
controls: Array<{
|
|
10
|
+
id: string;
|
|
11
|
+
effect: FlowControlEffect;
|
|
12
|
+
sdk: boolean;
|
|
13
|
+
patterns: RegExp[];
|
|
14
|
+
}>;
|
|
15
|
+
}
|
|
16
|
+
export declare function loadFlowControlRules(): FlowControlRules;
|
|
17
|
+
/** For each line, whether it is part of a Python triple-quoted string. */
|
|
18
|
+
export declare function docstringLines(lines: string[]): boolean[];
|
|
19
|
+
/** Names an import line binds: `from x import A, B as C`, `import x.y`, `import { A } from`, `const A = require(`. */
|
|
20
|
+
export declare function importedNames(line: string): string[];
|
|
21
|
+
/** Control evidence for one flow, or undefined when the flow is not checked. */
|
|
22
|
+
export declare function flowControls(flow: DetectedDataFlow, linesByPath: ReadonlyMap<string, string[]>, rules?: FlowControlRules, windowRules?: FlowAuthenticationRules): FlowControlEvidence[] | undefined;
|
|
23
|
+
/** Sets `controls` on each checked flow. Mutates the flows. */
|
|
24
|
+
export declare function annotateFlowControls(flows: DetectedDataFlow[], files: FileInfo[]): void;
|