@dataparade/cli 0.0.10 → 0.0.12
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 +1 -1
- package/dist/src/analyzers/php/dependency-manifests.d.ts +10 -0
- package/dist/src/analyzers/php/dependency-manifests.js +117 -0
- package/dist/src/analyzers/php/detector.d.ts +3 -0
- package/dist/src/analyzers/php/detector.js +20 -0
- package/dist/src/analyzers/php/index.d.ts +2 -0
- package/dist/src/analyzers/php/index.js +11 -0
- package/dist/src/analyzers/php/manifest-parsers.d.ts +14 -0
- package/dist/src/analyzers/php/manifest-parsers.js +40 -0
- package/dist/src/analyzers/php/parser.d.ts +42 -0
- package/dist/src/analyzers/php/parser.js +297 -0
- package/dist/src/analyzers/php/patterns.d.ts +3 -0
- package/dist/src/analyzers/php/patterns.js +49 -0
- package/dist/src/analyzers/php/php-detection-config.d.ts +104 -0
- package/dist/src/analyzers/php/php-detection-config.js +192 -0
- package/dist/src/analyzers/registry.js +3 -0
- package/dist/src/analyzers/shared/strip-comments.js +3 -2
- package/dist/src/classifier/postprocessing.d.ts +6 -0
- package/dist/src/classifier/postprocessing.js +61 -6
- package/dist/src/cli.js +27 -0
- package/dist/src/config/file.js +1 -0
- package/dist/src/config/resolve.js +1 -0
- package/dist/src/core/pipeline/classifier-phase.js +3 -3
- package/dist/src/core/pipeline/structural-scan.js +39 -14
- package/dist/src/core/schema/scan-config.schema.d.ts +1 -0
- package/dist/src/core/schema/scan-config.schema.js +1 -0
- package/dist/src/core/schema/scan-result.schema.d.ts +1 -0
- package/dist/src/core/schema/scan-result.schema.js +1 -0
- package/dist/src/core/sectioning/discover-service-sections.js +3 -0
- package/dist/src/core/types/file.d.ts +1 -1
- package/dist/src/ingest/file-system.js +3 -0
- package/dist/src/patterns/config.d.ts +2 -0
- package/dist/src/patterns/config.js +31 -0
- package/dist/src/patterns/detectors/php.d.ts +9 -0
- package/dist/src/patterns/detectors/php.js +466 -0
- package/dist/src/patterns/engine.js +7 -0
- package/dist/src/platform-api/telemetry-client.d.ts +6 -0
- package/dist/src/platform-api/telemetry-client.js +65 -0
- package/dist/src/platform-api/telemetry.types.d.ts +13 -0
- package/dist/src/platform-api/telemetry.types.js +2 -0
- package/dist/src/platform-api/upload-client.d.ts +2 -0
- package/dist/src/platform-api/upload-client.js +4 -0
- package/dist/src/platform-api/upload.types.d.ts +2 -0
- package/dist/src/upload/build-preview-url.d.ts +2 -2
- package/dist/src/upload/build-preview-url.js +10 -3
- package/dist/src/upload/run-upload.js +62 -19
- package/dist/src/upload/types.d.ts +2 -0
- package/dist/tests/unit/analyzers/php/dependency-manifests.spec.d.ts +1 -0
- package/dist/tests/unit/analyzers/php/dependency-manifests.spec.js +54 -0
- package/dist/tests/unit/analyzers/php/parser.spec.d.ts +1 -0
- package/dist/tests/unit/analyzers/php/parser.spec.js +128 -0
- package/dist/tests/unit/analyzers/php/patterns.spec.d.ts +1 -0
- package/dist/tests/unit/analyzers/php/patterns.spec.js +334 -0
- package/dist/tests/unit/classifier/classify.spec.js +68 -0
- package/dist/tests/unit/ingest/php-languages.spec.d.ts +1 -0
- package/dist/tests/unit/ingest/php-languages.spec.js +40 -0
- package/dist/tests/unit/platform-api/telemetry-client.spec.d.ts +1 -0
- package/dist/tests/unit/platform-api/telemetry-client.spec.js +48 -0
- package/dist/tests/unit/upload/build-preview-url.spec.js +10 -0
- package/dist/tests/unit/upload/run-upload.spec.js +18 -0
- package/package.json +1 -1
- package/patterns/php.md +74 -0
- package/patterns/php.patterns.yaml +311 -0
- package/patterns/third-party.patterns.yaml +10 -0
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const detector_1 = require("../../../../src/analyzers/php/detector");
|
|
4
|
+
function makePhpFile(content, path = "index.php") {
|
|
5
|
+
return {
|
|
6
|
+
path,
|
|
7
|
+
name: path,
|
|
8
|
+
content,
|
|
9
|
+
language: "php",
|
|
10
|
+
size: content.length,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
describe("PHP analyzer patterns", () => {
|
|
14
|
+
it("detects Laravel routes with their HTTP method", () => {
|
|
15
|
+
const content = [
|
|
16
|
+
"<?php",
|
|
17
|
+
"",
|
|
18
|
+
"Route::get('/customers', [CustomerController::class, 'index']);",
|
|
19
|
+
"Route::post('/charges', [ChargeController::class, 'store']);",
|
|
20
|
+
"",
|
|
21
|
+
].join("\n");
|
|
22
|
+
const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "routes/web.php"));
|
|
23
|
+
const routes = findings.filter((f) => f.pattern === "express_route");
|
|
24
|
+
expect(routes.map((r) => r.name).sort()).toEqual([
|
|
25
|
+
"GET /customers",
|
|
26
|
+
"POST /charges",
|
|
27
|
+
]);
|
|
28
|
+
expect(routes[0].properties.framework).toBe("laravel");
|
|
29
|
+
});
|
|
30
|
+
it("detects Slim routes when Slim is imported", () => {
|
|
31
|
+
const content = [
|
|
32
|
+
"<?php",
|
|
33
|
+
"",
|
|
34
|
+
"use Slim\\App;",
|
|
35
|
+
"",
|
|
36
|
+
"$app->get('/health', $healthHandler);",
|
|
37
|
+
"$app->post('/orders', $createOrder);",
|
|
38
|
+
"",
|
|
39
|
+
].join("\n");
|
|
40
|
+
const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "app.php"));
|
|
41
|
+
const routes = findings.filter((f) => f.pattern === "express_route");
|
|
42
|
+
expect(routes.map((r) => r.name).sort()).toEqual([
|
|
43
|
+
"GET /health",
|
|
44
|
+
"POST /orders",
|
|
45
|
+
]);
|
|
46
|
+
expect(routes[0].properties.framework).toBe("slim");
|
|
47
|
+
});
|
|
48
|
+
it("resolves the engine from a PDO DSN", () => {
|
|
49
|
+
const content = [
|
|
50
|
+
"<?php",
|
|
51
|
+
"",
|
|
52
|
+
'$db = new PDO("pgsql:host=localhost;dbname=app", $user, $pass);',
|
|
53
|
+
"",
|
|
54
|
+
].join("\n");
|
|
55
|
+
const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "db.php"));
|
|
56
|
+
const dbs = findings.filter((f) => f.pattern === "database_connection");
|
|
57
|
+
const pdoDsn = dbs.find((d) => d.properties.client === "pdo_dsn");
|
|
58
|
+
expect(pdoDsn).toBeDefined();
|
|
59
|
+
expect(pdoDsn?.properties.driver).toBe("pgsql");
|
|
60
|
+
expect(pdoDsn?.properties.databaseType).toBe("postgres");
|
|
61
|
+
});
|
|
62
|
+
it("detects Guzzle external API calls with a URL", () => {
|
|
63
|
+
const content = [
|
|
64
|
+
"<?php",
|
|
65
|
+
"",
|
|
66
|
+
"use GuzzleHttp\\Client;",
|
|
67
|
+
"",
|
|
68
|
+
"$client = new Client();",
|
|
69
|
+
'$response = $client->get("https://api.stripe.com/v1/charges");',
|
|
70
|
+
"",
|
|
71
|
+
].join("\n");
|
|
72
|
+
const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "billing.php"));
|
|
73
|
+
const apis = findings.filter((f) => f.pattern === "external_api_call");
|
|
74
|
+
expect(apis.length).toBeGreaterThan(0);
|
|
75
|
+
expect(apis.some((a) => String(a.properties.url ?? "").includes("stripe.com"))).toBe(true);
|
|
76
|
+
});
|
|
77
|
+
it("detects env() and getenv variable reads", () => {
|
|
78
|
+
const content = [
|
|
79
|
+
"<?php",
|
|
80
|
+
"",
|
|
81
|
+
'$key = getenv("APP_KEY");',
|
|
82
|
+
'$db = env("DB_CONNECTION");',
|
|
83
|
+
'$fromEnv = $_ENV["STRIPE_SECRET"];',
|
|
84
|
+
"",
|
|
85
|
+
].join("\n");
|
|
86
|
+
const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "config.php"));
|
|
87
|
+
const envs = findings.filter((f) => f.pattern === "env_variable");
|
|
88
|
+
expect(envs.map((e) => e.properties.key).sort()).toEqual([
|
|
89
|
+
"APP_KEY",
|
|
90
|
+
"DB_CONNECTION",
|
|
91
|
+
"STRIPE_SECRET",
|
|
92
|
+
]);
|
|
93
|
+
});
|
|
94
|
+
it("detects Sanctum auth from a use import", () => {
|
|
95
|
+
const content = [
|
|
96
|
+
"<?php",
|
|
97
|
+
"",
|
|
98
|
+
"use Laravel\\Sanctum\\HasApiTokens;",
|
|
99
|
+
"",
|
|
100
|
+
"class User",
|
|
101
|
+
"{",
|
|
102
|
+
" use HasApiTokens;",
|
|
103
|
+
"}",
|
|
104
|
+
"",
|
|
105
|
+
].join("\n");
|
|
106
|
+
const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "User.php"));
|
|
107
|
+
const auth = findings.filter((f) => f.pattern === "auth_middleware");
|
|
108
|
+
expect(auth.map((a) => a.name)).toContain("laravel_sanctum");
|
|
109
|
+
});
|
|
110
|
+
it("detects Symfony attribute routes", () => {
|
|
111
|
+
const content = [
|
|
112
|
+
"<?php",
|
|
113
|
+
"",
|
|
114
|
+
'#[Route("/api/users", methods: ["GET"])]',
|
|
115
|
+
"class UsersController",
|
|
116
|
+
"{",
|
|
117
|
+
"}",
|
|
118
|
+
"",
|
|
119
|
+
].join("\n");
|
|
120
|
+
const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "UsersController.php"));
|
|
121
|
+
const routes = findings.filter((f) => f.pattern === "express_route");
|
|
122
|
+
expect(routes.map((r) => r.name)).toContain("SYMFONY_ROUTE /api/users");
|
|
123
|
+
expect(routes[0].properties.framework).toBe("symfony");
|
|
124
|
+
});
|
|
125
|
+
it("detects Symfony docblock @Route annotations", () => {
|
|
126
|
+
const content = [
|
|
127
|
+
"<?php",
|
|
128
|
+
"",
|
|
129
|
+
"/**",
|
|
130
|
+
" * @Route(\"/legacy\")",
|
|
131
|
+
" */",
|
|
132
|
+
"class LegacyController",
|
|
133
|
+
"{",
|
|
134
|
+
"}",
|
|
135
|
+
"",
|
|
136
|
+
].join("\n");
|
|
137
|
+
const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "LegacyController.php"));
|
|
138
|
+
const routes = findings.filter((f) => f.pattern === "express_route");
|
|
139
|
+
expect(routes.map((r) => r.name)).toContain("SYMFONY_ROUTE /legacy");
|
|
140
|
+
expect(routes[0].properties.framework).toBe("symfony");
|
|
141
|
+
});
|
|
142
|
+
it("does not treat Guzzle new Client() as Predis", () => {
|
|
143
|
+
const content = [
|
|
144
|
+
"<?php",
|
|
145
|
+
"",
|
|
146
|
+
"use GuzzleHttp\\Client;",
|
|
147
|
+
"",
|
|
148
|
+
"$client = new Client();",
|
|
149
|
+
'$response = $client->get("https://api.stripe.com/v1/charges");',
|
|
150
|
+
"",
|
|
151
|
+
].join("\n");
|
|
152
|
+
const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "billing.php"));
|
|
153
|
+
const dbs = findings.filter((f) => f.pattern === "database_connection");
|
|
154
|
+
expect(dbs.map((d) => d.name)).not.toContain("predis");
|
|
155
|
+
});
|
|
156
|
+
it("detects Predis when Predis is imported", () => {
|
|
157
|
+
const content = [
|
|
158
|
+
"<?php",
|
|
159
|
+
"",
|
|
160
|
+
"use Predis\\Client;",
|
|
161
|
+
"",
|
|
162
|
+
"$redis = new Client();",
|
|
163
|
+
"",
|
|
164
|
+
].join("\n");
|
|
165
|
+
const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "cache.php"));
|
|
166
|
+
const dbs = findings.filter((f) => f.pattern === "database_connection");
|
|
167
|
+
expect(dbs.map((d) => d.name)).toContain("predis");
|
|
168
|
+
});
|
|
169
|
+
it("resolves the engine from a fully-qualified new \\PDO DSN", () => {
|
|
170
|
+
const content = [
|
|
171
|
+
"<?php",
|
|
172
|
+
"",
|
|
173
|
+
'$db = new \\PDO("pgsql:host=localhost;dbname=app", $user, $pass);',
|
|
174
|
+
"",
|
|
175
|
+
].join("\n");
|
|
176
|
+
const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "db.php"));
|
|
177
|
+
const dbs = findings.filter((f) => f.pattern === "database_connection");
|
|
178
|
+
const pdoDsn = dbs.find((d) => d.properties.client === "pdo_dsn");
|
|
179
|
+
expect(pdoDsn).toBeDefined();
|
|
180
|
+
expect(pdoDsn?.properties.driver).toBe("pgsql");
|
|
181
|
+
expect(pdoDsn?.properties.databaseType).toBe("postgres");
|
|
182
|
+
});
|
|
183
|
+
it("detects mysqli with a leading backslash", () => {
|
|
184
|
+
const content = [
|
|
185
|
+
"<?php",
|
|
186
|
+
"",
|
|
187
|
+
'$db = new \\mysqli("localhost", "user", "pass", "app");',
|
|
188
|
+
"",
|
|
189
|
+
].join("\n");
|
|
190
|
+
const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "db.php"));
|
|
191
|
+
const dbs = findings.filter((f) => f.pattern === "database_connection");
|
|
192
|
+
expect(dbs.map((d) => d.name)).toContain("mysqli");
|
|
193
|
+
});
|
|
194
|
+
it("detects Guzzle calls when imported via grouped use", () => {
|
|
195
|
+
const content = [
|
|
196
|
+
"<?php",
|
|
197
|
+
"",
|
|
198
|
+
"use GuzzleHttp\\{Client};",
|
|
199
|
+
"",
|
|
200
|
+
"$client = new Client();",
|
|
201
|
+
'$response = $client->get("https://api.stripe.com/v1/charges");',
|
|
202
|
+
"",
|
|
203
|
+
].join("\n");
|
|
204
|
+
const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "billing.php"));
|
|
205
|
+
const apis = findings.filter((f) => f.pattern === "external_api_call");
|
|
206
|
+
expect(apis.length).toBeGreaterThan(0);
|
|
207
|
+
expect(apis.some((a) => String(a.properties.url ?? "").includes("stripe.com"))).toBe(true);
|
|
208
|
+
});
|
|
209
|
+
it("detects Slim routes when imported via grouped use", () => {
|
|
210
|
+
const content = [
|
|
211
|
+
"<?php",
|
|
212
|
+
"",
|
|
213
|
+
"use Slim\\{App};",
|
|
214
|
+
"",
|
|
215
|
+
"$app->get('/health', $healthHandler);",
|
|
216
|
+
"$app->post('/orders', $createOrder);",
|
|
217
|
+
"",
|
|
218
|
+
].join("\n");
|
|
219
|
+
const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "app.php"));
|
|
220
|
+
const routes = findings.filter((f) => f.pattern === "express_route");
|
|
221
|
+
expect(routes.map((r) => r.name).sort()).toEqual([
|
|
222
|
+
"GET /health",
|
|
223
|
+
"POST /orders",
|
|
224
|
+
]);
|
|
225
|
+
expect(routes[0].properties.framework).toBe("slim");
|
|
226
|
+
});
|
|
227
|
+
it("detects Laravel config() helper as config_file", () => {
|
|
228
|
+
const content = ["<?php", "", '$name = config("app.name");', ""].join("\n");
|
|
229
|
+
const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "settings.php"));
|
|
230
|
+
const configs = findings.filter((f) => f.pattern === "config_file");
|
|
231
|
+
expect(configs.map((c) => c.name)).toContain("laravel_config");
|
|
232
|
+
});
|
|
233
|
+
it("detects Guzzle when the URL is on the line after ->get", () => {
|
|
234
|
+
const content = [
|
|
235
|
+
"<?php",
|
|
236
|
+
"",
|
|
237
|
+
"use GuzzleHttp\\Client;",
|
|
238
|
+
"",
|
|
239
|
+
"$client = new Client();",
|
|
240
|
+
"$response = $client->get(",
|
|
241
|
+
' "https://api.stripe.com/v1/charges"',
|
|
242
|
+
");",
|
|
243
|
+
"",
|
|
244
|
+
].join("\n");
|
|
245
|
+
const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "billing.php"));
|
|
246
|
+
const apis = findings.filter((f) => f.pattern === "external_api_call");
|
|
247
|
+
expect(apis.length).toBeGreaterThan(0);
|
|
248
|
+
expect(apis.some((a) => String(a.properties.url ?? "").includes("stripe.com"))).toBe(true);
|
|
249
|
+
});
|
|
250
|
+
it("emits a single curl finding for init/setopt/exec with one URL", () => {
|
|
251
|
+
const content = [
|
|
252
|
+
"<?php",
|
|
253
|
+
"",
|
|
254
|
+
"$ch = curl_init();",
|
|
255
|
+
'curl_setopt($ch, CURLOPT_URL, "https://api.example.com/v1");',
|
|
256
|
+
"curl_exec($ch);",
|
|
257
|
+
"",
|
|
258
|
+
].join("\n");
|
|
259
|
+
const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "http.php"));
|
|
260
|
+
const curls = findings.filter((f) => f.pattern === "external_api_call" &&
|
|
261
|
+
String(f.name).startsWith("curl"));
|
|
262
|
+
expect(curls).toHaveLength(1);
|
|
263
|
+
expect(String(curls[0].properties.url ?? "")).toContain("api.example.com");
|
|
264
|
+
});
|
|
265
|
+
it("detects Eloquent via Eloquent:: method calls when imported", () => {
|
|
266
|
+
const content = [
|
|
267
|
+
"<?php",
|
|
268
|
+
"",
|
|
269
|
+
"use Illuminate\\Database\\Eloquent\\Model;",
|
|
270
|
+
"",
|
|
271
|
+
"Eloquent::unguard();",
|
|
272
|
+
"",
|
|
273
|
+
].join("\n");
|
|
274
|
+
const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "model.php"));
|
|
275
|
+
const dbs = findings.filter((f) => f.pattern === "database_connection");
|
|
276
|
+
expect(dbs.map((d) => d.name)).toContain("eloquent");
|
|
277
|
+
});
|
|
278
|
+
it("detects Laravel Socialite as oauth2 auth_middleware", () => {
|
|
279
|
+
const content = [
|
|
280
|
+
"<?php",
|
|
281
|
+
"",
|
|
282
|
+
"use Laravel\\Socialite\\Facades\\Socialite;",
|
|
283
|
+
"",
|
|
284
|
+
"return Socialite::driver('google')->redirect();",
|
|
285
|
+
"",
|
|
286
|
+
].join("\n");
|
|
287
|
+
const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "oauth.php"));
|
|
288
|
+
const auth = findings.filter((f) => f.pattern === "auth_middleware");
|
|
289
|
+
expect(auth.map((a) => a.name)).toContain("laravel_socialite");
|
|
290
|
+
expect(auth.find((a) => a.name === "laravel_socialite")?.properties.strategy).toBe("oauth2");
|
|
291
|
+
});
|
|
292
|
+
it("detects league/oauth2-client as oauth2 auth_middleware", () => {
|
|
293
|
+
const content = [
|
|
294
|
+
"<?php",
|
|
295
|
+
"",
|
|
296
|
+
"use League\\OAuth2\\Client\\Provider\\GenericProvider;",
|
|
297
|
+
"",
|
|
298
|
+
"$provider = new GenericProvider([]);",
|
|
299
|
+
"",
|
|
300
|
+
].join("\n");
|
|
301
|
+
const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "oidc.php"));
|
|
302
|
+
const auth = findings.filter((f) => f.pattern === "auth_middleware");
|
|
303
|
+
expect(auth.map((a) => a.name)).toContain("league_oauth2_client");
|
|
304
|
+
expect(auth.find((a) => a.name === "league_oauth2_client")?.properties.strategy).toBe("oauth2");
|
|
305
|
+
});
|
|
306
|
+
it("detects AWS S3 from Aws\\S3 import presence", () => {
|
|
307
|
+
const content = [
|
|
308
|
+
"<?php",
|
|
309
|
+
"",
|
|
310
|
+
"use Aws\\S3\\S3Client;",
|
|
311
|
+
"",
|
|
312
|
+
"$client = new S3Client([]);",
|
|
313
|
+
"",
|
|
314
|
+
].join("\n");
|
|
315
|
+
const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "storage.php"));
|
|
316
|
+
const apis = findings.filter((f) => f.pattern === "external_api_call");
|
|
317
|
+
expect(apis.some((a) => a.properties.serviceName === "aws" ||
|
|
318
|
+
a.properties.client === "aws_s3")).toBe(true);
|
|
319
|
+
});
|
|
320
|
+
it("detects AWS S3 from league/flysystem-aws-s3-v3 package import", () => {
|
|
321
|
+
const content = [
|
|
322
|
+
"<?php",
|
|
323
|
+
"",
|
|
324
|
+
"use League\\Flysystem\\AwsS3V3\\AwsS3V3Adapter;",
|
|
325
|
+
"",
|
|
326
|
+
"$adapter = new AwsS3V3Adapter($client, 'bucket');",
|
|
327
|
+
"",
|
|
328
|
+
].join("\n");
|
|
329
|
+
const findings = (0, detector_1.detectPhpPatterns)(makePhpFile(content, "flysystem.php"));
|
|
330
|
+
const apis = findings.filter((f) => f.pattern === "external_api_call");
|
|
331
|
+
expect(apis.some((a) => a.properties.serviceName === "aws" ||
|
|
332
|
+
a.properties.client === "aws_s3")).toBe(true);
|
|
333
|
+
});
|
|
334
|
+
});
|
|
@@ -1099,6 +1099,74 @@ describe("classifier/dedupe & application asset - DP-P0-CLI-204", () => {
|
|
|
1099
1099
|
expect(auth0?.properties.authentication_method).toBe("jwt");
|
|
1100
1100
|
expect(auth0?.type).toBe("third_party");
|
|
1101
1101
|
});
|
|
1102
|
+
it("merges auth_service into HTTP API instead of database when no IdP or main app", () => {
|
|
1103
|
+
const components = [
|
|
1104
|
+
makeComponent({
|
|
1105
|
+
id: "api_1",
|
|
1106
|
+
name: "API",
|
|
1107
|
+
type: "asset",
|
|
1108
|
+
subType: "api",
|
|
1109
|
+
properties: {
|
|
1110
|
+
section_id: "root",
|
|
1111
|
+
isSectionApiNode: true,
|
|
1112
|
+
},
|
|
1113
|
+
detectedFrom: [
|
|
1114
|
+
{
|
|
1115
|
+
pattern: "express_route",
|
|
1116
|
+
sourceLocation: makeLocation({ filePath: "routes/web.php" }),
|
|
1117
|
+
},
|
|
1118
|
+
],
|
|
1119
|
+
}),
|
|
1120
|
+
makeComponent({
|
|
1121
|
+
id: "db_1",
|
|
1122
|
+
name: "Eloquent",
|
|
1123
|
+
type: "asset",
|
|
1124
|
+
subType: "database",
|
|
1125
|
+
properties: { section_id: "root", client: "eloquent" },
|
|
1126
|
+
}),
|
|
1127
|
+
makeComponent({
|
|
1128
|
+
id: "auth_1",
|
|
1129
|
+
name: "Laravel Socialite",
|
|
1130
|
+
type: "asset",
|
|
1131
|
+
subType: "auth_service",
|
|
1132
|
+
properties: {
|
|
1133
|
+
section_id: "root",
|
|
1134
|
+
strategy: "oauth2",
|
|
1135
|
+
authentication_method: "oauth_2_0",
|
|
1136
|
+
},
|
|
1137
|
+
}),
|
|
1138
|
+
];
|
|
1139
|
+
const compacted = (0, classify_1.compactAuthServiceComponents)(components);
|
|
1140
|
+
expect(compacted.find((c) => c.id === "auth_1")).toBeUndefined();
|
|
1141
|
+
const api = compacted.find((c) => c.id === "api_1");
|
|
1142
|
+
expect(api).toBeDefined();
|
|
1143
|
+
expect(api?.properties.strategy).toBe("oauth2");
|
|
1144
|
+
expect(api?.properties.authentication_method).toBe("oauth_2_0");
|
|
1145
|
+
expect(api?.subType).toBe("api");
|
|
1146
|
+
const db = compacted.find((c) => c.id === "db_1");
|
|
1147
|
+
expect(db?.detectedFrom.some((r) => r.pattern === "auth_middleware")).toBe(false);
|
|
1148
|
+
});
|
|
1149
|
+
it("keeps auth_service standalone when only database assets exist in section", () => {
|
|
1150
|
+
const components = [
|
|
1151
|
+
makeComponent({
|
|
1152
|
+
id: "db_1",
|
|
1153
|
+
name: "Eloquent",
|
|
1154
|
+
type: "asset",
|
|
1155
|
+
subType: "database",
|
|
1156
|
+
properties: { section_id: "root", client: "eloquent" },
|
|
1157
|
+
}),
|
|
1158
|
+
makeComponent({
|
|
1159
|
+
id: "auth_1",
|
|
1160
|
+
name: "Laravel Socialite",
|
|
1161
|
+
type: "asset",
|
|
1162
|
+
subType: "auth_service",
|
|
1163
|
+
properties: { section_id: "root", strategy: "oauth2" },
|
|
1164
|
+
}),
|
|
1165
|
+
];
|
|
1166
|
+
const compacted = (0, classify_1.compactAuthServiceComponents)(components);
|
|
1167
|
+
expect(compacted.find((c) => c.id === "auth_1")).toBeDefined();
|
|
1168
|
+
expect(compacted.find((c) => c.id === "db_1")).toBeDefined();
|
|
1169
|
+
});
|
|
1102
1170
|
});
|
|
1103
1171
|
it("merges third_party components by serviceName even when names differ", () => {
|
|
1104
1172
|
const components = [
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
7
|
+
const os_1 = __importDefault(require("os"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const file_system_1 = require("../../../src/ingest/file-system");
|
|
10
|
+
describe("ingest/file-system - PHP language mapping", () => {
|
|
11
|
+
let root;
|
|
12
|
+
beforeAll(async () => {
|
|
13
|
+
root = await promises_1.default.mkdtemp(path_1.default.join(os_1.default.tmpdir(), "dp-ingest-php-"));
|
|
14
|
+
const files = {
|
|
15
|
+
"index.php": "<?php echo 'ok';",
|
|
16
|
+
"view.phtml": "<?= $title ?>",
|
|
17
|
+
"notes.md": "# notes",
|
|
18
|
+
};
|
|
19
|
+
for (const [name, content] of Object.entries(files)) {
|
|
20
|
+
await promises_1.default.writeFile(path_1.default.join(root, name), content, "utf8");
|
|
21
|
+
}
|
|
22
|
+
await promises_1.default.mkdir(path_1.default.join(root, "vendor", "guzzlehttp"), { recursive: true });
|
|
23
|
+
await promises_1.default.writeFile(path_1.default.join(root, "vendor", "guzzlehttp", "Client.php"), "<?php class Client {}", "utf8");
|
|
24
|
+
});
|
|
25
|
+
afterAll(async () => {
|
|
26
|
+
await promises_1.default.rm(root, { recursive: true, force: true });
|
|
27
|
+
});
|
|
28
|
+
it("maps .php and .phtml to php", async () => {
|
|
29
|
+
const files = await (0, file_system_1.ingestFileSystem)(root);
|
|
30
|
+
const byName = new Map(files.map((file) => [file.name, file.language]));
|
|
31
|
+
expect(byName.get("index.php")).toBe("php");
|
|
32
|
+
expect(byName.get("view.phtml")).toBe("php");
|
|
33
|
+
expect(byName.has("notes.md")).toBe(false);
|
|
34
|
+
});
|
|
35
|
+
it("excludes Composer vendor/ by default", async () => {
|
|
36
|
+
const files = await (0, file_system_1.ingestFileSystem)(root);
|
|
37
|
+
const names = files.map((file) => file.name);
|
|
38
|
+
expect(names).not.toContain("Client.php");
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const telemetry_client_1 = require("../../../src/platform-api/telemetry-client");
|
|
4
|
+
describe("isCliTelemetryEnabled", () => {
|
|
5
|
+
const originalNodeEnv = process.env.NODE_ENV;
|
|
6
|
+
afterEach(() => {
|
|
7
|
+
delete process.env.DATAPARADE_TELEMETRY;
|
|
8
|
+
delete process.env.SCAN_TELEMETRY_ENABLED;
|
|
9
|
+
process.env.NODE_ENV = originalNodeEnv;
|
|
10
|
+
});
|
|
11
|
+
it("is off in test unless explicitly enabled", () => {
|
|
12
|
+
process.env.NODE_ENV = "test";
|
|
13
|
+
delete process.env.DATAPARADE_TELEMETRY;
|
|
14
|
+
expect((0, telemetry_client_1.isCliTelemetryEnabled)({ NODE_ENV: "test" })).toBe(false);
|
|
15
|
+
});
|
|
16
|
+
it("honors DATAPARADE_TELEMETRY=false", () => {
|
|
17
|
+
expect((0, telemetry_client_1.isCliTelemetryEnabled)({ DATAPARADE_TELEMETRY: "false", NODE_ENV: "production" })).toBe(false);
|
|
18
|
+
});
|
|
19
|
+
it("honors SCAN_TELEMETRY_ENABLED=false", () => {
|
|
20
|
+
expect((0, telemetry_client_1.isCliTelemetryEnabled)({
|
|
21
|
+
SCAN_TELEMETRY_ENABLED: "false",
|
|
22
|
+
NODE_ENV: "production",
|
|
23
|
+
})).toBe(false);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
describe("reportCliUsageEvent", () => {
|
|
27
|
+
const fetchMock = jest.fn();
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
fetchMock.mockReset();
|
|
30
|
+
global.fetch = fetchMock;
|
|
31
|
+
});
|
|
32
|
+
it("does not throw when the API returns 5xx", async () => {
|
|
33
|
+
fetchMock.mockResolvedValue({ ok: false, status: 500 });
|
|
34
|
+
await expect((0, telemetry_client_1.reportCliUsageEvent)({
|
|
35
|
+
sessionId: "11111111-1111-4111-8111-111111111111",
|
|
36
|
+
event: "scan_started",
|
|
37
|
+
command: "scan",
|
|
38
|
+
}, { DATAPARADE_TELEMETRY: "true", NODE_ENV: "test" })).resolves.toBeUndefined();
|
|
39
|
+
expect(fetchMock).toHaveBeenCalled();
|
|
40
|
+
});
|
|
41
|
+
it("is a no-op when telemetry is disabled", async () => {
|
|
42
|
+
await (0, telemetry_client_1.reportCliUsageEvent)({
|
|
43
|
+
sessionId: "11111111-1111-4111-8111-111111111111",
|
|
44
|
+
event: "scan_started",
|
|
45
|
+
}, { DATAPARADE_TELEMETRY: "false" });
|
|
46
|
+
expect(fetchMock).not.toHaveBeenCalled();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -16,6 +16,11 @@ describe("buildImportPreviewUrl", () => {
|
|
|
16
16
|
const url = (0, build_preview_url_1.buildImportPreviewUrl)("draft-abc");
|
|
17
17
|
expect(url).toBe("http://localhost:3001/dashboard?importDraft=draft-abc");
|
|
18
18
|
});
|
|
19
|
+
it("appends cliSession when provided", () => {
|
|
20
|
+
process.env.DATAPARADE_APP_URL = "http://localhost:3001";
|
|
21
|
+
const url = (0, build_preview_url_1.buildImportPreviewUrl)("draft-abc", "11111111-1111-4111-8111-111111111111");
|
|
22
|
+
expect(url).toContain("cliSession=11111111-1111-4111-8111-111111111111");
|
|
23
|
+
});
|
|
19
24
|
});
|
|
20
25
|
describe("buildAnonymousCliPreviewUrl", () => {
|
|
21
26
|
const original = process.env.DATAPARADE_APP_URL;
|
|
@@ -32,4 +37,9 @@ describe("buildAnonymousCliPreviewUrl", () => {
|
|
|
32
37
|
const url = (0, build_preview_url_1.buildAnonymousCliPreviewUrl)("claim-token-xyz");
|
|
33
38
|
expect(url).toBe("http://localhost:3001/preview/cli/claim-token-xyz");
|
|
34
39
|
});
|
|
40
|
+
it("appends cliSession when provided", () => {
|
|
41
|
+
process.env.DATAPARADE_APP_URL = "http://localhost:3001";
|
|
42
|
+
const url = (0, build_preview_url_1.buildAnonymousCliPreviewUrl)("claim-token-xyz", "11111111-1111-4111-8111-111111111111");
|
|
43
|
+
expect(url).toContain("cliSession=11111111-1111-4111-8111-111111111111");
|
|
44
|
+
});
|
|
35
45
|
});
|
|
@@ -5,11 +5,15 @@ jest.mock("../../../src/platform-api/upload-client", () => ({
|
|
|
5
5
|
cliUploadAnonymousPreview: jest.fn(),
|
|
6
6
|
cliUploadPreview: jest.fn(),
|
|
7
7
|
}));
|
|
8
|
+
jest.mock("../../../src/platform-api/telemetry-client", () => ({
|
|
9
|
+
reportCliUsageEvent: jest.fn().mockResolvedValue(undefined),
|
|
10
|
+
}));
|
|
8
11
|
jest.mock("../../../src/upload/build-preview-url", () => ({
|
|
9
12
|
buildAnonymousCliPreviewUrl: jest.fn((token) => `https://app.example/preview/cli/${token}`),
|
|
10
13
|
buildImportPreviewUrl: jest.fn((draftId) => `https://app.example/dashboard?importDraft=${draftId}`),
|
|
11
14
|
}));
|
|
12
15
|
const upload_client_1 = require("../../../src/platform-api/upload-client");
|
|
16
|
+
const telemetry_client_1 = require("../../../src/platform-api/telemetry-client");
|
|
13
17
|
describe("runDataflowUpload anonymous path", () => {
|
|
14
18
|
const logSpy = jest.spyOn(console, "log").mockImplementation(() => undefined);
|
|
15
19
|
afterEach(() => {
|
|
@@ -34,10 +38,24 @@ describe("runDataflowUpload anonymous path", () => {
|
|
|
34
38
|
dataflow: { schemaVersion: "1.0" },
|
|
35
39
|
projectName: "Proj",
|
|
36
40
|
scanJobId: "job-anon-1",
|
|
41
|
+
cliUsageSessionId: undefined,
|
|
42
|
+
command: "scan",
|
|
37
43
|
});
|
|
38
44
|
expect(upload_client_1.cliUploadPreview).not.toHaveBeenCalled();
|
|
39
45
|
expect(result.previewUrl).toContain("claim-1");
|
|
40
46
|
expect(logSpy).toHaveBeenCalledWith(expect.stringContaining("Claiming this preview after signup uses 1 scan slot"));
|
|
41
47
|
expect(logSpy).toHaveBeenCalledWith(expect.stringContaining("platform AI tokens"));
|
|
42
48
|
});
|
|
49
|
+
it("reports upload_failed and rethrows", async () => {
|
|
50
|
+
upload_client_1.cliUploadAnonymousPreview.mockRejectedValue(new Error("network down"));
|
|
51
|
+
await expect((0, run_upload_1.runDataflowUpload)({
|
|
52
|
+
dataflow: { schemaVersion: "1.0" },
|
|
53
|
+
cliUsageSessionId: "11111111-1111-4111-8111-111111111111",
|
|
54
|
+
logPrefix: "[scan]",
|
|
55
|
+
})).rejects.toThrow("network down");
|
|
56
|
+
expect(telemetry_client_1.reportCliUsageEvent).toHaveBeenCalledWith(expect.objectContaining({
|
|
57
|
+
event: "upload_failed",
|
|
58
|
+
errorCode: "upload_failed",
|
|
59
|
+
}));
|
|
60
|
+
});
|
|
43
61
|
});
|
package/package.json
CHANGED
package/patterns/php.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# PHP Patterns (CLI Scanner)
|
|
2
|
+
|
|
3
|
+
This document describes the PHP patterns implemented by the CLI codebase
|
|
4
|
+
scanner.
|
|
5
|
+
|
|
6
|
+
The PHP analyzer emits `RawFinding[]` using the **shared pattern IDs** from
|
|
7
|
+
`core/types/detection.ts`:
|
|
8
|
+
|
|
9
|
+
- `express_route`
|
|
10
|
+
- `database_connection`
|
|
11
|
+
- `external_api_call`
|
|
12
|
+
- `auth_middleware`
|
|
13
|
+
- `config_file`
|
|
14
|
+
- `env_variable`
|
|
15
|
+
- `lambda_handler`
|
|
16
|
+
|
|
17
|
+
These pattern IDs align with the TypeScript/JavaScript, Python, Go, C++, and C#
|
|
18
|
+
analyzers so that the classifier and data-flow detector treat every language
|
|
19
|
+
consistently.
|
|
20
|
+
|
|
21
|
+
## Structure
|
|
22
|
+
|
|
23
|
+
- **YAML configuration** at `cli/patterns/php.patterns.yaml` defines pattern
|
|
24
|
+
IDs, namespaces, Composer package names, call names, route regexes, and
|
|
25
|
+
confidences.
|
|
26
|
+
- **Config loader** (`cli/src/analyzers/php/php-detection-config.ts`) validates
|
|
27
|
+
the YAML and compiles its regexes.
|
|
28
|
+
- **Parser** (`cli/src/analyzers/php/parser.ts`) produces a source-file model:
|
|
29
|
+
namespace, `use` / `require` imports, classes/interfaces/traits, functions,
|
|
30
|
+
and call sites (`Class::method`, `$obj->method`, `new Class`, functions).
|
|
31
|
+
- **Detectors** (`cli/src/patterns/detectors/php.ts`) run inside the shared
|
|
32
|
+
`matchPatterns()` engine (one call per file).
|
|
33
|
+
|
|
34
|
+
### Namespace vs Composer package matching
|
|
35
|
+
|
|
36
|
+
| Field | Shape | Example |
|
|
37
|
+
| --- | --- | --- |
|
|
38
|
+
| `importNamespaces` | PSR namespace / class (`\`) | `GuzzleHttp`, `Illuminate\Database` |
|
|
39
|
+
| `packageNames` | Composer package (`/`) | `guzzlehttp/guzzle`, `laravel/framework` |
|
|
40
|
+
|
|
41
|
+
The two spaces stay disjoint so a `composer.json` hit does not also match as a
|
|
42
|
+
`use` statement (and vice versa).
|
|
43
|
+
|
|
44
|
+
## Routes
|
|
45
|
+
|
|
46
|
+
- **Laravel** — `Route::get/post/...` (ungated; facade is usually unimported)
|
|
47
|
+
- **Symfony** — `#[Route(...)]` (attributes kept when stripping `#` comments) and
|
|
48
|
+
`@Route(...)` (docblock annotations scanned from raw source)
|
|
49
|
+
- **Slim** — `$app->get/post/...` when Slim is imported
|
|
50
|
+
|
|
51
|
+
## Database
|
|
52
|
+
|
|
53
|
+
- PDO, Eloquent / Illuminate, Doctrine DBAL/ORM, mysqli, Predis, MongoDB
|
|
54
|
+
- `pdo_dsn` resolves `new PDO(...)` / `new \PDO(...)` to a concrete `databaseType`
|
|
55
|
+
- Gated clients (Predis, Eloquent, …) require a matching `use` or Composer
|
|
56
|
+
package so a bare `new Client()` does not false-positive
|
|
57
|
+
|
|
58
|
+
## External APIs
|
|
59
|
+
|
|
60
|
+
- Guzzle (`->get` / `->request` with URL)
|
|
61
|
+
- cURL (`curl_setopt` / `curl_exec`)
|
|
62
|
+
- Symfony HttpClient
|
|
63
|
+
- AWS S3 (`Aws\S3`, `league/flysystem-aws-s3-v3`; presence-gated)
|
|
64
|
+
|
|
65
|
+
## Auth / env
|
|
66
|
+
|
|
67
|
+
- Sanctum, Passport, Socialite, league/oauth2-client, firebase/php-jwt, Symfony Security, bearer headers
|
|
68
|
+
- `getenv` / `env()` / `$_ENV` / `$_SERVER`
|
|
69
|
+
|
|
70
|
+
## Dependency manifests
|
|
71
|
+
|
|
72
|
+
`composer.json` `require` / `require-dev` package names feed `matchPatterns`
|
|
73
|
+
the same way `go.mod` does for Go. Platform requirements (`php`, `ext-*`) are
|
|
74
|
+
skipped. `composer.json` is also a monorepo **service-section** marker.
|