deepscan-cli 1.0.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/LICENSE +201 -0
- package/README.md +419 -0
- package/dist/bin/deepscan.d.ts +1 -0
- package/dist/bin/deepscan.js +393 -0
- package/dist/bin/deepscan.js.map +1 -0
- package/dist/chunk-OSYJXVNF.js +7268 -0
- package/dist/chunk-OSYJXVNF.js.map +1 -0
- package/dist/index.d.ts +470 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/package.json +68 -0
- package/rules/built-in/converted-semgrep.yml +37 -0
- package/rules/built-in/default-config.yml +59 -0
- package/rules/built-in/quality.yml +117 -0
- package/rules/built-in/security.yml +383 -0
- package/rules/built-in/semgrep-apex.yml +336 -0
- package/rules/built-in/semgrep-bash.yml +362 -0
- package/rules/built-in/semgrep-c.yml +429 -0
- package/rules/built-in/semgrep-clojure.yml +166 -0
- package/rules/built-in/semgrep-csharp.yml +1260 -0
- package/rules/built-in/semgrep-dart.yml +21 -0
- package/rules/built-in/semgrep-dockerfile.yml +874 -0
- package/rules/built-in/semgrep-elixir.yml +146 -0
- package/rules/built-in/semgrep-generic.yml +2945 -0
- package/rules/built-in/semgrep-go.yml +2898 -0
- package/rules/built-in/semgrep-hcl.yml +8181 -0
- package/rules/built-in/semgrep-html.yml +94 -0
- package/rules/built-in/semgrep-java.yml +4219 -0
- package/rules/built-in/semgrep-javascript.yml +6243 -0
- package/rules/built-in/semgrep-json.yml +360 -0
- package/rules/built-in/semgrep-kotlin.yml +540 -0
- package/rules/built-in/semgrep-lua.yml +46 -0
- package/rules/built-in/semgrep-ocaml.yml +773 -0
- package/rules/built-in/semgrep-php.yml +1638 -0
- package/rules/built-in/semgrep-python.yml +11240 -0
- package/rules/built-in/semgrep-regex.yml +6444 -0
- package/rules/built-in/semgrep-ruby.yml +2687 -0
- package/rules/built-in/semgrep-rust.yml +278 -0
- package/rules/built-in/semgrep-scala.yml +807 -0
- package/rules/built-in/semgrep-sh.yml +46 -0
- package/rules/built-in/semgrep-solidity.yml +1046 -0
- package/rules/built-in/semgrep-swift.yml +200 -0
- package/rules/built-in/semgrep-terraform.yml +147 -0
- package/rules/built-in/semgrep-typescript.yml +6212 -0
- package/rules/built-in/semgrep-xml.yml +31 -0
- package/rules/built-in/semgrep-yaml.yml +2785 -0
- package/rules/examples/custom-api-security.yml +66 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
rules:
|
|
2
|
+
# ── Quality: Complexity ──
|
|
3
|
+
- id: quality/high-complexity
|
|
4
|
+
name: High Cyclomatic Complexity
|
|
5
|
+
description: Function has high cyclomatic complexity making it hard to understand and test
|
|
6
|
+
category: complexity
|
|
7
|
+
severity: medium
|
|
8
|
+
confidence: high
|
|
9
|
+
languages: ["*"]
|
|
10
|
+
patterns: []
|
|
11
|
+
tags: [maintainability]
|
|
12
|
+
|
|
13
|
+
- id: quality/deep-nesting
|
|
14
|
+
name: Deep Nesting
|
|
15
|
+
description: Code has deeply nested blocks making it hard to read
|
|
16
|
+
category: complexity
|
|
17
|
+
severity: medium
|
|
18
|
+
confidence: high
|
|
19
|
+
languages: ["*"]
|
|
20
|
+
patterns: []
|
|
21
|
+
tags: [maintainability]
|
|
22
|
+
|
|
23
|
+
- id: quality/long-function
|
|
24
|
+
name: Long Function
|
|
25
|
+
description: Function is too long - consider breaking it into smaller functions
|
|
26
|
+
category: complexity
|
|
27
|
+
severity: low
|
|
28
|
+
confidence: high
|
|
29
|
+
languages: ["*"]
|
|
30
|
+
patterns: []
|
|
31
|
+
tags: [maintainability]
|
|
32
|
+
|
|
33
|
+
# ── Quality: Code Smells ──
|
|
34
|
+
- id: quality/long-file
|
|
35
|
+
name: Long File
|
|
36
|
+
description: File exceeds the maximum recommended line count
|
|
37
|
+
category: code-smells
|
|
38
|
+
severity: low
|
|
39
|
+
confidence: high
|
|
40
|
+
languages: ["*"]
|
|
41
|
+
patterns: []
|
|
42
|
+
tags: [maintainability]
|
|
43
|
+
|
|
44
|
+
- id: quality/magic-number
|
|
45
|
+
name: Magic Number
|
|
46
|
+
description: Use named constants instead of magic numbers for better readability
|
|
47
|
+
category: code-smells
|
|
48
|
+
severity: low
|
|
49
|
+
confidence: medium
|
|
50
|
+
languages: ["*"]
|
|
51
|
+
patterns:
|
|
52
|
+
- regex: "(?:if|while|for|return|===?|!==?|[<>]=?)\\s*\\b(?:[2-9]\\d{2,}|[1-9]\\d{3,})\\b"
|
|
53
|
+
message: Magic number - use a named constant
|
|
54
|
+
tags: [maintainability]
|
|
55
|
+
|
|
56
|
+
- id: quality/todo-comment
|
|
57
|
+
name: TODO/FIXME Comment
|
|
58
|
+
description: Unresolved TODO or FIXME comment found
|
|
59
|
+
category: code-smells
|
|
60
|
+
severity: low
|
|
61
|
+
confidence: high
|
|
62
|
+
languages: ["*"]
|
|
63
|
+
patterns:
|
|
64
|
+
- regex: "(?://|#|/\\*)\\s*(?:TODO|FIXME|HACK|XXX|BUG)\\b"
|
|
65
|
+
message: Unresolved TODO/FIXME comment
|
|
66
|
+
tags: [maintainability]
|
|
67
|
+
|
|
68
|
+
- id: quality/empty-catch
|
|
69
|
+
name: Empty Catch Block
|
|
70
|
+
description: Empty catch block silently swallows errors
|
|
71
|
+
category: code-smells
|
|
72
|
+
severity: medium
|
|
73
|
+
confidence: high
|
|
74
|
+
cwe: [CWE-390]
|
|
75
|
+
languages: [javascript, typescript, java, csharp, php]
|
|
76
|
+
patterns:
|
|
77
|
+
- regex: "catch\\s*\\([^)]*\\)\\s*\\{\\s*\\}"
|
|
78
|
+
message: Empty catch block - at minimum log the error
|
|
79
|
+
fix:
|
|
80
|
+
description: Add error handling or at minimum log the error
|
|
81
|
+
tags: [error-handling]
|
|
82
|
+
|
|
83
|
+
- id: quality/console-log
|
|
84
|
+
name: Console Log Statement
|
|
85
|
+
description: Console log/print statements should be removed from production code
|
|
86
|
+
category: code-smells
|
|
87
|
+
severity: low
|
|
88
|
+
confidence: medium
|
|
89
|
+
languages: [javascript, typescript]
|
|
90
|
+
patterns:
|
|
91
|
+
- regex: "console\\.(?:log|debug|warn|info|trace)\\s*\\("
|
|
92
|
+
message: console.log() left in code
|
|
93
|
+
fix:
|
|
94
|
+
description: Use a proper logging library or remove debug statements
|
|
95
|
+
tags: [debug]
|
|
96
|
+
|
|
97
|
+
# ── Quality: Duplication ──
|
|
98
|
+
- id: quality/code-duplication
|
|
99
|
+
name: Code Duplication
|
|
100
|
+
description: Duplicated code block detected - consider extracting to a shared function
|
|
101
|
+
category: duplication
|
|
102
|
+
severity: medium
|
|
103
|
+
confidence: medium
|
|
104
|
+
languages: ["*"]
|
|
105
|
+
patterns: []
|
|
106
|
+
tags: [maintainability, dry]
|
|
107
|
+
|
|
108
|
+
# ── Quality: Metrics ──
|
|
109
|
+
- id: quality/low-comment-ratio
|
|
110
|
+
name: Low Comment Ratio
|
|
111
|
+
description: File has very few comments relative to code
|
|
112
|
+
category: metrics
|
|
113
|
+
severity: low
|
|
114
|
+
confidence: low
|
|
115
|
+
languages: ["*"]
|
|
116
|
+
patterns: []
|
|
117
|
+
tags: [documentation]
|
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
rules:
|
|
2
|
+
# ── Security: Injection ──
|
|
3
|
+
- id: security/sql-injection
|
|
4
|
+
name: SQL Injection
|
|
5
|
+
description: Detects potential SQL injection vulnerabilities where user input may be directly concatenated into SQL queries
|
|
6
|
+
category: injection
|
|
7
|
+
subcategory: sql
|
|
8
|
+
severity: critical
|
|
9
|
+
confidence: high
|
|
10
|
+
cwe: [CWE-89]
|
|
11
|
+
owasp: ["A03:2021"]
|
|
12
|
+
languages: [javascript, typescript, python, java, php, ruby, go, csharp]
|
|
13
|
+
patterns:
|
|
14
|
+
- regex: "(?:query|execute|exec)\\s*\\(\\s*[`\"']\\s*\\b(?:SELECT|INSERT|UPDATE|DELETE|DROP|CREATE|ALTER)\\b.*\\$\\{"
|
|
15
|
+
message: SQL query with template literal interpolation
|
|
16
|
+
- regex: "(?:query|execute|exec)\\s*\\(\\s*[\"']\\s*\\b(?:SELECT|INSERT|UPDATE|DELETE|DROP|CREATE|ALTER)\\b.*[\"']\\s*\\+"
|
|
17
|
+
message: SQL query with string concatenation
|
|
18
|
+
- regex: "f[\"']\\s*\\b(?:SELECT|INSERT|UPDATE|DELETE|DROP|CREATE|ALTER)\\b.*\\{"
|
|
19
|
+
message: SQL query with f-string interpolation (Python)
|
|
20
|
+
- regex: "\\.raw\\s*\\(\\s*[`\"'\\$]"
|
|
21
|
+
message: Raw SQL query usage
|
|
22
|
+
- regex: "(?:DB\\s*::\\s*(?:select|statement|insert|update|delete|raw)|whereRaw|havingRaw|orderByRaw)\\s*\\(\\s*[\"']\\b(?:SELECT|INSERT|UPDATE|DELETE|DROP|ALTER|CREATE|UNION)\\b[^\"']*[\"']\\s*\\.\\s*\\$\\w+"
|
|
23
|
+
message: Laravel raw SQL query built with string concatenation
|
|
24
|
+
fix:
|
|
25
|
+
description: Use parameterized queries or prepared statements instead of string concatenation
|
|
26
|
+
replacement: Use db.query("SELECT * FROM users WHERE id = ?", [userId])
|
|
27
|
+
tags: [owasp-top-10, injection, a03]
|
|
28
|
+
references:
|
|
29
|
+
- https://owasp.org/Top10/A03_2021-Injection/
|
|
30
|
+
- https://cwe.mitre.org/data/definitions/89.html
|
|
31
|
+
|
|
32
|
+
- id: security/command-injection
|
|
33
|
+
name: Command Injection
|
|
34
|
+
description: Detects potential OS command injection where user input flows into command execution functions
|
|
35
|
+
category: injection
|
|
36
|
+
subcategory: command
|
|
37
|
+
severity: critical
|
|
38
|
+
confidence: high
|
|
39
|
+
cwe: [CWE-78]
|
|
40
|
+
owasp: ["A03:2021"]
|
|
41
|
+
languages: [javascript, typescript, python, java, php, ruby, go, c, cpp]
|
|
42
|
+
patterns:
|
|
43
|
+
- regex: "(?:exec|execSync|spawn|spawnSync)\\s*\\(\\s*(?:[`\"'].*\\$\\{|[\"'].*\\+)"
|
|
44
|
+
message: Command execution with interpolated/concatenated input
|
|
45
|
+
- regex: "child_process.*(?:exec|spawn)\\s*\\("
|
|
46
|
+
message: child_process usage detected - verify input sanitization
|
|
47
|
+
- regex: "os\\.system\\s*\\(\\s*(?:f[\"']|[\"'].*%|.*\\+)"
|
|
48
|
+
message: os.system() with dynamic input (Python)
|
|
49
|
+
- regex: "subprocess\\.(?:call|run|Popen)\\s*\\(\\s*(?:f[\"']|.*\\+|.*%)"
|
|
50
|
+
message: subprocess with dynamic input (Python)
|
|
51
|
+
- regex: "Runtime\\.getRuntime\\(\\)\\.exec\\s*\\("
|
|
52
|
+
message: Runtime.exec() usage (Java)
|
|
53
|
+
- regex: "\\bsystem\\s*\\(\\s*(?:\\$|.*\\+|.*\\.)"
|
|
54
|
+
message: system() call with dynamic input
|
|
55
|
+
fix:
|
|
56
|
+
description: Use parameterized APIs (e.g., execFile with array args) or whitelist-validate input
|
|
57
|
+
tags: [owasp-top-10, injection, a03]
|
|
58
|
+
references:
|
|
59
|
+
- https://owasp.org/Top10/A03_2021-Injection/
|
|
60
|
+
- https://cwe.mitre.org/data/definitions/78.html
|
|
61
|
+
|
|
62
|
+
- id: security/code-injection
|
|
63
|
+
name: Code Injection (eval)
|
|
64
|
+
description: Detects usage of eval() and similar dynamic code execution functions
|
|
65
|
+
category: injection
|
|
66
|
+
subcategory: code
|
|
67
|
+
severity: critical
|
|
68
|
+
confidence: high
|
|
69
|
+
cwe: [CWE-94, CWE-95]
|
|
70
|
+
owasp: ["A03:2021"]
|
|
71
|
+
languages: [javascript, typescript, python, php, ruby]
|
|
72
|
+
patterns:
|
|
73
|
+
- regex: "\\beval\\s*\\("
|
|
74
|
+
message: eval() usage detected
|
|
75
|
+
- regex: "new\\s+Function\\s*\\("
|
|
76
|
+
message: new Function() is equivalent to eval()
|
|
77
|
+
- regex: "setTimeout\\s*\\(\\s*[\"']"
|
|
78
|
+
message: setTimeout with string argument acts like eval()
|
|
79
|
+
- regex: "setInterval\\s*\\(\\s*[\"']"
|
|
80
|
+
message: setInterval with string argument acts like eval()
|
|
81
|
+
- regex: "\\bexec\\s*\\(\\s*compile\\s*\\("
|
|
82
|
+
message: exec(compile()) in Python
|
|
83
|
+
fix:
|
|
84
|
+
description: Avoid eval() and dynamic code execution. Use JSON.parse() for data, or safe alternatives.
|
|
85
|
+
tags: [owasp-top-10, injection]
|
|
86
|
+
references:
|
|
87
|
+
- https://cwe.mitre.org/data/definitions/94.html
|
|
88
|
+
|
|
89
|
+
# ── Security: XSS ──
|
|
90
|
+
- id: security/xss-innerhtml
|
|
91
|
+
name: XSS via innerHTML
|
|
92
|
+
description: Detects assignment to innerHTML which can lead to Cross-Site Scripting
|
|
93
|
+
category: xss
|
|
94
|
+
severity: high
|
|
95
|
+
confidence: medium
|
|
96
|
+
cwe: [CWE-79]
|
|
97
|
+
owasp: ["A03:2021"]
|
|
98
|
+
languages: [javascript, typescript]
|
|
99
|
+
patterns:
|
|
100
|
+
- regex: "\\.innerHTML\\s*="
|
|
101
|
+
message: innerHTML assignment can lead to XSS
|
|
102
|
+
- regex: "\\.outerHTML\\s*="
|
|
103
|
+
message: outerHTML assignment can lead to XSS
|
|
104
|
+
- regex: "document\\.write\\s*\\("
|
|
105
|
+
message: document.write() can lead to XSS
|
|
106
|
+
- regex: "document\\.writeln\\s*\\("
|
|
107
|
+
message: document.writeln() can lead to XSS
|
|
108
|
+
- regex: dangerouslySetInnerHTML
|
|
109
|
+
message: React dangerouslySetInnerHTML usage
|
|
110
|
+
- regex: "\\$\\(.*\\)\\.html\\s*\\("
|
|
111
|
+
message: jQuery .html() can lead to XSS
|
|
112
|
+
fix:
|
|
113
|
+
description: Use textContent instead of innerHTML, or sanitize with DOMPurify
|
|
114
|
+
tags: [owasp-top-10, xss]
|
|
115
|
+
references:
|
|
116
|
+
- https://owasp.org/Top10/A03_2021-Injection/
|
|
117
|
+
- https://cwe.mitre.org/data/definitions/79.html
|
|
118
|
+
|
|
119
|
+
- id: security/xss-response
|
|
120
|
+
name: Reflected XSS in HTTP Responses
|
|
121
|
+
description: Detects dynamic HTML generation in HTTP responses which can lead to reflected XSS
|
|
122
|
+
category: xss
|
|
123
|
+
severity: high
|
|
124
|
+
confidence: medium
|
|
125
|
+
cwe: [CWE-79]
|
|
126
|
+
owasp: ["A03:2021"]
|
|
127
|
+
languages: [javascript, typescript, python, php]
|
|
128
|
+
patterns:
|
|
129
|
+
- regex: "res\\.(?:send|write|end)\\s*\\(\\s*`[^`]*<[a-zA-Z]+[^>]*>[^`]*\\$\\{"
|
|
130
|
+
message: Dynamic HTML template literal sent directly in HTTP response
|
|
131
|
+
- regex: "res\\.(?:send|write|end)\\s*\\(\\s*(?:[\"'][^\"']*<[a-zA-Z]+[^>]*>[^\"']*[\"']\\s*\\+|[^)]+\\s*\\+\\s*[\"'][^\"']*<[a-zA-Z]+[^>]*>)"
|
|
132
|
+
message: HTML string concatenation sent directly in HTTP response
|
|
133
|
+
- regex: "return\\s+['\"][^'\"]*<[a-zA-Z]+[^>]*>[^'\"]*['\"]\\s*%\\s*\\w+"
|
|
134
|
+
message: Python string formatting used to return HTML response
|
|
135
|
+
- regex: "return\\s+f['\"][^'\"]*<[a-zA-Z]+[^>]*>[^'\"]*\\{"
|
|
136
|
+
message: Python f-string used to return HTML response
|
|
137
|
+
- regex: "mark_safe\\s*\\(\\s*(?!(?:['\"`][^'\"`]*['\"`])\\s*\\))\\S"
|
|
138
|
+
message: Django mark_safe called with dynamic content or variable
|
|
139
|
+
fix:
|
|
140
|
+
description: Always escape HTML inputs, use template autoescaping, or sanitize with a library like DOMPurify/bleach.
|
|
141
|
+
tags: [owasp-top-10, xss]
|
|
142
|
+
references:
|
|
143
|
+
- https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html
|
|
144
|
+
|
|
145
|
+
# ── Security: Secrets ──
|
|
146
|
+
- id: security/hardcoded-secret
|
|
147
|
+
name: Hardcoded Secret
|
|
148
|
+
description: Detects hardcoded passwords, API keys, and tokens in source code
|
|
149
|
+
category: secrets
|
|
150
|
+
severity: critical
|
|
151
|
+
confidence: high
|
|
152
|
+
cwe: [CWE-798]
|
|
153
|
+
owasp: ["A07:2021"]
|
|
154
|
+
languages: ["*"]
|
|
155
|
+
patterns:
|
|
156
|
+
- regex: "(?:password|passwd|pwd|secret|api_key|apikey|api_secret|access_key|access_token|auth_token|private_key)\\s*[:=]\\s*[\"'][^\"']{8,}[\"']"
|
|
157
|
+
message: Hardcoded secret value detected
|
|
158
|
+
- regex: "AKIA[0-9A-Z]{16}"
|
|
159
|
+
message: AWS Access Key ID detected
|
|
160
|
+
- regex: "ghp_[a-zA-Z0-9]{36}"
|
|
161
|
+
message: GitHub Personal Access Token detected
|
|
162
|
+
- regex: "gho_[a-zA-Z0-9]{36}"
|
|
163
|
+
message: GitHub OAuth Token detected
|
|
164
|
+
- regex: "xox[bpras]-[a-zA-Z0-9-]+"
|
|
165
|
+
message: Slack Token detected
|
|
166
|
+
- regex: "sk-[a-zA-Z0-9]{20,}"
|
|
167
|
+
message: OpenAI/Stripe Secret Key detected
|
|
168
|
+
- regex: "sk_live_[a-zA-Z0-9]{24,}"
|
|
169
|
+
message: Stripe Live Secret Key detected
|
|
170
|
+
- regex: "sq0csp-[a-zA-Z0-9\\-_]{43}"
|
|
171
|
+
message: Square Access Token detected
|
|
172
|
+
- regex: "SG\\.[a-zA-Z0-9\\-_]{22}\\.[a-zA-Z0-9\\-_]{43}"
|
|
173
|
+
message: SendGrid API Key detected
|
|
174
|
+
- regex: "ya29\\.[a-zA-Z0-9_-]+"
|
|
175
|
+
message: Google OAuth Access Token detected
|
|
176
|
+
- regex: "-----BEGIN (?:RSA |EC |DSA |OPENSSH )?PRIVATE KEY-----"
|
|
177
|
+
message: Private key detected in source code
|
|
178
|
+
- regex: "(?:mongodb|postgres|mysql|redis)://[^\\s\"'{}$]+:[^\\s\"'{}$]+@"
|
|
179
|
+
message: Database connection string with credentials
|
|
180
|
+
fix:
|
|
181
|
+
description: Use environment variables or a secrets manager. Never commit secrets to source control.
|
|
182
|
+
tags: [owasp-top-10, secrets, a07]
|
|
183
|
+
references:
|
|
184
|
+
- https://owasp.org/Top10/A07_2021-Identification_and_Authentication_Failures/
|
|
185
|
+
|
|
186
|
+
# ── Security: Auth ──
|
|
187
|
+
- id: security/weak-auth
|
|
188
|
+
name: Weak Authentication Pattern
|
|
189
|
+
description: Detects weak authentication patterns that could lead to security vulnerabilities
|
|
190
|
+
category: auth
|
|
191
|
+
severity: high
|
|
192
|
+
confidence: medium
|
|
193
|
+
cwe: [CWE-287]
|
|
194
|
+
owasp: ["A07:2021"]
|
|
195
|
+
languages: [javascript, typescript, python, java, php]
|
|
196
|
+
patterns:
|
|
197
|
+
- regex: "jwt\\.sign\\s*\\([^)]*[\"']secret[\"']"
|
|
198
|
+
message: JWT signed with weak/default secret
|
|
199
|
+
- regex: "algorithm\\s*[:=]\\s*[\"'](?:none)[\"']"
|
|
200
|
+
message: JWT using weak algorithm (none or HS256)
|
|
201
|
+
- regex: "session\\.cookie\\.secure\\s*[:=]\\s*false"
|
|
202
|
+
message: Session cookie not using secure flag
|
|
203
|
+
- regex: "httpOnly\\s*[:=]\\s*false"
|
|
204
|
+
message: Cookie httpOnly flag disabled
|
|
205
|
+
- regex: "verify\\s*[:=]\\s*(?:false|False)"
|
|
206
|
+
message: SSL/TLS verification disabled
|
|
207
|
+
- regex: "check_hostname\\s*[:=]\\s*(?:false|False)"
|
|
208
|
+
message: SSL/TLS hostname verification disabled
|
|
209
|
+
- regex: "verify_mode\\s*[:=]\\s*(?:ssl\\.CERT_NONE|CERT_NONE)"
|
|
210
|
+
message: SSL/TLS certificate verification disabled (CERT_NONE)
|
|
211
|
+
- regex: "password\\s*===?\\s*[\"']"
|
|
212
|
+
message: Direct password comparison (use bcrypt/argon2)
|
|
213
|
+
fix:
|
|
214
|
+
description: Use strong secrets, secure cookie flags, and proper password hashing (bcrypt/argon2)
|
|
215
|
+
tags: [auth, a07]
|
|
216
|
+
references:
|
|
217
|
+
- https://cwe.mitre.org/data/definitions/287.html
|
|
218
|
+
|
|
219
|
+
# ── Security: Crypto ──
|
|
220
|
+
- id: security/weak-crypto
|
|
221
|
+
name: Weak Cryptography
|
|
222
|
+
description: Detects usage of weak or deprecated cryptographic algorithms
|
|
223
|
+
category: crypto
|
|
224
|
+
severity: high
|
|
225
|
+
confidence: high
|
|
226
|
+
cwe: [CWE-327, CWE-328]
|
|
227
|
+
owasp: ["A02:2021"]
|
|
228
|
+
languages: ["*"]
|
|
229
|
+
patterns:
|
|
230
|
+
- regex: "(?:createHash|MessageDigest\\.getInstance|hashlib\\.)\\s*\\(?\\s*[\"'](?:md5|md4|sha1|sha-1)[\"']"
|
|
231
|
+
message: Weak hash algorithm (MD5/SHA1) - use SHA-256 or stronger
|
|
232
|
+
- regex: "(?:createCipher|Cipher\\.getInstance)\\s*\\(?\\s*[\"'](?:des|rc4|rc2|blowfish)[\"']"
|
|
233
|
+
message: Weak encryption algorithm - use AES-256-GCM
|
|
234
|
+
- regex: "Math\\.random\\s*\\("
|
|
235
|
+
message: Math.random() is not cryptographically secure - use crypto.getRandomValues()
|
|
236
|
+
- regex: "random\\.random\\s*\\("
|
|
237
|
+
message: random.random() is not cryptographically secure (Python) - use secrets module
|
|
238
|
+
- regex: "(?:createCipher(?:iv)?|new.*Cipher)\\s*\\([^)]*[\"'][^\"']{1,32}[\"']"
|
|
239
|
+
message: Possible hardcoded encryption key
|
|
240
|
+
fix:
|
|
241
|
+
description: Use SHA-256+ for hashing, AES-256-GCM for encryption, and crypto.getRandomValues/secrets for randomness
|
|
242
|
+
tags: [crypto, a02]
|
|
243
|
+
references:
|
|
244
|
+
- https://cwe.mitre.org/data/definitions/327.html
|
|
245
|
+
|
|
246
|
+
# ── Security: File Operations ──
|
|
247
|
+
- id: security/path-traversal
|
|
248
|
+
name: Path Traversal
|
|
249
|
+
description: Detects potential path traversal vulnerabilities in file operations
|
|
250
|
+
category: file-ops
|
|
251
|
+
severity: high
|
|
252
|
+
confidence: medium
|
|
253
|
+
cwe: [CWE-22]
|
|
254
|
+
owasp: ["A01:2021"]
|
|
255
|
+
languages: ["*"]
|
|
256
|
+
patterns:
|
|
257
|
+
- regex: "\\b(?:readFile|writeFile|createReadStream|createWriteStream|open)\\b\\s*\\(\\s*(?:req\\.|request\\.|params\\.|query\\.)"
|
|
258
|
+
message: File operation with user-controlled path
|
|
259
|
+
- regex: "\\.\\.[\\\\/]"
|
|
260
|
+
message: Path traversal sequence detected
|
|
261
|
+
- regex: "\\bpath\\.join\\b\\s*\\([^)]*(?:req\\.|request\\.|params\\.|query\\.)"
|
|
262
|
+
message: path.join with user input
|
|
263
|
+
- regex: "\\b(?:ioutil\\.|os\\.)(?:ReadFile|Open|OpenFile|Create|Remove)\\b\\s*\\(\\s*[^'\"`)]*\\b(?:req|request|params|query|body|args|input|user|filename|uri|url)\\b"
|
|
264
|
+
message: File read/open with dynamic path (Go/Generic)
|
|
265
|
+
- regex: "\\b(?:filepath\\.|path\\.|os\\.path\\.)Join\\b\\s*\\(\\s*[^,]+,\\s*\\b(?:req|request|params|query|body|args|input|user|filename|uri|url)\\b"
|
|
266
|
+
message: Path construction with user input/variables
|
|
267
|
+
fix:
|
|
268
|
+
description: Validate and sanitize file paths. Use path.resolve() and verify the result is within allowed directory.
|
|
269
|
+
tags: [file-ops, a01]
|
|
270
|
+
references:
|
|
271
|
+
- https://cwe.mitre.org/data/definitions/22.html
|
|
272
|
+
|
|
273
|
+
# ── Security: XXE ──
|
|
274
|
+
- id: security/xxe
|
|
275
|
+
name: XML External Entity (XXE)
|
|
276
|
+
description: Detects unsafe XML parsers where external entity resolution is not disabled
|
|
277
|
+
category: api-security
|
|
278
|
+
subcategory: xxe
|
|
279
|
+
severity: critical
|
|
280
|
+
confidence: medium
|
|
281
|
+
cwe: [CWE-611]
|
|
282
|
+
owasp: ["A05:2021"]
|
|
283
|
+
languages: [java, javascript, typescript, python]
|
|
284
|
+
patterns:
|
|
285
|
+
- regex: "DocumentBuilderFactory\\s*\\.\\s*(?:newInstance|newDefaultInstance)"
|
|
286
|
+
message: Java DocumentBuilderFactory instantiated
|
|
287
|
+
- regex: "XMLInputFactory\\s*\\.\\s*(?:newInstance|newFactory)"
|
|
288
|
+
message: Java XMLInputFactory instantiated
|
|
289
|
+
- regex: "libxmljs\\s*\\.\\s*parseXml\\s*\\(\\s*[^,)]+\\s*,\\s*\\{\\s*noent\\s*:\\s*true"
|
|
290
|
+
message: "libxmljs parseXml with noent: true enables XXE"
|
|
291
|
+
fix:
|
|
292
|
+
description: Disable DTDs and external entities in your XML parser configuration.
|
|
293
|
+
tags: [xxe, xml, api-security]
|
|
294
|
+
references:
|
|
295
|
+
- https://cheatsheetseries.owasp.org/cheatsheets/XML_External_Entity_Prevention_Cheat_Sheet.html
|
|
296
|
+
|
|
297
|
+
# ── Security: SSRF ──
|
|
298
|
+
- id: security/ssrf
|
|
299
|
+
name: Server-Side Request Forgery (SSRF)
|
|
300
|
+
description: Detects HTTP requests made with user-controlled URLs
|
|
301
|
+
category: api-security
|
|
302
|
+
subcategory: ssrf
|
|
303
|
+
severity: critical
|
|
304
|
+
confidence: high
|
|
305
|
+
cwe: [CWE-918]
|
|
306
|
+
owasp: ["A10:2021"]
|
|
307
|
+
languages: [javascript, typescript, python, java]
|
|
308
|
+
patterns:
|
|
309
|
+
- regex: "axios\\s*\\.\\s*(?:get|post|request)\\s*\\(\\s*(?:req|request|params|query|body|args|input|user|url)"
|
|
310
|
+
message: Axios request with user input
|
|
311
|
+
- regex: "fetch\\s*\\(\\s*(?:req|request|params|query|body|args|input|user|url)"
|
|
312
|
+
message: Fetch request with user input
|
|
313
|
+
- regex: "requests\\s*\\.\\s*(?:get|post|request)\\s*\\(\\s*(?:req|request|params|user_input|url)"
|
|
314
|
+
message: Python requests call with user input
|
|
315
|
+
fix:
|
|
316
|
+
description: Validate user input before sending HTTP requests. Restrict to a whitelist of allowed domains.
|
|
317
|
+
tags: [ssrf, api-security]
|
|
318
|
+
references:
|
|
319
|
+
- https://cheatsheetseries.owasp.org/cheatsheets/Server_Side_Request_Forgery_Prevention_Cheat_Sheet.html
|
|
320
|
+
|
|
321
|
+
# ── Security: CORS Misconfiguration ──
|
|
322
|
+
- id: security/cors-wildcard
|
|
323
|
+
name: Unsafe CORS Wildcard
|
|
324
|
+
description: Detects CORS configurations that permit wildcard (*) origins
|
|
325
|
+
category: api-security
|
|
326
|
+
subcategory: cors
|
|
327
|
+
severity: high
|
|
328
|
+
confidence: high
|
|
329
|
+
cwe: [CWE-942]
|
|
330
|
+
owasp: ["A02:2021"]
|
|
331
|
+
languages: [javascript, typescript]
|
|
332
|
+
patterns:
|
|
333
|
+
- regex: "Access-Control-Allow-Origin[\"']\\s*[\\s,:=]\\s*[\"']\\*[\"']"
|
|
334
|
+
message: CORS header set to wildcard (*)
|
|
335
|
+
- regex: "origin\\s*:\\s*[\"']\\*[\"']"
|
|
336
|
+
message: Express CORS middleware wildcard origin
|
|
337
|
+
fix:
|
|
338
|
+
description: Specify trusted domains instead of a wildcard (*), especially if cookies or credentials are sent.
|
|
339
|
+
tags: [cors, api-security]
|
|
340
|
+
references:
|
|
341
|
+
- https://owasp.org/www-community/attacks/CORS_Origin_Reflection
|
|
342
|
+
|
|
343
|
+
# ── Security: CSRF Disabled ──
|
|
344
|
+
- id: security/csrf-disabled
|
|
345
|
+
name: CSRF Protection Disabled
|
|
346
|
+
description: Detects configurations where CSRF protection has been explicitly disabled
|
|
347
|
+
category: api-security
|
|
348
|
+
subcategory: csrf
|
|
349
|
+
severity: high
|
|
350
|
+
confidence: high
|
|
351
|
+
cwe: [CWE-352]
|
|
352
|
+
owasp: ["A01:2021"]
|
|
353
|
+
languages: [java, kotlin]
|
|
354
|
+
patterns:
|
|
355
|
+
- regex: "csrf\\s*\\(\\s*\\)\\s*\\.\\s*disable\\s*\\(\\s*\\)"
|
|
356
|
+
message: CSRF protection disabled in Spring Security
|
|
357
|
+
fix:
|
|
358
|
+
description: Do not disable CSRF unless using token-based authentication (like JWT) that is not stored in cookies.
|
|
359
|
+
tags: [csrf, api-security]
|
|
360
|
+
references:
|
|
361
|
+
- https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html
|
|
362
|
+
|
|
363
|
+
# ── Security: Missing Rate Limiting ──
|
|
364
|
+
- id: security/missing-rate-limit
|
|
365
|
+
name: Missing Rate Limiting
|
|
366
|
+
description: Detects sensitive authentication endpoints defined without rate limiting middleware
|
|
367
|
+
category: api-security
|
|
368
|
+
subcategory: rate-limiting
|
|
369
|
+
severity: medium
|
|
370
|
+
confidence: high
|
|
371
|
+
cwe: [CWE-770]
|
|
372
|
+
owasp: ["A04:2021-API"]
|
|
373
|
+
languages: [javascript, typescript]
|
|
374
|
+
patterns:
|
|
375
|
+
- regex: "app\\.(?:post|get)\\s*\\(\\s*[\"']\\/api\/auth\/login[\"']\\s*,\\s*(?!(?:[a-zA-Z0-9_]+Limit|limiter)\\b)"
|
|
376
|
+
message: Login route missing rate limit
|
|
377
|
+
- regex: "app\\.(?:post|get)\\s*\\(\\s*[\"']\\/api\/auth\/register[\"']\\s*,\\s*(?!(?:[a-zA-Z0-9_]+Limit|limiter)\\b)"
|
|
378
|
+
message: Registration route missing rate limit
|
|
379
|
+
fix:
|
|
380
|
+
description: Add a rate limiter middleware (e.g., express-rate-limit) to prevent brute-force attacks.
|
|
381
|
+
tags: [rate-limiting, api-security]
|
|
382
|
+
references:
|
|
383
|
+
- https://cheatsheetseries.owasp.org/cheatsheets/Denial_of_Service_Cheat_Sheet.html
|