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,562 @@
|
|
|
1
|
+
# codewatch built-in rules for JavaScript/TypeScript web code (Express, Angular, MongoDB).
|
|
2
|
+
rules:
|
|
3
|
+
- id: codewatch.js.angular-bypass-sanitizer
|
|
4
|
+
languages: [typescript, javascript]
|
|
5
|
+
severity: ERROR
|
|
6
|
+
message: >-
|
|
7
|
+
Angular's sanitizer is bypassed for a value that isn't a fixed string, so HTML or script in it reaches the
|
|
8
|
+
page. Let Angular sanitize it (bind to [innerHTML] without bypassing), or only bypass for constants.
|
|
9
|
+
metadata:
|
|
10
|
+
category: security
|
|
11
|
+
subcategory: [vuln]
|
|
12
|
+
type: vulnerability
|
|
13
|
+
title: Angular sanitizer bypassed for dynamic data
|
|
14
|
+
cwe: ["CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')"]
|
|
15
|
+
owasp: ["A05:2025 - Injection"]
|
|
16
|
+
references:
|
|
17
|
+
- https://angular.dev/best-practices/security#bypass-security-apis-sparingly
|
|
18
|
+
- https://angular.dev/api/platform-browser/DomSanitizer
|
|
19
|
+
patterns:
|
|
20
|
+
- pattern: $SANITIZER.$BYPASS($VALUE)
|
|
21
|
+
- metavariable-regex: {metavariable: $BYPASS, regex: '^bypassSecurityTrust(Html|Script|Style|Url|ResourceUrl)$'}
|
|
22
|
+
- pattern-not: $SANITIZER.$BYPASS("...")
|
|
23
|
+
- pattern-not: $SANITIZER.$BYPASS(`...`)
|
|
24
|
+
|
|
25
|
+
- id: codewatch.js.substring-url-allowlist
|
|
26
|
+
languages: [typescript, javascript]
|
|
27
|
+
severity: WARNING
|
|
28
|
+
message: >-
|
|
29
|
+
A URL is checked against an allowlist with a substring test, so "https://evil.example/?https://good.example"
|
|
30
|
+
passes. Parse the URL (new URL(value)) and compare its origin or hostname exactly.
|
|
31
|
+
metadata:
|
|
32
|
+
category: security
|
|
33
|
+
subcategory: [vuln]
|
|
34
|
+
type: vulnerability
|
|
35
|
+
title: URL allowlist checked with a substring test
|
|
36
|
+
cwe: ["CWE-20: Improper Input Validation", "CWE-601: URL Redirection to Untrusted Site ('Open Redirect')"]
|
|
37
|
+
owasp: ["A01:2025 - Broken Access Control"]
|
|
38
|
+
references:
|
|
39
|
+
- https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html
|
|
40
|
+
- https://developer.mozilla.org/en-US/docs/Web/API/URL
|
|
41
|
+
patterns:
|
|
42
|
+
- pattern-either:
|
|
43
|
+
- pattern: $URL.includes($ALLOWED)
|
|
44
|
+
- pattern: $URL.indexOf($ALLOWED) !== -1
|
|
45
|
+
- pattern: $URL.indexOf($ALLOWED) > -1
|
|
46
|
+
- pattern: $URL.indexOf($ALLOWED) >= 0
|
|
47
|
+
- metavariable-regex: {metavariable: $URL, regex: '(?i).*(url|uri|redirect|href|location|target|returnto|next)'}
|
|
48
|
+
- metavariable-regex: {metavariable: $ALLOWED, regex: '(?i).*(allow|white|trusted|safe|permitted)'}
|
|
49
|
+
|
|
50
|
+
- id: codewatch.js.nosql-injection
|
|
51
|
+
mode: taint
|
|
52
|
+
languages: [typescript, javascript]
|
|
53
|
+
severity: ERROR
|
|
54
|
+
message: >-
|
|
55
|
+
A value from the request body is placed directly in a MongoDB query. A JSON body can send an object such as
|
|
56
|
+
{"$ne": null} instead of a string and change what the query matches. Convert it to the expected type
|
|
57
|
+
(String(), Number()) or validate it first.
|
|
58
|
+
metadata:
|
|
59
|
+
category: security
|
|
60
|
+
subcategory: [vuln]
|
|
61
|
+
type: vulnerability
|
|
62
|
+
title: Request body used in a MongoDB query
|
|
63
|
+
cwe: ["CWE-943: Improper Neutralization of Special Elements in Data Query Logic"]
|
|
64
|
+
owasp: ["A05:2025 - Injection"]
|
|
65
|
+
references:
|
|
66
|
+
- https://cheatsheetseries.owasp.org/cheatsheets/Injection_Prevention_Cheat_Sheet.html
|
|
67
|
+
- https://www.mongodb.com/docs/manual/core/server-side-javascript/
|
|
68
|
+
pattern-sources:
|
|
69
|
+
- pattern: $REQ.body
|
|
70
|
+
- pattern: $REQ.query
|
|
71
|
+
pattern-sanitizers:
|
|
72
|
+
- pattern: String(...)
|
|
73
|
+
- pattern: Number(...)
|
|
74
|
+
- pattern: parseInt(...)
|
|
75
|
+
- pattern: $X.toString()
|
|
76
|
+
pattern-sinks:
|
|
77
|
+
# $where runs as JavaScript on the database server, so request data in it is code, whatever its type.
|
|
78
|
+
- patterns:
|
|
79
|
+
- pattern-either:
|
|
80
|
+
- pattern: '{..., $where: $QUERY, ...}'
|
|
81
|
+
- pattern: '{..., "$where": $QUERY, ...}'
|
|
82
|
+
- pattern: $MODEL.$where($QUERY)
|
|
83
|
+
- focus-metavariable: $QUERY
|
|
84
|
+
- patterns:
|
|
85
|
+
- pattern: $COLL.$METHOD($QUERY, ...)
|
|
86
|
+
- metavariable-regex: {metavariable: $COLL, regex: '(?i).*(collection|mongo)'}
|
|
87
|
+
- metavariable-regex:
|
|
88
|
+
metavariable: $METHOD
|
|
89
|
+
regex: '^(find|findOne|update|updateOne|updateMany|remove|deleteOne|deleteMany|count|countDocuments|findOneAndUpdate|findOneAndDelete|findOneAndReplace|replaceOne)$'
|
|
90
|
+
- focus-metavariable: $QUERY
|
|
91
|
+
|
|
92
|
+
- id: codewatch.js.unauthenticated-metrics
|
|
93
|
+
languages: [typescript, javascript]
|
|
94
|
+
severity: INFO
|
|
95
|
+
message: >-
|
|
96
|
+
The metrics endpoint is served with no middleware in front of it, so anyone can read internal counters,
|
|
97
|
+
paths and versions. Put it behind authentication or serve it on an internal-only port.
|
|
98
|
+
metadata:
|
|
99
|
+
category: security
|
|
100
|
+
subcategory: [audit]
|
|
101
|
+
type: security_hotspot
|
|
102
|
+
title: Metrics endpoint without authentication
|
|
103
|
+
cwe: ["CWE-200: Exposure of Sensitive Information to an Unauthorized Actor"]
|
|
104
|
+
owasp: ["A02:2025 - Security Misconfiguration"]
|
|
105
|
+
references:
|
|
106
|
+
- https://prometheus.io/docs/operating/security/
|
|
107
|
+
pattern-either:
|
|
108
|
+
- pattern: $APP.get("/metrics", $HANDLER)
|
|
109
|
+
- pattern: $APP.use("/metrics", $HANDLER)
|
|
110
|
+
|
|
111
|
+
- id: codewatch.js.weak-hash
|
|
112
|
+
languages: [typescript, javascript]
|
|
113
|
+
severity: WARNING
|
|
114
|
+
message: >-
|
|
115
|
+
MD4, MD5 and SHA-1 are broken for security use. Use SHA-256 or better, or a password hash
|
|
116
|
+
(scrypt, argon2, bcrypt) for passwords.
|
|
117
|
+
metadata:
|
|
118
|
+
category: security
|
|
119
|
+
subcategory: [vuln]
|
|
120
|
+
type: vulnerability
|
|
121
|
+
title: Weak hash algorithm
|
|
122
|
+
security-purpose: required
|
|
123
|
+
cwe: ["CWE-328: Use of Weak Hash"]
|
|
124
|
+
owasp: ["A04:2025 - Cryptographic Failures"]
|
|
125
|
+
references:
|
|
126
|
+
- https://nodejs.org/api/crypto.html#cryptocreatehashalgorithm-options
|
|
127
|
+
- https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html
|
|
128
|
+
pattern: $CRYPTO.createHash("=~/(?i)^(md4|md5|sha1|sha-1|ripemd160)$/", ...)
|
|
129
|
+
|
|
130
|
+
- id: codewatch.js.directory-listing
|
|
131
|
+
languages: [typescript, javascript]
|
|
132
|
+
severity: WARNING
|
|
133
|
+
message: >-
|
|
134
|
+
Directory listing is switched on for this path, so anyone can browse every file in the folder, including
|
|
135
|
+
ones nobody linked to (backups, logs, keys). Serve the files that are meant to be public by name instead.
|
|
136
|
+
metadata:
|
|
137
|
+
category: security
|
|
138
|
+
subcategory: [vuln]
|
|
139
|
+
type: vulnerability
|
|
140
|
+
title: Directory listing enabled
|
|
141
|
+
cwe: ["CWE-548: Exposure of Information Through Directory Listing"]
|
|
142
|
+
owasp: ["A02:2025 - Security Misconfiguration"]
|
|
143
|
+
references:
|
|
144
|
+
- https://github.com/expressjs/serve-index#readme
|
|
145
|
+
pattern-either:
|
|
146
|
+
- pattern: $APP.use(..., serveIndex(...), ...)
|
|
147
|
+
- pattern: $APP.use(..., $MOD.serveIndex(...), ...)
|
|
148
|
+
|
|
149
|
+
- id: codewatch.js.template-autoescape-disabled
|
|
150
|
+
languages: [typescript, javascript]
|
|
151
|
+
severity: ERROR
|
|
152
|
+
message: >-
|
|
153
|
+
HTML escaping is switched off for every template this engine renders, so any request data a template prints
|
|
154
|
+
becomes markup and script (XSS). Leave autoescape on and mark the few trusted fragments safe one by one.
|
|
155
|
+
metadata:
|
|
156
|
+
category: security
|
|
157
|
+
subcategory: [vuln]
|
|
158
|
+
type: vulnerability
|
|
159
|
+
title: Template auto-escaping disabled
|
|
160
|
+
cwe: ["CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')"]
|
|
161
|
+
owasp: ["A05:2025 - Injection"]
|
|
162
|
+
references:
|
|
163
|
+
- https://mozilla.github.io/nunjucks/api.html#configure
|
|
164
|
+
- https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html
|
|
165
|
+
pattern-either:
|
|
166
|
+
- pattern: '$SWIG.setDefaults({..., autoescape: false, ...})'
|
|
167
|
+
- pattern: '$NUNJUCKS.configure(..., {..., autoescape: false, ...})'
|
|
168
|
+
- pattern: '$NUNJUCKS.configure({..., autoescape: false, ...})'
|
|
169
|
+
- pattern: 'new $ENV(..., {..., autoescape: false, ...})'
|
|
170
|
+
- pattern: '$HANDLEBARS.compile($TEMPLATE, {..., noEscape: true, ...})'
|
|
171
|
+
|
|
172
|
+
- id: codewatch.js.unrestricted-upload
|
|
173
|
+
languages: [typescript, javascript]
|
|
174
|
+
severity: WARNING
|
|
175
|
+
message: >-
|
|
176
|
+
An uploaded file is stored under the name the client sent, extension included. An .html, .svg or script
|
|
177
|
+
file served back from this site runs as part of it. Check the extension and type against an allowlist
|
|
178
|
+
(multer's fileFilter), or store the file under a generated name with an extension you choose.
|
|
179
|
+
# For review: harmless if the folder is never served; multer and busboy already drop any directory part.
|
|
180
|
+
metadata:
|
|
181
|
+
category: security
|
|
182
|
+
subcategory: [audit]
|
|
183
|
+
type: security_hotspot
|
|
184
|
+
title: Upload stored under the client's file name
|
|
185
|
+
cwe: ["CWE-434: Unrestricted Upload of File with Dangerous Type"]
|
|
186
|
+
owasp: ["A06:2025 - Insecure Design"]
|
|
187
|
+
references:
|
|
188
|
+
- https://cheatsheetseries.owasp.org/cheatsheets/File_Upload_Cheat_Sheet.html
|
|
189
|
+
- https://github.com/expressjs/multer#diskstorage
|
|
190
|
+
pattern-either:
|
|
191
|
+
# multer.diskStorage({ filename: (req, file, cb) => cb(null, Date.now() + "-" + file.originalname) })
|
|
192
|
+
- patterns:
|
|
193
|
+
- pattern-inside: multer.diskStorage({...})
|
|
194
|
+
- pattern: '$CB(null, <... $FILE.originalname ...>)'
|
|
195
|
+
- pattern-not: '$CB(null, <... path.parse($FILE.originalname).name ...>)'
|
|
196
|
+
# The same options check the type: { fileFilter, storage: diskStorage({ filename }) }
|
|
197
|
+
- pattern-not-inside: '$FN({..., fileFilter: $FILTER, ...})'
|
|
198
|
+
- pattern-not-inside: '({..., fileFilter: $FILTER, ...})'
|
|
199
|
+
- pattern-not-inside: '$FN({..., fileFilter: (...) => $BODY, ...})'
|
|
200
|
+
- pattern-not-inside: '({..., fileFilter: (...) => $BODY, ...})'
|
|
201
|
+
- pattern-not-inside: '$FN({..., fileFilter: function (...) { ... }, ...})'
|
|
202
|
+
- pattern-not-inside: '({..., fileFilter: function (...) { ... }, ...})'
|
|
203
|
+
- pattern-not-inside: '$FN({..., fileFilter, ...})'
|
|
204
|
+
- pattern-not-inside: '({..., fileFilter, ...})'
|
|
205
|
+
- pattern-not-inside: '$FN({..., fileFilter(...) { ... }, ...})'
|
|
206
|
+
- pattern-not-inside: '({..., fileFilter(...) { ... }, ...})'
|
|
207
|
+
# express-fileupload: file.mv(dir + file.name)
|
|
208
|
+
- patterns:
|
|
209
|
+
- pattern: '$FILE.mv(<... $FILE.name ...>, ...)'
|
|
210
|
+
|
|
211
|
+
- id: codewatch.js.mass-assignment
|
|
212
|
+
languages: [typescript, javascript]
|
|
213
|
+
severity: WARNING
|
|
214
|
+
message: >-
|
|
215
|
+
The whole request body is written to a model, so a client can also set fields the form never offers
|
|
216
|
+
(isAdmin, role, ownerId, price). Pick the fields this route should change, or validate the body against a
|
|
217
|
+
schema that strips unknown keys.
|
|
218
|
+
# For review: fine if the model has no field a client mustn't set, or validation middleware strips them.
|
|
219
|
+
metadata:
|
|
220
|
+
category: security
|
|
221
|
+
subcategory: [audit]
|
|
222
|
+
type: security_hotspot
|
|
223
|
+
title: Whole request body assigned to a model
|
|
224
|
+
cwe: ["CWE-915: Improperly Controlled Modification of Dynamically-Determined Object Attributes"]
|
|
225
|
+
owasp: ["A08:2025 - Software or Data Integrity Failures"]
|
|
226
|
+
references:
|
|
227
|
+
- https://cheatsheetseries.owasp.org/cheatsheets/Mass_Assignment_Cheat_Sheet.html
|
|
228
|
+
patterns:
|
|
229
|
+
# The body itself, spread into an object, or a variable holding it.
|
|
230
|
+
- pattern-either:
|
|
231
|
+
- patterns:
|
|
232
|
+
- pattern-either: &js-model-writes
|
|
233
|
+
- patterns:
|
|
234
|
+
- pattern-either:
|
|
235
|
+
- pattern: $MODEL.create($BODY, ...)
|
|
236
|
+
- pattern: $MODEL.insertMany($BODY, ...)
|
|
237
|
+
- pattern: $MODEL.build($BODY, ...)
|
|
238
|
+
- pattern: $MODEL.update($BODY, ...)
|
|
239
|
+
- pattern: $MODEL.findByIdAndUpdate($ID, $BODY, ...)
|
|
240
|
+
- pattern: $MODEL.findOneAndUpdate($FILTER, $BODY, ...)
|
|
241
|
+
- pattern: $MODEL.updateOne($FILTER, $BODY, ...)
|
|
242
|
+
- pattern: $MODEL.updateMany($FILTER, $BODY, ...)
|
|
243
|
+
- pattern: new $MODEL($BODY)
|
|
244
|
+
- metavariable-regex: {metavariable: $MODEL, regex: '^[A-Z]\w*$'}
|
|
245
|
+
- pattern: $REPO.save($BODY)
|
|
246
|
+
- pattern: '$PRISMA.$TABLE.create({..., data: $BODY, ...})'
|
|
247
|
+
- pattern: '$PRISMA.$TABLE.update({..., data: $BODY, ...})'
|
|
248
|
+
- pattern: '$PRISMA.$TABLE.upsert({..., update: $BODY, ...})'
|
|
249
|
+
- pattern: Object.assign($TARGET, $BODY)
|
|
250
|
+
- pattern: $DOC.set($BODY)
|
|
251
|
+
- metavariable-regex: &js-whole-body
|
|
252
|
+
metavariable: $BODY
|
|
253
|
+
regex: '^((req|request|ctx\.request)\.body|\{[\s\S]*\.\.\.\s*(req|request|ctx\.request)\.body\s*(,[\s\S]*)?\})$'
|
|
254
|
+
- patterns:
|
|
255
|
+
- pattern-either: *js-model-writes
|
|
256
|
+
- pattern-either:
|
|
257
|
+
- pattern-inside: |
|
|
258
|
+
const $BODY = $WHOLE;
|
|
259
|
+
...
|
|
260
|
+
- pattern-inside: |
|
|
261
|
+
let $BODY = $WHOLE;
|
|
262
|
+
...
|
|
263
|
+
- pattern-inside: |
|
|
264
|
+
$BODY = $WHOLE;
|
|
265
|
+
...
|
|
266
|
+
- metavariable-regex:
|
|
267
|
+
<<: *js-whole-body
|
|
268
|
+
metavariable: $WHOLE
|
|
269
|
+
- focus-metavariable: $BODY
|
|
270
|
+
|
|
271
|
+
- id: codewatch.js.cors-any-origin-with-credentials
|
|
272
|
+
languages: [typescript, javascript]
|
|
273
|
+
severity: ERROR
|
|
274
|
+
message: >-
|
|
275
|
+
CORS echoes back whatever Origin the browser sends and also allows credentials, so any website can make
|
|
276
|
+
logged-in requests to this API and read the answers. List the origins that may call it.
|
|
277
|
+
metadata:
|
|
278
|
+
category: security
|
|
279
|
+
subcategory: [vuln]
|
|
280
|
+
type: vulnerability
|
|
281
|
+
title: Any origin allowed together with credentials
|
|
282
|
+
cwe: ["CWE-942: Permissive Cross-domain Security Policy with Untrusted Domains"]
|
|
283
|
+
owasp: ["A02:2025 - Security Misconfiguration"]
|
|
284
|
+
references:
|
|
285
|
+
- https://portswigger.net/web-security/cors
|
|
286
|
+
- https://github.com/expressjs/cors#configuration-options
|
|
287
|
+
pattern-either:
|
|
288
|
+
# The cors package: origin: true (or a callback that accepts everything) reflects the request's Origin.
|
|
289
|
+
- patterns:
|
|
290
|
+
- pattern-either:
|
|
291
|
+
- pattern: 'cors({..., origin: true, ...})'
|
|
292
|
+
- pattern: 'cors({..., origin: ($O, $CB) => $CB(null, true), ...})'
|
|
293
|
+
- pattern: 'cors({..., origin: function ($O, $CB) { $CB(null, true); }, ...})'
|
|
294
|
+
- pattern: '$APP.enableCors({..., origin: true, ...})'
|
|
295
|
+
- pattern-either:
|
|
296
|
+
- pattern: 'cors({..., credentials: true, ...})'
|
|
297
|
+
- pattern: '$APP.enableCors({..., credentials: true, ...})'
|
|
298
|
+
# By hand: the request's Origin echoed on a response that also allows credentials.
|
|
299
|
+
- patterns:
|
|
300
|
+
- pattern-either:
|
|
301
|
+
- pattern: |
|
|
302
|
+
$RES.$SET($ACAO, <... $REQ.headers.origin ...>);
|
|
303
|
+
...
|
|
304
|
+
$RES.$SET2($ACAC, $TRUE);
|
|
305
|
+
- pattern: |
|
|
306
|
+
$RES.$SET2($ACAC, $TRUE);
|
|
307
|
+
...
|
|
308
|
+
$RES.$SET($ACAO, <... $REQ.headers.origin ...>);
|
|
309
|
+
- pattern: |
|
|
310
|
+
$RES.$SET($ACAO, <... $REQ.get($ORIGIN) ...>);
|
|
311
|
+
...
|
|
312
|
+
$RES.$SET2($ACAC, $TRUE);
|
|
313
|
+
- pattern: |
|
|
314
|
+
$RES.$SET2($ACAC, $TRUE);
|
|
315
|
+
...
|
|
316
|
+
$RES.$SET($ACAO, <... $REQ.get($ORIGIN) ...>);
|
|
317
|
+
- pattern: |
|
|
318
|
+
$RES.$SET($ACAO, <... $REQ.header($ORIGIN) ...>);
|
|
319
|
+
...
|
|
320
|
+
$RES.$SET2($ACAC, $TRUE);
|
|
321
|
+
- pattern: |
|
|
322
|
+
$RES.$SET2($ACAC, $TRUE);
|
|
323
|
+
...
|
|
324
|
+
$RES.$SET($ACAO, <... $REQ.header($ORIGIN) ...>);
|
|
325
|
+
# An allowlist check around it means only listed origins are echoed.
|
|
326
|
+
- pattern-not-inside: 'if ($COND) { ... }'
|
|
327
|
+
- pattern-not-inside: '$COND ? $A : $B'
|
|
328
|
+
- metavariable-regex: {metavariable: $SET, regex: '^(setHeader|header|set|append)$'}
|
|
329
|
+
- metavariable-regex: {metavariable: $SET2, regex: '^(setHeader|header|set|append)$'}
|
|
330
|
+
- metavariable-regex: {metavariable: $ACAO, regex: '(?i)^[''"`]access-control-allow-origin[''"`]$'}
|
|
331
|
+
- metavariable-regex: {metavariable: $ACAC, regex: '(?i)^[''"`]access-control-allow-credentials[''"`]$'}
|
|
332
|
+
- metavariable-regex: {metavariable: $TRUE, regex: '^([''"`]true[''"`]|true)$'}
|
|
333
|
+
|
|
334
|
+
- id: codewatch.js.timing-unsafe-signature-check
|
|
335
|
+
languages: [typescript, javascript]
|
|
336
|
+
severity: WARNING
|
|
337
|
+
message: >-
|
|
338
|
+
An HMAC or signature is compared with === or ==, which stops at the first differing character: by timing
|
|
339
|
+
responses an attacker can guess a valid signature byte by byte. Compare with crypto.timingSafeEqual().
|
|
340
|
+
metadata:
|
|
341
|
+
category: security
|
|
342
|
+
subcategory: [vuln]
|
|
343
|
+
type: vulnerability
|
|
344
|
+
title: Signature compared in variable time
|
|
345
|
+
cwe: ["CWE-208: Observable Timing Discrepancy"]
|
|
346
|
+
owasp: ["A04:2025 - Cryptographic Failures"]
|
|
347
|
+
references:
|
|
348
|
+
- https://nodejs.org/api/crypto.html#cryptotimingsafeequala-b
|
|
349
|
+
pattern-either:
|
|
350
|
+
- pattern: <... $C.createHmac(...) ...> === $B
|
|
351
|
+
- pattern: $A === <... $C.createHmac(...) ...>
|
|
352
|
+
- pattern: <... $C.createHmac(...) ...> !== $B
|
|
353
|
+
- pattern: $A !== <... $C.createHmac(...) ...>
|
|
354
|
+
- pattern: <... $C.createHmac(...) ...> == $B
|
|
355
|
+
- pattern: $A == <... $C.createHmac(...) ...>
|
|
356
|
+
- patterns:
|
|
357
|
+
- pattern-either:
|
|
358
|
+
- pattern-inside: |
|
|
359
|
+
const $MAC = <... $C.createHmac(...) ...>;
|
|
360
|
+
...
|
|
361
|
+
- pattern-inside: |
|
|
362
|
+
let $MAC = <... $C.createHmac(...) ...>;
|
|
363
|
+
...
|
|
364
|
+
- pattern-either:
|
|
365
|
+
- pattern: $MAC === $B
|
|
366
|
+
- pattern: $A === $MAC
|
|
367
|
+
- pattern: $MAC !== $B
|
|
368
|
+
- pattern: $A !== $MAC
|
|
369
|
+
- pattern: $MAC == $B
|
|
370
|
+
- pattern: $A == $MAC
|
|
371
|
+
|
|
372
|
+
- id: codewatch.js.cookie-without-secure
|
|
373
|
+
languages: [typescript, javascript]
|
|
374
|
+
severity: WARNING
|
|
375
|
+
message: >-
|
|
376
|
+
This cookie can be sent over plain HTTP, where it can be intercepted. Set secure: true (and httpOnly:
|
|
377
|
+
true unless JavaScript needs it).
|
|
378
|
+
metadata:
|
|
379
|
+
category: security
|
|
380
|
+
subcategory: [vuln]
|
|
381
|
+
type: vulnerability
|
|
382
|
+
title: Cookie without the Secure flag
|
|
383
|
+
cwe: ["CWE-614: Sensitive Cookie in HTTPS Session Without 'Secure' Attribute"]
|
|
384
|
+
owasp: ["A02:2025 - Security Misconfiguration"]
|
|
385
|
+
references:
|
|
386
|
+
- https://expressjs.com/en/api.html#res.cookie
|
|
387
|
+
patterns:
|
|
388
|
+
- pattern-either:
|
|
389
|
+
- pattern: $RES.cookie($NAME, $VALUE)
|
|
390
|
+
- pattern: '$RES.cookie($NAME, $VALUE, {...})'
|
|
391
|
+
- pattern: '$RES.cookie($NAME, $VALUE, {..., secure: false, ...})'
|
|
392
|
+
- pattern-not: '$RES.cookie($NAME, $VALUE, {..., secure: $SET, ...})'
|
|
393
|
+
- metavariable-regex: {metavariable: $RES, regex: '^(res|response|reply|ctx\.cookies)$'}
|
|
394
|
+
# Only cookies that carry a credential: a theme or locale cookie isn't worth intercepting.
|
|
395
|
+
- metavariable-regex:
|
|
396
|
+
metavariable: $NAME
|
|
397
|
+
regex: '(?i).*(sess|sid|token|auth|jwt|remember|login|csrf|xsrf|refresh|access)'
|
|
398
|
+
# Clearing a cookie sends nothing worth intercepting.
|
|
399
|
+
- pattern-not: $RES.cookie($NAME, "", ...)
|
|
400
|
+
- pattern-not: '$RES.cookie($NAME, $VALUE, {..., maxAge: 0, ...})'
|
|
401
|
+
- pattern-not: '$RES.cookie($NAME, $VALUE, {..., expires: new Date(0), ...})'
|
|
402
|
+
|
|
403
|
+
- id: codewatch.js.session-cookie-flags
|
|
404
|
+
languages: [typescript, javascript]
|
|
405
|
+
severity: WARNING
|
|
406
|
+
message: >-
|
|
407
|
+
The session cookie's protection is switched off here: without httpOnly any injected script can read the
|
|
408
|
+
session, without secure it travels over plain HTTP, and sameSite "none" sends it on cross-site requests.
|
|
409
|
+
Keep httpOnly: true, secure: true (behind a proxy, also set "trust proxy") and sameSite "lax" or "strict".
|
|
410
|
+
# For review: secure: false is common in development configs.
|
|
411
|
+
metadata:
|
|
412
|
+
category: security
|
|
413
|
+
subcategory: [audit]
|
|
414
|
+
type: security_hotspot
|
|
415
|
+
title: Session cookie protection switched off
|
|
416
|
+
cwe: ["CWE-1004: Sensitive Cookie Without 'HttpOnly' Flag", "CWE-614: Sensitive Cookie in HTTPS Session Without 'Secure' Attribute", "CWE-1275: Sensitive Cookie with Improper SameSite Attribute"]
|
|
417
|
+
owasp: ["A07:2025 - Authentication Failures"]
|
|
418
|
+
references:
|
|
419
|
+
- https://github.com/expressjs/session#cookie
|
|
420
|
+
pattern-either:
|
|
421
|
+
- pattern: 'session({..., cookie: {..., httpOnly: false, ...}, ...})'
|
|
422
|
+
- pattern: 'session({..., cookie: {..., secure: false, ...}, ...})'
|
|
423
|
+
- pattern: 'session({..., cookie: {..., sameSite: "none", ...}, ...})'
|
|
424
|
+
- pattern: 'cookieSession({..., httpOnly: false, ...})'
|
|
425
|
+
- pattern: 'cookieSession({..., secure: false, ...})'
|
|
426
|
+
- pattern: '$RES.cookie($NAME, $VALUE, {..., httpOnly: false, ...})'
|
|
427
|
+
- pattern: '$RES.cookie($NAME, $VALUE, {..., sameSite: "none", ...})'
|
|
428
|
+
|
|
429
|
+
- id: codewatch.js.secret-in-log
|
|
430
|
+
languages: [typescript, javascript]
|
|
431
|
+
severity: INFO
|
|
432
|
+
message: >-
|
|
433
|
+
A password, token or secret is written to the log, where it is kept and read by more people and systems
|
|
434
|
+
than the secret itself. Log that it was present, not its value.
|
|
435
|
+
# For review: the name suggests a secret, but it might be a token's ID or a password-policy setting.
|
|
436
|
+
metadata:
|
|
437
|
+
category: security
|
|
438
|
+
subcategory: [audit]
|
|
439
|
+
type: security_hotspot
|
|
440
|
+
title: Secret written to the log
|
|
441
|
+
cwe: ["CWE-532: Insertion of Sensitive Information into Log File"]
|
|
442
|
+
owasp: ["A09:2025 - Security Logging and Alerting Failures"]
|
|
443
|
+
references:
|
|
444
|
+
- https://cheatsheetseries.owasp.org/cheatsheets/Logging_Cheat_Sheet.html#data-to-exclude
|
|
445
|
+
patterns:
|
|
446
|
+
- pattern-either:
|
|
447
|
+
- pattern: console.$LEVEL(..., $SECRET, ...)
|
|
448
|
+
- pattern: 'console.$LEVEL(..., `...${$SECRET}...`, ...)'
|
|
449
|
+
- patterns:
|
|
450
|
+
- pattern-either:
|
|
451
|
+
- pattern: $LOGGER.$LEVEL(..., $SECRET, ...)
|
|
452
|
+
- pattern: '$LOGGER.$LEVEL(..., `...${$SECRET}...`, ...)'
|
|
453
|
+
- metavariable-regex: {metavariable: $LOGGER, regex: '(?i)^(this\.)?(log|logger|winston|pino|bunyan)$'}
|
|
454
|
+
- metavariable-regex: {metavariable: $LEVEL, regex: '^(log|info|warn|error|debug|trace|fatal)$'}
|
|
455
|
+
- metavariable-regex:
|
|
456
|
+
metavariable: $SECRET
|
|
457
|
+
regex: '(?i)^([\w$]+\.)*[\w$]*(password|passwd|secret|token|api_?key|authorization|credentials?|private_?key)$'
|
|
458
|
+
|
|
459
|
+
- id: codewatch.js.route-without-auth
|
|
460
|
+
languages: [typescript, javascript]
|
|
461
|
+
severity: WARNING
|
|
462
|
+
message: >-
|
|
463
|
+
This route changes data but has no authentication middleware, while other routes in the same file do.
|
|
464
|
+
Check that anonymous users may really call it; if not, add the same middleware here.
|
|
465
|
+
# For review: some routes are meant to be public; one missing middleware in a protected router often isn't.
|
|
466
|
+
metadata:
|
|
467
|
+
category: security
|
|
468
|
+
subcategory: [audit]
|
|
469
|
+
type: security_hotspot
|
|
470
|
+
title: Changing route without the authentication other routes use
|
|
471
|
+
cwe: ["CWE-306: Missing Authentication for Critical Function"]
|
|
472
|
+
owasp: ["A07:2025 - Authentication Failures"]
|
|
473
|
+
references:
|
|
474
|
+
- https://cheatsheetseries.owasp.org/cheatsheets/Authorization_Cheat_Sheet.html
|
|
475
|
+
patterns:
|
|
476
|
+
- pattern-either:
|
|
477
|
+
- pattern: $APP.$METHOD($PATH, $HANDLER)
|
|
478
|
+
- patterns:
|
|
479
|
+
- pattern: $APP.$METHOD($PATH, $MW1, $HANDLER)
|
|
480
|
+
- metavariable-regex: {metavariable: $MW1, regex: '^(?!(?i:.*(auth|login|logged|protect|guard|session|passport|jwt|token|permission|role|admin|require|verify|ensure|isuser|currentuser))).*$'}
|
|
481
|
+
- patterns:
|
|
482
|
+
- pattern: $APP.$METHOD($PATH, $MW1, $MW2, $HANDLER)
|
|
483
|
+
- metavariable-regex: {metavariable: $MW1, regex: '^(?!(?i:.*(auth|login|logged|protect|guard|session|passport|jwt|token|permission|role|admin|require|verify|ensure|isuser|currentuser))).*$'}
|
|
484
|
+
- metavariable-regex: {metavariable: $MW2, regex: '^(?!(?i:.*(auth|login|logged|protect|guard|session|passport|jwt|token|permission|role|admin|require|verify|ensure|isuser|currentuser))).*$'}
|
|
485
|
+
- metavariable-regex: {metavariable: $METHOD, regex: '^(post|put|patch|delete)$'}
|
|
486
|
+
- metavariable-regex: {metavariable: $APP, regex: '(?i)^(app|router|\w*router|api|server)$'}
|
|
487
|
+
- metavariable-regex: {metavariable: $PATH, regex: '^[''"`]/'}
|
|
488
|
+
# Routes that are public by nature, and sign-up as POST to the users collection.
|
|
489
|
+
- pattern-not: $APP.post("=~/^\/(api\/)?(v\d+\/)?(users?|accounts?|members?)\/?$/", ...)
|
|
490
|
+
- pattern-not: $APP.$METHOD("=~/(?i).*(login|logout|register|signup|sign-up|sign_up|signin|sign-in|forgot|reset|verify|confirm|activate|token|refresh|oauth|callback|webhook|public|health|status|contact|subscribe|newsletter)/", ...)
|
|
491
|
+
# Another route in this file names an authentication middleware first.
|
|
492
|
+
- pattern-either:
|
|
493
|
+
- pattern-inside: |
|
|
494
|
+
$APP.$OTHER($OTHERPATH, $AUTH, ...);
|
|
495
|
+
...
|
|
496
|
+
- pattern-inside: |
|
|
497
|
+
$APP.$METHOD($PATH, ...);
|
|
498
|
+
...
|
|
499
|
+
$APP.$OTHER($OTHERPATH, $AUTH, ...);
|
|
500
|
+
- metavariable-regex: {metavariable: $AUTH, regex: '(?i).*(auth|login|logged|protect|guard|session|passport|jwt|token|permission|role|admin|require|verify|ensure|isUser|currentUser)'}
|
|
501
|
+
- metavariable-regex: {metavariable: $OTHER, regex: '^(get|post|put|patch|delete|all)$'}
|
|
502
|
+
|
|
503
|
+
- id: codewatch.js.upload-without-limits
|
|
504
|
+
languages: [typescript, javascript]
|
|
505
|
+
severity: INFO
|
|
506
|
+
message: >-
|
|
507
|
+
multer is set up without limits, so a client can send files of any size and number until the disk or
|
|
508
|
+
memory runs out. Set limits: { fileSize, files }.
|
|
509
|
+
# For review: a proxy in front may already cap the request size.
|
|
510
|
+
metadata:
|
|
511
|
+
category: security
|
|
512
|
+
subcategory: [audit]
|
|
513
|
+
type: security_hotspot
|
|
514
|
+
title: File uploads without a size limit
|
|
515
|
+
cwe: ["CWE-770: Allocation of Resources Without Limits or Throttling"]
|
|
516
|
+
owasp: ["A06:2025 - Insecure Design"]
|
|
517
|
+
references:
|
|
518
|
+
- https://github.com/expressjs/multer#limits
|
|
519
|
+
patterns:
|
|
520
|
+
- pattern-either:
|
|
521
|
+
- pattern: multer()
|
|
522
|
+
- pattern: 'multer({...})'
|
|
523
|
+
- pattern-not: 'multer({..., limits: $LIMITS, ...})'
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
- id: codewatch.js.path-prefix-check
|
|
527
|
+
languages: [typescript, javascript]
|
|
528
|
+
severity: INFO
|
|
529
|
+
message: >-
|
|
530
|
+
A resolved path is checked against its base directory with startsWith, and the base doesn't end in a
|
|
531
|
+
separator, so "/srv/data-evil/x" passes a check for "/srv/data". Compare path.relative(base, target) instead
|
|
532
|
+
(reject results starting with ".." or absolute), or check against base + path.sep.
|
|
533
|
+
# For review: harmless if nothing outside the base shares its prefix, which the code can't show.
|
|
534
|
+
metadata:
|
|
535
|
+
category: security
|
|
536
|
+
subcategory: [audit]
|
|
537
|
+
type: security_hotspot
|
|
538
|
+
title: Path containment checked by string prefix
|
|
539
|
+
cwe: ["CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')"]
|
|
540
|
+
owasp: ["A01:2025 - Broken Access Control"]
|
|
541
|
+
references:
|
|
542
|
+
- https://cheatsheetseries.owasp.org/cheatsheets/File_Upload_Cheat_Sheet.html
|
|
543
|
+
- https://nodejs.org/api/path.html#pathrelativefrom-to
|
|
544
|
+
patterns:
|
|
545
|
+
- pattern: $P.startsWith($BASE)
|
|
546
|
+
- pattern-either:
|
|
547
|
+
- pattern-inside: |
|
|
548
|
+
$P = $FN(...);
|
|
549
|
+
...
|
|
550
|
+
- pattern-inside: |
|
|
551
|
+
$BASE = $FN(...);
|
|
552
|
+
...
|
|
553
|
+
- pattern-inside: |
|
|
554
|
+
$BASE = $COND ? $FN(...) : $OTHER;
|
|
555
|
+
...
|
|
556
|
+
- metavariable-regex: {metavariable: $FN, regex: '^((path|posix|win32|fs|fsp)\.)*(resolve|join|normalize|realpath|realpathSync)$'}
|
|
557
|
+
- pattern-not: $P.startsWith("...")
|
|
558
|
+
- pattern-not: $P.startsWith(`...`)
|
|
559
|
+
- pattern-not: $P.startsWith($X + $SEP)
|
|
560
|
+
- pattern-not-inside: |
|
|
561
|
+
$BASE = $X + $SEP;
|
|
562
|
+
...
|