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.
Files changed (136) hide show
  1. codewatch/__init__.py +0 -0
  2. codewatch/__main__.py +14 -0
  3. codewatch/asgi.py +16 -0
  4. codewatch/settings.py +175 -0
  5. codewatch/urls.py +40 -0
  6. codewatch/wsgi.py +16 -0
  7. codewatch_scan-0.1.0.dist-info/METADATA +81 -0
  8. codewatch_scan-0.1.0.dist-info/RECORD +136 -0
  9. codewatch_scan-0.1.0.dist-info/WHEEL +5 -0
  10. codewatch_scan-0.1.0.dist-info/entry_points.txt +4 -0
  11. codewatch_scan-0.1.0.dist-info/licenses/LICENSE +21 -0
  12. codewatch_scan-0.1.0.dist-info/top_level.txt +2 -0
  13. core/__init__.py +0 -0
  14. core/analyzers/__init__.py +19 -0
  15. core/analyzers/accessibility.py +199 -0
  16. core/analyzers/base.py +192 -0
  17. core/analyzers/body_models.py +154 -0
  18. core/analyzers/codewatch_checks.py +394 -0
  19. core/analyzers/constant_branches.py +251 -0
  20. core/analyzers/containers.py +316 -0
  21. core/analyzers/coverage.py +131 -0
  22. core/analyzers/dependencies.py +347 -0
  23. core/analyzers/drf_serializers.py +65 -0
  24. core/analyzers/else_branches.py +106 -0
  25. core/analyzers/extra.py +400 -0
  26. core/analyzers/flask_resources.py +65 -0
  27. core/analyzers/inline_scripts.py +50 -0
  28. core/analyzers/jinja_sandboxes.py +63 -0
  29. core/analyzers/match_statements.py +148 -0
  30. core/analyzers/multi_tools.py +888 -0
  31. core/analyzers/php_template_sinks.py +444 -0
  32. core/analyzers/project_checks.py +150 -0
  33. core/analyzers/python_tools.py +333 -0
  34. core/analyzers/route_converters.py +237 -0
  35. core/analyzers/slices.py +94 -0
  36. core/analyzers/starred_targets.py +42 -0
  37. core/analyzers/stored_fields.py +386 -0
  38. core/analyzers/summaries.py +1387 -0
  39. core/analyzers/template_sinks.py +162 -0
  40. core/api.py +360 -0
  41. core/apps.py +6 -0
  42. core/benchmark.py +955 -0
  43. core/bundled/catalog/codewatch/rules/javascript-crypto.yml +224 -0
  44. core/bundled/catalog/codewatch/rules/javascript-injection.yml +116 -0
  45. core/bundled/catalog/codewatch/rules/javascript-taint.yml +1539 -0
  46. core/bundled/catalog/codewatch/rules/javascript-web.yml +562 -0
  47. core/bundled/catalog/codewatch/rules/php-web.yml +719 -0
  48. core/bundled/catalog/codewatch/rules/python-crypto.yml +203 -0
  49. core/bundled/catalog/codewatch/rules/python-django.yml +267 -0
  50. core/bundled/catalog/codewatch/rules/python-injection.yml +115 -0
  51. core/bundled/catalog/codewatch/rules/python-web.yml +3382 -0
  52. core/bundled/catalog/custom/mappings.json +360 -0
  53. core/bundled/catalog/custom/overrides.json +4 -0
  54. core/bundled/catalog/custom/rules/django-settings.yml +19 -0
  55. core/bundled/catalog/imported/changes.json +5 -0
  56. core/bundled/catalog/imported/docs.json +1143 -0
  57. core/bundled/catalog/imported/meta.json +54 -0
  58. core/bundled/catalog/imported/rules.json +85421 -0
  59. core/bundled/catalog/imported/standards.json +11191 -0
  60. core/bundled/tools/analyzers.lock +786 -0
  61. core/bundled/tools/axe-scan.mjs +45 -0
  62. core/bundled/tools/checkov.lock +2463 -0
  63. core/bundled/tools/codewatch-checks.mjs +99 -0
  64. core/bundled/tools/eslint-a11y.config.js +16 -0
  65. core/bundled/tools/eslint-quality.config.js +63 -0
  66. core/bundled/tools/eslint-typed.config.js +18 -0
  67. core/bundled/tools/package-lock.json +6102 -0
  68. core/bundled/tools/package.json +32 -0
  69. core/bundled/tools/rule-metadata.mjs +56 -0
  70. core/bundled/tools/semgrep.lock +1232 -0
  71. core/bundled/tools/stylelint.config.json +11 -0
  72. core/catalog/__init__.py +190 -0
  73. core/catalog/build.py +84 -0
  74. core/catalog/merge.py +122 -0
  75. core/catalog/sources.py +418 -0
  76. core/catalog/standards.py +119 -0
  77. core/catalog/update.py +99 -0
  78. core/catalog_views.py +115 -0
  79. core/client.py +645 -0
  80. core/collect.py +518 -0
  81. core/duplicates.py +60 -0
  82. core/fingerprint.py +25 -0
  83. core/folders.py +73 -0
  84. core/gate.py +77 -0
  85. core/git.py +149 -0
  86. core/jobs.py +86 -0
  87. core/management/__init__.py +0 -0
  88. core/management/commands/__init__.py +0 -0
  89. core/management/commands/addproject.py +40 -0
  90. core/management/commands/buildcatalog.py +15 -0
  91. core/management/commands/scan.py +74 -0
  92. core/management/commands/updatecatalog.py +14 -0
  93. core/mcp_server.py +140 -0
  94. core/middleware.py +17 -0
  95. core/migrations/0001_initial.py +115 -0
  96. core/migrations/0002_auth_tokens_a11y.py +60 -0
  97. core/migrations/0003_default_admin.py +43 -0
  98. core/migrations/0004_project_members.py +28 -0
  99. core/migrations/0005_uploads_and_sources.py +55 -0
  100. core/migrations/0006_thresholds.py +28 -0
  101. core/migrations/0007_also_reported_by.py +18 -0
  102. core/migrations/0008_new_code_period.py +18 -0
  103. core/migrations/0009_resolution_safe.py +18 -0
  104. core/migrations/0010_analysis_progress.py +18 -0
  105. core/migrations/0011_overall_gate_conditions.py +20 -0
  106. core/migrations/__init__.py +0 -0
  107. core/models.py +323 -0
  108. core/network.py +41 -0
  109. core/paths.py +29 -0
  110. core/ratings.py +67 -0
  111. core/runner.py +168 -0
  112. core/templates/core/account.html +30 -0
  113. core/templates/core/analysis.html +49 -0
  114. core/templates/core/base.html +121 -0
  115. core/templates/core/form_table.html +12 -0
  116. core/templates/core/gate_badge.html +1 -0
  117. core/templates/core/index.html +26 -0
  118. core/templates/core/issues.html +38 -0
  119. core/templates/core/login.html +13 -0
  120. core/templates/core/new_project.html +27 -0
  121. core/templates/core/password_change.html +10 -0
  122. core/templates/core/project.html +40 -0
  123. core/templates/core/rating.html +1 -0
  124. core/templates/core/ratings.html +32 -0
  125. core/templates/core/rule.html +33 -0
  126. core/templates/core/rules.html +42 -0
  127. core/templates/core/scan_progress.html +2 -0
  128. core/templates/core/settings.html +36 -0
  129. core/templates/core/source.html +15 -0
  130. core/templates/core/standards.html +30 -0
  131. core/templates/core/user_edit.html +15 -0
  132. core/templates/core/users.html +18 -0
  133. core/templatetags/__init__.py +0 -0
  134. core/templatetags/codewatch.py +42 -0
  135. core/tool_setup.py +68 -0
  136. core/views.py +564 -0
