@dataparade/cli 0.0.30 → 0.0.32
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/dist/package.json +3 -3
- package/dist/src/ai-enrichment/fallbacks.js +12 -1
- package/dist/src/cli.js +3 -0
- package/dist/src/core/pipeline/omit-internal-implementation.js +13 -6
- package/dist/src/output/git-context.d.ts +17 -0
- package/dist/src/output/git-context.js +104 -0
- package/dist/tests/unit/ai-enrichment/fallbacks.spec.js +30 -0
- package/dist/tests/unit/core/omit-internal-implementation.spec.js +21 -0
- package/dist/tests/unit/output/git-context.spec.d.ts +1 -0
- package/dist/tests/unit/output/git-context.spec.js +79 -0
- package/dist/vendor/scanner/dist/src/analyzers/python/python-detection-config.d.ts +11 -0
- package/dist/vendor/scanner/dist/src/analyzers/python/python-detection-config.js +2 -0
- package/dist/vendor/scanner/dist/src/analyzers/registry.d.ts +2 -0
- package/dist/vendor/scanner/dist/src/analyzers/registry.js +3 -2
- package/dist/vendor/scanner/dist/src/analyzers/typescript/typescript-detection-config.d.ts +17 -0
- package/dist/vendor/scanner/dist/src/analyzers/typescript/typescript-detection-config.js +11 -0
- package/dist/vendor/scanner/dist/src/classifier/component-factory.js +33 -3
- package/dist/vendor/scanner/dist/src/classifier/enhance.js +14 -0
- package/dist/vendor/scanner/dist/src/classifier/external-url-third-party.d.ts +8 -0
- package/dist/vendor/scanner/dist/src/classifier/external-url-third-party.js +43 -2
- package/dist/vendor/scanner/dist/src/classifier/postprocessing.js +4 -1
- package/dist/vendor/scanner/dist/src/config/third-party-detection-config.d.ts +41 -0
- package/dist/vendor/scanner/dist/src/config/third-party-detection-config.js +65 -1
- package/dist/vendor/scanner/dist/src/core/pipeline/diagram-layout/constants.d.ts +2 -0
- package/dist/vendor/scanner/dist/src/core/pipeline/diagram-layout/constants.js +3 -1
- package/dist/vendor/scanner/dist/src/core/pipeline/diagram-layout/section-packing.d.ts +9 -0
- package/dist/vendor/scanner/dist/src/core/pipeline/diagram-layout/section-packing.js +40 -0
- package/dist/vendor/scanner/dist/src/core/pipeline/graph-mapping.js +2 -0
- package/dist/vendor/scanner/dist/src/core/pipeline/structural-scan.js +2 -0
- package/dist/vendor/scanner/dist/src/eval/canonical/scanner/components.d.ts +5 -0
- package/dist/vendor/scanner/dist/src/eval/canonical/scanner/components.js +10 -2
- package/dist/vendor/scanner/dist/src/eval/canonical/scanner/data-flows.js +4 -4
- package/dist/vendor/scanner/dist/src/patterns/config.js +7 -1
- package/dist/vendor/scanner/dist/src/patterns/detectors/git-remote-owner.d.ts +14 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/git-remote-owner.js +108 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/python-outbound-http.d.ts +93 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/python-outbound-http.js +1206 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/python-source.d.ts +180 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/python-source.js +1022 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/python.d.ts +6 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/python.js +49 -1
- package/dist/vendor/scanner/dist/src/patterns/detectors/repo-declared-domains.d.ts +2 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/repo-declared-domains.js +80 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/source-module-index.d.ts +23 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/source-module-index.js +145 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/typescript-outbound-http.d.ts +30 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/typescript-outbound-http.js +575 -0
- package/dist/vendor/scanner/dist/src/patterns/detectors/typescript.js +12 -0
- package/dist/vendor/scanner/dist/src/patterns/engine.js +6 -1
- package/dist/vendor/scanner/patterns/classifier/third-party.classifier.yaml +188 -0
- package/dist/vendor/scanner/patterns/python.patterns.yaml +10 -0
- package/dist/vendor/scanner/patterns/third-party.patterns.yaml +246 -0
- package/dist/vendor/scanner/patterns/typescript.patterns.yaml +21 -0
- package/package.json +3 -3
|
@@ -5,5 +5,11 @@ export declare function detectPythonDatabaseConnectionsFromImportsAndContent(ctx
|
|
|
5
5
|
export declare function detectPythonAuthFromConfig(ctx: PatternContext, config: UnifiedPatternConfig): RawFinding[];
|
|
6
6
|
export declare function detectPythonEnvAndConfigFromConfig(ctx: PatternContext, config: UnifiedPatternConfig): RawFinding[];
|
|
7
7
|
export declare function detectPythonRoutesFromConfig(ctx: PatternContext, config: UnifiedPatternConfig): RawFinding[];
|
|
8
|
+
/**
|
|
9
|
+
* Drop the `openai` import finding when every OpenAI client in the file is built with a
|
|
10
|
+
* `base_url` on another provider's host (OpenRouter, Cerebras ...): the code imports the
|
|
11
|
+
* OpenAI SDK but does not call OpenAI (DATAP-818).
|
|
12
|
+
*/
|
|
13
|
+
export declare function dropRedirectedOpenAiImportFindings(ctx: PatternContext, config: UnifiedPatternConfig, findings: RawFinding[]): RawFinding[];
|
|
8
14
|
export declare function detectPythonExternalApisFromConfig(ctx: PatternContext, config: UnifiedPatternConfig): RawFinding[];
|
|
9
15
|
export declare function detectPythonServerlessHandlersFromConfig(ctx: PatternContext, config: UnifiedPatternConfig): RawFinding[];
|
|
@@ -4,11 +4,13 @@ exports.detectPythonDatabaseConnectionsFromImportsAndContent = detectPythonDatab
|
|
|
4
4
|
exports.detectPythonAuthFromConfig = detectPythonAuthFromConfig;
|
|
5
5
|
exports.detectPythonEnvAndConfigFromConfig = detectPythonEnvAndConfigFromConfig;
|
|
6
6
|
exports.detectPythonRoutesFromConfig = detectPythonRoutesFromConfig;
|
|
7
|
+
exports.dropRedirectedOpenAiImportFindings = dropRedirectedOpenAiImportFindings;
|
|
7
8
|
exports.detectPythonExternalApisFromConfig = detectPythonExternalApisFromConfig;
|
|
8
9
|
exports.detectPythonServerlessHandlersFromConfig = detectPythonServerlessHandlersFromConfig;
|
|
9
10
|
const external_url_third_party_1 = require("../../classifier/external-url-third-party");
|
|
10
11
|
const organization_domains_scan_scope_1 = require("../../classifier/organization-domains-scan-scope");
|
|
11
12
|
const helpers_1 = require("./helpers");
|
|
13
|
+
const python_outbound_http_1 = require("./python-outbound-http");
|
|
12
14
|
function pythonImportLocations(ctx, modules) {
|
|
13
15
|
if (modules.length === 0)
|
|
14
16
|
return [];
|
|
@@ -105,9 +107,19 @@ function detectPythonAuthFromConfig(ctx, config) {
|
|
|
105
107
|
});
|
|
106
108
|
}
|
|
107
109
|
}
|
|
110
|
+
const outgoing = authConfig.libraries.some((lib) => lib.outgoingHeader)
|
|
111
|
+
? new Set(outboundHttpFor(ctx, config).outgoingRequestLines)
|
|
112
|
+
: new Set();
|
|
108
113
|
for (const lib of authConfig.libraries) {
|
|
109
114
|
const importLocations = pythonImportLocations(ctx, lib.importModules);
|
|
110
|
-
|
|
115
|
+
let contentLocations = (0, helpers_1.locationsForContentRegexes)(ctx.file, content, lib.contentRegexes);
|
|
116
|
+
if (lib.outgoingHeader) {
|
|
117
|
+
const before = contentLocations.length;
|
|
118
|
+
contentLocations = contentLocations.filter((loc) => !outgoing.has(loc.startLine));
|
|
119
|
+
// Every match is a header sent on an outbound request: nothing to report.
|
|
120
|
+
if (before > 0 && contentLocations.length === 0 && importLocations.length === 0)
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
111
123
|
const hasImport = importLocations.length > 0;
|
|
112
124
|
const matchesContent = lib.contentRegexes.some((re) => re.test(content));
|
|
113
125
|
if (!hasImport && !matchesContent)
|
|
@@ -432,16 +444,52 @@ function detectPythonRoutesFromConfig(ctx, config) {
|
|
|
432
444
|
}
|
|
433
445
|
return findings;
|
|
434
446
|
}
|
|
447
|
+
function outboundHttpFor(ctx, config) {
|
|
448
|
+
const libraries = config.python.externalApis.httpClients
|
|
449
|
+
.filter((client) => client.clientConstructors.length > 0)
|
|
450
|
+
.map((client) => ({
|
|
451
|
+
name: client.clientName,
|
|
452
|
+
importModules: client.importModules,
|
|
453
|
+
constructors: client.clientConstructors,
|
|
454
|
+
patternId: client.patternId,
|
|
455
|
+
confidence: client.confidence,
|
|
456
|
+
}));
|
|
457
|
+
return (0, python_outbound_http_1.detectPythonOutboundHttp)({
|
|
458
|
+
filePath: ctx.file.path,
|
|
459
|
+
content: ctx.file.content ?? "",
|
|
460
|
+
libraries,
|
|
461
|
+
config,
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Drop the `openai` import finding when every OpenAI client in the file is built with a
|
|
466
|
+
* `base_url` on another provider's host (OpenRouter, Cerebras ...): the code imports the
|
|
467
|
+
* OpenAI SDK but does not call OpenAI (DATAP-818).
|
|
468
|
+
*/
|
|
469
|
+
function dropRedirectedOpenAiImportFindings(ctx, config, findings) {
|
|
470
|
+
if (ctx.language !== "python")
|
|
471
|
+
return findings;
|
|
472
|
+
if (!outboundHttpFor(ctx, config).openAiClientsRedirected)
|
|
473
|
+
return findings;
|
|
474
|
+
return findings.filter((f) => !(f.pattern === "external_api_call" &&
|
|
475
|
+
f.properties?.client === "openai" &&
|
|
476
|
+
f.properties?.serviceName === "openai"));
|
|
477
|
+
}
|
|
435
478
|
function detectPythonExternalApisFromConfig(ctx, config) {
|
|
436
479
|
if (ctx.language !== "python")
|
|
437
480
|
return [];
|
|
438
481
|
const imports = ctx.imports ?? [];
|
|
439
482
|
const calls = ctx.moduleLevelCalls ?? [];
|
|
440
483
|
const findings = [];
|
|
484
|
+
// Raw HTTP libraries (httpx, requests, aiohttp): resolve each request call's destination
|
|
485
|
+
// in the same file; the library itself is never the destination (DATAP-818).
|
|
486
|
+
findings.push(...outboundHttpFor(ctx, config).findings);
|
|
441
487
|
if (calls.length === 0)
|
|
442
488
|
return findings;
|
|
443
489
|
const urlHostPatterns = (0, helpers_1.buildThirdPartyUrlHostPatterns)(config);
|
|
444
490
|
for (const client of config.python.externalApis.httpClients) {
|
|
491
|
+
if (client.clientConstructors.length > 0)
|
|
492
|
+
continue;
|
|
445
493
|
const hasImport = client.importModules.length === 0
|
|
446
494
|
? true
|
|
447
495
|
: client.importModules.some((mod) => imports.some((imp) => imp.module.includes(mod) || imp.names.includes(mod)));
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.collectRepoDeclaredDomains = collectRepoDeclaredDomains;
|
|
4
|
+
const external_url_third_party_1 = require("../../classifier/external-url-third-party");
|
|
5
|
+
const third_party_detection_config_1 = require("../../config/third-party-detection-config");
|
|
6
|
+
/**
|
|
7
|
+
* Domains a repository declares as its own (DATAP-818), used as organization domains when
|
|
8
|
+
* none are configured, so a website calling its company's API on another subdomain is a
|
|
9
|
+
* first-party call and not a vendor named after the company.
|
|
10
|
+
*
|
|
11
|
+
* Conservative on purpose. Sources:
|
|
12
|
+
* - `homepage` in a package.json;
|
|
13
|
+
* - site URL settings in env example files and source code: `SITE_URL`, `APP_URL`,
|
|
14
|
+
* `WEBSITE_URL`, `PUBLIC_URL`, `CANONICAL_URL`, `FRONTEND_URL` (with `NEXT_PUBLIC_`,
|
|
15
|
+
* `VITE_`, `REACT_APP_`, `PUBLIC_` prefixes), assigned a literal https URL.
|
|
16
|
+
* Never: code and package hosts (github.com ...), shared hosting platforms (*.run.app ...),
|
|
17
|
+
* placeholder and local hosts, and hosts of catalog vendors. `BASE_URL`/`API_URL` are not
|
|
18
|
+
* read: they usually hold a vendor's API. README links and CNAME files are not ingested.
|
|
19
|
+
*/
|
|
20
|
+
const SITE_URL_SETTING = /\b(?:NEXT_PUBLIC_|VITE_|REACT_APP_|PUBLIC_)?(?:SITE|APP|WEBSITE|PUBLIC|CANONICAL|FRONTEND)_URL\b["']?\s*[:=]\s*["'`]?(https:\/\/[^"'`\s/]+)/g;
|
|
21
|
+
const NEVER_OWN = new Set([
|
|
22
|
+
"github.com", "githubusercontent.com", "gitlab.com", "bitbucket.org", "npmjs.com", "npmjs.org",
|
|
23
|
+
"pypi.org", "readthedocs.io", "google.com", "medium.com", "notion.site", "localhost",
|
|
24
|
+
]);
|
|
25
|
+
function hostOf(url) {
|
|
26
|
+
try {
|
|
27
|
+
return new URL(url).hostname.toLowerCase();
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function isCatalogVendorHost(host) {
|
|
34
|
+
return (0, third_party_detection_config_1.loadThirdPartyDetectionConfig)().services.some((svc) => svc.urlHostPatterns.some((p) => {
|
|
35
|
+
const pattern = p.toLowerCase().replace(/^\./, "");
|
|
36
|
+
return host === pattern || host.endsWith(`.${pattern}`);
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
function collectRepoDeclaredDomains(files) {
|
|
40
|
+
const hosts = new Set();
|
|
41
|
+
for (const file of files) {
|
|
42
|
+
const base = file.path.split("/").pop() ?? "";
|
|
43
|
+
const content = file.content ?? "";
|
|
44
|
+
if (base === "package.json") {
|
|
45
|
+
try {
|
|
46
|
+
const homepage = JSON.parse(content).homepage;
|
|
47
|
+
if (typeof homepage === "string") {
|
|
48
|
+
const host = hostOf(homepage);
|
|
49
|
+
if (host)
|
|
50
|
+
hosts.add(host);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
// Not JSON: ignore.
|
|
55
|
+
}
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const isEnvExample = file.language === "env" || /^\.env\./.test(base);
|
|
59
|
+
const isSource = file.language === "typescript" || file.language === "javascript" || file.language === "python";
|
|
60
|
+
if (!isEnvExample && !isSource)
|
|
61
|
+
continue;
|
|
62
|
+
if (!/_URL/.test(content))
|
|
63
|
+
continue;
|
|
64
|
+
for (const m of content.matchAll(SITE_URL_SETTING)) {
|
|
65
|
+
const host = hostOf(m[1]);
|
|
66
|
+
if (host)
|
|
67
|
+
hosts.add(host);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const domains = new Set();
|
|
71
|
+
for (const host of hosts) {
|
|
72
|
+
if (!host.includes(".") || (0, external_url_third_party_1.isReservedPlaceholderHost)(host) || (0, third_party_detection_config_1.platformOfHost)(host) || isCatalogVendorHost(host))
|
|
73
|
+
continue;
|
|
74
|
+
const domain = (0, external_url_third_party_1.registrableDomainOf)(host);
|
|
75
|
+
if (NEVER_OWN.has(domain))
|
|
76
|
+
continue;
|
|
77
|
+
domains.add(domain);
|
|
78
|
+
}
|
|
79
|
+
return [...domains].sort();
|
|
80
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { FileInfo } from "../../core/types/file";
|
|
2
|
+
export interface SourceScopeOptions {
|
|
3
|
+
/** Owner of the repository's git `origin` remote (see git-remote-owner.ts). */
|
|
4
|
+
gitRemoteOwner?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function runWithPythonModuleIndex<T>(files: readonly FileInfo[], fn: () => T, options?: SourceScopeOptions): T;
|
|
7
|
+
/** Normalized owner name of the repository's git remote, when known. */
|
|
8
|
+
export declare function repoOwnerKey(): string | undefined;
|
|
9
|
+
/** Domains the scanned repository declares as its own (see repo-declared-domains.ts). */
|
|
10
|
+
export declare function repoDeclaredDomains(): readonly string[];
|
|
11
|
+
/** Changes whenever the active index changes, for cache keys. */
|
|
12
|
+
export declare function pythonModuleIndexGeneration(): number;
|
|
13
|
+
export declare function pythonModuleIndexSize(): number;
|
|
14
|
+
/** Repo-relative file of a relative TS/JS import (`./settings`, `../lib/http`), seen from `fromFile`. */
|
|
15
|
+
export declare function resolveTsModulePath(fromFile: string, spec: string): string | undefined;
|
|
16
|
+
export declare function sourceModule(filePath: string): string | undefined;
|
|
17
|
+
export declare function pythonModuleSource(filePath: string): string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Repo-relative file of an imported module, seen from `fromFile`: relative imports
|
|
20
|
+
* (`.settings`, `..pkg.mod`) resolve from the importing file's package; absolute imports
|
|
21
|
+
* (`app.settings`) match a path suffix, preferring the file nearest to the importer.
|
|
22
|
+
*/
|
|
23
|
+
export declare function resolvePythonModulePath(fromFile: string, moduleSpec: string): string | undefined;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runWithPythonModuleIndex = runWithPythonModuleIndex;
|
|
4
|
+
exports.repoOwnerKey = repoOwnerKey;
|
|
5
|
+
exports.repoDeclaredDomains = repoDeclaredDomains;
|
|
6
|
+
exports.pythonModuleIndexGeneration = pythonModuleIndexGeneration;
|
|
7
|
+
exports.pythonModuleIndexSize = pythonModuleIndexSize;
|
|
8
|
+
exports.resolveTsModulePath = resolveTsModulePath;
|
|
9
|
+
exports.sourceModule = sourceModule;
|
|
10
|
+
exports.pythonModuleSource = pythonModuleSource;
|
|
11
|
+
exports.resolvePythonModulePath = resolvePythonModulePath;
|
|
12
|
+
const git_remote_owner_1 = require("./git-remote-owner");
|
|
13
|
+
const repo_declared_domains_1 = require("./repo-declared-domains");
|
|
14
|
+
/**
|
|
15
|
+
* The Python, TypeScript and JavaScript files of the scan, by repo-relative path, while
|
|
16
|
+
* analyzers run. Detectors use it to follow same-repo imports (`from .settings import
|
|
17
|
+
* settings`, `import { X } from "./settings"`) when they resolve a value (DATAP-818).
|
|
18
|
+
* Outside a scan the index is empty and resolution stays in one file.
|
|
19
|
+
*/
|
|
20
|
+
let activeIndex;
|
|
21
|
+
let activeDeclaredDomains = [];
|
|
22
|
+
let activeOwnerKey;
|
|
23
|
+
let generation = 0;
|
|
24
|
+
function normalize(filePath) {
|
|
25
|
+
return filePath.replace(/\\/g, "/").replace(/^\.\/+/, "");
|
|
26
|
+
}
|
|
27
|
+
function runWithPythonModuleIndex(files, fn, options = {}) {
|
|
28
|
+
const prev = activeIndex;
|
|
29
|
+
const index = new Map();
|
|
30
|
+
for (const file of files) {
|
|
31
|
+
if (file.language === "python" || file.language === "typescript" || file.language === "javascript" || /\.(py|[cm]?[jt]sx?)$/.test(file.path)) {
|
|
32
|
+
index.set(normalize(file.path), file.content);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const prevDomains = activeDeclaredDomains;
|
|
36
|
+
const prevOwner = activeOwnerKey;
|
|
37
|
+
activeIndex = index;
|
|
38
|
+
activeDeclaredDomains = (0, repo_declared_domains_1.collectRepoDeclaredDomains)(files);
|
|
39
|
+
activeOwnerKey = options.gitRemoteOwner ? (0, git_remote_owner_1.normalizeOrganizationName)(options.gitRemoteOwner) || undefined : undefined;
|
|
40
|
+
generation += 1;
|
|
41
|
+
try {
|
|
42
|
+
return fn();
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
activeIndex = prev;
|
|
46
|
+
activeDeclaredDomains = prevDomains;
|
|
47
|
+
activeOwnerKey = prevOwner;
|
|
48
|
+
generation += 1;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** Normalized owner name of the repository's git remote, when known. */
|
|
52
|
+
function repoOwnerKey() {
|
|
53
|
+
return activeOwnerKey;
|
|
54
|
+
}
|
|
55
|
+
/** Domains the scanned repository declares as its own (see repo-declared-domains.ts). */
|
|
56
|
+
function repoDeclaredDomains() {
|
|
57
|
+
return activeDeclaredDomains;
|
|
58
|
+
}
|
|
59
|
+
/** Changes whenever the active index changes, for cache keys. */
|
|
60
|
+
function pythonModuleIndexGeneration() {
|
|
61
|
+
return generation;
|
|
62
|
+
}
|
|
63
|
+
function pythonModuleIndexSize() {
|
|
64
|
+
if (!activeIndex)
|
|
65
|
+
return 0;
|
|
66
|
+
let n = 0;
|
|
67
|
+
for (const key of activeIndex.keys())
|
|
68
|
+
if (key.endsWith(".py"))
|
|
69
|
+
n += 1;
|
|
70
|
+
return n;
|
|
71
|
+
}
|
|
72
|
+
const TS_EXTENSIONS = [".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"];
|
|
73
|
+
/** Repo-relative file of a relative TS/JS import (`./settings`, `../lib/http`), seen from `fromFile`. */
|
|
74
|
+
function resolveTsModulePath(fromFile, spec) {
|
|
75
|
+
if (!activeIndex || !spec.startsWith("."))
|
|
76
|
+
return undefined;
|
|
77
|
+
const parts = dirname(normalize(fromFile)).split("/").filter(Boolean);
|
|
78
|
+
for (const segment of spec.split("/")) {
|
|
79
|
+
if (segment === "." || segment === "")
|
|
80
|
+
continue;
|
|
81
|
+
if (segment === "..")
|
|
82
|
+
parts.pop();
|
|
83
|
+
else
|
|
84
|
+
parts.push(segment);
|
|
85
|
+
}
|
|
86
|
+
const base = parts.join("/");
|
|
87
|
+
const stem = base.replace(/\.(?:[cm]?js|jsx)$/, "");
|
|
88
|
+
const candidates = [base, ...TS_EXTENSIONS.map((e) => `${stem}${e}`), ...TS_EXTENSIONS.map((e) => `${base}/index${e}`)];
|
|
89
|
+
return candidates.find((p) => activeIndex.has(p));
|
|
90
|
+
}
|
|
91
|
+
function sourceModule(filePath) {
|
|
92
|
+
return activeIndex?.get(normalize(filePath));
|
|
93
|
+
}
|
|
94
|
+
function pythonModuleSource(filePath) {
|
|
95
|
+
return activeIndex?.get(normalize(filePath));
|
|
96
|
+
}
|
|
97
|
+
function dirname(filePath) {
|
|
98
|
+
const i = filePath.lastIndexOf("/");
|
|
99
|
+
return i === -1 ? "" : filePath.slice(0, i);
|
|
100
|
+
}
|
|
101
|
+
function join(dir, rel) {
|
|
102
|
+
return dir ? `${dir}/${rel}` : rel;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Repo-relative file of an imported module, seen from `fromFile`: relative imports
|
|
106
|
+
* (`.settings`, `..pkg.mod`) resolve from the importing file's package; absolute imports
|
|
107
|
+
* (`app.settings`) match a path suffix, preferring the file nearest to the importer.
|
|
108
|
+
*/
|
|
109
|
+
function resolvePythonModulePath(fromFile, moduleSpec) {
|
|
110
|
+
if (!activeIndex)
|
|
111
|
+
return undefined;
|
|
112
|
+
const from = normalize(fromFile);
|
|
113
|
+
const dots = /^\.*/.exec(moduleSpec)?.[0].length ?? 0;
|
|
114
|
+
const parts = moduleSpec.slice(dots).split(".").filter(Boolean);
|
|
115
|
+
const candidates = (base) => {
|
|
116
|
+
const rel = parts.join("/");
|
|
117
|
+
return rel ? [join(base, `${rel}.py`), join(base, `${rel}/__init__.py`)] : [join(base, "__init__.py")];
|
|
118
|
+
};
|
|
119
|
+
if (dots > 0) {
|
|
120
|
+
let dir = dirname(from);
|
|
121
|
+
for (let i = 1; i < dots; i += 1)
|
|
122
|
+
dir = dirname(dir);
|
|
123
|
+
return candidates(dir).find((p) => activeIndex.has(p));
|
|
124
|
+
}
|
|
125
|
+
if (parts.length === 0)
|
|
126
|
+
return undefined;
|
|
127
|
+
const suffixes = candidates("");
|
|
128
|
+
let best;
|
|
129
|
+
for (const path of activeIndex.keys()) {
|
|
130
|
+
if (!suffixes.some((s) => path === s || path.endsWith(`/${s}`)))
|
|
131
|
+
continue;
|
|
132
|
+
const shared = sharedPrefix(path, from);
|
|
133
|
+
if (!best || shared > best.shared)
|
|
134
|
+
best = { path, shared };
|
|
135
|
+
}
|
|
136
|
+
return best?.path;
|
|
137
|
+
}
|
|
138
|
+
function sharedPrefix(a, b) {
|
|
139
|
+
const x = a.split("/");
|
|
140
|
+
const y = b.split("/");
|
|
141
|
+
let n = 0;
|
|
142
|
+
while (n < x.length && n < y.length && x[n] === y[n])
|
|
143
|
+
n += 1;
|
|
144
|
+
return n;
|
|
145
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript/JavaScript outbound HTTP destinations (DATAP-818), the counterpart of
|
|
3
|
+
* `python-outbound-http.ts`.
|
|
4
|
+
*
|
|
5
|
+
* It parses the file with the TypeScript compiler API (the TS analyzer's parser already
|
|
6
|
+
* depends on it) and finds request calls: the global `fetch`, and the raw HTTP libraries
|
|
7
|
+
* marked `rawHttp` in `typescript.patterns.yaml` (axios, got, ky, node-fetch ...), including
|
|
8
|
+
* instances made with `axios.create({ baseURL })` / `got.extend({ prefixUrl })`. The URL is
|
|
9
|
+
* resolved from literals and template literals, `const` bindings, parameter defaults,
|
|
10
|
+
* `??` / `||` defaults on `process.env`, object-literal constants, and `const` exports of
|
|
11
|
+
* same-repo modules imported with a relative path. A known host names the vendor; a URL that
|
|
12
|
+
* only comes from the environment (`import.meta.env.VITE_*`, `process.env.X` with no default)
|
|
13
|
+
* gives an outbound call with no vendor. A library is never the destination. Relative URLs
|
|
14
|
+
* with no base are same-origin calls and are not reported.
|
|
15
|
+
*/
|
|
16
|
+
import type { RawFinding } from "../../core/types/detection";
|
|
17
|
+
import type { UnifiedPatternConfig } from "../config";
|
|
18
|
+
export interface TsOutboundHttpResult {
|
|
19
|
+
findings: RawFinding[];
|
|
20
|
+
/** 1-based line spans of the request calls the detector handled (resolved or not). */
|
|
21
|
+
coveredSpans: Array<{
|
|
22
|
+
startLine: number;
|
|
23
|
+
endLine: number;
|
|
24
|
+
}>;
|
|
25
|
+
}
|
|
26
|
+
export declare function detectTsOutboundHttp(input: {
|
|
27
|
+
filePath: string;
|
|
28
|
+
content: string;
|
|
29
|
+
config: UnifiedPatternConfig;
|
|
30
|
+
}): TsOutboundHttpResult;
|