codewatch-scan 0.1.0__py3-none-any.whl
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.
- codewatch/__init__.py +0 -0
- codewatch/__main__.py +14 -0
- codewatch/asgi.py +16 -0
- codewatch/settings.py +175 -0
- codewatch/urls.py +40 -0
- codewatch/wsgi.py +16 -0
- codewatch_scan-0.1.0.dist-info/METADATA +81 -0
- codewatch_scan-0.1.0.dist-info/RECORD +136 -0
- codewatch_scan-0.1.0.dist-info/WHEEL +5 -0
- codewatch_scan-0.1.0.dist-info/entry_points.txt +4 -0
- codewatch_scan-0.1.0.dist-info/licenses/LICENSE +21 -0
- codewatch_scan-0.1.0.dist-info/top_level.txt +2 -0
- core/__init__.py +0 -0
- core/analyzers/__init__.py +19 -0
- core/analyzers/accessibility.py +199 -0
- core/analyzers/base.py +192 -0
- core/analyzers/body_models.py +154 -0
- core/analyzers/codewatch_checks.py +394 -0
- core/analyzers/constant_branches.py +251 -0
- core/analyzers/containers.py +316 -0
- core/analyzers/coverage.py +131 -0
- core/analyzers/dependencies.py +347 -0
- core/analyzers/drf_serializers.py +65 -0
- core/analyzers/else_branches.py +106 -0
- core/analyzers/extra.py +400 -0
- core/analyzers/flask_resources.py +65 -0
- core/analyzers/inline_scripts.py +50 -0
- core/analyzers/jinja_sandboxes.py +63 -0
- core/analyzers/match_statements.py +148 -0
- core/analyzers/multi_tools.py +888 -0
- core/analyzers/php_template_sinks.py +444 -0
- core/analyzers/project_checks.py +150 -0
- core/analyzers/python_tools.py +333 -0
- core/analyzers/route_converters.py +237 -0
- core/analyzers/slices.py +94 -0
- core/analyzers/starred_targets.py +42 -0
- core/analyzers/stored_fields.py +386 -0
- core/analyzers/summaries.py +1387 -0
- core/analyzers/template_sinks.py +162 -0
- core/api.py +360 -0
- core/apps.py +6 -0
- core/benchmark.py +955 -0
- core/bundled/catalog/codewatch/rules/javascript-crypto.yml +224 -0
- core/bundled/catalog/codewatch/rules/javascript-injection.yml +116 -0
- core/bundled/catalog/codewatch/rules/javascript-taint.yml +1539 -0
- core/bundled/catalog/codewatch/rules/javascript-web.yml +562 -0
- core/bundled/catalog/codewatch/rules/php-web.yml +719 -0
- core/bundled/catalog/codewatch/rules/python-crypto.yml +203 -0
- core/bundled/catalog/codewatch/rules/python-django.yml +267 -0
- core/bundled/catalog/codewatch/rules/python-injection.yml +115 -0
- core/bundled/catalog/codewatch/rules/python-web.yml +3382 -0
- core/bundled/catalog/custom/mappings.json +360 -0
- core/bundled/catalog/custom/overrides.json +4 -0
- core/bundled/catalog/custom/rules/django-settings.yml +19 -0
- core/bundled/catalog/imported/changes.json +5 -0
- core/bundled/catalog/imported/docs.json +1143 -0
- core/bundled/catalog/imported/meta.json +54 -0
- core/bundled/catalog/imported/rules.json +85421 -0
- core/bundled/catalog/imported/standards.json +11191 -0
- core/bundled/tools/analyzers.lock +786 -0
- core/bundled/tools/axe-scan.mjs +45 -0
- core/bundled/tools/checkov.lock +2463 -0
- core/bundled/tools/codewatch-checks.mjs +99 -0
- core/bundled/tools/eslint-a11y.config.js +16 -0
- core/bundled/tools/eslint-quality.config.js +63 -0
- core/bundled/tools/eslint-typed.config.js +18 -0
- core/bundled/tools/package-lock.json +6102 -0
- core/bundled/tools/package.json +32 -0
- core/bundled/tools/rule-metadata.mjs +56 -0
- core/bundled/tools/semgrep.lock +1232 -0
- core/bundled/tools/stylelint.config.json +11 -0
- core/catalog/__init__.py +190 -0
- core/catalog/build.py +84 -0
- core/catalog/merge.py +122 -0
- core/catalog/sources.py +418 -0
- core/catalog/standards.py +119 -0
- core/catalog/update.py +99 -0
- core/catalog_views.py +115 -0
- core/client.py +645 -0
- core/collect.py +518 -0
- core/duplicates.py +60 -0
- core/fingerprint.py +25 -0
- core/folders.py +73 -0
- core/gate.py +77 -0
- core/git.py +149 -0
- core/jobs.py +86 -0
- core/management/__init__.py +0 -0
- core/management/commands/__init__.py +0 -0
- core/management/commands/addproject.py +40 -0
- core/management/commands/buildcatalog.py +15 -0
- core/management/commands/scan.py +74 -0
- core/management/commands/updatecatalog.py +14 -0
- core/mcp_server.py +140 -0
- core/middleware.py +17 -0
- core/migrations/0001_initial.py +115 -0
- core/migrations/0002_auth_tokens_a11y.py +60 -0
- core/migrations/0003_default_admin.py +43 -0
- core/migrations/0004_project_members.py +28 -0
- core/migrations/0005_uploads_and_sources.py +55 -0
- core/migrations/0006_thresholds.py +28 -0
- core/migrations/0007_also_reported_by.py +18 -0
- core/migrations/0008_new_code_period.py +18 -0
- core/migrations/0009_resolution_safe.py +18 -0
- core/migrations/0010_analysis_progress.py +18 -0
- core/migrations/0011_overall_gate_conditions.py +20 -0
- core/migrations/__init__.py +0 -0
- core/models.py +323 -0
- core/network.py +41 -0
- core/paths.py +29 -0
- core/ratings.py +67 -0
- core/runner.py +168 -0
- core/templates/core/account.html +30 -0
- core/templates/core/analysis.html +49 -0
- core/templates/core/base.html +121 -0
- core/templates/core/form_table.html +12 -0
- core/templates/core/gate_badge.html +1 -0
- core/templates/core/index.html +26 -0
- core/templates/core/issues.html +38 -0
- core/templates/core/login.html +13 -0
- core/templates/core/new_project.html +27 -0
- core/templates/core/password_change.html +10 -0
- core/templates/core/project.html +40 -0
- core/templates/core/rating.html +1 -0
- core/templates/core/ratings.html +32 -0
- core/templates/core/rule.html +33 -0
- core/templates/core/rules.html +42 -0
- core/templates/core/scan_progress.html +2 -0
- core/templates/core/settings.html +36 -0
- core/templates/core/source.html +15 -0
- core/templates/core/standards.html +30 -0
- core/templates/core/user_edit.html +15 -0
- core/templates/core/users.html +18 -0
- core/templatetags/__init__.py +0 -0
- core/templatetags/codewatch.py +42 -0
- core/tool_setup.py +68 -0
- core/views.py +564 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
# codewatch built-in rules for misused cryptography, TLS, tokens and request metadata in JavaScript/TypeScript:
|
|
2
|
+
# calls that are wrong whatever data reaches them, so they are reported as vulnerabilities.
|
|
3
|
+
rules:
|
|
4
|
+
- id: codewatch.js.tls-verification-disabled
|
|
5
|
+
languages: [typescript, javascript]
|
|
6
|
+
severity: ERROR
|
|
7
|
+
message: >-
|
|
8
|
+
Certificate verification is switched off, so anyone on the network path can impersonate the server. Keep it
|
|
9
|
+
on; for a private CA pass its certificate (ca: fs.readFileSync(...)) instead.
|
|
10
|
+
metadata:
|
|
11
|
+
category: security
|
|
12
|
+
subcategory: [vuln]
|
|
13
|
+
type: vulnerability
|
|
14
|
+
title: TLS certificate verification disabled
|
|
15
|
+
cwe: ["CWE-295: Improper Certificate Validation"]
|
|
16
|
+
owasp: ["A04:2025 - Cryptographic Failures"]
|
|
17
|
+
references:
|
|
18
|
+
- https://nodejs.org/api/tls.html#tlsconnectoptions-callback
|
|
19
|
+
pattern-either:
|
|
20
|
+
- pattern: '{..., rejectUnauthorized: false, ...}'
|
|
21
|
+
- pattern: process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"
|
|
22
|
+
- pattern: process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0
|
|
23
|
+
|
|
24
|
+
- id: codewatch.js.weak-cipher
|
|
25
|
+
languages: [typescript, javascript]
|
|
26
|
+
severity: ERROR
|
|
27
|
+
message: >-
|
|
28
|
+
This cipher doesn't protect the data: DES, 3DES, RC4 and Blowfish are broken, ECB leaks patterns, and
|
|
29
|
+
createCipher() derives a weak key with no IV. Use createCipheriv("aes-256-gcm", key, randomIv).
|
|
30
|
+
metadata:
|
|
31
|
+
category: security
|
|
32
|
+
subcategory: [vuln]
|
|
33
|
+
type: vulnerability
|
|
34
|
+
title: Weak cipher or ECB mode
|
|
35
|
+
cwe: ["CWE-327: Use of a Broken or Risky Cryptographic Algorithm"]
|
|
36
|
+
owasp: ["A04:2025 - Cryptographic Failures"]
|
|
37
|
+
references:
|
|
38
|
+
- https://nodejs.org/api/crypto.html#cryptocreatecipherivalgorithm-key-iv-options
|
|
39
|
+
pattern-either:
|
|
40
|
+
- pattern: crypto.createCipher(...)
|
|
41
|
+
- pattern: crypto.createDecipher(...)
|
|
42
|
+
- patterns:
|
|
43
|
+
- pattern-either:
|
|
44
|
+
- pattern: crypto.createCipheriv("$ALGO", ...)
|
|
45
|
+
- pattern: crypto.createDecipheriv("$ALGO", ...)
|
|
46
|
+
- metavariable-regex: {metavariable: $ALGO, regex: '(?i)^(des|des-.*|des3|rc2.*|rc4.*|bf.*|blowfish.*|cast.*|idea.*|seed.*|.*-ecb)$'}
|
|
47
|
+
|
|
48
|
+
- id: codewatch.js.static-iv
|
|
49
|
+
languages: [typescript, javascript]
|
|
50
|
+
severity: ERROR
|
|
51
|
+
message: >-
|
|
52
|
+
The IV is a constant, so equal plaintexts encrypt equally (and GCM/CTR key streams repeat). Use
|
|
53
|
+
crypto.randomBytes() for every message and store the IV with the ciphertext.
|
|
54
|
+
metadata:
|
|
55
|
+
category: security
|
|
56
|
+
subcategory: [vuln]
|
|
57
|
+
type: vulnerability
|
|
58
|
+
title: Constant IV
|
|
59
|
+
cwe: ["CWE-329: Generation of Predictable IV with CBC Mode", "CWE-1204: Generation of Weak Initialization Vector (IV)"]
|
|
60
|
+
owasp: ["A04:2025 - Cryptographic Failures"]
|
|
61
|
+
references:
|
|
62
|
+
- https://nodejs.org/api/crypto.html#cryptocreatecipherivalgorithm-key-iv-options
|
|
63
|
+
pattern-either:
|
|
64
|
+
- patterns:
|
|
65
|
+
- pattern: crypto.createCipheriv($ALGO, $KEY, $IV, ...)
|
|
66
|
+
- metavariable-pattern:
|
|
67
|
+
metavariable: $IV
|
|
68
|
+
pattern-either: &js-constant-bytes
|
|
69
|
+
- pattern: '"..."'
|
|
70
|
+
- pattern: Buffer.from("...", ...)
|
|
71
|
+
- pattern: Buffer.alloc($N)
|
|
72
|
+
- pattern: Buffer.alloc($N, ...)
|
|
73
|
+
- pattern: new Uint8Array($N)
|
|
74
|
+
- patterns:
|
|
75
|
+
- pattern: crypto.createCipheriv($ALGO, $KEY, $IV, ...)
|
|
76
|
+
- pattern-inside: |
|
|
77
|
+
const $IV = $INIT
|
|
78
|
+
...
|
|
79
|
+
- metavariable-pattern:
|
|
80
|
+
metavariable: $INIT
|
|
81
|
+
pattern-either: *js-constant-bytes
|
|
82
|
+
|
|
83
|
+
- id: codewatch.js.jwt-insecure
|
|
84
|
+
languages: [typescript, javascript]
|
|
85
|
+
severity: ERROR
|
|
86
|
+
message: >-
|
|
87
|
+
Tokens are signed or accepted with the "none" algorithm, or decoded without verifying the signature, so
|
|
88
|
+
anyone can forge one. Sign and verify with a real algorithm and pass algorithms: [...] to verify().
|
|
89
|
+
metadata:
|
|
90
|
+
category: security
|
|
91
|
+
subcategory: [vuln]
|
|
92
|
+
type: vulnerability
|
|
93
|
+
title: JWT without signature verification
|
|
94
|
+
cwe: ["CWE-347: Improper Verification of Cryptographic Signature"]
|
|
95
|
+
owasp: ["A07:2025 - Authentication Failures"]
|
|
96
|
+
references:
|
|
97
|
+
- https://github.com/auth0/node-jsonwebtoken#jwtverifytoken-secretorpublickey-options-callback
|
|
98
|
+
pattern-either:
|
|
99
|
+
- pattern: 'jwt.sign($PAYLOAD, $KEY, {..., algorithm: "none", ...}, ...)'
|
|
100
|
+
- pattern: 'jwt.verify($TOKEN, $KEY, {..., algorithms: [..., "none", ...], ...}, ...)'
|
|
101
|
+
|
|
102
|
+
- id: codewatch.js.hardcoded-jwt-secret
|
|
103
|
+
languages: [typescript, javascript]
|
|
104
|
+
severity: ERROR
|
|
105
|
+
message: >-
|
|
106
|
+
The JWT signing secret is written in the code, so anyone with the source can mint valid tokens. Load it from
|
|
107
|
+
configuration or a secret store, and rotate it if this was ever committed.
|
|
108
|
+
metadata:
|
|
109
|
+
category: security
|
|
110
|
+
subcategory: [vuln]
|
|
111
|
+
type: vulnerability
|
|
112
|
+
title: Hard-coded JWT secret
|
|
113
|
+
cwe: ["CWE-798: Use of Hard-coded Credentials"]
|
|
114
|
+
owasp: ["A07:2025 - Authentication Failures"]
|
|
115
|
+
references:
|
|
116
|
+
- https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html
|
|
117
|
+
pattern-either:
|
|
118
|
+
- pattern: jwt.sign($PAYLOAD, "...", ...)
|
|
119
|
+
- pattern: jwt.verify($TOKEN, "...", ...)
|
|
120
|
+
|
|
121
|
+
- id: codewatch.js.weak-random-secret
|
|
122
|
+
languages: [typescript, javascript]
|
|
123
|
+
severity: WARNING
|
|
124
|
+
message: >-
|
|
125
|
+
Math.random() is predictable, and here it makes a token, password or id that an attacker must not guess.
|
|
126
|
+
Use crypto.randomBytes(), crypto.randomUUID() or crypto.getRandomValues().
|
|
127
|
+
metadata:
|
|
128
|
+
category: security
|
|
129
|
+
subcategory: [vuln]
|
|
130
|
+
type: vulnerability
|
|
131
|
+
title: Math.random() used for a secret
|
|
132
|
+
cwe: ["CWE-338: Use of Cryptographically Weak Pseudo-Random Number Generator (PRNG)"]
|
|
133
|
+
owasp: ["A04:2025 - Cryptographic Failures"]
|
|
134
|
+
references:
|
|
135
|
+
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
|
|
136
|
+
patterns:
|
|
137
|
+
- pattern: Math.random()
|
|
138
|
+
# A generated display value (linkwarden: { username: "user" + Math.round(Math.random() * 1e9) }) isn't a secret.
|
|
139
|
+
- pattern-not-inside: '{..., username: <... Math.random() ...>, ...}'
|
|
140
|
+
- pattern-not-inside: '{..., name: <... Math.random() ...>, ...}'
|
|
141
|
+
- pattern-not-inside: '{..., nickname: <... Math.random() ...>, ...}'
|
|
142
|
+
- pattern-not-inside: '{..., displayName: <... Math.random() ...>, ...}'
|
|
143
|
+
- pattern-not-inside: '{..., label: <... Math.random() ...>, ...}'
|
|
144
|
+
- pattern-not-inside: '{..., title: <... Math.random() ...>, ...}'
|
|
145
|
+
- pattern-not-inside: '{..., color: <... Math.random() ...>, ...}'
|
|
146
|
+
- pattern-either:
|
|
147
|
+
# Inside a function named for secrets, unless it goes to a variable named for display: a
|
|
148
|
+
# generated username in an auth callback (linkwarden: "user" + Math.round(Math.random() * 1e9)).
|
|
149
|
+
- patterns:
|
|
150
|
+
- pattern-inside: |
|
|
151
|
+
function $FN(...) { ... }
|
|
152
|
+
- metavariable-regex: {metavariable: $FN, regex: &secret-name '(?i).*(token|secret|passw|nonce|salt|otp|csrf|session_?id|api_?key|auth|cred|uuid).*'}
|
|
153
|
+
- ¬-a-display-name
|
|
154
|
+
pattern-either:
|
|
155
|
+
- patterns:
|
|
156
|
+
- pattern: Math.random()
|
|
157
|
+
- pattern-not-inside: const $SHOWN = <... Math.random() ...>
|
|
158
|
+
- pattern-not-inside: let $SHOWN = <... Math.random() ...>
|
|
159
|
+
- patterns:
|
|
160
|
+
- pattern-either:
|
|
161
|
+
- pattern-inside: const $SHOWN = <... Math.random() ...>
|
|
162
|
+
- pattern-inside: let $SHOWN = <... Math.random() ...>
|
|
163
|
+
- metavariable-regex:
|
|
164
|
+
metavariable: $SHOWN
|
|
165
|
+
regex: '^(?!(?i:.*(user_?name|nick_?name|display_?name|label|title|colou?r|avatar|placeholder))).*$'
|
|
166
|
+
- patterns:
|
|
167
|
+
- pattern-inside: |
|
|
168
|
+
const $FN = (...) => { ... }
|
|
169
|
+
- metavariable-regex: {metavariable: $FN, regex: *secret-name}
|
|
170
|
+
- *not-a-display-name
|
|
171
|
+
- patterns:
|
|
172
|
+
- pattern-inside: |
|
|
173
|
+
$FN(...) { ... }
|
|
174
|
+
- metavariable-regex: {metavariable: $FN, regex: *secret-name}
|
|
175
|
+
- *not-a-display-name
|
|
176
|
+
- patterns:
|
|
177
|
+
- pattern-inside: const $VAR = <... Math.random() ...>
|
|
178
|
+
- metavariable-regex: {metavariable: $VAR, regex: *secret-name}
|
|
179
|
+
- patterns:
|
|
180
|
+
- pattern-inside: $OBJ.$VAR = <... Math.random() ...>
|
|
181
|
+
- metavariable-regex: {metavariable: $VAR, regex: *secret-name}
|
|
182
|
+
|
|
183
|
+
- id: codewatch.js.rate-limit-spoofable-key
|
|
184
|
+
languages: [typescript, javascript]
|
|
185
|
+
severity: WARNING
|
|
186
|
+
message: >-
|
|
187
|
+
The rate limit is keyed on X-Forwarded-For, which the client sets, so changing the header resets the limit.
|
|
188
|
+
Key on req.ip with Express's "trust proxy" set to your actual proxy count.
|
|
189
|
+
metadata:
|
|
190
|
+
category: security
|
|
191
|
+
subcategory: [vuln]
|
|
192
|
+
type: vulnerability
|
|
193
|
+
title: Rate limit keyed on a client-controlled header
|
|
194
|
+
cwe: ["CWE-348: Use of Less Trusted Source", "CWE-307: Improper Restriction of Excessive Authentication Attempts"]
|
|
195
|
+
owasp: ["A07:2025 - Authentication Failures"]
|
|
196
|
+
references:
|
|
197
|
+
- https://express-rate-limit.mintlify.app/reference/configuration#keygenerator
|
|
198
|
+
- https://expressjs.com/en/guide/behind-proxies.html
|
|
199
|
+
patterns:
|
|
200
|
+
- pattern-inside: $LIMIT({...})
|
|
201
|
+
- metavariable-regex: {metavariable: $LIMIT, regex: '(?i)^(.*\.)?(rate_?limit|ratelimiter|slow_?down|limiter)\w{0,20}$'}
|
|
202
|
+
- pattern-either:
|
|
203
|
+
- pattern: $HEADERS["=~/(?i)^x-forwarded-for$/"]
|
|
204
|
+
- pattern: $REQ.get("=~/(?i)^x-forwarded-for$/")
|
|
205
|
+
- pattern: $REQ.header("=~/(?i)^x-forwarded-for$/")
|
|
206
|
+
|
|
207
|
+
- id: codewatch.js.xml-external-entities
|
|
208
|
+
languages: [typescript, javascript]
|
|
209
|
+
severity: ERROR
|
|
210
|
+
message: >-
|
|
211
|
+
External entities are expanded for this XML, so a crafted document can read local files or make network
|
|
212
|
+
requests (XXE). Leave noent off.
|
|
213
|
+
metadata:
|
|
214
|
+
category: security
|
|
215
|
+
subcategory: [vuln]
|
|
216
|
+
type: vulnerability
|
|
217
|
+
title: XML parsed with external entities enabled
|
|
218
|
+
cwe: ["CWE-611: Improper Restriction of XML External Entity Reference"]
|
|
219
|
+
owasp: ["A02:2025 - Security Misconfiguration"]
|
|
220
|
+
references:
|
|
221
|
+
- https://cheatsheetseries.owasp.org/cheatsheets/XML_External_Entity_Prevention_Cheat_Sheet.html
|
|
222
|
+
pattern-either:
|
|
223
|
+
- pattern: '$LIB.parseXml($XML, {..., noent: true, ...})'
|
|
224
|
+
- pattern: '$LIB.parseXmlString($XML, {..., noent: true, ...})'
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# codewatch built-in rules for JavaScript/TypeScript injection flaws visible in the code itself, wherever the data
|
|
2
|
+
# comes from: a value spliced into a query, or a recursive merge that lets "__proto__" through.
|
|
3
|
+
rules:
|
|
4
|
+
- id: codewatch.js.sql-value-formatting
|
|
5
|
+
languages: [typescript, javascript]
|
|
6
|
+
severity: ERROR
|
|
7
|
+
message: >-
|
|
8
|
+
A value is concatenated into the SQL text where the query compares or stores it, so a quote in it changes
|
|
9
|
+
the query (SQL injection). Pass it as a bound parameter: db.query("... WHERE name = $1", [name]).
|
|
10
|
+
metadata:
|
|
11
|
+
category: security
|
|
12
|
+
subcategory: [vuln]
|
|
13
|
+
type: vulnerability
|
|
14
|
+
title: Value concatenated into SQL instead of bound
|
|
15
|
+
cwe: ["CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')"]
|
|
16
|
+
owasp: ["A05:2025 - Injection"]
|
|
17
|
+
references:
|
|
18
|
+
- https://node-postgres.com/features/queries#parameterized-query
|
|
19
|
+
- https://cheatsheetseries.owasp.org/cheatsheets/Query_Parameterization_Cheat_Sheet.html
|
|
20
|
+
# Only values inside SQL quotes, which are always data that should have been bound: table and column names
|
|
21
|
+
# can't be bound, and an unquoted value is often a number (the taint rules cover request data there).
|
|
22
|
+
pattern-either:
|
|
23
|
+
- patterns:
|
|
24
|
+
- pattern-either:
|
|
25
|
+
- pattern: $DB.$EXEC("$SQL" + $VALUE, ...)
|
|
26
|
+
- pattern: $DB.$EXEC("$SQL" + $VALUE + $REST, ...)
|
|
27
|
+
- patterns:
|
|
28
|
+
- pattern: $DB.$EXEC($QUERY, ...)
|
|
29
|
+
- pattern-either:
|
|
30
|
+
- pattern-inside: |
|
|
31
|
+
$QUERY = "$SQL" + $VALUE
|
|
32
|
+
...
|
|
33
|
+
- pattern-inside: |
|
|
34
|
+
$QUERY = "$SQL" + $VALUE + $REST
|
|
35
|
+
...
|
|
36
|
+
- metavariable-regex: {metavariable: $EXEC, regex: ^(query|execute|raw|run|all|get|exec|prepare|\$queryRawUnsafe|\$executeRawUnsafe)$}
|
|
37
|
+
- metavariable-regex:
|
|
38
|
+
metavariable: $SQL
|
|
39
|
+
regex: (?is)^\s*(select|insert|update|delete|with|replace|merge)\b.*['"]$
|
|
40
|
+
- pattern-not: $DB.$EXEC("$SQL" + "..." + $REST, ...)
|
|
41
|
+
- patterns:
|
|
42
|
+
- pattern-either:
|
|
43
|
+
- pattern: $DB.$EXEC($QUERY, ...)
|
|
44
|
+
- patterns:
|
|
45
|
+
- pattern: $DB.$EXEC($VAR, ...)
|
|
46
|
+
- pattern-inside: |
|
|
47
|
+
$VAR = $QUERY
|
|
48
|
+
...
|
|
49
|
+
- metavariable-regex: {metavariable: $EXEC, regex: ^(query|execute|raw|run|all|get|exec|prepare|\$queryRawUnsafe|\$executeRawUnsafe)$}
|
|
50
|
+
- metavariable-pattern:
|
|
51
|
+
metavariable: $QUERY
|
|
52
|
+
patterns:
|
|
53
|
+
- pattern: '`...`'
|
|
54
|
+
- pattern-regex: (?is)^`\s*(select|insert|update|delete|with|replace|merge)\b.*['"]\$\{[^}]{1,80}\}['"]
|
|
55
|
+
|
|
56
|
+
- id: codewatch.js.prototype-pollution-merge
|
|
57
|
+
languages: [typescript, javascript]
|
|
58
|
+
severity: ERROR
|
|
59
|
+
message: >-
|
|
60
|
+
This recursive merge copies every key of the source, including "__proto__" and "constructor", so merging
|
|
61
|
+
JSON from a request can change Object.prototype for the whole process. Skip those keys, or merge into
|
|
62
|
+
Object.create(null).
|
|
63
|
+
metadata:
|
|
64
|
+
category: security
|
|
65
|
+
subcategory: [vuln]
|
|
66
|
+
type: vulnerability
|
|
67
|
+
title: Recursive merge without a prototype-key check
|
|
68
|
+
cwe: ["CWE-1321: Improperly Controlled Modification of Object Prototype Attributes ('Prototype Pollution')"]
|
|
69
|
+
owasp: ["A08:2025 - Software or Data Integrity Failures"]
|
|
70
|
+
references:
|
|
71
|
+
- https://cheatsheetseries.owasp.org/cheatsheets/Prototype_Pollution_Prevention_Cheat_Sheet.html
|
|
72
|
+
patterns:
|
|
73
|
+
- pattern: $TARGET[$KEY] = $SOURCE[$KEY]
|
|
74
|
+
- pattern-either:
|
|
75
|
+
- pattern-inside: |
|
|
76
|
+
function $MERGE($TARGET, $SOURCE, ...) {
|
|
77
|
+
...
|
|
78
|
+
$MERGE($TARGET[$KEY], $SOURCE[$KEY], ...);
|
|
79
|
+
...
|
|
80
|
+
}
|
|
81
|
+
- pattern-inside: |
|
|
82
|
+
function $MERGE($TARGET, $SOURCE, ...) {
|
|
83
|
+
...
|
|
84
|
+
for (...) {
|
|
85
|
+
...
|
|
86
|
+
$MERGE($TARGET[$KEY], $SOURCE[$KEY], ...);
|
|
87
|
+
...
|
|
88
|
+
}
|
|
89
|
+
...
|
|
90
|
+
}
|
|
91
|
+
- pattern-not-inside: |
|
|
92
|
+
function $MERGE(...) {
|
|
93
|
+
...
|
|
94
|
+
if (<... "__proto__" ...>) $STMT;
|
|
95
|
+
...
|
|
96
|
+
}
|
|
97
|
+
- pattern-not-inside: |
|
|
98
|
+
function $MERGE(...) {
|
|
99
|
+
...
|
|
100
|
+
for (...) {
|
|
101
|
+
...
|
|
102
|
+
if (<... "__proto__" ...>) $STMT;
|
|
103
|
+
...
|
|
104
|
+
}
|
|
105
|
+
...
|
|
106
|
+
}
|
|
107
|
+
- pattern-not-inside: |
|
|
108
|
+
function $MERGE(...) {
|
|
109
|
+
...
|
|
110
|
+
for (...) {
|
|
111
|
+
...
|
|
112
|
+
if (<... "__proto__" ...>) { ... }
|
|
113
|
+
...
|
|
114
|
+
}
|
|
115
|
+
...
|
|
116
|
+
}
|