deepscan-cli 1.2.0 → 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/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
@@ -523,4 +624,5 @@ declare class CVEScanner implements IScanner {
523
624
  destroy(): Promise<void>;
524
625
  }
525
626
 
526
- export { type AIValidationResult, type BaselineFile, CVEScanner, type CodeContext, type Confidence, DEEPSCAN_VERSION, type DeepScanConfig, type Finding, type IReporter, type IScanner, type LanguageConfig, OperationsScanner, type OutputFormat, QualityScanner, type Rule, type RuleCondition, RuleEngine, type RulePattern, ScanPipeline, type ScanResult, type ScanSummary, type ScannerType, SecurityScanner, type Severity, type SourceLocation, type TaintFlowStep, applyBaseline, generateFingerprint, getReporter, loadBaseline, loadConfig, saveBaseline };
627
+ export { CVEScanner, DEEPSCAN_VERSION, OperationsScanner, QualityScanner, RuleEngine, ScanPipeline, SecurityScanner, applyBaseline, generateFingerprint, getReporter, loadBaseline, loadConfig, saveBaseline };
628
+ export type { AIValidationResult, BaselineFile, CodeContext, Confidence, DeepScanConfig, Finding, IReporter, IScanner, LanguageConfig, OutputFormat, Rule, RuleCondition, RulePattern, ScanResult, ScanSummary, ScannerType, Severity, SourceLocation, TaintFlowStep };
package/dist/index.js CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  loadBaseline,
13
13
  loadConfig,
14
14
  saveBaseline
15
- } from "./chunk-KITQQYNW.js";
15
+ } from "./chunk-ZP6AOU5P.js";
16
16
  export {
17
17
  CVEScanner,
18
18
  DEEPSCAN_VERSION,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deepscan-cli",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Open-source security & code quality scanner - combines SAST, SCA/CVE, and secrets detection in a single CLI tool",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -30,9 +30,16 @@
30
30
  "sast",
31
31
  "sca",
32
32
  "cve",
33
+ "devsecops",
34
+ "secret-detection",
35
+ "sarif",
36
+ "tree-sitter",
37
+ "oom-kill",
38
+ "github-action",
33
39
  "code-quality",
34
40
  "vulnerability",
35
41
  "deepscan",
42
+ "semgrep-alternative",
36
43
  "sonarqube-alternative"
37
44
  ],
38
45
  "author": "Mai Đức Tuấn",
@@ -46,7 +53,7 @@
46
53
  },
47
54
  "homepage": "https://github.com/maiductuan/code-security-scanner#readme",
48
55
  "engines": {
49
- "node": ">=18.0.0"
56
+ "node": ">=20.0.0"
50
57
  },
51
58
  "files": [
52
59
  "dist",
@@ -62,25 +69,26 @@
62
69
  "chalk": "^5.3.0",
63
70
  "commander": "^12.1.0",
64
71
  "consola": "^3.2.3",
65
- "glob": "^11.0.0",
72
+ "glob": "^15.0.0",
66
73
  "ignore": "^6.0.2",
67
- "js-yaml": "^4.1.0",
74
+ "js-yaml": "^4.3.2",
68
75
  "tree-sitter-go": "^0.25.0",
69
76
  "tree-sitter-java": "^0.23.5",
70
77
  "tree-sitter-javascript": "^0.25.0",
71
78
  "tree-sitter-python": "^0.25.0",
72
79
  "tree-sitter-typescript": "^0.23.2",
73
80
  "web-tree-sitter": "^0.26.10",
74
- "zod": "^3.23.8"
81
+ "zod": "^4.6.7"
75
82
  },
76
83
  "devDependencies": {
77
84
  "@types/js-yaml": "^4.0.9",
78
85
  "@types/node": "^22.10.0",
79
86
  "eslint": "^10.16.0",
80
- "tsup": "^8.3.5",
81
- "tsx": "^4.19.0",
87
+ "tsup": "^9.0.0",
88
+ "tsx": "^4.23.15",
82
89
  "typescript": "^5.7.0",
83
90
  "typescript-eslint": "^8.74.0",
84
- "vitest": "^2.1.0"
91
+ "vite": "^8.4.1",
92
+ "vitest": "^5.1.2"
85
93
  }
86
94
  }
@@ -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