deepscan-cli 1.2.1 → 1.3.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 +3 -2
- package/dist/bin/deepscan.js +3 -2
- package/dist/bin/deepscan.js.map +1 -1
- package/dist/{chunk-4TWV5TES.js → chunk-ZP6AOU5P.js} +2699 -622
- package/dist/chunk-ZP6AOU5P.js.map +1 -0
- package/dist/index.d.ts +101 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/rules/built-in/operations.yml +120 -0
- package/dist/chunk-4TWV5TES.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -226,6 +226,102 @@ interface Rule {
|
|
|
226
226
|
enabled?: boolean;
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
+
interface FunctionScope {
|
|
230
|
+
id: number;
|
|
231
|
+
name: string;
|
|
232
|
+
params: string[];
|
|
233
|
+
destructuredReqParams: string[];
|
|
234
|
+
startLine: number;
|
|
235
|
+
endLine: number;
|
|
236
|
+
isAsync: boolean;
|
|
237
|
+
isExported: boolean;
|
|
238
|
+
isMethod: boolean;
|
|
239
|
+
isRepr: boolean;
|
|
240
|
+
isRouteHandler: boolean;
|
|
241
|
+
}
|
|
242
|
+
interface CallArg {
|
|
243
|
+
text: string;
|
|
244
|
+
isLiteral: boolean;
|
|
245
|
+
hasInterpolation: boolean;
|
|
246
|
+
startLine: number;
|
|
247
|
+
endLine: number;
|
|
248
|
+
}
|
|
249
|
+
interface CallSite {
|
|
250
|
+
callee: string;
|
|
251
|
+
receiver: string | null;
|
|
252
|
+
methodName: string;
|
|
253
|
+
args: CallArg[];
|
|
254
|
+
startLine: number;
|
|
255
|
+
endLine: number;
|
|
256
|
+
startColumn: number;
|
|
257
|
+
fullText: string;
|
|
258
|
+
scopeId: number;
|
|
259
|
+
}
|
|
260
|
+
interface AssignmentSite {
|
|
261
|
+
targets: string[];
|
|
262
|
+
rhsText: string;
|
|
263
|
+
startLine: number;
|
|
264
|
+
endLine: number;
|
|
265
|
+
scopeId: number;
|
|
266
|
+
isDestructuring: boolean;
|
|
267
|
+
}
|
|
268
|
+
interface FileCodeModel {
|
|
269
|
+
filePath: string;
|
|
270
|
+
language: string;
|
|
271
|
+
scopes: FunctionScope[];
|
|
272
|
+
callSites: CallSite[];
|
|
273
|
+
assignments: AssignmentSite[];
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
interface CrossFileSinkHit {
|
|
277
|
+
paramIndex: number;
|
|
278
|
+
sinkType: string;
|
|
279
|
+
sinkLine: number;
|
|
280
|
+
sinkSnippet: string;
|
|
281
|
+
sinkDescription: string;
|
|
282
|
+
}
|
|
283
|
+
interface ExportedFunctionSummary {
|
|
284
|
+
name: string;
|
|
285
|
+
filePath: string;
|
|
286
|
+
params: string[];
|
|
287
|
+
startLine: number;
|
|
288
|
+
passthroughParamIndices: number[];
|
|
289
|
+
sinkHits: CrossFileSinkHit[];
|
|
290
|
+
}
|
|
291
|
+
interface PhpCrossFileTaint {
|
|
292
|
+
varName: string;
|
|
293
|
+
sourceFile: string;
|
|
294
|
+
sourceLine: number;
|
|
295
|
+
sourceSnippet: string;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Lightweight two-pass cross-file symbol & taint summary graph across a repository.
|
|
299
|
+
*/
|
|
300
|
+
declare class ProjectSymbolGraph {
|
|
301
|
+
/** filePath.toLowerCase() -> functionName -> ExportedFunctionSummary */
|
|
302
|
+
private exportsByFile;
|
|
303
|
+
/** callerFile.toLowerCase() -> localCalleeName -> ImportEdge */
|
|
304
|
+
private importsByFile;
|
|
305
|
+
/** packageDir.toLowerCase() (Go) -> Map<funcName, ExportedFunctionSummary> */
|
|
306
|
+
private goPackageFuncs;
|
|
307
|
+
/** phpFile.toLowerCase() -> unsanitized $_GET/$_POST/$_REQUEST var assignments */
|
|
308
|
+
private phpTaintedSourcesByFile;
|
|
309
|
+
/** phpFile.toLowerCase() -> list of resolved included/module php files */
|
|
310
|
+
private phpIncludesByFile;
|
|
311
|
+
addExportedFunction(filePath: string, language: string, summary: ExportedFunctionSummary): void;
|
|
312
|
+
addImportEdge(callerFile: string, localName: string, targetFile: string, exportedName: string): void;
|
|
313
|
+
addPhpSourceVar(filePath: string, entry: PhpCrossFileTaint): void;
|
|
314
|
+
addPhpInclude(callerFile: string, includedFile: string): void;
|
|
315
|
+
/**
|
|
316
|
+
* Resolve a call inside `callerFilePath` (either imported name `foo`, namespace `ns.foo`, or Go same-package `foo`).
|
|
317
|
+
*/
|
|
318
|
+
resolveImportedFunction(callerFilePath: string, calleeName: string): ExportedFunctionSummary | null;
|
|
319
|
+
/**
|
|
320
|
+
* Return tainted superglobal variables assigned inside PHP files included by `filePath`.
|
|
321
|
+
*/
|
|
322
|
+
getPhpCrossFileTaintedVars(filePath: string): PhpCrossFileTaint[];
|
|
323
|
+
}
|
|
324
|
+
|
|
229
325
|
/** Context passed to scanners for each file */
|
|
230
326
|
interface ScanFileContext {
|
|
231
327
|
filePath: string;
|
|
@@ -237,6 +333,10 @@ interface ScanFileContext {
|
|
|
237
333
|
rules: Rule[];
|
|
238
334
|
/** Absolute lowercased paths of lockfiles discovered in the current scan run */
|
|
239
335
|
discoveredLockFiles?: Set<string>;
|
|
336
|
+
/** Unified multi-line AST & call-site model for the file */
|
|
337
|
+
codeModel?: FileCodeModel;
|
|
338
|
+
/** Repository-wide cross-file symbol & include graph */
|
|
339
|
+
projectGraph?: ProjectSymbolGraph | null;
|
|
240
340
|
}
|
|
241
341
|
/** Interface that all scanner engines must implement */
|
|
242
342
|
interface IScanner {
|
|
@@ -318,6 +418,7 @@ declare class ScanPipeline {
|
|
|
318
418
|
private findings;
|
|
319
419
|
private seenLargeFileHashes;
|
|
320
420
|
private discoveredLockFiles;
|
|
421
|
+
private projectGraph;
|
|
321
422
|
constructor(config: DeepScanConfig);
|
|
322
423
|
/**
|
|
323
424
|
* Register a scanner engine
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -88,6 +88,26 @@ rules:
|
|
|
88
88
|
- https://cwe.mitre.org/data/definitions/400.html
|
|
89
89
|
- https://cwe.mitre.org/data/definitions/401.html
|
|
90
90
|
|
|
91
|
+
- id: ops/excessive-query-limit
|
|
92
|
+
name: Excessive Hardcoded Query Limit
|
|
93
|
+
description: Detects large hardcoded load-all limits (e.g., LIMIT 500/1000+ without pagination or streaming) that cause oversized payloads, memory spikes, or truncated datasets
|
|
94
|
+
category: oom-memory
|
|
95
|
+
subcategory: excessive-query-limit
|
|
96
|
+
severity: medium
|
|
97
|
+
confidence: medium
|
|
98
|
+
cwe: [CWE-400, CWE-770]
|
|
99
|
+
owasp: ["API4:2023"]
|
|
100
|
+
languages: [javascript, typescript, python, php, java, go, ruby, csharp]
|
|
101
|
+
patterns:
|
|
102
|
+
- regex: "\\bLIMIT\\s+(?:[1-9]\\d{3,}|[5-9]\\d{2})\\b"
|
|
103
|
+
message: Query uses a large hardcoded LIMIT without pagination or streaming
|
|
104
|
+
fix:
|
|
105
|
+
description: Replace large load-all limits with server-side pagination (e.g., LIMIT 25..100 with OFFSET or keyset cursor) or stream results in smaller batches
|
|
106
|
+
tags: [ops, oom-kill, excessive-query-limit, pagination]
|
|
107
|
+
references:
|
|
108
|
+
- https://owasp.org/API-Security/editions/2023/en/0xa4-unrestricted-resource-consumption/
|
|
109
|
+
- https://cwe.mitre.org/data/definitions/400.html
|
|
110
|
+
|
|
91
111
|
# ── Operations: Timeouts & Resilience ──
|
|
92
112
|
- id: ops/missing-timeout
|
|
93
113
|
name: Outbound HTTP Client Without Timeout
|
|
@@ -285,3 +305,103 @@ rules:
|
|
|
285
305
|
references:
|
|
286
306
|
- https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS
|
|
287
307
|
- https://cwe.mitre.org/data/definitions/1333.html
|
|
308
|
+
|
|
309
|
+
- id: ops/correlated-subquery
|
|
310
|
+
name: Multiple Correlated SQL Subqueries (SQL N+1)
|
|
311
|
+
description: Detects SQL queries embedding multiple inline correlated aggregate subqueries per row instead of pre-aggregated CTEs or JOINs
|
|
312
|
+
category: ops-performance
|
|
313
|
+
subcategory: correlated-subquery
|
|
314
|
+
severity: medium
|
|
315
|
+
confidence: medium
|
|
316
|
+
cwe: [CWE-1050]
|
|
317
|
+
owasp: ["API4:2023"]
|
|
318
|
+
languages: [javascript, typescript, python, php, java, go, ruby, csharp]
|
|
319
|
+
patterns:
|
|
320
|
+
- regex: "\\(\\s*SELECT\\s+(?:COUNT|SUM|AVG|MIN|MAX)\\s*\\([^)]*\\)[\\s\\S]{0,200}?\\bFROM\\b"
|
|
321
|
+
message: SQL query embeds multiple correlated aggregate subqueries
|
|
322
|
+
fix:
|
|
323
|
+
description: Replace inline correlated subqueries with pre-aggregated CTEs (WITH ... GROUP BY) joined via LEFT JOIN
|
|
324
|
+
tags: [ops, performance, sql-n-plus-one, database]
|
|
325
|
+
references:
|
|
326
|
+
- https://cwe.mitre.org/data/definitions/1050.html
|
|
327
|
+
|
|
328
|
+
# ── Operations: Database Connections & Locks ──
|
|
329
|
+
- id: ops/io-in-transaction
|
|
330
|
+
name: External Network or Blocking I/O Inside DB Transaction
|
|
331
|
+
description: Detects slow external HTTP calls or sleeps executed inside an open database transaction, pinning connections and holding row locks
|
|
332
|
+
category: db-operations
|
|
333
|
+
subcategory: io-in-transaction
|
|
334
|
+
severity: high
|
|
335
|
+
confidence: high
|
|
336
|
+
cwe: [CWE-667, CWE-400]
|
|
337
|
+
owasp: ["A04:2021", "API4:2023"]
|
|
338
|
+
languages: [javascript, typescript, python, go, java, php]
|
|
339
|
+
patterns:
|
|
340
|
+
- regex: "\\.\\$?transaction\\s*\\("
|
|
341
|
+
message: External network or sleep call inside database transaction
|
|
342
|
+
fix:
|
|
343
|
+
description: Move outbound HTTP requests, webhooks, emails, and sleeps outside the database transaction (run before BEGIN or after COMMIT via an outbox/queue)
|
|
344
|
+
tags: [ops, database, io-in-transaction, lock-contention]
|
|
345
|
+
references:
|
|
346
|
+
- https://cwe.mitre.org/data/definitions/667.html
|
|
347
|
+
- https://cwe.mitre.org/data/definitions/400.html
|
|
348
|
+
|
|
349
|
+
- id: ops/missing-rollback
|
|
350
|
+
name: Manual DB Transaction Missing Rollback Handler
|
|
351
|
+
description: Detects explicit database transactions (BEGIN / beginTransaction) without ROLLBACK handling on error paths
|
|
352
|
+
category: db-operations
|
|
353
|
+
subcategory: missing-rollback
|
|
354
|
+
severity: high
|
|
355
|
+
confidence: high
|
|
356
|
+
cwe: [CWE-404, CWE-667]
|
|
357
|
+
owasp: ["A04:2021"]
|
|
358
|
+
languages: [javascript, typescript, python, go, java, php]
|
|
359
|
+
patterns:
|
|
360
|
+
- regex: "\\.(?:query|execute|exec)\\s*\\(\\s*[`\"']\\s*BEGIN\\s*[`\"']"
|
|
361
|
+
message: Manual database transaction missing ROLLBACK handler
|
|
362
|
+
fix:
|
|
363
|
+
description: Wrap manual transactions in try/catch (or defer tx.Rollback()) and invoke ROLLBACK on errors before releasing the connection
|
|
364
|
+
tags: [ops, database, missing-rollback, transaction]
|
|
365
|
+
references:
|
|
366
|
+
- https://cwe.mitre.org/data/definitions/404.html
|
|
367
|
+
- https://cwe.mitre.org/data/definitions/667.html
|
|
368
|
+
|
|
369
|
+
- id: ops/blocking-db-lock
|
|
370
|
+
name: Blocking Database Lock or Unbounded Pool Configuration
|
|
371
|
+
description: Detects SELECT ... FOR UPDATE without NOWAIT/SKIP LOCKED or lock_timeout, explicit table locks, and pools configured without size/timeout bounds
|
|
372
|
+
category: db-operations
|
|
373
|
+
subcategory: blocking-db-lock
|
|
374
|
+
severity: medium
|
|
375
|
+
confidence: medium
|
|
376
|
+
cwe: [CWE-667, CWE-770]
|
|
377
|
+
owasp: ["API4:2023"]
|
|
378
|
+
languages: [javascript, typescript, python, go, java, php]
|
|
379
|
+
patterns:
|
|
380
|
+
- regex: "\\bFOR\\s+(?:UPDATE|SHARE)\\b"
|
|
381
|
+
message: Blocking row lock without NOWAIT, SKIP LOCKED, or lock_timeout
|
|
382
|
+
fix:
|
|
383
|
+
description: Add NOWAIT or SKIP LOCKED with lock_timeout/statement_timeout on row locks, avoid table locks, and set explicit max pool size and timeouts
|
|
384
|
+
tags: [ops, database, blocking-db-lock, lock-contention]
|
|
385
|
+
references:
|
|
386
|
+
- https://cwe.mitre.org/data/definitions/667.html
|
|
387
|
+
- https://cwe.mitre.org/data/definitions/770.html
|
|
388
|
+
|
|
389
|
+
- id: ops/pinned-db-connection
|
|
390
|
+
name: Dedicated or Keep-Alive DB Connection Held Without Close or Pool
|
|
391
|
+
description: Detects dedicated database client connections (e.g., pg.Client, psycopg2.connect, sql.Conn) held persistently or missing finally close/pool usage
|
|
392
|
+
category: db-operations
|
|
393
|
+
subcategory: pinned-db-connection
|
|
394
|
+
severity: high
|
|
395
|
+
confidence: high
|
|
396
|
+
cwe: [CWE-404, CWE-770]
|
|
397
|
+
owasp: ["API4:2023"]
|
|
398
|
+
languages: [javascript, typescript, python, go]
|
|
399
|
+
patterns:
|
|
400
|
+
- regex: "\\bnew\\s+(?:pg\\.)?Client\\s*\\("
|
|
401
|
+
message: Dedicated DB Client used without connection pool or guaranteed close
|
|
402
|
+
fix:
|
|
403
|
+
description: Use a managed connection pool (pg.Pool, psycopg_pool, sql.DB) or wrap short-lived connections in try/finally or context managers with explicit close/end
|
|
404
|
+
tags: [ops, database, pinned-db-connection, connection-leak]
|
|
405
|
+
references:
|
|
406
|
+
- https://cwe.mitre.org/data/definitions/404.html
|
|
407
|
+
- https://cwe.mitre.org/data/definitions/770.html
|