deepscan-cli 1.0.0 → 1.2.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/NOTICE +5 -0
- package/README.md +174 -59
- package/dist/bin/deepscan.js +189 -71
- package/dist/bin/deepscan.js.map +1 -1
- package/dist/{chunk-OSYJXVNF.js → chunk-KITQQYNW.js} +5071 -596
- package/dist/chunk-KITQQYNW.js.map +1 -0
- package/dist/index.d.ts +61 -5
- package/dist/index.js +13 -3
- package/package.json +23 -5
- package/rules/built-in/default-config.yml +28 -3
- package/rules/built-in/operations.yml +287 -0
- package/rules/built-in/security.yml +12 -6
- package/dist/chunk-OSYJXVNF.js.map +0 -1
- package/rules/built-in/converted-semgrep.yml +0 -37
- package/rules/built-in/semgrep-apex.yml +0 -336
- package/rules/built-in/semgrep-bash.yml +0 -362
- package/rules/built-in/semgrep-c.yml +0 -429
- package/rules/built-in/semgrep-clojure.yml +0 -166
- package/rules/built-in/semgrep-csharp.yml +0 -1260
- package/rules/built-in/semgrep-dart.yml +0 -21
- package/rules/built-in/semgrep-dockerfile.yml +0 -874
- package/rules/built-in/semgrep-elixir.yml +0 -146
- package/rules/built-in/semgrep-generic.yml +0 -2945
- package/rules/built-in/semgrep-go.yml +0 -2898
- package/rules/built-in/semgrep-hcl.yml +0 -8181
- package/rules/built-in/semgrep-html.yml +0 -94
- package/rules/built-in/semgrep-java.yml +0 -4219
- package/rules/built-in/semgrep-javascript.yml +0 -6243
- package/rules/built-in/semgrep-json.yml +0 -360
- package/rules/built-in/semgrep-kotlin.yml +0 -540
- package/rules/built-in/semgrep-lua.yml +0 -46
- package/rules/built-in/semgrep-ocaml.yml +0 -773
- package/rules/built-in/semgrep-php.yml +0 -1638
- package/rules/built-in/semgrep-python.yml +0 -11240
- package/rules/built-in/semgrep-regex.yml +0 -6444
- package/rules/built-in/semgrep-ruby.yml +0 -2687
- package/rules/built-in/semgrep-rust.yml +0 -278
- package/rules/built-in/semgrep-scala.yml +0 -807
- package/rules/built-in/semgrep-sh.yml +0 -46
- package/rules/built-in/semgrep-solidity.yml +0 -1046
- package/rules/built-in/semgrep-swift.yml +0 -200
- package/rules/built-in/semgrep-terraform.yml +0 -147
- package/rules/built-in/semgrep-typescript.yml +0 -6212
- package/rules/built-in/semgrep-xml.yml +0 -31
- package/rules/built-in/semgrep-yaml.yml +0 -2785
- package/rules/examples/custom-api-security.yml +0 -66
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ type Severity = 'critical' | 'high' | 'medium' | 'low';
|
|
|
5
5
|
/** Confidence levels for findings */
|
|
6
6
|
type Confidence = 'high' | 'medium' | 'low';
|
|
7
7
|
/** Scanner engine types */
|
|
8
|
-
type ScannerType = 'security' | 'quality' | 'cve';
|
|
8
|
+
type ScannerType = 'security' | 'quality' | 'cve' | 'ops';
|
|
9
9
|
/** Source location in a file */
|
|
10
10
|
interface SourceLocation {
|
|
11
11
|
file: string;
|
|
@@ -113,6 +113,10 @@ interface CVEScannerConfig {
|
|
|
113
113
|
sources: string[];
|
|
114
114
|
failOnSeverity?: Severity;
|
|
115
115
|
}
|
|
116
|
+
interface OpsScannerConfig {
|
|
117
|
+
enabled: boolean;
|
|
118
|
+
severity: Severity[];
|
|
119
|
+
}
|
|
116
120
|
/** AI validation configuration */
|
|
117
121
|
interface AIConfig {
|
|
118
122
|
enabled: boolean;
|
|
@@ -156,6 +160,7 @@ interface DeepScanConfig {
|
|
|
156
160
|
security: SecurityScannerConfig;
|
|
157
161
|
quality: QualityScannerConfig;
|
|
158
162
|
cve: CVEScannerConfig;
|
|
163
|
+
ops: OpsScannerConfig;
|
|
159
164
|
};
|
|
160
165
|
rules: RulesConfig;
|
|
161
166
|
languages: string[];
|
|
@@ -166,6 +171,10 @@ interface DeepScanConfig {
|
|
|
166
171
|
parallel: number;
|
|
167
172
|
incremental: boolean;
|
|
168
173
|
deep: boolean;
|
|
174
|
+
cache?: boolean;
|
|
175
|
+
cacheLocation?: string;
|
|
176
|
+
failOn?: Severity[];
|
|
177
|
+
watch?: boolean;
|
|
169
178
|
}
|
|
170
179
|
|
|
171
180
|
/** Pattern definition within a rule */
|
|
@@ -226,11 +235,13 @@ interface ScanFileContext {
|
|
|
226
235
|
parser: Parser | null;
|
|
227
236
|
config: DeepScanConfig;
|
|
228
237
|
rules: Rule[];
|
|
238
|
+
/** Absolute lowercased paths of lockfiles discovered in the current scan run */
|
|
239
|
+
discoveredLockFiles?: Set<string>;
|
|
229
240
|
}
|
|
230
241
|
/** Interface that all scanner engines must implement */
|
|
231
242
|
interface IScanner {
|
|
232
243
|
name: string;
|
|
233
|
-
type: 'security' | 'quality' | 'cve';
|
|
244
|
+
type: 'security' | 'quality' | 'cve' | 'ops';
|
|
234
245
|
/** Initialize the scanner with configuration */
|
|
235
246
|
initialize(config: DeepScanConfig): Promise<void>;
|
|
236
247
|
/** Scan a single file and return findings */
|
|
@@ -303,7 +314,10 @@ declare class ScanPipeline {
|
|
|
303
314
|
private scanners;
|
|
304
315
|
private ruleEngine;
|
|
305
316
|
private astParser;
|
|
317
|
+
private cache;
|
|
306
318
|
private findings;
|
|
319
|
+
private seenLargeFileHashes;
|
|
320
|
+
private discoveredLockFiles;
|
|
307
321
|
constructor(config: DeepScanConfig);
|
|
308
322
|
/**
|
|
309
323
|
* Register a scanner engine
|
|
@@ -327,6 +341,31 @@ declare class ScanPipeline {
|
|
|
327
341
|
*/
|
|
328
342
|
declare function generateFingerprint(ruleId: string, filePath: string, line: number, snippet: string): string;
|
|
329
343
|
|
|
344
|
+
interface BaselineFile {
|
|
345
|
+
version: string;
|
|
346
|
+
generatedAt: string;
|
|
347
|
+
count: number;
|
|
348
|
+
fingerprints: string[];
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Load finding fingerprints from either a DeepScan baseline JSON file
|
|
352
|
+
* or a prior full DeepScan JSON scan report.
|
|
353
|
+
*/
|
|
354
|
+
declare function loadBaseline(filePath: string): Set<string>;
|
|
355
|
+
/**
|
|
356
|
+
* Save unique sorted finding fingerprints to a baseline JSON file.
|
|
357
|
+
*/
|
|
358
|
+
declare function saveBaseline(filePath: string, findings: Finding[]): void;
|
|
359
|
+
/**
|
|
360
|
+
* Filter out findings whose fingerprints exist in the baseline and recalculate ScanSummary counts.
|
|
361
|
+
*/
|
|
362
|
+
declare function applyBaseline(result: ScanResult, baselineFingerprints: Set<string>): {
|
|
363
|
+
result: ScanResult;
|
|
364
|
+
suppressedCount: number;
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
declare const DEEPSCAN_VERSION: string;
|
|
368
|
+
|
|
330
369
|
/**
|
|
331
370
|
* Load and merge configuration from multiple sources.
|
|
332
371
|
* Priority: CLI args > project config file > preset > defaults
|
|
@@ -360,11 +399,15 @@ declare class RuleEngine {
|
|
|
360
399
|
/**
|
|
361
400
|
* Get rules for a specific scanner type
|
|
362
401
|
*/
|
|
363
|
-
getRulesForScanner(scannerType: 'security' | 'quality'): Rule[];
|
|
402
|
+
getRulesForScanner(scannerType: 'security' | 'quality' | 'ops'): Rule[];
|
|
364
403
|
/**
|
|
365
404
|
* Get a specific rule by ID
|
|
366
405
|
*/
|
|
367
406
|
getRule(id: string): Rule | undefined;
|
|
407
|
+
/**
|
|
408
|
+
* Get a deterministic hash representing the current loaded rules
|
|
409
|
+
*/
|
|
410
|
+
getRulesHash(): string;
|
|
368
411
|
/**
|
|
369
412
|
* Load built-in rules from the rules directory
|
|
370
413
|
*/
|
|
@@ -405,7 +448,7 @@ declare function getReporter(format: OutputFormat): IReporter;
|
|
|
405
448
|
*/
|
|
406
449
|
declare abstract class BaseScanner implements IScanner {
|
|
407
450
|
abstract name: string;
|
|
408
|
-
abstract type: 'security' | 'quality' | 'cve';
|
|
451
|
+
abstract type: 'security' | 'quality' | 'cve' | 'ops';
|
|
409
452
|
protected config: DeepScanConfig | null;
|
|
410
453
|
initialize(config: DeepScanConfig): Promise<void>;
|
|
411
454
|
abstract scanFile(context: ScanFileContext): Promise<Finding[]>;
|
|
@@ -434,6 +477,19 @@ declare class SecurityScanner extends BaseScanner implements IScanner {
|
|
|
434
477
|
destroy(): Promise<void>;
|
|
435
478
|
}
|
|
436
479
|
|
|
480
|
+
/**
|
|
481
|
+
* Operations & Reliability Scanner - detects OOM-kill risks, missing timeouts,
|
|
482
|
+
* resource/connection leaks, N+1 queries, blocking sync I/O, and ReDoS.
|
|
483
|
+
*/
|
|
484
|
+
declare class OperationsScanner extends BaseScanner implements IScanner {
|
|
485
|
+
name: string;
|
|
486
|
+
type: "ops";
|
|
487
|
+
private enabledSeverities;
|
|
488
|
+
initialize(config: DeepScanConfig): Promise<void>;
|
|
489
|
+
scanFile(context: ScanFileContext): Promise<Finding[]>;
|
|
490
|
+
destroy(): Promise<void>;
|
|
491
|
+
}
|
|
492
|
+
|
|
437
493
|
/**
|
|
438
494
|
* Quality Scanner - Orchestrates all code quality analyzers
|
|
439
495
|
*
|
|
@@ -467,4 +523,4 @@ declare class CVEScanner implements IScanner {
|
|
|
467
523
|
destroy(): Promise<void>;
|
|
468
524
|
}
|
|
469
525
|
|
|
470
|
-
export { type AIValidationResult, CVEScanner, type CodeContext, type Confidence, type DeepScanConfig, type Finding, type IReporter, type IScanner, type LanguageConfig, type OutputFormat, QualityScanner, type Rule, type RuleCondition, RuleEngine, type RulePattern, ScanPipeline, type ScanResult, type ScanSummary, type ScannerType, SecurityScanner, type Severity, type SourceLocation, type TaintFlowStep, generateFingerprint, getReporter, loadConfig };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,31 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CVEScanner,
|
|
3
|
+
DEEPSCAN_VERSION,
|
|
4
|
+
OperationsScanner,
|
|
3
5
|
QualityScanner,
|
|
4
6
|
RuleEngine,
|
|
5
7
|
ScanPipeline,
|
|
6
8
|
SecurityScanner,
|
|
9
|
+
applyBaseline,
|
|
7
10
|
generateFingerprint,
|
|
8
11
|
getReporter,
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
loadBaseline,
|
|
13
|
+
loadConfig,
|
|
14
|
+
saveBaseline
|
|
15
|
+
} from "./chunk-KITQQYNW.js";
|
|
11
16
|
export {
|
|
12
17
|
CVEScanner,
|
|
18
|
+
DEEPSCAN_VERSION,
|
|
19
|
+
OperationsScanner,
|
|
13
20
|
QualityScanner,
|
|
14
21
|
RuleEngine,
|
|
15
22
|
ScanPipeline,
|
|
16
23
|
SecurityScanner,
|
|
24
|
+
applyBaseline,
|
|
17
25
|
generateFingerprint,
|
|
18
26
|
getReporter,
|
|
19
|
-
|
|
27
|
+
loadBaseline,
|
|
28
|
+
loadConfig,
|
|
29
|
+
saveBaseline
|
|
20
30
|
};
|
|
21
31
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deepscan-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.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",
|
|
@@ -12,12 +12,16 @@
|
|
|
12
12
|
"dev": "tsx src/bin/deepscan.ts",
|
|
13
13
|
"rules:update": "tsx scripts/update-rules.ts",
|
|
14
14
|
"evaluate": "tsx scripts/evaluate.ts",
|
|
15
|
+
"benchmark": "tsx scripts/benchmark.ts",
|
|
15
16
|
"build": "tsup",
|
|
16
17
|
"typecheck": "tsc --noEmit",
|
|
17
18
|
"test": "vitest run",
|
|
18
19
|
"test:watch": "vitest",
|
|
19
20
|
"lint": "eslint src/",
|
|
20
|
-
"prepublishOnly": "npm run build"
|
|
21
|
+
"prepublishOnly": "npm run build",
|
|
22
|
+
"release:patch": "npm version patch && git push --follow-tags",
|
|
23
|
+
"release:minor": "npm version minor && git push --follow-tags",
|
|
24
|
+
"release:major": "npm version major && git push --follow-tags"
|
|
21
25
|
},
|
|
22
26
|
"keywords": [
|
|
23
27
|
"security",
|
|
@@ -31,16 +35,28 @@
|
|
|
31
35
|
"deepscan",
|
|
32
36
|
"sonarqube-alternative"
|
|
33
37
|
],
|
|
34
|
-
"author": "",
|
|
38
|
+
"author": "Mai Đức Tuấn",
|
|
35
39
|
"license": "Apache-2.0",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/maiductuan/code-security-scanner.git"
|
|
43
|
+
},
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/maiductuan/code-security-scanner/issues"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://github.com/maiductuan/code-security-scanner#readme",
|
|
36
48
|
"engines": {
|
|
37
49
|
"node": ">=18.0.0"
|
|
38
50
|
},
|
|
39
51
|
"files": [
|
|
40
52
|
"dist",
|
|
41
|
-
"rules",
|
|
53
|
+
"rules/built-in/default-config.yml",
|
|
54
|
+
"rules/built-in/security.yml",
|
|
55
|
+
"rules/built-in/quality.yml",
|
|
56
|
+
"rules/built-in/operations.yml",
|
|
42
57
|
"README.md",
|
|
43
|
-
"LICENSE"
|
|
58
|
+
"LICENSE",
|
|
59
|
+
"NOTICE"
|
|
44
60
|
],
|
|
45
61
|
"dependencies": {
|
|
46
62
|
"chalk": "^5.3.0",
|
|
@@ -60,9 +76,11 @@
|
|
|
60
76
|
"devDependencies": {
|
|
61
77
|
"@types/js-yaml": "^4.0.9",
|
|
62
78
|
"@types/node": "^22.10.0",
|
|
79
|
+
"eslint": "^10.16.0",
|
|
63
80
|
"tsup": "^8.3.5",
|
|
64
81
|
"tsx": "^4.19.0",
|
|
65
82
|
"typescript": "^5.7.0",
|
|
83
|
+
"typescript-eslint": "^8.74.0",
|
|
66
84
|
"vitest": "^2.1.0"
|
|
67
85
|
}
|
|
68
86
|
}
|
|
@@ -15,12 +15,19 @@ scanners:
|
|
|
15
15
|
maxFileLength: 500
|
|
16
16
|
maxFunctionLength: 50
|
|
17
17
|
maxNestingDepth: 4
|
|
18
|
-
minCommentRatio: 0.
|
|
18
|
+
minCommentRatio: 0.02
|
|
19
19
|
cve:
|
|
20
20
|
enabled: false
|
|
21
21
|
sources:
|
|
22
22
|
- osv
|
|
23
23
|
failOnSeverity: critical
|
|
24
|
+
ops:
|
|
25
|
+
enabled: true
|
|
26
|
+
severity:
|
|
27
|
+
- critical
|
|
28
|
+
- high
|
|
29
|
+
- medium
|
|
30
|
+
- low
|
|
24
31
|
rules:
|
|
25
32
|
include:
|
|
26
33
|
- "*"
|
|
@@ -34,13 +41,31 @@ paths:
|
|
|
34
41
|
exclude:
|
|
35
42
|
- "node_modules/"
|
|
36
43
|
- ".git/"
|
|
44
|
+
- "vendor/"
|
|
45
|
+
- "dist/"
|
|
46
|
+
- "build/"
|
|
47
|
+
- ".venv/"
|
|
48
|
+
- "venv/"
|
|
49
|
+
- ".next/"
|
|
50
|
+
- ".nuxt/"
|
|
51
|
+
- ".output/"
|
|
52
|
+
- "target/"
|
|
37
53
|
- "**/node_modules/**"
|
|
38
54
|
- "**/.git/**"
|
|
55
|
+
- "**/vendor/**"
|
|
56
|
+
- "**/dist/**"
|
|
57
|
+
- "**/build/**"
|
|
58
|
+
- "**/.venv/**"
|
|
59
|
+
- "**/venv/**"
|
|
60
|
+
- "**/.next/**"
|
|
61
|
+
- "**/.nuxt/**"
|
|
62
|
+
- "**/.output/**"
|
|
63
|
+
- "**/target/**"
|
|
39
64
|
- "**/*.min.js"
|
|
40
65
|
- "**/*.min.css"
|
|
66
|
+
- "**/*.bundle.js"
|
|
67
|
+
- "**/*.chunk.js"
|
|
41
68
|
- "**/*.map"
|
|
42
|
-
- "**/*.lock"
|
|
43
|
-
- "**/package-lock.json"
|
|
44
69
|
output:
|
|
45
70
|
format: console
|
|
46
71
|
verbose: false
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
rules:
|
|
2
|
+
# ── Operations: OOM & Unbounded Memory ──
|
|
3
|
+
- id: ops/unbounded-query
|
|
4
|
+
name: Unbounded Database / ORM Query Without Pagination
|
|
5
|
+
description: Detects database or ORM queries that load all rows into memory without pagination, LIMIT, or streaming, which can trigger OOM kills under production load
|
|
6
|
+
category: oom-memory
|
|
7
|
+
subcategory: unbounded-query
|
|
8
|
+
severity: high
|
|
9
|
+
confidence: high
|
|
10
|
+
cwe: [CWE-400, CWE-770]
|
|
11
|
+
owasp: ["API4:2023"]
|
|
12
|
+
languages: [javascript, typescript, python, php, java, go, ruby, csharp]
|
|
13
|
+
patterns:
|
|
14
|
+
- regex: "\\.(?:findMany|findAll|getMany)\\s*\\("
|
|
15
|
+
message: Unbounded ORM query without pagination or limit
|
|
16
|
+
- regex: "::all\\s*\\(\\s*\\)"
|
|
17
|
+
message: Unbounded Eloquent ::all() query without pagination
|
|
18
|
+
- regex: "\\.objects\\.all\\s*\\(\\s*\\)"
|
|
19
|
+
message: Unbounded Django QuerySet.all() without pagination or slice
|
|
20
|
+
fix:
|
|
21
|
+
description: Add pagination (limit/offset or cursor-based pagination), enforce a maximum page size, or stream rows in batches
|
|
22
|
+
replacement: "Use take/limit + skip/cursor or paginate() with a bounded page size (e.g., Math.min(limit, 100))"
|
|
23
|
+
tags: [ops, oom-kill, pagination, memory, reliability]
|
|
24
|
+
references:
|
|
25
|
+
- https://owasp.org/API-Security/editions/2023/en/0xa4-unrestricted-resource-consumption/
|
|
26
|
+
- https://cwe.mitre.org/data/definitions/400.html
|
|
27
|
+
- https://cwe.mitre.org/data/definitions/770.html
|
|
28
|
+
|
|
29
|
+
- id: ops/unbounded-buffer
|
|
30
|
+
name: Unbounded File or HTTP Body Buffering in Memory
|
|
31
|
+
description: Detects reading entire HTTP request bodies or uploaded files into memory without enforcing size limits, risking OOM crashes
|
|
32
|
+
category: oom-memory
|
|
33
|
+
subcategory: unbounded-buffer
|
|
34
|
+
severity: high
|
|
35
|
+
confidence: high
|
|
36
|
+
cwe: [CWE-400, CWE-789]
|
|
37
|
+
owasp: ["API4:2023"]
|
|
38
|
+
languages: [javascript, typescript, go, python, java]
|
|
39
|
+
patterns:
|
|
40
|
+
- regex: "memoryStorage\\s*\\(\\s*\\)"
|
|
41
|
+
message: In-memory file upload storage without fileSize limits
|
|
42
|
+
- regex: "(?:io|ioutil)\\.ReadAll\\s*\\(\\s*(?:r|req|request|resp|response)\\.Body\\s*\\)"
|
|
43
|
+
message: Unbounded io.ReadAll on HTTP body without MaxBytesReader or LimitReader
|
|
44
|
+
fix:
|
|
45
|
+
description: Enforce strict maximum payload/file size limits (e.g., http.MaxBytesReader, multer limits.fileSize) or stream directly to disk/object storage
|
|
46
|
+
tags: [ops, oom-kill, memory, streaming]
|
|
47
|
+
references:
|
|
48
|
+
- https://owasp.org/API-Security/editions/2023/en/0xa4-unrestricted-resource-consumption/
|
|
49
|
+
- https://cwe.mitre.org/data/definitions/789.html
|
|
50
|
+
|
|
51
|
+
- id: ops/unbounded-pagination-limit
|
|
52
|
+
name: Unbounded Client-Controlled Pagination Limit
|
|
53
|
+
description: Detects passing client-supplied pageSize or limit parameters directly into database queries without server-side upper-bound clamping
|
|
54
|
+
category: oom-memory
|
|
55
|
+
subcategory: unbounded-pagination-limit
|
|
56
|
+
severity: high
|
|
57
|
+
confidence: high
|
|
58
|
+
cwe: [CWE-770]
|
|
59
|
+
owasp: ["API4:2023"]
|
|
60
|
+
languages: [javascript, typescript, python, php, java]
|
|
61
|
+
patterns:
|
|
62
|
+
- regex: "\\.(?:limit|take|paginate)\\s*\\(\\s*[^)]*(?:req\\.query|request\\.args|request\\.GET|\\$request->|pageSize|perPage)"
|
|
63
|
+
message: Client-controlled pagination limit passed without clamping
|
|
64
|
+
fix:
|
|
65
|
+
description: Clamp client-supplied limit/pageSize values with an explicit upper bound (e.g., Math.min(Math.max(1, limit), 100))
|
|
66
|
+
tags: [ops, oom-kill, pagination, dos]
|
|
67
|
+
references:
|
|
68
|
+
- https://owasp.org/API-Security/editions/2023/en/0xa4-unrestricted-resource-consumption/
|
|
69
|
+
- https://cwe.mitre.org/data/definitions/770.html
|
|
70
|
+
|
|
71
|
+
- id: ops/unbounded-memory-growth
|
|
72
|
+
name: Unbounded In-Memory Cache or Collection Growth
|
|
73
|
+
description: Detects module-level or static caches, stores, and buffers that grow indefinitely on requests without eviction or max-size limits
|
|
74
|
+
category: oom-memory
|
|
75
|
+
subcategory: unbounded-memory-growth
|
|
76
|
+
severity: high
|
|
77
|
+
confidence: medium
|
|
78
|
+
cwe: [CWE-400, CWE-401]
|
|
79
|
+
owasp: ["API4:2023"]
|
|
80
|
+
languages: [javascript, typescript, python, java]
|
|
81
|
+
patterns:
|
|
82
|
+
- regex: "(?:cache|store|sessions|history|buffer|metrics)\\s*=\\s*new\\s+(?:Map|Set)\\s*\\("
|
|
83
|
+
message: Potentially unbounded in-memory Map/Set cache without eviction or max-size cap
|
|
84
|
+
fix:
|
|
85
|
+
description: Use a bounded LRU/TTL cache (e.g., lru-cache, cachetools.TTLCache, Caffeine) or external store like Redis with eviction policies
|
|
86
|
+
tags: [ops, oom-kill, memory-leak, cache]
|
|
87
|
+
references:
|
|
88
|
+
- https://cwe.mitre.org/data/definitions/400.html
|
|
89
|
+
- https://cwe.mitre.org/data/definitions/401.html
|
|
90
|
+
|
|
91
|
+
# ── Operations: Timeouts & Resilience ──
|
|
92
|
+
- id: ops/missing-timeout
|
|
93
|
+
name: Outbound HTTP Client Without Timeout
|
|
94
|
+
description: Detects outbound HTTP calls and clients configured without an explicit timeout, risking thread/worker exhaustion when upstream services hang
|
|
95
|
+
category: timeout-resilience
|
|
96
|
+
subcategory: missing-timeout
|
|
97
|
+
severity: medium
|
|
98
|
+
confidence: high
|
|
99
|
+
cwe: [CWE-400, CWE-1088]
|
|
100
|
+
owasp: ["API4:2023"]
|
|
101
|
+
languages: [javascript, typescript, python, go, java, php]
|
|
102
|
+
patterns:
|
|
103
|
+
- regex: "http\\.(?:Get|Post|PostForm|Head)\\s*\\("
|
|
104
|
+
message: Go http.DefaultClient call without timeout
|
|
105
|
+
- regex: "\\b(?:requests|httpx)\\.(?:get|post|put|patch|delete|head|request)\\s*\\("
|
|
106
|
+
message: Python HTTP request without explicit timeout parameter
|
|
107
|
+
fix:
|
|
108
|
+
description: "Always set explicit connect and read/request timeouts on outbound HTTP clients (e.g., timeout=5, AbortSignal.timeout(5000), http.Client with Timeout)"
|
|
109
|
+
tags: [ops, resilience, timeout, availability]
|
|
110
|
+
references:
|
|
111
|
+
- https://cwe.mitre.org/data/definitions/1088.html
|
|
112
|
+
|
|
113
|
+
- id: ops/unbounded-retry
|
|
114
|
+
name: Unbounded Retry Loop Without Max Attempts
|
|
115
|
+
description: Detects infinite loops performing network or database I/O without a maximum retry count or cancellation check
|
|
116
|
+
category: timeout-resilience
|
|
117
|
+
subcategory: unbounded-retry
|
|
118
|
+
severity: high
|
|
119
|
+
confidence: high
|
|
120
|
+
cwe: [CWE-835, CWE-400]
|
|
121
|
+
owasp: ["API4:2023"]
|
|
122
|
+
languages: [javascript, typescript, python, go, java, php]
|
|
123
|
+
patterns:
|
|
124
|
+
- regex: "\\bwhile\\s*\\(\\s*true\\s*\\)|\\bwhile\\s+True\\s*:"
|
|
125
|
+
message: Potentially unbounded retry loop around I/O operation
|
|
126
|
+
fix:
|
|
127
|
+
description: Bound retry loops with a maximum attempt limit, exponential backoff with jitter, and context/cancellation checks
|
|
128
|
+
tags: [ops, resilience, retry, infinite-loop]
|
|
129
|
+
references:
|
|
130
|
+
- https://cwe.mitre.org/data/definitions/835.html
|
|
131
|
+
|
|
132
|
+
- id: ops/unsafe-pool-config
|
|
133
|
+
name: Unsafe Database or Connection Pool Configuration
|
|
134
|
+
description: Detects connection pools explicitly configured with unlimited connections or zero acquire timeouts
|
|
135
|
+
category: timeout-resilience
|
|
136
|
+
subcategory: unsafe-pool-config
|
|
137
|
+
severity: medium
|
|
138
|
+
confidence: high
|
|
139
|
+
cwe: [CWE-770]
|
|
140
|
+
owasp: ["API4:2023"]
|
|
141
|
+
languages: [javascript, typescript, python, go, java]
|
|
142
|
+
patterns:
|
|
143
|
+
- regex: "connectionLimit\\s*:\\s*0\\b|SetMaxOpenConns\\s*\\(\\s*0\\s*\\)"
|
|
144
|
+
message: Unbounded database connection pool limit (0 = unlimited)
|
|
145
|
+
fix:
|
|
146
|
+
description: Configure explicit finite maximum pool sizes and acquire timeouts appropriate for your database capacity
|
|
147
|
+
tags: [ops, resilience, database, pool]
|
|
148
|
+
references:
|
|
149
|
+
- https://cwe.mitre.org/data/definitions/770.html
|
|
150
|
+
|
|
151
|
+
# ── Operations: Resource & Connection Leaks ──
|
|
152
|
+
- id: ops/unclosed-resource
|
|
153
|
+
name: Unclosed HTTP Response, DB Connection, or File Handle
|
|
154
|
+
description: Detects opened connections, HTTP responses, or file handles that are not reliably closed or released
|
|
155
|
+
category: resource-leaks
|
|
156
|
+
subcategory: unclosed-resource
|
|
157
|
+
severity: high
|
|
158
|
+
confidence: high
|
|
159
|
+
cwe: [CWE-404, CWE-772]
|
|
160
|
+
owasp: ["API4:2023"]
|
|
161
|
+
languages: [javascript, typescript, python, go, java]
|
|
162
|
+
patterns:
|
|
163
|
+
- regex: "\\b\\w+\\.connect\\s*\\(\\s*\\)"
|
|
164
|
+
message: Acquired database connection without visible release() in finally block
|
|
165
|
+
fix:
|
|
166
|
+
description: Ensure every opened resource is closed in a finally block, defer statement, try-with-resources, or Python with context manager
|
|
167
|
+
tags: [ops, resource-leak, file-descriptor, connection-leak]
|
|
168
|
+
references:
|
|
169
|
+
- https://cwe.mitre.org/data/definitions/404.html
|
|
170
|
+
- https://cwe.mitre.org/data/definitions/772.html
|
|
171
|
+
|
|
172
|
+
- id: ops/timer-listener-leak
|
|
173
|
+
name: Uncleaned Timer or Event Listener in Request/Effect Scope
|
|
174
|
+
description: Detects setInterval timers or event listeners registered inside request handlers or effects without cleanup
|
|
175
|
+
category: resource-leaks
|
|
176
|
+
subcategory: timer-listener-leak
|
|
177
|
+
severity: medium
|
|
178
|
+
confidence: medium
|
|
179
|
+
cwe: [CWE-401, CWE-772]
|
|
180
|
+
owasp: ["API4:2023"]
|
|
181
|
+
languages: [javascript, typescript]
|
|
182
|
+
patterns:
|
|
183
|
+
- regex: "\\bsetInterval\\s*\\("
|
|
184
|
+
message: setInterval inside handler/effect without corresponding clearInterval
|
|
185
|
+
fix:
|
|
186
|
+
description: Always pair setInterval with clearInterval and event listeners with off/removeListener in cleanup or finally blocks
|
|
187
|
+
tags: [ops, memory-leak, timer, event-listener]
|
|
188
|
+
references:
|
|
189
|
+
- https://cwe.mitre.org/data/definitions/401.html
|
|
190
|
+
|
|
191
|
+
- id: ops/per-request-db-client
|
|
192
|
+
name: Database or Cache Client Instantiated Per Request
|
|
193
|
+
description: Detects creating new database pools, ORM clients, or Redis connections inside HTTP route handlers, causing connection exhaustion
|
|
194
|
+
category: resource-leaks
|
|
195
|
+
subcategory: per-request-db-client
|
|
196
|
+
severity: high
|
|
197
|
+
confidence: high
|
|
198
|
+
cwe: [CWE-770, CWE-404]
|
|
199
|
+
owasp: ["API4:2023"]
|
|
200
|
+
languages: [javascript, typescript, python, php]
|
|
201
|
+
patterns:
|
|
202
|
+
- regex: "new\\s+(?:PrismaClient|Pool|MongoClient|Redis)\\s*\\("
|
|
203
|
+
message: Database/cache client instantiated inside a request handler instead of module-level singleton
|
|
204
|
+
fix:
|
|
205
|
+
description: Instantiate database pools and ORM/cache clients once at application startup and reuse the shared singleton across requests
|
|
206
|
+
tags: [ops, connection-exhaustion, database, scalability]
|
|
207
|
+
references:
|
|
208
|
+
- https://cwe.mitre.org/data/definitions/770.html
|
|
209
|
+
|
|
210
|
+
# ── Operations: Performance & Bottlenecks ──
|
|
211
|
+
- id: ops/n-plus-one-query
|
|
212
|
+
name: N+1 Database Query or HTTP Call Inside Loop
|
|
213
|
+
description: Detects executing database queries or outbound HTTP requests inside loops, causing latency spikes and DB exhaustion
|
|
214
|
+
category: ops-performance
|
|
215
|
+
subcategory: n-plus-one-query
|
|
216
|
+
severity: high
|
|
217
|
+
confidence: high
|
|
218
|
+
cwe: [CWE-1050]
|
|
219
|
+
owasp: ["API4:2023"]
|
|
220
|
+
languages: [javascript, typescript, python, php, java]
|
|
221
|
+
patterns:
|
|
222
|
+
- regex: "await\\s+.*\\.(?:findUnique|findFirst|findOne|findById|query)\\s*\\("
|
|
223
|
+
message: Potential N+1 query executed inside a loop
|
|
224
|
+
fix:
|
|
225
|
+
description: Batch lookups outside the loop using WHERE IN (...), JOINs, DataLoader, or eager loading (include/with)
|
|
226
|
+
tags: [ops, performance, n-plus-one, database]
|
|
227
|
+
references:
|
|
228
|
+
- https://cwe.mitre.org/data/definitions/1050.html
|
|
229
|
+
|
|
230
|
+
- id: ops/blocking-sync-io
|
|
231
|
+
name: Synchronous Blocking I/O or Crypto in Async Handler
|
|
232
|
+
description: Detects synchronous filesystem, child_process, compression, or hashing calls inside async handlers that block the Node.js event loop
|
|
233
|
+
category: ops-performance
|
|
234
|
+
subcategory: blocking-sync-io
|
|
235
|
+
severity: high
|
|
236
|
+
confidence: high
|
|
237
|
+
cwe: [CWE-400, CWE-1050]
|
|
238
|
+
owasp: ["API4:2023"]
|
|
239
|
+
languages: [javascript, typescript]
|
|
240
|
+
patterns:
|
|
241
|
+
- regex: "\\bfs\\.(?:readFileSync|writeFileSync|readdirSync|statSync)\\s*\\("
|
|
242
|
+
message: Synchronous fs.*Sync call inside async or HTTP handler blocks the event loop
|
|
243
|
+
fix:
|
|
244
|
+
description: Replace *Sync calls with async equivalents (fs.promises.*, streams, async bcrypt/crypto) inside request handlers
|
|
245
|
+
tags: [ops, event-loop, blocking-io, performance]
|
|
246
|
+
references:
|
|
247
|
+
- https://nodejs.org/en/docs/guides/dont-block-the-event-loop
|
|
248
|
+
- https://cwe.mitre.org/data/definitions/1050.html
|
|
249
|
+
|
|
250
|
+
- id: ops/unbounded-promise-all
|
|
251
|
+
name: Unbounded Concurrent Promise.all Fan-Out
|
|
252
|
+
description: Detects Promise.all(items.map(async ...)) over arbitrary-length arrays performing I/O without concurrency limits
|
|
253
|
+
category: ops-performance
|
|
254
|
+
subcategory: unbounded-promise-all
|
|
255
|
+
severity: medium
|
|
256
|
+
confidence: medium
|
|
257
|
+
cwe: [CWE-400, CWE-770]
|
|
258
|
+
owasp: ["API4:2023"]
|
|
259
|
+
languages: [javascript, typescript]
|
|
260
|
+
patterns:
|
|
261
|
+
- regex: "Promise\\.all\\s*\\(\\s*[\\w$.]+\\.map\\s*\\(\\s*async\\b"
|
|
262
|
+
message: Unbounded Promise.all fan-out over array without concurrency limit
|
|
263
|
+
fix:
|
|
264
|
+
description: Bound concurrency using p-limit, p-map, or batch chunking to avoid exhausting sockets, DB pools, or memory
|
|
265
|
+
tags: [ops, concurrency, backpressure, scalability]
|
|
266
|
+
references:
|
|
267
|
+
- https://cwe.mitre.org/data/definitions/400.html
|
|
268
|
+
|
|
269
|
+
- id: ops/redos
|
|
270
|
+
name: Catastrophic Backtracking Regular Expression (ReDoS)
|
|
271
|
+
description: Detects nested quantifiers in regular expressions that can cause exponential CPU usage and freeze the worker thread
|
|
272
|
+
category: ops-performance
|
|
273
|
+
subcategory: redos
|
|
274
|
+
severity: high
|
|
275
|
+
confidence: high
|
|
276
|
+
cwe: [CWE-1333]
|
|
277
|
+
owasp: ["API4:2023"]
|
|
278
|
+
languages: [javascript, typescript, python, java, go, php]
|
|
279
|
+
patterns:
|
|
280
|
+
- regex: "\\([^()\\\\]*[+*][^()\\\\]*\\)[+*]"
|
|
281
|
+
message: Nested quantifier regex vulnerable to catastrophic backtracking (ReDoS)
|
|
282
|
+
fix:
|
|
283
|
+
description: Rewrite the regex to avoid nested quantifiers, use atomic groups/possessive quantifiers where supported, or use a linear-time regex engine (RE2)
|
|
284
|
+
tags: [ops, redos, cpu-exhaustion, dos]
|
|
285
|
+
references:
|
|
286
|
+
- https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS
|
|
287
|
+
- https://cwe.mitre.org/data/definitions/1333.html
|
|
@@ -15,7 +15,7 @@ rules:
|
|
|
15
15
|
message: SQL query with template literal interpolation
|
|
16
16
|
- regex: "(?:query|execute|exec)\\s*\\(\\s*[\"']\\s*\\b(?:SELECT|INSERT|UPDATE|DELETE|DROP|CREATE|ALTER)\\b.*[\"']\\s*\\+"
|
|
17
17
|
message: SQL query with string concatenation
|
|
18
|
-
- regex: "f[\"']\\s*\\b(?:SELECT|INSERT|UPDATE|DELETE|DROP|CREATE|ALTER)\\b.*\\{"
|
|
18
|
+
- regex: "f[\"']\\s*\\b(?:SELECT\\b[\\s\\S]*?\\bFROM|INSERT\\s+INTO|UPDATE\\s+\\w+\\s+SET|DELETE\\s+FROM|DROP\\s+(?:TABLE|DATABASE)|CREATE\\s+(?:TABLE|DATABASE)|ALTER\\s+TABLE)\\b.*\\{"
|
|
19
19
|
message: SQL query with f-string interpolation (Python)
|
|
20
20
|
- regex: "\\.raw\\s*\\(\\s*[`\"'\\$]"
|
|
21
21
|
message: Raw SQL query usage
|
|
@@ -46,11 +46,11 @@ rules:
|
|
|
46
46
|
message: child_process usage detected - verify input sanitization
|
|
47
47
|
- regex: "os\\.system\\s*\\(\\s*(?:f[\"']|[\"'].*%|.*\\+)"
|
|
48
48
|
message: os.system() with dynamic input (Python)
|
|
49
|
-
- regex: "subprocess\\.(?:call|run|Popen)\\s*\\(\\s*(?:f[\"']
|
|
49
|
+
- regex: "subprocess\\.(?:call|run|Popen)\\s*\\(\\s*(?!\\[)(?:f[\"']|[\"'][^\"']*[\"']\\s*(?:\\+|%))"
|
|
50
50
|
message: subprocess with dynamic input (Python)
|
|
51
51
|
- regex: "Runtime\\.getRuntime\\(\\)\\.exec\\s*\\("
|
|
52
52
|
message: Runtime.exec() usage (Java)
|
|
53
|
-
- regex: "\\bsystem\\s*\\(\\s*(
|
|
53
|
+
- regex: "(?<!\\.)\\bsystem\\s*\\(\\s*(?:\\$\\w+|[\"'][^\"']*[\"']\\s*[\\+.])"
|
|
54
54
|
message: system() call with dynamic input
|
|
55
55
|
fix:
|
|
56
56
|
description: Use parameterized APIs (e.g., execFile with array args) or whitelist-validate input
|
|
@@ -70,7 +70,7 @@ rules:
|
|
|
70
70
|
owasp: ["A03:2021"]
|
|
71
71
|
languages: [javascript, typescript, python, php, ruby]
|
|
72
72
|
patterns:
|
|
73
|
-
- regex: "\\beval\\s*\\("
|
|
73
|
+
- regex: "(?<!\\.|\\w)\\beval\\s*\\(|(?:window|globalThis|global)\\s*\\.\\s*eval\\s*\\("
|
|
74
74
|
message: eval() usage detected
|
|
75
75
|
- regex: "new\\s+Function\\s*\\("
|
|
76
76
|
message: new Function() is equivalent to eval()
|
|
@@ -155,6 +155,12 @@ rules:
|
|
|
155
155
|
patterns:
|
|
156
156
|
- regex: "(?:password|passwd|pwd|secret|api_key|apikey|api_secret|access_key|access_token|auth_token|private_key)\\s*[:=]\\s*[\"'][^\"']{8,}[\"']"
|
|
157
157
|
message: Hardcoded secret value detected
|
|
158
|
+
- regex: "process\\.env\\.(?![A-Z0-9_]*_(?:TABLE|BROKER|TIMEOUT|TTL|EXPIRY|EXPIRES|DRIVER|GUARD|PROVIDER|COLUMN|FIELD|PATH|URL|URI|ENABLED|LENGTH|COUNT|ALGO|ALGORITHM)\\b)[A-Z0-9_]*(?:PASSWORD|PASSWD|PASS|PWD|SECRET|TOKEN|PRIVATE_KEY)[A-Z0-9_]*\\s*(?:\\|\\||\\?\\?)\\s*[\"'][^\"']{4,}[\"']"
|
|
159
|
+
message: Hardcoded fallback secret in environment variable expression
|
|
160
|
+
- regex: "\\b(?:env|os\\.getenv|getenv)\\s*\\(\\s*[\"'](?![A-Z0-9_]*_(?:TABLE|BROKER|TIMEOUT|TTL|EXPIRY|EXPIRES|DRIVER|GUARD|PROVIDER|COLUMN|FIELD|PATH|URL|URI|ENABLED|LENGTH|COUNT|ALGO|ALGORITHM)\\b)[A-Z0-9_]*(?:PASSWORD|PASSWD|PASS|PWD|SECRET|TOKEN|PRIVATE_KEY)[A-Z0-9_]*[\"']\\s*,\\s*[\"'][^\"']{4,}[\"']\\s*\\)"
|
|
161
|
+
message: Hardcoded fallback secret in environment lookup (env/getenv)
|
|
162
|
+
- regex: "GOCSPX-[0-9A-Za-z\\-_]{28}"
|
|
163
|
+
message: Google OAuth Client Secret detected
|
|
158
164
|
- regex: "AKIA[0-9A-Z]{16}"
|
|
159
165
|
message: AWS Access Key ID detected
|
|
160
166
|
- regex: "ghp_[a-zA-Z0-9]{36}"
|
|
@@ -235,7 +241,7 @@ rules:
|
|
|
235
241
|
message: Math.random() is not cryptographically secure - use crypto.getRandomValues()
|
|
236
242
|
- regex: "random\\.random\\s*\\("
|
|
237
243
|
message: random.random() is not cryptographically secure (Python) - use secrets module
|
|
238
|
-
- regex: "(?:createCipher(?:iv)
|
|
244
|
+
- regex: "(?:createCipher(?:iv)?\\s*\\(\\s*[\"'][^\"']+[\"']\\s*,\\s*[\"'][^\"']{1,64}[\"']|new\\s+\\w*Cipher\\s*\\(\\s*[\"'][^\"']{1,32}[\"'])"
|
|
239
245
|
message: Possible hardcoded encryption key
|
|
240
246
|
fix:
|
|
241
247
|
description: Use SHA-256+ for hashing, AES-256-GCM for encryption, and crypto.getRandomValues/secrets for randomness
|
|
@@ -256,7 +262,7 @@ rules:
|
|
|
256
262
|
patterns:
|
|
257
263
|
- regex: "\\b(?:readFile|writeFile|createReadStream|createWriteStream|open)\\b\\s*\\(\\s*(?:req\\.|request\\.|params\\.|query\\.)"
|
|
258
264
|
message: File operation with user-controlled path
|
|
259
|
-
- regex: "\\.\\.[
|
|
265
|
+
- regex: "(?<!\\.)\\.\\.(?:\\/|\\\\(?![nrt\"'0\\\\]))"
|
|
260
266
|
message: Path traversal sequence detected
|
|
261
267
|
- regex: "\\bpath\\.join\\b\\s*\\([^)]*(?:req\\.|request\\.|params\\.|query\\.)"
|
|
262
268
|
message: path.join with user input
|