@@ -0,0 +1,719 @@
1
+ # codewatch built-in taint rules for PHP web apps: request data (superglobals and the common frameworks' request
2
+ # objects) reaching a dangerous call in the same function. PHP has no summary passes yet, so each rule sets
3
+ # `interprocedural: false`, which keeps it out of summaries.py (whose patterns are Python and JavaScript).
4
+ rules:
5
+ - id: codewatch.php.web.xss
6
+ mode: taint
7
+ languages: [php]
8
+ severity: ERROR
9
+ message: >-
10
+ Data from the HTTP request is written into the page without escaping. Escape it for where it goes:
11
+ htmlspecialchars($value, ENT_QUOTES) in HTML, esc_html()/esc_attr() in WordPress, e() or {{ }} in Laravel.
12
+ metadata: &xss-meta
13
+ category: security
14
+ subcategory: [vuln]
15
+ type: vulnerability
16
+ interprocedural: false
17
+ title: Request data in an HTML response without escaping
18
+ cwe: ["CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')"]
19
+ owasp: ["A05:2025 - Injection"]
20
+ references:
21
+ - https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html
22
+ - https://www.php.net/manual/en/function.htmlspecialchars.php
23
+ pattern-sources: &php-sources
24
+ - pattern-either:
25
+ - pattern: $_GET
26
+ - pattern: $_POST
27
+ - pattern: $_REQUEST
28
+ - pattern: $_COOKIE
29
+ - pattern: $_FILES[...]['name']
30
+ - patterns:
31
+ - pattern: $_SERVER[$KEY]
32
+ - metavariable-regex:
33
+ metavariable: $KEY
34
+ regex: ^['"](REQUEST_URI|PHP_SELF|PATH_INFO|QUERY_STRING|HTTP_[A-Z_]+)['"]$
35
+ - pattern: filter_input($TYPE, ...)
36
+ - pattern: filter_input_array(...)
37
+ - pattern: getallheaders()
38
+ - pattern: file_get_contents('php://input')
39
+ # Laravel, Symfony, CakePHP, CodeIgniter, Yii, Craft, Slim, Laminas, Joomla and Magento request objects.
40
+ - patterns:
41
+ - pattern-either:
42
+ - pattern: $REQ->$GET(...)
43
+ - pattern: $REQ->$BAG->$GET(...)
44
+ - metavariable-regex:
45
+ metavariable: $REQ
46
+ regex: ^\$(request|req|httpRequest|serverRequest)$
47
+ - metavariable-regex:
48
+ metavariable: $GET
49
+ regex: ^(input|get|query|post|all|only|except|cookie|header|getParam|getParams|getQuery|getQueryParam|getQueryParams|getBodyParam|getBodyParams|getParsedBody|getQueryString|getRequestUri|getPathInfo|getData|getPost|getCookie|getHeader|getContent|getUri|getValue|param|params|data|segment|get_post|post_get|getVar|getString|getRaw|getHtml|getUserParam)$
50
+ - patterns:
51
+ - pattern-either:
52
+ - pattern: request()->$GET(...)
53
+ - pattern: request($KEY)
54
+ - pattern: Request::$GET(...)
55
+ - pattern: Input::$GET(...)
56
+ - pattern: Yii::$app->request->$GET(...)
57
+ - pattern: Craft::$app->getRequest()->$GET(...)
58
+ - pattern: Craft::$app->request->$GET(...)
59
+ - pattern: $THIS->getRequest()->$GET(...)
60
+ - pattern: $THIS->request->$GET(...)
61
+ - pattern: $THIS->input->$GET(...)
62
+ - pattern: $APP->input->$GET(...)
63
+ - metavariable-regex:
64
+ metavariable: $GET
65
+ regex: ^(input|get|query|post|all|only|except|cookie|header|getParam|getParams|getQuery|getQueryParam|getQueryParams|getBodyParam|getBodyParams|getParsedBody|getQueryString|getRequestUri|getPathInfo|getData|getPost|getCookie|getHeader|getContent|getUri|getValue|param|params|data|segment|get_post|post_get|getVar|getString|getRaw|getHtml|getUserParam)$
66
+ - pattern: Tools::getValue(...)
67
+ # CakePHP 2's request properties, in controllers and views (MISP GHSA-p9m5: $this->request->data echoed
68
+ # by a .ctp view), and OpenCart's ($this->request->get['route'], GHSA-qx44). Not a bare $this->data or
69
+ # $this->params, which other classes use for their own state.
70
+ - patterns:
71
+ - pattern: $THIS->request->$PROP
72
+ - metavariable-regex:
73
+ metavariable: $PROP
74
+ regex: ^(data|query|pass|named|here|url|get|post|cookie)$
75
+ # Routing's free text only: params['action'] and ['controller'] are names the router matched.
76
+ - patterns:
77
+ - pattern: $THIS->request->params[$KEY]
78
+ - metavariable-regex:
79
+ metavariable: $KEY
80
+ regex: ^['"](named|pass)['"]$
81
+ # CakePHP's Referer header (MISP GHSA-p8fp printed it into a link); not a source for open-redirect,
82
+ # where going back to it is the idiom.
83
+ - pattern: $this->referer(...)
84
+ - pattern: $this->Controller->referer(...)
85
+ - pattern: $this->controller->referer(...)
86
+ - patterns:
87
+ - pattern: $THIS->params[$KEY]
88
+ - metavariable-regex:
89
+ metavariable: $KEY
90
+ regex: ^['"](named|pass|url|form|data)['"]$
91
+ - pattern: $THIS->passedArgs
92
+ pattern-sanitizers: &escaped
93
+ - patterns:
94
+ - pattern-either:
95
+ - pattern: htmlspecialchars(...)
96
+ - pattern: htmlentities(...)
97
+ - pattern: strip_tags(...)
98
+ - pattern: e(...)
99
+ - pattern: h(...)
100
+ - pattern: esc_html(...)
101
+ - pattern: esc_attr(...)
102
+ - pattern: esc_url(...)
103
+ - pattern: esc_js(...)
104
+ - pattern: esc_textarea(...)
105
+ - pattern: esc_html__(...)
106
+ - pattern: esc_attr__(...)
107
+ - pattern: wp_kses(...)
108
+ - pattern: wp_kses_post(...)
109
+ - pattern: sanitize_text_field(...)
110
+ - pattern: sanitize_key(...)
111
+ - pattern: sanitize_title(...)
112
+ - pattern: sanitize_email(...)
113
+ - pattern: Html::encode(...)
114
+ - pattern: Html::escape(...)
115
+ - pattern: CHtml::encode(...)
116
+ - pattern: Xss::filter(...)
117
+ - pattern: Purifier::clean(...)
118
+ - pattern: $PURIFIER->purify(...)
119
+ - pattern: json_encode(...)
120
+ - pattern: urlencode(...)
121
+ - pattern: rawurlencode(...)
122
+ - pattern: http_build_query(...)
123
+ - pattern: filter_var($X, FILTER_SANITIZE_FULL_SPECIAL_CHARS, ...)
124
+ - pattern: filter_var($X, FILTER_SANITIZE_SPECIAL_CHARS, ...)
125
+ - pattern: filter_input($T, $N, FILTER_SANITIZE_FULL_SPECIAL_CHARS, ...)
126
+ - pattern: filter_input($T, $N, FILTER_SANITIZE_SPECIAL_CHARS, ...)
127
+ # CakePHP's view helpers ($this->Html->link(), $this->Form->create()) escape what they are given; a
128
+ # component's $this->Controller is no helper (MISP GHSA-p8fp: ->referer() into ->set()).
129
+ - patterns:
130
+ - pattern: $THIS->$HELPER->$METHOD(...)
131
+ - metavariable-regex: {metavariable: $HELPER, regex: '^(?!Controller$)[A-Z][A-Za-z]*$'}
132
+ # An escaper called as a function or a method, named for what it does: Strings::htmlentities() (phpMyFAQ),
133
+ # escape_input() (phpIPAM), $escaper->escapeHtml() (Laminas, Magento).
134
+ - patterns:
135
+ - pattern-either:
136
+ - pattern: $F(...)
137
+ - pattern: $OBJ->$F(...)
138
+ - pattern: $CLS::$F(...)
139
+ - metavariable-regex:
140
+ metavariable: $F
141
+ regex: '(?i)^(html_?(entities|special_?chars|escape|encode|safe)|escape_?(html\w*|attr\w*|input|output|js|url)|esc_?(html|attr|url|js)\w*|encode_?html|sanitize_?(html|text|string|input|output)\w*|purify|xss_?clean|clean_?xss|remove_?xss)$'
142
+ # A named check that the value passed: `if ($this->isLocalUrl($request, $target)) { return
143
+ # $this->redirect($target); }` (GHSA-62f9), or one that said no and ended the request before the use.
144
+ - &php-checked
145
+ patterns:
146
+ - pattern-either:
147
+ - pattern-inside: if (<... $CHECK(..., $X, ...) ...>) { ... }
148
+ - pattern-inside: if (<... $OBJ->$CHECK(..., $X, ...) ...>) { ... }
149
+ - pattern-inside: if (<... $CLS::$CHECK(..., $X, ...) ...>) { ... }
150
+ - pattern-not-inside: if (<... !$CHECK(..., $X, ...) ...>) { ... }
151
+ - pattern-not-inside: if (<... !$OBJ->$CHECK(..., $X, ...) ...>) { ... }
152
+ - pattern-not-inside: if (<... !$CLS::$CHECK(..., $X, ...) ...>) { ... }
153
+ - metavariable-regex:
154
+ metavariable: $CHECK
155
+ regex: '(?i)^(is_?|check_?)?(safe|valid|allowed|permitted|trusted|whitelisted|allowlisted|local)\w{0,40}$'
156
+ - pattern: $X
157
+ - &php-guarded
158
+ patterns:
159
+ - pattern-either:
160
+ - pattern-inside: |
161
+ if (!$CHECK(..., $X, ...)) {
162
+ ...
163
+ return ...;
164
+ }
165
+ ...
166
+ - pattern-inside: |
167
+ if (!$CHECK(..., $X, ...)) {
168
+ ...
169
+ return;
170
+ }
171
+ ...
172
+ - pattern-inside: |
173
+ if (!$CHECK(..., $X, ...)) {
174
+ ...
175
+ exit;
176
+ }
177
+ ...
178
+ - pattern-inside: |
179
+ if (!$CHECK(..., $X, ...)) {
180
+ ...
181
+ exit(...);
182
+ }
183
+ ...
184
+ - pattern-inside: |
185
+ if (!$CHECK(..., $X, ...)) {
186
+ ...
187
+ die(...);
188
+ }
189
+ ...
190
+ - pattern-inside: |
191
+ if (!$CHECK(..., $X, ...)) {
192
+ ...
193
+ die;
194
+ }
195
+ ...
196
+ - pattern-inside: |
197
+ if (!$CHECK(..., $X, ...)) {
198
+ ...
199
+ throw $E;
200
+ }
201
+ ...
202
+ - pattern-inside: |
203
+ if (!$CHECK(..., $X, ...)) {
204
+ ...
205
+ wp_die(...);
206
+ }
207
+ ...
208
+ - pattern-inside: |
209
+ if (!$OBJ->$CHECK(..., $X, ...)) {
210
+ ...
211
+ return ...;
212
+ }
213
+ ...
214
+ - pattern-inside: |
215
+ if (!$OBJ->$CHECK(..., $X, ...)) {
216
+ ...
217
+ return;
218
+ }
219
+ ...
220
+ - pattern-inside: |
221
+ if (!$OBJ->$CHECK(..., $X, ...)) {
222
+ ...
223
+ exit;
224
+ }
225
+ ...
226
+ - pattern-inside: |
227
+ if (!$OBJ->$CHECK(..., $X, ...)) {
228
+ ...
229
+ exit(...);
230
+ }
231
+ ...
232
+ - pattern-inside: |
233
+ if (!$OBJ->$CHECK(..., $X, ...)) {
234
+ ...
235
+ die(...);
236
+ }
237
+ ...
238
+ - pattern-inside: |
239
+ if (!$OBJ->$CHECK(..., $X, ...)) {
240
+ ...
241
+ die;
242
+ }
243
+ ...
244
+ - pattern-inside: |
245
+ if (!$OBJ->$CHECK(..., $X, ...)) {
246
+ ...
247
+ throw $E;
248
+ }
249
+ ...
250
+ - pattern-inside: |
251
+ if (!$OBJ->$CHECK(..., $X, ...)) {
252
+ ...
253
+ wp_die(...);
254
+ }
255
+ ...
256
+ - pattern-inside: |
257
+ if (!$CLS::$CHECK(..., $X, ...)) {
258
+ ...
259
+ return ...;
260
+ }
261
+ ...
262
+ - pattern-inside: |
263
+ if (!$CLS::$CHECK(..., $X, ...)) {
264
+ ...
265
+ return;
266
+ }
267
+ ...
268
+ - pattern-inside: |
269
+ if (!$CLS::$CHECK(..., $X, ...)) {
270
+ ...
271
+ exit;
272
+ }
273
+ ...
274
+ - pattern-inside: |
275
+ if (!$CLS::$CHECK(..., $X, ...)) {
276
+ ...
277
+ exit(...);
278
+ }
279
+ ...
280
+ - pattern-inside: |
281
+ if (!$CLS::$CHECK(..., $X, ...)) {
282
+ ...
283
+ die(...);
284
+ }
285
+ ...
286
+ - pattern-inside: |
287
+ if (!$CLS::$CHECK(..., $X, ...)) {
288
+ ...
289
+ die;
290
+ }
291
+ ...
292
+ - pattern-inside: |
293
+ if (!$CLS::$CHECK(..., $X, ...)) {
294
+ ...
295
+ throw $E;
296
+ }
297
+ ...
298
+ - pattern-inside: |
299
+ if (!$CLS::$CHECK(..., $X, ...)) {
300
+ ...
301
+ wp_die(...);
302
+ }
303
+ ...
304
+ - metavariable-regex:
305
+ metavariable: $CHECK
306
+ regex: '(?i)^(is_?|check_?|validate_?)?(safe|valid|allowed|permitted|trusted|whitelisted|allowlisted|local)\w{0,40}$'
307
+ - pattern: $X
308
+ - &numeric
309
+ pattern-either:
310
+ - pattern: intval(...)
311
+ - pattern: floatval(...)
312
+ - pattern: absint(...)
313
+ - pattern: (int) $X
314
+ - pattern: (integer) $X
315
+ - pattern: (float) $X
316
+ - pattern: (bool) $X
317
+ - pattern: (boolean) $X
318
+ - pattern: count(...)
319
+ - pattern: strlen(...)
320
+ - pattern: isset(...)
321
+ - pattern: empty(...)
322
+ - pattern: is_numeric(...)
323
+ - pattern: ctype_digit(...)
324
+ - pattern: ctype_alnum(...)
325
+ - pattern: in_array(...)
326
+ - pattern: array_key_exists(...)
327
+ - pattern: md5(...)
328
+ - pattern: sha1(...)
329
+ - pattern: hash(...)
330
+ - pattern: password_hash(...)
331
+ - pattern: filter_var($X, FILTER_VALIDATE_INT, ...)
332
+ - pattern: filter_var($X, FILTER_VALIDATE_FLOAT, ...)
333
+ - pattern: filter_var($X, FILTER_VALIDATE_BOOLEAN, ...)
334
+ - pattern: filter_input($T, $N, FILTER_VALIDATE_INT, ...)
335
+ - pattern: filter_input($T, $N, FILTER_SANITIZE_NUMBER_INT, ...)
336
+ - pattern: sprintf("%d", ...)
337
+ - pattern: number_format(...)
338
+ # Arithmetic gives a number (users.php?offset=<?= $_GET['offset'] + 6 ?>, GHSA-m473), and so do dates.
339
+ - pattern: $A + $B
340
+ - pattern: $A - $B
341
+ - pattern: $A * $B
342
+ - pattern: $A / $B
343
+ - pattern: $A % $B
344
+ - pattern: date(...)
345
+ - pattern: gmdate(...)
346
+ - pattern: mktime(...)
347
+ - pattern: strtotime(...)
348
+ - pattern: round(...)
349
+ - pattern: abs(...)
350
+ - pattern: min(...)
351
+ - pattern: max(...)
352
+ - pattern: $A == $B
353
+ - pattern: $A === $B
354
+ - pattern: $A != $B
355
+ - pattern: $A !== $B
356
+ pattern-sinks:
357
+ - patterns:
358
+ - pattern-either:
359
+ - pattern: echo $X;
360
+ - pattern: print $X;
361
+ - pattern: print($X);
362
+ - pattern: exit($X);
363
+ - pattern: die($X);
364
+ - focus-metavariable: $X
365
+ - pattern: printf(...)
366
+ - pattern: vprintf(...)
367
+
368
+ - id: codewatch.php.web.sql-injection
369
+ mode: taint
370
+ languages: [php]
371
+ severity: ERROR
372
+ message: >-
373
+ Data from the HTTP request is built into an SQL statement. Use a prepared statement with placeholders
374
+ (PDO::prepare, mysqli bind_param, $wpdb->prepare, the query builder's bindings) instead of concatenation.
375
+ metadata:
376
+ category: security
377
+ subcategory: [vuln]
378
+ type: vulnerability
379
+ interprocedural: false
380
+ title: Request data built into an SQL statement
381
+ cwe: ["CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')"]
382
+ owasp: ["A05:2025 - Injection"]
383
+ references:
384
+ - https://cheatsheetseries.owasp.org/cheatsheets/Query_Parameterization_Cheat_Sheet.html
385
+ - https://www.php.net/manual/en/pdo.prepared-statements.php
386
+ pattern-sources: *php-sources
387
+ pattern-sanitizers:
388
+ - *php-checked
389
+ - *php-guarded
390
+ - *numeric
391
+ # Escaping keeps a value inside its quotes; an unquoted escaped value is still injectable, but flagging every
392
+ # escaped value would bury the rest.
393
+ - pattern-either:
394
+ - pattern: mysqli_real_escape_string(...)
395
+ - pattern: mysql_real_escape_string(...)
396
+ - pattern: mysql_escape_string(...)
397
+ - pattern: pg_escape_string(...)
398
+ - pattern: pg_escape_literal(...)
399
+ - pattern: sqlite_escape_string(...)
400
+ - pattern: addslashes(...)
401
+ - pattern: esc_sql(...)
402
+ - pattern: $DB->real_escape_string(...)
403
+ - pattern: $DB->escape(...)
404
+ - pattern: $DB->escapeString(...)
405
+ - pattern: $DB->escape_string(...)
406
+ - pattern: $DB->quote(...)
407
+ - pattern: $DB->quoteValue(...)
408
+ - pattern: $DB->qstr(...)
409
+ - pattern: $wpdb->prepare(...)
410
+ - pattern: $DB->quoteName(...)
411
+ - pattern: $DB->quoteIdentifier(...)
412
+ pattern-sinks:
413
+ - patterns:
414
+ - pattern-either:
415
+ - pattern: mysql_query($SQL, ...)
416
+ - pattern: mysql_db_query($D, $SQL, ...)
417
+ - pattern: mysqli_query($C, $SQL, ...)
418
+ - pattern: mysqli_multi_query($C, $SQL, ...)
419
+ - pattern: mysqli_real_query($C, $SQL, ...)
420
+ - pattern: mysqli_prepare($C, $SQL)
421
+ - pattern: $DB->prepare($SQL)
422
+ - pattern: pg_query($C, $SQL)
423
+ - pattern: pg_query($SQL)
424
+ - pattern: pg_send_query($C, $SQL)
425
+ - pattern: sqlsrv_query($C, $SQL, ...)
426
+ - pattern: odbc_exec($C, $SQL, ...)
427
+ - patterns:
428
+ - pattern: $DB->$QUERY($SQL, ...)
429
+ - metavariable-regex:
430
+ metavariable: $QUERY
431
+ regex: ^(query|exec|multi_query|real_query|unbuffered_query|get_results|get_row|get_var|get_col|executeQuery|executeStatement|executeUpdate|fetchAll|fetchAssoc|fetchOne|fetchColumn|fetchAllAssociative|fetchAssociative|createQuery|createNativeQuery|whereRaw|orWhereRaw|havingRaw|orderByRaw|selectRaw|groupByRaw|raw|unprepared|setQuery|Execute|GetAll|GetRow|GetOne|GetCol|SelectLimit|sql_query|createCommand|findBySql)$
432
+ - focus-metavariable: $SQL
433
+ - patterns:
434
+ - pattern: DB::$RAW($SQL, ...)
435
+ - metavariable-regex:
436
+ metavariable: $RAW
437
+ regex: ^(raw|select|statement|unprepared|insert|update|delete|selectOne)$
438
+ - focus-metavariable: $SQL
439
+
440
+ - id: codewatch.php.web.path-traversal
441
+ mode: taint
442
+ languages: [php]
443
+ severity: ERROR
444
+ message: >-
445
+ Data from the HTTP request is used in a file path or include, so "../" (or an absolute path) can reach
446
+ files outside the intended folder. Take only the file name (basename()) or check the resolved path
447
+ (realpath()) stays inside the folder.
448
+ metadata:
449
+ category: security
450
+ subcategory: [vuln]
451
+ type: vulnerability
452
+ interprocedural: false
453
+ title: Request data in a file path
454
+ cwe: ["CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')"]
455
+ owasp: ["A01:2025 - Broken Access Control"]
456
+ references:
457
+ - https://cheatsheetseries.owasp.org/cheatsheets/File_Upload_Cheat_Sheet.html
458
+ - https://owasp.org/www-community/attacks/Path_Traversal
459
+ pattern-sources: *php-sources
460
+ pattern-sanitizers:
461
+ - *php-checked
462
+ - *php-guarded
463
+ - *numeric
464
+ - pattern-either:
465
+ - pattern: basename(...)
466
+ - pattern: sanitize_file_name(...)
467
+ - pattern: realpath(...)
468
+ - pattern: md5(...)
469
+ pattern-sinks:
470
+ - patterns:
471
+ - pattern-either:
472
+ - pattern: include $X;
473
+ - pattern: include_once $X;
474
+ - pattern: require $X;
475
+ - pattern: require_once $X;
476
+ - pattern: file_get_contents($X, ...)
477
+ - pattern: file_put_contents($X, ...)
478
+ - pattern: fopen($X, ...)
479
+ - pattern: file($X, ...)
480
+ - pattern: readfile($X, ...)
481
+ - pattern: unlink($X, ...)
482
+ - pattern: rmdir($X, ...)
483
+ - pattern: mkdir($X, ...)
484
+ - pattern: copy($X, ...)
485
+ - pattern: copy($S, $X, ...)
486
+ - pattern: rename($X, ...)
487
+ - pattern: rename($S, $X, ...)
488
+ - pattern: move_uploaded_file($S, $X)
489
+ - pattern: opendir($X, ...)
490
+ - pattern: scandir($X, ...)
491
+ - pattern: glob($X, ...)
492
+ - pattern: parse_ini_file($X, ...)
493
+ - pattern: highlight_file($X, ...)
494
+ - pattern: show_source($X, ...)
495
+ - pattern: fpassthru($X)
496
+ - pattern: touch($X, ...)
497
+ - pattern: symlink($S, $X)
498
+ - pattern: chmod($X, ...)
499
+ - pattern: tempnam($X, ...)
500
+ - pattern: simplexml_load_file($X, ...)
501
+ - pattern: new SplFileObject($X, ...)
502
+ - pattern: new SplFileInfo($X, ...)
503
+ - pattern: $ZIP->extractTo($X, ...)
504
+ - focus-metavariable: $X
505
+
506
+ - id: codewatch.php.web.command-injection
507
+ mode: taint
508
+ languages: [php]
509
+ severity: ERROR
510
+ message: >-
511
+ Data from the HTTP request reaches a shell command, so a user can run their own commands. Quote each
512
+ argument with escapeshellarg(), or pass an argument array to proc_open() or Symfony Process.
513
+ metadata:
514
+ category: security
515
+ subcategory: [vuln]
516
+ type: vulnerability
517
+ interprocedural: false
518
+ title: Request data in a shell command
519
+ cwe: ["CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')"]
520
+ owasp: ["A05:2025 - Injection"]
521
+ references:
522
+ - https://cheatsheetseries.owasp.org/cheatsheets/OS_Command_Injection_Defense_Cheat_Sheet.html
523
+ - https://www.php.net/manual/en/function.escapeshellarg.php
524
+ pattern-sources: *php-sources
525
+ pattern-sanitizers:
526
+ - *php-checked
527
+ - *php-guarded
528
+ - *numeric
529
+ - pattern-either:
530
+ - pattern: escapeshellarg(...)
531
+ - pattern: escapeshellcmd(...)
532
+ pattern-sinks:
533
+ - patterns:
534
+ - pattern-either:
535
+ - pattern: exec($X, ...)
536
+ - pattern: system($X, ...)
537
+ - pattern: shell_exec($X)
538
+ - pattern: passthru($X, ...)
539
+ - pattern: popen($X, ...)
540
+ - pattern: proc_open($X, ...)
541
+ - pattern: pcntl_exec($X, ...)
542
+ - pattern: Process::fromShellCommandline($X, ...)
543
+ - pattern-not: proc_open([...], ...)
544
+ - focus-metavariable: $X
545
+ - pattern: "`...`"
546
+
547
+ - id: codewatch.php.web.code-injection
548
+ mode: taint
549
+ languages: [php]
550
+ severity: ERROR
551
+ message: >-
552
+ Data from the HTTP request is run as PHP code. Never evaluate request data; map it to one of a fixed set of
553
+ functions or values instead.
554
+ metadata:
555
+ category: security
556
+ subcategory: [vuln]
557
+ type: vulnerability
558
+ interprocedural: false
559
+ title: Request data run as code
560
+ cwe: ["CWE-94: Improper Control of Generation of Code ('Code Injection')"]
561
+ owasp: ["A05:2025 - Injection"]
562
+ references:
563
+ - https://owasp.org/www-community/attacks/Code_Injection
564
+ pattern-sources: *php-sources
565
+ pattern-sanitizers:
566
+ - *php-checked
567
+ - *php-guarded
568
+ - *numeric
569
+ pattern-sinks:
570
+ - patterns:
571
+ - pattern-either:
572
+ - pattern: eval($X);
573
+ - pattern: assert($X, ...)
574
+ - pattern: create_function($A, $X)
575
+ - pattern: create_function($X, ...)
576
+ - pattern: call_user_func($X, ...)
577
+ - pattern: call_user_func_array($X, ...)
578
+ - pattern: preg_replace("=~/e[a-z]*$/", $X, ...)
579
+ - focus-metavariable: $X
580
+ # A variable used as the function or class name: $_GET['f']() or new $class().
581
+ - patterns:
582
+ - pattern-either:
583
+ - pattern: $X(...)
584
+ - pattern: new $X(...)
585
+ - metavariable-regex:
586
+ metavariable: $X
587
+ regex: ^\$\w+$
588
+ - focus-metavariable: $X
589
+
590
+ - id: codewatch.php.web.ssrf
591
+ mode: taint
592
+ languages: [php]
593
+ severity: ERROR
594
+ message: >-
595
+ Data from the HTTP request chooses the URL the server fetches, so a user can make it call internal
596
+ services. Check the host against a list of allowed hosts before the request.
597
+ metadata:
598
+ category: security
599
+ subcategory: [vuln]
600
+ type: vulnerability
601
+ interprocedural: false
602
+ title: Request data chooses the server's outbound URL
603
+ cwe: ["CWE-918: Server-Side Request Forgery (SSRF)"]
604
+ owasp: ["A01:2025 - Broken Access Control"]
605
+ references:
606
+ - https://cheatsheetseries.owasp.org/cheatsheets/Server_Side_Request_Forgery_Prevention_Cheat_Sheet.html
607
+ pattern-sources: *php-sources
608
+ pattern-sanitizers:
609
+ - *php-checked
610
+ - *php-guarded
611
+ - *numeric
612
+ - pattern-either:
613
+ - pattern: urlencode(...)
614
+ - pattern: rawurlencode(...)
615
+ - pattern: http_build_query(...)
616
+ pattern-sinks:
617
+ - patterns:
618
+ - pattern-either:
619
+ - pattern: $CLIENT->request($M, $X, ...)
620
+ - pattern: $CLIENT->$VERB($X, ...)
621
+ - metavariable-regex:
622
+ metavariable: $CLIENT
623
+ regex: ^\$(client|http|httpClient|guzzle|this->client|this->httpClient)$
624
+ - metavariable-regex:
625
+ metavariable: $VERB
626
+ regex: ^(get|post|put|patch|delete|head|request|send|sendRequest|getAsync|postAsync)$
627
+ - focus-metavariable: $X
628
+ - patterns:
629
+ - pattern-either:
630
+ - pattern: curl_init($X)
631
+ - pattern: curl_setopt($C, CURLOPT_URL, $X)
632
+ - pattern: fsockopen($X, ...)
633
+ - pattern: get_headers($X, ...)
634
+ - pattern: wp_remote_get($X, ...)
635
+ - pattern: wp_remote_post($X, ...)
636
+ - pattern: wp_remote_request($X, ...)
637
+ - pattern: wp_remote_head($X, ...)
638
+ - pattern: wp_safe_remote_get($X, ...)
639
+ - pattern: Http::get($X, ...)
640
+ - pattern: Http::post($X, ...)
641
+ - focus-metavariable: $X
642
+
643
+ - id: codewatch.php.web.open-redirect
644
+ mode: taint
645
+ languages: [php]
646
+ severity: WARNING
647
+ message: >-
648
+ Data from the HTTP request chooses where the user is redirected, so a link to this site can send them to
649
+ any other. Redirect only to a path on this site, or check the URL against a list of allowed hosts
650
+ (wp_safe_redirect() in WordPress).
651
+ metadata:
652
+ category: security
653
+ subcategory: [vuln]
654
+ type: vulnerability
655
+ interprocedural: false
656
+ title: Request data chooses the redirect target
657
+ cwe: ["CWE-601: URL Redirection to Untrusted Site ('Open Redirect')"]
658
+ owasp: ["A01:2025 - Broken Access Control"]
659
+ references:
660
+ - https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html
661
+ pattern-sources: *php-sources
662
+ pattern-sanitizers:
663
+ - *php-checked
664
+ - *php-guarded
665
+ - *numeric
666
+ - pattern-either:
667
+ - pattern: urlencode(...)
668
+ - pattern: rawurlencode(...)
669
+ - pattern: $this->referer(...)
670
+ - pattern: $this->Controller->referer(...)
671
+ - pattern: $this->controller->referer(...)
672
+ - pattern: wp_validate_redirect(...)
673
+ - pattern: wp_sanitize_redirect(...)
674
+ pattern-sinks:
675
+ - patterns:
676
+ - pattern-either:
677
+ - patterns:
678
+ - pattern: header($X, ...)
679
+ - metavariable-regex:
680
+ metavariable: $X
681
+ regex: '(?i)^["'']\s*location\s*:'
682
+ - pattern: wp_redirect($X, ...)
683
+ - pattern: redirect($X, ...)
684
+ - pattern: redirect()->to($X, ...)
685
+ - pattern: redirect()->away($X, ...)
686
+ - pattern: Redirect::to($X, ...)
687
+ - pattern: Redirect::away($X, ...)
688
+ - pattern: new RedirectResponse($X, ...)
689
+ - pattern: $THIS->redirect($X, ...)
690
+ - focus-metavariable: $X
691
+
692
+ - id: codewatch.php.web.unsafe-deserialization
693
+ mode: taint
694
+ languages: [php]
695
+ severity: ERROR
696
+ message: >-
697
+ Data from the HTTP request is passed to unserialize(), which can build objects whose magic methods run
698
+ code. Use json_decode(), or unserialize($data, ['allowed_classes' => false]).
699
+ metadata:
700
+ category: security
701
+ subcategory: [vuln]
702
+ type: vulnerability
703
+ interprocedural: false
704
+ title: Request data unserialized
705
+ cwe: ["CWE-502: Deserialization of Untrusted Data"]
706
+ owasp: ["A08:2025 - Software or Data Integrity Failures"]
707
+ references:
708
+ - https://cheatsheetseries.owasp.org/cheatsheets/Deserialization_Cheat_Sheet.html
709
+ pattern-sources: *php-sources
710
+ pattern-sanitizers:
711
+ - *php-checked
712
+ - *php-guarded
713
+ - *numeric
714
+ pattern-sinks:
715
+ - patterns:
716
+ - pattern: unserialize($X, ...)
717
+ - pattern-not: "unserialize($Y, ['allowed_classes' => false])"
718
+ - pattern-not: "unserialize($Y, array('allowed_classes' => false))"
719
+ - focus-metavariable: $X