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,1539 @@
1
+ # codewatch built-in taint rules for JavaScript/TypeScript: data from the HTTP request (Express, Koa, Next.js
2
+ # route handlers) or, in the browser, from the URL and messages, reaching an injection sink unchecked.
3
+ rules:
4
+ - id: codewatch.js.sql-injection
5
+ mode: taint
6
+ languages: [typescript, javascript]
7
+ severity: ERROR
8
+ message: >-
9
+ Data from the request is built into a SQL query. Pass it as a bound parameter instead
10
+ (sequelize.query(sql, { replacements }), pool.query(sql, [value]), knex.raw(sql, [value])).
11
+ metadata: &js-meta-sql
12
+ category: security
13
+ subcategory: [vuln]
14
+ type: vulnerability
15
+ title: Request data built into a SQL query
16
+ cwe: ["CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')"]
17
+ owasp: ["A05:2025 - Injection"]
18
+ references:
19
+ - https://cheatsheetseries.owasp.org/cheatsheets/SQL_Injection_Prevention_Cheat_Sheet.html
20
+ - https://sequelize.org/docs/v6/core-concepts/raw-queries/#replacements
21
+ pattern-sources: &js-sources
22
+ - &src-request-field
23
+ patterns:
24
+ - pattern-either:
25
+ - pattern: $REQ.$FIELD
26
+ - pattern: $REQ.$FIELD.$ANY
27
+ - metavariable-regex: {metavariable: $REQ, regex: '^(req|request|ctx|ctx\.request|context\.req)$'}
28
+ - metavariable-regex:
29
+ metavariable: $FIELD
30
+ regex: '^(body|query|params|cookies|headers|path|url|originalUrl|baseUrl|hostname|files|file)$'
31
+ # Where multer (default storage) put the upload is the server's choice, not the client's: req.file.path,
32
+ # req.file.filename, req.files[i].path. originalname is the client's and stays request data.
33
+ - pattern-not-inside: $REQ.file.path
34
+ - pattern-not-inside: $REQ.file.filename
35
+ - pattern-not-inside: $REQ.files[$I].path
36
+ - pattern-not-inside: $REQ.files[$I].filename
37
+ - pattern-not-inside: $REQ.files.$NAME[$I].path
38
+ - pattern-not-inside: $REQ.files.$NAME[$I].filename
39
+ # NocoBase resource actions (Koa): ctx.action.params holds the request's filter, values and query.
40
+ # Added for GHSA-p849-8hwh-84j9 (cve-pairs-javascript).
41
+ - &src-resource-action-params
42
+ pattern-either:
43
+ - pattern: ctx.action.params
44
+ - pattern: ctx.action?.params
45
+ - pattern: ctx.action.params.$ANY
46
+ - pattern: ctx.action?.params.$ANY
47
+ # A name destructured with a default, `const { filter = {} } = req.body`: Semgrep's taint loses it there.
48
+ # Added for GHSA-p849-8hwh-84j9 (cve-pairs-javascript).
49
+ - &src-destructured-default
50
+ patterns:
51
+ - pattern-either:
52
+ - pattern-inside: |
53
+ const {..., $X = $D, ...} = $RHS;
54
+ ...
55
+ - pattern-inside: |
56
+ let {..., $X = $D, ...} = $RHS;
57
+ ...
58
+ - pattern: $X
59
+ - metavariable-pattern:
60
+ metavariable: $RHS
61
+ pattern-either:
62
+ - pattern-either:
63
+ - pattern: ctx.action.params
64
+ - pattern: ctx.action?.params
65
+ - pattern: ctx.action.params ?? $E
66
+ - pattern: ctx.action?.params ?? $E
67
+ - pattern: ctx.action.params || $E
68
+ - pattern: ctx.action?.params || $E
69
+ - patterns:
70
+ - pattern-either:
71
+ - pattern: $REQ.$FIELD
72
+ - pattern: $REQ.$FIELD ?? $E
73
+ - pattern: $REQ.$FIELD || $E
74
+ - metavariable-regex: {metavariable: $REQ, regex: '^(req|request|ctx|ctx\.request|context\.req)$'}
75
+ - metavariable-regex: {metavariable: $FIELD, regex: '^(body|query|params|cookies|headers|files|file)$'}
76
+ # Exact: the call's value, not its argument. Otherwise `request.header('accept')` with `request` the incoming
77
+ # request also matched the request library's request.$METHOD(url) sink around its own argument (immich).
78
+ - &src-request-getter
79
+ patterns:
80
+ - pattern: $REQ.$GETTER(...)
81
+ - metavariable-regex: {metavariable: $REQ, regex: '^(req|request|ctx|ctx\.request)$'}
82
+ - metavariable-regex: {metavariable: $GETTER, regex: '^(get|header|param|cookies|json|text|formData)$'}
83
+ exact: true
84
+ - &src-search-params
85
+ pattern: new URLSearchParams(...).get(...)
86
+ - &src-url-search-params
87
+ pattern: $URL.searchParams.get(...)
88
+ # Handlers that destructure the request: ({ params, body }: Request, res) => ...
89
+ - &src-destructured-request
90
+ patterns:
91
+ - pattern-either:
92
+ - pattern-inside: '({..., $FIELD, ...}: Request, ...) => { ... }'
93
+ - pattern-inside: 'function $F({..., $FIELD, ...}: Request, ...) { ... }'
94
+ - pattern-inside: '$APP.$METHOD($PATH, ..., ({..., $FIELD, ...}, $RES, ...) => { ... })'
95
+ - pattern: $FIELD
96
+ - metavariable-regex: {metavariable: $FIELD, regex: '^(body|query|params|cookies|headers|files|file)$'}
97
+ # NestJS controller parameters: @Body() dto, @Query('q') q, @Param('id') id, @Headers() headers. Not those a
98
+ # pipe or a number/boolean/Date type converts (ParseIntPipe, `id: number` under ValidationPipe's transform).
99
+ - &src-nest-param
100
+ patterns:
101
+ - pattern-inside: |
102
+ $M(..., @$DEC(...) $PARAM, ...) { ... }
103
+ - pattern-not-inside: |
104
+ $M(..., @$DEC(..., ParseIntPipe, ...) $PARAM, ...) { ... }
105
+ - pattern-not-inside: |
106
+ $M(..., @$DEC(..., new ParseIntPipe(...), ...) $PARAM, ...) { ... }
107
+ - pattern-not-inside: |
108
+ $M(..., @$DEC(..., ParseFloatPipe, ...) $PARAM, ...) { ... }
109
+ - pattern-not-inside: |
110
+ $M(..., @$DEC(..., new ParseFloatPipe(...), ...) $PARAM, ...) { ... }
111
+ - pattern-not-inside: |
112
+ $M(..., @$DEC(..., ParseBoolPipe, ...) $PARAM, ...) { ... }
113
+ - pattern-not-inside: |
114
+ $M(..., @$DEC(..., new ParseBoolPipe(...), ...) $PARAM, ...) { ... }
115
+ - pattern-not-inside: |
116
+ $M(..., @$DEC(..., ParseUUIDPipe, ...) $PARAM, ...) { ... }
117
+ - pattern-not-inside: |
118
+ $M(..., @$DEC(..., new ParseUUIDPipe(...), ...) $PARAM, ...) { ... }
119
+ - pattern-not-inside: |
120
+ $M(..., @$DEC(..., ParseEnumPipe, ...) $PARAM, ...) { ... }
121
+ - pattern-not-inside: |
122
+ $M(..., @$DEC(..., new ParseEnumPipe(...), ...) $PARAM, ...) { ... }
123
+ - pattern-not-inside: |
124
+ $M(..., @$DEC(...) $PARAM: number, ...) { ... }
125
+ - pattern-not-inside: |
126
+ $M(..., @$DEC(...) $PARAM: boolean, ...) { ... }
127
+ - pattern-not-inside: |
128
+ $M(..., @$DEC(...) $PARAM: Date, ...) { ... }
129
+ - pattern-not-inside: |
130
+ $M(..., @$DEC(...) $PARAM: bigint, ...) { ... }
131
+ - pattern-not-inside: |
132
+ $M(..., @$DEC(...) $PARAM: number[], ...) { ... }
133
+ - pattern-not-inside: |
134
+ $M(..., @$DEC(...) $PARAM: boolean[], ...) { ... }
135
+ - pattern: $PARAM
136
+ - metavariable-regex: {metavariable: $DEC, regex: '^(Body|Query|Param|Headers)$'}
137
+ pattern-sanitizers: &js-sanitizers
138
+ - &san-numeric
139
+ pattern-either:
140
+ - pattern: parseInt(...)
141
+ - pattern: parseFloat(...)
142
+ - pattern: Number(...)
143
+ - pattern: Number.parseInt(...)
144
+ - pattern: Number.parseFloat(...)
145
+ - pattern: Boolean(...)
146
+ - pattern: Math.$F(...)
147
+ - pattern: $X.length
148
+ - pattern: typeof $X
149
+ # Functions named as validators (isValid, validateId, sanitizeName, escapeHtml, outline's getValidatedHost)
150
+ # return checked data.
151
+ - &san-named
152
+ patterns:
153
+ - pattern: $CHECK(...)
154
+ - metavariable-regex: {metavariable: $CHECK, regex: '(?i)(.*\.)?(get_?)?(is_?valid|validat|sanitiz|escape|clean|safe|whitelist|allowlist)\w{0,40}$'}
155
+ # [allowed].includes(x) ? x : fallback only ever yields an allowed value.
156
+ - &san-allowlist-ternary
157
+ pattern: '$ALLOWED.includes($X) ? $X : $FALLBACK'
158
+ # A cookie the server signed holds what the server stored there, like a session (wiki.js reads its login
159
+ # flow back with Fastify's req.unsignCookie(raw)); req.signedCookies (Express) isn't a source for the same reason.
160
+ - &san-signed
161
+ pattern: $REQ.unsignCookie(...)
162
+ # A check on the value that bails out: if (!next.startsWith("/") || next.startsWith("//")) return ...
163
+ - &san-guard
164
+ pattern-either:
165
+ # A named check that said no ends the request: `if (!isValidRedirectUrl(url)) { ...; return; }` (actual).
166
+ # Not in that branch itself, and only a check named for it (`if (!url) return` says nothing).
167
+ - patterns:
168
+ - pattern-either:
169
+ - pattern-inside: |
170
+ if (!$CHECK(..., $X, ...)) { ... return ...; }
171
+ ...
172
+ - pattern-inside: |
173
+ if (!$CHECK(..., $X, ...)) { ... return; }
174
+ ...
175
+ - pattern-inside: |
176
+ if (!$CHECK(..., $X, ...)) return ...;
177
+ ...
178
+ - pattern-inside: |
179
+ if (!$CHECK(..., $X, ...)) { ... throw $E; }
180
+ ...
181
+ - pattern-inside: |
182
+ if (!$CHECK(..., $X, ...)) throw $E;
183
+ ...
184
+ - pattern-not-inside: |
185
+ if (!$CHECK(..., $X, ...)) { ... }
186
+ - pattern-not-inside: |
187
+ if (!$CHECK(..., $X, ...)) $STMT;
188
+ - metavariable-regex:
189
+ metavariable: $CHECK
190
+ regex: '(?i)^(.*\.)?(is|check|can)\w{0,30}(safe|valid|allowed|permitted|trusted|whitelist|allowlist)\w{0,30}$'
191
+ - pattern: $X
192
+ - patterns:
193
+ - pattern-either:
194
+ - pattern-inside: |
195
+ if (<... $X.startsWith(...) ...>) { ... return ...; }
196
+ ...
197
+ - pattern-inside: |
198
+ if (<... $X.startsWith(...) ...>) return ...;
199
+ ...
200
+ - pattern-inside: |
201
+ if (<... $X.startsWith(...) ...>) { ... throw $E; }
202
+ ...
203
+ - pattern-inside: |
204
+ if (<... $X.startsWith(...) ...>) throw $E;
205
+ ...
206
+ - pattern-inside: |
207
+ if (<... $X.endsWith(...) ...>) { ... return ...; }
208
+ ...
209
+ - pattern-inside: |
210
+ if (<... $X.endsWith(...) ...>) return ...;
211
+ ...
212
+ - pattern-inside: |
213
+ if (<... $X.endsWith(...) ...>) { ... throw $E; }
214
+ ...
215
+ - pattern-inside: |
216
+ if (<... $X.endsWith(...) ...>) throw $E;
217
+ ...
218
+ - pattern-inside: |
219
+ if (<... $X.includes(...) ...>) { ... return ...; }
220
+ ...
221
+ - pattern-inside: |
222
+ if (<... $X.includes(...) ...>) return ...;
223
+ ...
224
+ - pattern-inside: |
225
+ if (<... $X.includes(...) ...>) { ... throw $E; }
226
+ ...
227
+ - pattern-inside: |
228
+ if (<... $X.includes(...) ...>) throw $E;
229
+ ...
230
+ - pattern-inside: |
231
+ if (<... $ALLOWED.includes($X) ...>) { ... return ...; }
232
+ ...
233
+ - pattern-inside: |
234
+ if (<... $ALLOWED.includes($X) ...>) return ...;
235
+ ...
236
+ - pattern-inside: |
237
+ if (<... $ALLOWED.includes($X) ...>) { ... throw $E; }
238
+ ...
239
+ - pattern-inside: |
240
+ if (<... $ALLOWED.includes($X) ...>) throw $E;
241
+ ...
242
+ - pattern-inside: |
243
+ if (<... $ALLOWED.has($X) ...>) { ... return ...; }
244
+ ...
245
+ - pattern-inside: |
246
+ if (<... $ALLOWED.has($X) ...>) return ...;
247
+ ...
248
+ - pattern-inside: |
249
+ if (<... $ALLOWED.has($X) ...>) { ... throw $E; }
250
+ ...
251
+ - pattern-inside: |
252
+ if (<... $ALLOWED.has($X) ...>) throw $E;
253
+ ...
254
+ - pattern-inside: |
255
+ if (<... $RE.test($X) ...>) { ... return ...; }
256
+ ...
257
+ - pattern-inside: |
258
+ if (<... $RE.test($X) ...>) return ...;
259
+ ...
260
+ - pattern-inside: |
261
+ if (<... $RE.test($X) ...>) { ... throw $E; }
262
+ ...
263
+ - pattern-inside: |
264
+ if (<... $RE.test($X) ...>) throw $E;
265
+ ...
266
+ - pattern-inside: |
267
+ if (<... $X.match(...) ...>) { ... return ...; }
268
+ ...
269
+ - pattern-inside: |
270
+ if (<... $X.match(...) ...>) return ...;
271
+ ...
272
+ - pattern-inside: |
273
+ if (<... $X.match(...) ...>) { ... throw $E; }
274
+ ...
275
+ - pattern-inside: |
276
+ if (<... $X.match(...) ...>) throw $E;
277
+ ...
278
+ - pattern: $X
279
+ # What a file contains is the server's data, whatever path was used to read it (path-traversal checks the path).
280
+ - &san-file-content
281
+ pattern-either:
282
+ - pattern: fs.readFile(...)
283
+ - pattern: fs.readFileSync(...)
284
+ - pattern: fs.promises.readFile(...)
285
+ - pattern: readFile(...)
286
+ - pattern: readFileSync(...)
287
+ # What a helper looks up with the request value (outline's loadPublicShare by share id) is stored data: the
288
+ # variable assigned from a getX/fetchX/loadX/findX/lookupX call, not the call, so a sink among its arguments
289
+ # still counts. Request-shaped names (getQuery, getRedirectUrl) aren't lookups; a project helper the
290
+ # returner pass finds returning request data still counts (summaries.without_lookup_result).
291
+ - &san-lookup-result
292
+ patterns:
293
+ - pattern-either:
294
+ - pattern-inside: |
295
+ $RESULT = $LOOKUP(...);
296
+ ...
297
+ - pattern-inside: |
298
+ $RESULT = await $LOOKUP(...);
299
+ ...
300
+ - pattern: $RESULT
301
+ - metavariable-regex:
302
+ metavariable: $LOOKUP
303
+ regex: '^_?(get|fetch|load|find|lookup)(?!(Json|Data|Params?|Args?|Query|Queries|Headers?|Cookies?|Body|Form|Fields?|Values?|Inputs?|Text|Str|String|Url|Uri|Path|File|Filename|Name|Key|Id|Var|Env|Config|Setting|Content|Request|Req|Payload|Redirect|Next|Return|Target|Dest|Destination|Location|Callback|Referr?er|Host|Origin)([A-Z]|$))[A-Z]\w*$'
304
+ pattern-sinks:
305
+ - patterns:
306
+ - pattern-either:
307
+ - pattern: $DB.query($SQL, ...)
308
+ - pattern: $DB.raw($SQL, ...)
309
+ - pattern: $DB.$queryRawUnsafe($SQL, ...)
310
+ - pattern: $DB.$executeRawUnsafe($SQL, ...)
311
+ - pattern: $DB.execute($SQL, ...)
312
+ - metavariable-regex:
313
+ metavariable: $DB
314
+ regex: '(?i)^(.*\.)?(sequelize|db|database|conn|connection|pool|client|knex|pg|mysql|sql|sqlite|prisma|tx|trx|transaction|datasource|queryrunner|manager|entitymanager|\w*repository|\w*repo)$'
315
+ - focus-metavariable: $SQL
316
+ # Raw SQL fragment inside a Sequelize query (GHSA-p849-8hwh-84j9).
317
+ - patterns:
318
+ - pattern-either:
319
+ - pattern: Sequelize.literal($SQL)
320
+ - pattern: sequelize.literal($SQL)
321
+ - focus-metavariable: $SQL
322
+
323
+ - id: codewatch.js.command-injection
324
+ mode: taint
325
+ languages: [typescript, javascript]
326
+ severity: ERROR
327
+ message: >-
328
+ Data from the request reaches a shell command. Call execFile()/spawn() with an argument array and no
329
+ shell, so the value can't add commands.
330
+ metadata:
331
+ category: security
332
+ subcategory: [vuln]
333
+ type: vulnerability
334
+ title: Request data in a shell command
335
+ cwe: ["CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')"]
336
+ owasp: ["A05:2025 - Injection"]
337
+ references:
338
+ - https://nodejs.org/api/child_process.html#child_processexecfilefile-args-options-callback
339
+ pattern-sources: *js-sources
340
+ pattern-sanitizers: *js-sanitizers
341
+ pattern-sinks:
342
+ - patterns:
343
+ - pattern-either:
344
+ - pattern: child_process.exec($CMD, ...)
345
+ - pattern: child_process.execSync($CMD, ...)
346
+ - pattern: require('child_process').exec($CMD, ...)
347
+ - pattern: require('child_process').execSync($CMD, ...)
348
+ - pattern: 'child_process.spawn($CMD, ..., {..., shell: true, ...})'
349
+ - pattern: 'child_process.spawnSync($CMD, ..., {..., shell: true, ...})'
350
+ # With shell: true the argument array is joined into the shell command too (GHSA-79wm-x847-7cvg).
351
+ - pattern: 'child_process.spawn($PROG, [..., $CMD, ...], {..., shell: true, ...})'
352
+ - pattern: 'child_process.spawnSync($PROG, [..., $CMD, ...], {..., shell: true, ...})'
353
+ - pattern: execa.command($CMD, ...)
354
+ - pattern: shelljs.exec($CMD, ...)
355
+ # A shell started by hand: spawn("sh", ["-c", cmd])
356
+ - pattern: 'child_process.$SPAWN("=~/^(\/bin\/|\/usr\/bin\/)?(sh|bash|zsh|dash|cmd|cmd\.exe|powershell)$/", [..., $CMD, ...], ...)'
357
+ # const exec = require('child_process').exec
358
+ - patterns:
359
+ - pattern: $EXEC($CMD, ...)
360
+ - pattern-inside: |
361
+ $EXEC = require('child_process').$METHOD
362
+ ...
363
+ - metavariable-regex: {metavariable: $METHOD, regex: ^(exec|execSync)$}
364
+ - focus-metavariable: $CMD
365
+ # node:child_process, however it's bound. Semgrep resolves require('child_process') and its imports to
366
+ # child_process.exec, which javascript-taint.yml covers, but not the `node:` specifier.
367
+ - patterns:
368
+ - pattern-either:
369
+ - pattern-inside: |
370
+ $CP = require("node:child_process");
371
+ ...
372
+ - pattern-inside: |
373
+ import * as $CP from "node:child_process";
374
+ ...
375
+ - pattern-inside: |
376
+ import $CP from "node:child_process";
377
+ ...
378
+ - pattern: $CP.$EXEC($CMD, ...)
379
+ - metavariable-regex: {metavariable: $EXEC, regex: '^(exec|execSync)$'}
380
+ - focus-metavariable: $CMD
381
+ - patterns:
382
+ - pattern-either:
383
+ - pattern-inside: |
384
+ $CP = require("node:child_process");
385
+ ...
386
+ - pattern-inside: |
387
+ import * as $CP from "node:child_process";
388
+ ...
389
+ - pattern-inside: |
390
+ import $CP from "node:child_process";
391
+ ...
392
+ - pattern-either:
393
+ - pattern: '$CP.$SPAWN($CMD, ..., {..., shell: true, ...})'
394
+ - pattern: '$CP.$SPAWN($PROG, [..., $CMD, ...], {..., shell: true, ...})'
395
+ - pattern: '$CP.$SPAWN("=~/^(\/bin\/|\/usr\/bin\/)?(sh|bash|zsh|dash|cmd|cmd\.exe|powershell)$/", [..., $CMD, ...], ...)'
396
+ - metavariable-regex: {metavariable: $SPAWN, regex: '^(spawn|spawnSync|execFile|execFileSync)$'}
397
+ - focus-metavariable: $CMD
398
+ - patterns:
399
+ - pattern: require("node:child_process").$EXEC($CMD, ...)
400
+ - metavariable-regex: {metavariable: $EXEC, regex: '^(exec|execSync)$'}
401
+ - focus-metavariable: $CMD
402
+ - patterns:
403
+ - pattern-either:
404
+ - pattern-inside: |
405
+ import { $EXEC } from "node:child_process";
406
+ ...
407
+ - pattern-inside: |
408
+ const { $EXEC } = require("node:child_process");
409
+ ...
410
+ - pattern: $EXEC($CMD, ...)
411
+ - metavariable-regex: {metavariable: $EXEC, regex: '^(exec|execSync)$'}
412
+ - focus-metavariable: $CMD
413
+ - patterns:
414
+ - pattern-either:
415
+ - pattern-inside: |
416
+ import { $SPAWN } from "node:child_process";
417
+ ...
418
+ - pattern-inside: |
419
+ const { $SPAWN } = require("node:child_process");
420
+ ...
421
+ - pattern-either:
422
+ - pattern: '$SPAWN($CMD, ..., {..., shell: true, ...})'
423
+ - pattern: '$SPAWN($PROG, [..., $CMD, ...], {..., shell: true, ...})'
424
+ - pattern: '$SPAWN("=~/^(\/bin\/|\/usr\/bin\/)?(sh|bash|zsh|dash|cmd|cmd\.exe|powershell)$/", [..., $CMD, ...], ...)'
425
+ - metavariable-regex: {metavariable: $SPAWN, regex: '^(spawn|spawnSync|execFile|execFileSync)$'}
426
+ - focus-metavariable: $CMD
427
+ # const run = util.promisify(exec); await run(cmd)
428
+ - patterns:
429
+ - pattern-either:
430
+ - pattern-inside: |
431
+ $RUN = util.promisify($EXEC);
432
+ ...
433
+ - pattern-inside: |
434
+ $RUN = promisify($EXEC);
435
+ ...
436
+ - pattern: $RUN($CMD, ...)
437
+ - metavariable-pattern:
438
+ metavariable: $EXEC
439
+ pattern-either:
440
+ - pattern: exec
441
+ - pattern: $CP.exec
442
+ - pattern: require("$M").exec
443
+ - focus-metavariable: $CMD
444
+ # execa runs the program directly unless told to use a shell; execaCommand splits a whole command line.
445
+ - patterns:
446
+ - pattern-either:
447
+ - pattern: '$EXECA($CMD, ..., {..., shell: true, ...})'
448
+ - pattern: '$EXECA($PROG, [..., $CMD, ...], {..., shell: true, ...})'
449
+ - pattern: '$EXECA("=~/^(\/bin\/|\/usr\/bin\/)?(sh|bash|zsh|dash|cmd|cmd\.exe|powershell)$/", [..., $CMD, ...], ...)'
450
+ - metavariable-regex: {metavariable: $EXECA, regex: '^(execa|execaSync)$'}
451
+ - focus-metavariable: $CMD
452
+ - patterns:
453
+ - pattern-either:
454
+ - pattern: execaCommand($CMD, ...)
455
+ - pattern: execaCommandSync($CMD, ...)
456
+ - pattern: execa.commandSync($CMD, ...)
457
+ - focus-metavariable: $CMD
458
+
459
+ - id: codewatch.js.path-traversal
460
+ mode: taint
461
+ languages: [typescript, javascript]
462
+ severity: ERROR
463
+ message: >-
464
+ Data from the request is used as a file path, so "../" can reach files outside the intended folder. Take
465
+ path.basename() of it, or resolve it and check the result still starts with the base folder.
466
+ metadata:
467
+ category: security
468
+ subcategory: [vuln]
469
+ type: vulnerability
470
+ title: Request data used as a file path
471
+ cwe: ["CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')"]
472
+ owasp: ["A01:2025 - Broken Access Control"]
473
+ references:
474
+ - https://cheatsheetseries.owasp.org/cheatsheets/Nodejs_Security_Cheat_Sheet.html
475
+ - https://expressjs.com/en/api.html#res.sendFile
476
+ pattern-sources: *js-sources
477
+ pattern-sanitizers:
478
+ - *san-numeric
479
+ - *san-named
480
+ - *san-allowlist-ternary
481
+ - *san-guard
482
+ - *san-signed
483
+ - *san-lookup-result
484
+ - pattern: path.basename(...)
485
+ # multer and express-fileupload take the file name through busboy, which drops any directory part.
486
+ - pattern-either:
487
+ - pattern: $REQ.file.originalname
488
+ - pattern: $REQ.files.$FIELD.name
489
+ - pattern: $REQ.files[$FIELD].originalname
490
+ - pattern: $REQ.files[$FIELD].name
491
+ - patterns:
492
+ - pattern-either:
493
+ - pattern-inside: |
494
+ const $F = $REQ.files.$FIELD;
495
+ ...
496
+ - pattern-inside: |
497
+ let $F = $REQ.files.$FIELD;
498
+ ...
499
+ - pattern-inside: |
500
+ const $F = $REQ.files[$FIELD];
501
+ ...
502
+ - pattern-either:
503
+ - pattern: $F.name
504
+ - pattern: $F.originalname
505
+ # if (!resolved.startsWith(base)) return/throw ...
506
+ - patterns:
507
+ - pattern-inside: |
508
+ if (<... !$X.startsWith(...) ...>) { ... }
509
+ ...
510
+ - pattern: $X
511
+ pattern-sinks:
512
+ - patterns:
513
+ - pattern-either:
514
+ - patterns:
515
+ - pattern-either:
516
+ - pattern: fs.$FN($PATH, ...)
517
+ - pattern: fs.promises.$FN($PATH, ...)
518
+ - pattern: fsPromises.$FN($PATH, ...)
519
+ - metavariable-regex: &js-file-functions
520
+ metavariable: $FN
521
+ regex: '^(readFile|readFileSync|createReadStream|writeFile|writeFileSync|createWriteStream|appendFile|appendFileSync|unlink|unlinkSync|rm|rmSync|readdir|readdirSync|open|openSync|copyFile|copyFileSync|rename|renameSync|rmdir|rmdirSync|cp|cpSync|opendir|opendirSync|truncate|truncateSync|symlink|symlinkSync|remove|removeSync|outputFile|outputFileSync|outputJson|outputJsonSync|outputJSON|readJson|readJsonSync|readJSON|writeJson|writeJsonSync|writeJSON|copy|copySync|move|moveSync)$'
522
+ - patterns:
523
+ - pattern: $RES.sendFile($PATH)
524
+ - metavariable-regex: {metavariable: $RES, regex: '^(res|response|reply)$'}
525
+ - patterns:
526
+ - pattern: $RES.download($PATH, ...)
527
+ - metavariable-regex: {metavariable: $RES, regex: '^(res|response|reply)$'}
528
+ # express-fileupload: req.files.upload.mv(path)
529
+ - pattern: $FILE.mv($PATH, ...)
530
+ - focus-metavariable: $PATH
531
+ # A file module under any name, or one Semgrep doesn't resolve to fs: const fsp = require('fs/promises'),
532
+ # import fse from 'fs-extra', node:fs, node:fs/promises.
533
+ - patterns:
534
+ - pattern-either:
535
+ - pattern-inside: |
536
+ $FS = require("$MOD");
537
+ ...
538
+ - pattern-inside: |
539
+ import * as $FS from "$MOD";
540
+ ...
541
+ - pattern-inside: |
542
+ import $FS from "$MOD";
543
+ ...
544
+ - pattern: $FS.$FN($PATH, ...)
545
+ - metavariable-regex: &js-file-modules {metavariable: $MOD, regex: '^(node:)?fs(/promises)?$|^(fs-extra|graceful-fs)$'}
546
+ - metavariable-regex: {metavariable: $FS, regex: '^[A-Za-z_$][\w$]*$'}
547
+ # Semgrep also binds a destructured name to itself (const { readFile } = require('fs') as readFile.readFile).
548
+ - metavariable-comparison: {comparison: str($FS) != str($FN)}
549
+ - metavariable-regex: *js-file-functions
550
+ - focus-metavariable: $PATH
551
+ # require('fs').createReadStream(p), inline.
552
+ - patterns:
553
+ - pattern: require("$MOD").$FN($PATH, ...)
554
+ - metavariable-regex: *js-file-modules
555
+ - metavariable-regex: *js-file-functions
556
+ - focus-metavariable: $PATH
557
+ # import { readFile } from 'fs/promises'
558
+ - patterns:
559
+ - pattern-either:
560
+ - pattern-inside: |
561
+ import { $FN } from "$MOD";
562
+ ...
563
+ - pattern-inside: |
564
+ const { $FN } = require("$MOD");
565
+ ...
566
+ - pattern: $FN($PATH, ...)
567
+ - metavariable-regex: *js-file-modules
568
+ - metavariable-regex: *js-file-functions
569
+ - focus-metavariable: $PATH
570
+ # The destination of a move or copy: fs.rename(upload.path, path.join(dir, req.body.name)).
571
+ - patterns:
572
+ - pattern-either:
573
+ - pattern: $FS.$FN($SRC, $PATH, ...)
574
+ - pattern: $FN($SRC, $PATH, ...)
575
+ - metavariable-regex: {metavariable: $FN, regex: '^(rename|renameSync|copyFile|copyFileSync|cp|cpSync|copy|copySync|move|moveSync|symlink|symlinkSync)$'}
576
+ - metavariable-regex: {metavariable: $FS, regex: '^(fs|fsPromises|fsp|fse|fsExtra|fs\.promises)$'}
577
+ - focus-metavariable: $PATH
578
+ # res.sendFile(p, options) without a root, or with a callback. With root, send rejects "..".
579
+ - patterns:
580
+ - pattern-either:
581
+ - pattern: '$RES.sendFile($PATH, {...}, ...)'
582
+ - pattern: '$RES.sendFile($PATH, function (...) { ... })'
583
+ - pattern: '$RES.sendFile($PATH, (...) => $BODY)'
584
+ - pattern-not: '$RES.sendFile($PATH, {..., root: $ROOT, ...}, ...)'
585
+ - metavariable-regex: {metavariable: $RES, regex: '^(res|response|reply)$'}
586
+ - focus-metavariable: $PATH
587
+
588
+ - id: codewatch.js.xss
589
+ mode: taint
590
+ languages: [typescript, javascript]
591
+ severity: ERROR
592
+ message: >-
593
+ Data from the request, the URL or a form field is written into HTML without escaping, so it can carry
594
+ script. Escape it
595
+ (escape-html, he.encode, DOMPurify.sanitize for markup), use textContent, or render through a template engine
596
+ that escapes by default.
597
+ metadata:
598
+ category: security
599
+ subcategory: [vuln]
600
+ type: vulnerability
601
+ title: Request or URL data written into HTML
602
+ cwe: ["CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')"]
603
+ owasp: ["A05:2025 - Injection"]
604
+ references:
605
+ - https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html
606
+ pattern-sources:
607
+ - *src-request-field
608
+ - *src-request-getter
609
+ - *src-search-params
610
+ - *src-url-search-params
611
+ - *src-nest-param
612
+ - &dom-sources
613
+ pattern-either:
614
+ - pattern: location.hash
615
+ - pattern: location.search
616
+ - pattern: location.href
617
+ - pattern: window.location.hash
618
+ - pattern: window.location.search
619
+ - pattern: window.location.href
620
+ - pattern: document.location.hash
621
+ - pattern: document.location.search
622
+ - pattern: document.location.href
623
+ - pattern: document.URL
624
+ - pattern: document.documentURI
625
+ - pattern: document.referrer
626
+ - pattern: window.name
627
+ - patterns:
628
+ - pattern-inside: |
629
+ $W.addEventListener("message", ($E) => { ... })
630
+ - pattern: $E.data
631
+ # A form field's value is whatever was typed or pasted into it (calibre-web GHSA-wrp6: an upload's file name
632
+ # from $(this).val() into .html(); Modoboa GHSA-c467: $("#id_name").val()). For this rule only: as a URL or
633
+ # a path it is the user's own navigation.
634
+ - pattern-either:
635
+ - pattern: $($SEL).val()
636
+ - pattern: $($SEL).$FIND(...).val()
637
+ - pattern: document.getElementById(...).value
638
+ - pattern: document.querySelector(...).value
639
+ pattern-sanitizers:
640
+ - *san-numeric
641
+ - *san-named
642
+ - *san-allowlist-ternary
643
+ - *san-guard
644
+ - *san-signed
645
+ - *san-file-content
646
+ - *san-lookup-result
647
+ # The Host and X-Forwarded-* headers: a victim's browser sends the real host for a page, and a proxy sets the
648
+ # rest, so a link can't make them carry markup (linkwarden: an RSS feed's site_url from req.headers.host).
649
+ - patterns:
650
+ - pattern-either:
651
+ - pattern: $REQ.headers.host
652
+ - pattern: $REQ.hostname
653
+ - pattern: $REQ.host
654
+ - pattern: $REQ.protocol
655
+ - metavariable-regex: {metavariable: $REQ, regex: '^(req|request|ctx|ctx\.request|context\.req)$'}
656
+ - patterns:
657
+ - pattern-either:
658
+ - pattern: $REQ.headers[$HEADER]
659
+ - pattern: $REQ.get($HEADER)
660
+ - pattern: $REQ.header($HEADER)
661
+ - metavariable-regex: {metavariable: $REQ, regex: '^(req|request|ctx|ctx\.request|context\.req)$'}
662
+ - metavariable-regex: {metavariable: $HEADER, regex: '(?i)^[''"](host|x-forwarded-[a-z-]+)[''"]$'}
663
+ - pattern-either:
664
+ - pattern: escapeHtml(...)
665
+ - pattern: escape(...)
666
+ - pattern: he.encode(...)
667
+ - pattern: he.escape(...)
668
+ - pattern: DOMPurify.sanitize(...)
669
+ - pattern: sanitizeHtml(...)
670
+ - pattern: xss(...)
671
+ - pattern: validator.escape(...)
672
+ - pattern: encodeURIComponent(...)
673
+ - pattern: encodeURI(...)
674
+ - pattern: $X.textContent
675
+ # A fetch to a path on the page's own server returns that server's reply, not the text the request carried: a
676
+ # form value posted with fetch('/api/compare', {body: ...}) doesn't make the reply's fields the user's input.
677
+ # Only a same-origin path: a proxy that fetches a URL from the request sends back whatever that site serves
678
+ # (actual's app-cors-proxy.js passes text/html on with res.send).
679
+ - patterns:
680
+ - pattern: fetch($URL, ...)
681
+ - metavariable-regex: {metavariable: $URL, regex: '^[`''"]/(?![/\\])'}
682
+ # A type looked up from a file name follows the file actually served (mime.getType(req.path) in a static
683
+ # file handler), not text the request chose.
684
+ - patterns:
685
+ - pattern-either:
686
+ - pattern: $MIME.getType(...)
687
+ - pattern: $MIME.lookup(...)
688
+ - pattern: $MIME.contentType(...)
689
+ - metavariable-regex: {metavariable: $MIME, regex: '(?i)^(mime|mime_?types|mimetypes?)$'}
690
+ # htmlEncode(str) / encodeHTML / html_encode: named for escaping markup (Modoboa's fix for GHSA-c467).
691
+ - patterns:
692
+ - pattern: $ENCODE(...)
693
+ - metavariable-regex: {metavariable: $ENCODE, regex: '(?i)(.*\.)?(html_?encode|encode_?html|html_?entities)\w*$'}
694
+ # A record from the data layer, found or saved using the request's values, is the stored object rather
695
+ # than the request's text: await userService.getUserById(req.params.id), WIKI.models.assets.getAsset(...)
696
+ - patterns:
697
+ - pattern: await $DATA.$ACCESS(...)
698
+ - metavariable-regex:
699
+ metavariable: $DATA
700
+ regex: '(?i)(.*\.)?(\w*(service|repo|repository|model|dao|store)|db|prisma|collection|knex|models?\.\w+)$'
701
+ - metavariable-regex:
702
+ metavariable: $ACCESS
703
+ regex: '^(?!.*(?i:html|render|template|markup|view|page))(find|get|create|update|save|insert|upsert|delete|remove|query|fetch|load|count|resolve)\w*$'
704
+ # A fixed template rendered with the request's values: these engines escape <%= %>, {{ }} and #{} unless the
705
+ # template asks for raw output (<%-, {{{, !{, !=, | safe).
706
+ - patterns:
707
+ - pattern-either:
708
+ - pattern: $ENGINE.render($TEMPLATE, ...)
709
+ - pattern: $ENGINE.renderString($TEMPLATE, ...)
710
+ - pattern: $ENGINE.compile($TEMPLATE, ...)(...)
711
+ - metavariable-regex: {metavariable: $ENGINE, regex: '(?i)^(pug|jade|ejs|handlebars|hbs|nunjucks|mustache|eta)$'}
712
+ - metavariable-regex:
713
+ metavariable: $TEMPLATE
714
+ regex: '^[''"`](?![\s\S]*(<%-|\{\{\{|!\{|!=|\|\s*safe|\$\{))[\s\S]*[''"`]$'
715
+ pattern-sinks:
716
+ # The response's type chosen by the request: text/html makes whatever the body holds run as a page on the
717
+ # app's origin (n8n GHSA-c8hm: a stored upload served with ?mimeType=text/html). Express/Node, Fastify's
718
+ # reply and Koa's ctx. Not when the same handler sends a `Content-Security-Policy: sandbox` (n8n's fix) or
719
+ # makes the response an attachment, and not a type looked up in an upper-case table (TYPES[ext]).
720
+ - patterns:
721
+ - pattern-either:
722
+ - patterns:
723
+ - pattern-either:
724
+ - pattern: $RES.setHeader($K, $CT)
725
+ - pattern: $RES.set($K, $CT)
726
+ - pattern: $RES.header($K, $CT)
727
+ - pattern: '$RES.set({..., $K: $CT, ...})'
728
+ - pattern: '$RES.headers({..., $K: $CT, ...})'
729
+ - pattern: '$RES.writeHead($S, {..., $K: $CT, ...})'
730
+ - pattern: '$RES.writeHead($S, $MSG, {..., $K: $CT, ...})'
731
+ - metavariable-regex: {metavariable: $K, regex: '(?i)^[''"`]?content-type[''"`]?$'}
732
+ - pattern: $RES.type($CT)
733
+ - pattern: $RES.contentType($CT)
734
+ - pattern: $RES.type = $CT
735
+ - metavariable-regex: {metavariable: $RES, regex: '^(res|response|reply|ctx|ctx\.response)$'}
736
+ - metavariable-regex: {metavariable: $CT, regex: '^(?![A-Z][A-Z0-9_]*\[)'}
737
+ - pattern-not-inside: |
738
+ $RES.$SETCT(...);
739
+ ...
740
+ $RES.$SETCSP("=~/(?i)^content-security-policy$/", "=~/sandbox/");
741
+ - pattern-not-inside: |
742
+ $RES.$SETCSP("=~/(?i)^content-security-policy$/", "=~/sandbox/");
743
+ ...
744
+ - pattern-not-inside: |
745
+ $RES.attachment(...);
746
+ ...
747
+ - pattern-not-inside: |
748
+ $RES.$SETCT(...);
749
+ ...
750
+ $RES.attachment(...);
751
+ - focus-metavariable: $CT
752
+ - patterns:
753
+ - pattern-either:
754
+ - pattern: $RES.send($HTML)
755
+ - pattern: $RES.write($HTML)
756
+ - pattern: $RES.end($HTML)
757
+ - metavariable-regex: {metavariable: $RES, regex: '^(res|response)$'}
758
+ # Objects and arrays go out as JSON, not HTML.
759
+ - pattern-not: $RES.$SEND({...})
760
+ - pattern-not: $RES.$SEND([...])
761
+ # So does anything after the response was given a non-HTML type (JSON, plain text, an event stream).
762
+ - pattern-not-inside: |
763
+ $RES.setHeader("=~/(?i)^content-type$/", "=~/(?i)(json|event-stream|text\/plain|octet-stream)/");
764
+ ...
765
+ - pattern-not-inside: |
766
+ $RES.set("=~/(?i)^content-type$/", "=~/(?i)(json|event-stream|text\/plain|octet-stream)/");
767
+ ...
768
+ - pattern-not-inside: |
769
+ $RES.type("=~/(?i)(json|text|plain|event-stream)/");
770
+ ...
771
+ - focus-metavariable: $HTML
772
+ - &dom-html-sinks
773
+ patterns:
774
+ - pattern-either:
775
+ - pattern: $EL.innerHTML = $HTML
776
+ - pattern: $EL.outerHTML = $HTML
777
+ - pattern: $EL.insertAdjacentHTML($POS, $HTML)
778
+ - pattern: document.write($HTML)
779
+ - pattern: document.writeln($HTML)
780
+ - pattern: $($SEL).html($HTML)
781
+ - pattern: $($SEL).append($HTML)
782
+ # A jQuery object kept in a variable, named with a $ as jQuery code does: $span.html(...)
783
+ - patterns:
784
+ - pattern-either:
785
+ - pattern: $JQ.html($HTML)
786
+ - pattern: $JQ.append($HTML)
787
+ - metavariable-regex: {metavariable: $JQ, regex: '^\$\w+$'}
788
+ # jQuery builds elements from a string that starts with a tag, and sets `html:` as innerHTML:
789
+ # $("<p>" + text + "</p>") (OctoPrint GHSA-x7mf), $('<div>', {html: message}) (Indico GHSA-fmqq).
790
+ - patterns:
791
+ - pattern: $($HTML)
792
+ - metavariable-regex: {metavariable: $HTML, regex: '^[''"`]\s*<[\s\S]*[+$]'}
793
+ - pattern: '$($TAG, {..., html: $HTML, ...})'
794
+ - focus-metavariable: $HTML
795
+
796
+ # Review: what a page's own script fetched, field by field, written into HTML. The server's JSON answer carries
797
+ # what users stored (a translation unit's text, a download's name, a webcam's reply), and the page has to escape
798
+ # it: weblate GHSA-6wxc (search results into a template string appended), OctoPrint GHSA-x7mf (a response field
799
+ # into $("<p>" + ...)), pyLoad GHSA-wcm6. Only fields of the parsed answer, not the whole answer: a fragment of HTML
800
+ # the server rendered (`.then(r => r.text()).then(html => el.innerHTML = html)`, `$(el).html(response)`) is meant
801
+ # to be markup. Not fields named for markup (data.html, rendered, template), counts or status. PLAN.md step 131.
802
+ - id: codewatch.js.fetched-data-into-html
803
+ mode: taint
804
+ languages: [typescript, javascript]
805
+ severity: WARNING
806
+ message: >-
807
+ A field of data the page fetched (a JSON answer from the server) is written into HTML. If it holds text users
808
+ stored, it can carry script: escape it or set it with textContent.
809
+ metadata:
810
+ category: security
811
+ subcategory: [audit]
812
+ type: security_hotspot
813
+ title: Fetched data written into HTML
814
+ cwe: ["CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')"]
815
+ owasp: ["A05:2025 - Injection"]
816
+ references:
817
+ - https://cheatsheetseries.owasp.org/cheatsheets/DOM_based_XSS_Prevention_Cheat_Sheet.html
818
+ pattern-sources:
819
+ - patterns:
820
+ - pattern-either:
821
+ - pattern-inside: $P.done(function ($R, ...) { ... })
822
+ - pattern-inside: $P.done(($R, ...) => { ... })
823
+ - pattern-inside: $P.then(function ($R, ...) { ... }, ...)
824
+ - pattern-inside: $P.then(($R, ...) => { ... }, ...)
825
+ - pattern-inside: $P.then(($R, ...) => $BODY, ...)
826
+ - pattern-inside: '$.ajax({..., success: function ($R, ...) { ... }, ...})'
827
+ - pattern-inside: '$.ajax({..., success: ($R, ...) => { ... }, ...})'
828
+ - patterns:
829
+ - pattern-either:
830
+ - pattern-inside: $.$GET(..., function ($R, ...) { ... })
831
+ - pattern-inside: $.$GET(..., ($R, ...) => { ... })
832
+ - metavariable-regex: {metavariable: $GET, regex: '^(get|post|getJSON)$'}
833
+ - patterns:
834
+ - pattern-inside: |
835
+ $R = await $CLIENT.$METHOD(...);
836
+ ...
837
+ - metavariable-regex: {metavariable: $CLIENT, regex: '^(axios|\$http|http|api|client)$'}
838
+ - pattern: $R.$FIELD
839
+ - metavariable-regex:
840
+ metavariable: $FIELD
841
+ regex: '^(?!(?i:.*(html|markup|rendered|template|partial)|ok|status|statusText|length|count|total|headers|json|text|blob|arrayBuffer|then|done|fail)$)\w+$'
842
+ # jQuery's loop hands each element to its callback: $.each(data.links, function (key, link) {...}) (pyLoad).
843
+ pattern-propagators:
844
+ - {pattern: '$.each($FROM, function ($K, $TO) { ... })', from: $FROM, to: $TO}
845
+ - {pattern: '$.each($FROM, ($K, $TO) => { ... })', from: $FROM, to: $TO}
846
+ pattern-sanitizers:
847
+ - *san-numeric
848
+ - *san-named
849
+ - pattern-either:
850
+ - pattern: escapeHtml(...)
851
+ - pattern: escape(...)
852
+ - pattern: _.escape(...)
853
+ - pattern: he.encode(...)
854
+ - pattern: he.escape(...)
855
+ - pattern: DOMPurify.sanitize(...)
856
+ - pattern: sanitizeHtml(...)
857
+ - pattern: encodeURIComponent(...)
858
+ - pattern: $X.textContent
859
+ - patterns:
860
+ - pattern: $ENCODE(...)
861
+ - metavariable-regex: {metavariable: $ENCODE, regex: '(?i)(.*\.)?(html_?encode|encode_?html|html_?entities)\w*$'}
862
+ pattern-sinks:
863
+ - *dom-html-sinks
864
+
865
+ - id: codewatch.js.open-redirect
866
+ mode: taint
867
+ languages: [typescript, javascript]
868
+ severity: WARNING
869
+ message: >-
870
+ Data from the request or the URL decides where the user is redirected, so a link to this page can send them
871
+ to any site. Redirect only to relative paths or to hosts on an exact allowlist (compare new URL(x).origin).
872
+ metadata:
873
+ category: security
874
+ subcategory: [vuln]
875
+ type: vulnerability
876
+ title: Redirect target taken from the request
877
+ cwe: ["CWE-601: URL Redirection to Untrusted Site ('Open Redirect')"]
878
+ owasp: ["A01:2025 - Broken Access Control"]
879
+ references:
880
+ - https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html
881
+ pattern-sources:
882
+ - *src-request-field
883
+ - *src-request-getter
884
+ - *src-search-params
885
+ - *src-url-search-params
886
+ - *src-nest-param
887
+ - *src-destructured-request
888
+ - *dom-sources
889
+ pattern-sanitizers:
890
+ - *san-numeric
891
+ - *san-named
892
+ - *san-allowlist-ternary
893
+ - *san-guard
894
+ - *san-signed
895
+ - *san-file-content
896
+ - *san-lookup-result
897
+ - patterns:
898
+ - pattern-inside: |
899
+ if (<... $ALLOWED.includes($X) ...>) { ... }
900
+ - pattern: $X
901
+ - patterns:
902
+ - pattern-inside: |
903
+ if (<... $ALLOWED.has($X) ...>) { ... }
904
+ - pattern: $X
905
+ # The Host header is the site the browser is already on; a link can't change it (HTTPS-upgrade redirects).
906
+ - patterns:
907
+ - pattern-either:
908
+ - pattern: $REQ.headers.host
909
+ - pattern: $REQ.hostname
910
+ - pattern: $REQ.host
911
+ - pattern: $REQ.get("host")
912
+ - pattern: $REQ.header("host")
913
+ - metavariable-regex: {metavariable: $REQ, regex: '^(req|request|ctx|ctx\.request)$'}
914
+ # The request's own path stays on this site unless it starts with "//"; open-redirect-path covers that
915
+ # (outline: /share/... rewritten to /s/..., and a URL on the team's host given the request's path).
916
+ - patterns:
917
+ - pattern-either:
918
+ - pattern: $REQ.$PATH
919
+ - pattern: $REQ.$PATH.$ANY
920
+ - metavariable-regex: {metavariable: $REQ, regex: '^(req|request|ctx|ctx\.request)$'}
921
+ - metavariable-regex: {metavariable: $PATH, regex: '^(url|originalUrl|path|baseUrl)$'}
922
+ # A literal prefix of "/" and a character other than "/" or "\", or one with "?" or "#" before the value,
923
+ # keeps the target on this site: the value can change the path or query, not the host (outline:
924
+ # `/?notice=auth-error&description=${description}`). A bare "/" + value is still open ("//evil.example").
925
+ - &san-fixed-prefix
926
+ pattern-either:
927
+ - patterns:
928
+ - pattern: $TEMPLATE
929
+ - metavariable-regex: {metavariable: $TEMPLATE, regex: '^`(/[^/\\`$]|[^`$]*[?#])'}
930
+ - patterns:
931
+ - pattern: $PREFIX + $REST
932
+ - metavariable-regex: {metavariable: $PREFIX, regex: '^[''"](/[^/\\''"]|[^''"]*[?#])'}
933
+ # A variable that starts as such a path stays on this site whatever is appended to it (habitica:
934
+ # let url = `/static/apple-redirect?code=${code}`; url += `&name=${name}`): the append is clean. Semgrep sees
935
+ # `url += x` as an assignment to url like any other, so a later `url = req.body.next` can't be told apart;
936
+ # it stays tainted because it isn't an append, but one appended to after that would be missed.
937
+ - patterns:
938
+ - pattern-either:
939
+ - pattern-inside: |
940
+ let $U = $START;
941
+ ...
942
+ - pattern-inside: |
943
+ var $U = $START;
944
+ ...
945
+ - metavariable-regex:
946
+ metavariable: $START
947
+ regex: '^(`(/[^/\\`$]|[^`$]*[?#])|[''"](/[^/\\''"]|[^''"]*[?#]))'
948
+ - pattern-either:
949
+ - pattern: $U + $X
950
+ - pattern: $U += $X
951
+ # The same after the app's configured base URL, which a link can't change (CTFd:
952
+ # CTFd.config.urlRoot + "/login?next=" + ..., `${CTFd.config.urlRoot}/login?next=...`).
953
+ - pattern-either:
954
+ - patterns:
955
+ - pattern: $TEMPLATE
956
+ - metavariable-regex:
957
+ metavariable: $TEMPLATE
958
+ regex: '(?i)^`\$\{[\w$.]*\.(url_?root|root_?url|base_?url|base_?path|app_?url|site_?url)\}(/[^/\\`$]|[^`$]*[?#])'
959
+ # Each value added after that prefix, however long the chain: `+` nests to the left, so in
960
+ # root + "/login?next=" + root + location.pathname + location.hash the prefix is deep inside the
961
+ # left operand of every later value.
962
+ - patterns:
963
+ - pattern-inside: $LEFT + $VALUE
964
+ - metavariable-pattern:
965
+ metavariable: $LEFT
966
+ patterns:
967
+ - pattern: <... $ROOT + $LITERAL ...>
968
+ - metavariable-regex:
969
+ metavariable: $ROOT
970
+ regex: '(?i)^[\w$.]*\.(url_?root|root_?url|base_?url|base_?path|app_?url|site_?url)$'
971
+ - metavariable-regex: {metavariable: $LITERAL, regex: '^[''"](/[^/\\''"]|[^''"]*[?#])'}
972
+ - pattern: $VALUE
973
+ # The page's own address up to its fragment is this site, path included, so nothing appended can change the
974
+ # host: a same-page jump (CTFd: window.location.href.split("#")[0] + "#preview"). Not location.origin, which
975
+ # "@evil.example" or ".evil.example" appended would move to another host.
976
+ - patterns:
977
+ - pattern-either:
978
+ - pattern: $LOC.href.split(...)[0]
979
+ - pattern: $LOC.href.split(...)[0] + $REST
980
+ - pattern: $LOC.href.split(...)[0] + $REST + $MORE
981
+ - metavariable-regex: {metavariable: $LOC, regex: '^((window|document)\.)?location$'}
982
+ # A URL object made from the page's own address keeps its origin when only its path or query is changed
983
+ # (a filter link). What its query holds is still tainted: only the whole URL is clean.
984
+ - patterns:
985
+ - pattern-inside: |
986
+ $U = new URL($LOC);
987
+ ...
988
+ - pattern-not-inside: |
989
+ $U.href = $V;
990
+ ...
991
+ - pattern-not-inside: |
992
+ $U.host = $V;
993
+ ...
994
+ - pattern-not-inside: |
995
+ $U.hostname = $V;
996
+ ...
997
+ - pattern-not-inside: |
998
+ $U.protocol = $V;
999
+ ...
1000
+ - pattern-either:
1001
+ - pattern: $U.toString()
1002
+ - pattern: $U.href
1003
+ - pattern: String($U)
1004
+ - metavariable-regex: {metavariable: $LOC, regex: '^((window|document)\.)?(location(\.href)?|URL)$'}
1005
+ pattern-sinks: &js-redirect-sinks
1006
+ - patterns:
1007
+ - pattern-either:
1008
+ - pattern: $RES.redirect($URL)
1009
+ - pattern: $RES.redirect($STATUS, $URL)
1010
+ - metavariable-regex: {metavariable: $RES, regex: '^(res|response|ctx|reply)$'}
1011
+ - focus-metavariable: $URL
1012
+ - patterns:
1013
+ - pattern-either:
1014
+ - pattern: $RES.setHeader($NAME, $URL)
1015
+ - pattern: $RES.set($NAME, $URL)
1016
+ - pattern: $RES.header($NAME, $URL)
1017
+ - pattern: '$RES.writeHead($STATUS, {..., $NAME: $URL, ...})'
1018
+ - metavariable-regex: {metavariable: $RES, regex: '^(res|response|reply)$'}
1019
+ - metavariable-regex: {metavariable: $NAME, regex: '(?i)^[''"]?location[''"]?$'}
1020
+ - focus-metavariable: $URL
1021
+ - patterns:
1022
+ - pattern: $RES.location($URL)
1023
+ - metavariable-regex: {metavariable: $RES, regex: '^(res|response)$'}
1024
+ - focus-metavariable: $URL
1025
+ - patterns:
1026
+ - pattern-either:
1027
+ - pattern: location.href = $URL
1028
+ - pattern: window.location.href = $URL
1029
+ - pattern: window.location = $URL
1030
+ - pattern: location.assign($URL)
1031
+ - pattern: location.replace($URL)
1032
+ - pattern: window.location.assign($URL)
1033
+ - pattern: window.location.replace($URL)
1034
+ - pattern: window.open($URL, ...)
1035
+ - focus-metavariable: $URL
1036
+
1037
+ - id: codewatch.js.open-redirect-path
1038
+ mode: taint
1039
+ languages: [typescript, javascript]
1040
+ severity: INFO
1041
+ message: >-
1042
+ The redirect target is built from the request's own path. That stays on this site unless the path can
1043
+ start with "//" (a request for "//evil.example/..." becomes a redirect to another host): check that the
1044
+ routes can't match such a path, or collapse repeated slashes first.
1045
+ # For review, as in Python: whether "//host" can reach this handler depends on the routing.
1046
+ metadata:
1047
+ category: security
1048
+ subcategory: [audit]
1049
+ type: security_hotspot
1050
+ title: Redirect built from the request path
1051
+ interprocedural: false
1052
+ cwe: ["CWE-601: URL Redirection to Untrusted Site ('Open Redirect')"]
1053
+ owasp: ["A01:2025 - Broken Access Control"]
1054
+ references:
1055
+ - https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html
1056
+ pattern-sources:
1057
+ - patterns:
1058
+ - pattern: $REQ.$PATH
1059
+ - metavariable-regex: {metavariable: $REQ, regex: '^(req|request|ctx|ctx\.request)$'}
1060
+ - metavariable-regex: {metavariable: $PATH, regex: '^(url|originalUrl|path|baseUrl)$'}
1061
+ pattern-sanitizers:
1062
+ - *san-named
1063
+ - *san-guard
1064
+ - *san-signed
1065
+ - *san-lookup-result
1066
+ - *san-fixed-prefix
1067
+ # After a literal "https://host" prefix the path stays on that host.
1068
+ - patterns:
1069
+ - pattern: $TEMPLATE
1070
+ - metavariable-regex: {metavariable: $TEMPLATE, regex: '^`https?://[^`$]*\$\{[^}]*\}[^`$/]*\$\{'}
1071
+ - patterns:
1072
+ - pattern-inside: $PREFIX + $REQ.$PATH
1073
+ - pattern: $REQ.$PATH
1074
+ - metavariable-regex: {metavariable: $PREFIX, regex: '^[''"`]https?://'}
1075
+ - patterns:
1076
+ - pattern: $X.replace($PATTERN, "/")
1077
+ - metavariable-regex: {metavariable: $PATTERN, regex: '^/(\\/\{2,\}|\\/\+|\\/\\/\+)/g?$'}
1078
+ # A URL object on a fixed host keeps that host when only its path is set from the request.
1079
+ - patterns:
1080
+ - pattern-inside: |
1081
+ $U = new URL($BASE);
1082
+ ...
1083
+ - pattern-not-inside: |
1084
+ $U.href = $V;
1085
+ ...
1086
+ - pattern-not-inside: |
1087
+ $U.host = $V;
1088
+ ...
1089
+ - pattern-either:
1090
+ - pattern: $U.toString()
1091
+ - pattern: $U.href
1092
+ - pattern: String($U)
1093
+ pattern-sinks: *js-redirect-sinks
1094
+
1095
+ - id: codewatch.js.code-injection
1096
+ mode: taint
1097
+ languages: [typescript, javascript]
1098
+ severity: ERROR
1099
+ message: >-
1100
+ Data from the request or the URL is run as code. Parse it as data instead (JSON.parse, a lookup table of
1101
+ allowed operations); never evaluate it.
1102
+ metadata:
1103
+ category: security
1104
+ subcategory: [vuln]
1105
+ type: vulnerability
1106
+ title: Request or URL data evaluated as code
1107
+ cwe: ["CWE-94: Improper Control of Generation of Code ('Code Injection')", "CWE-95: Improper Neutralization of Directives in Dynamically Evaluated Code ('Eval Injection')"]
1108
+ owasp: ["A05:2025 - Injection"]
1109
+ references:
1110
+ - https://nodejs.org/api/vm.html#vm-executing-javascript
1111
+ - https://cheatsheetseries.owasp.org/cheatsheets/Nodejs_Security_Cheat_Sheet.html
1112
+ pattern-sources:
1113
+ - *src-request-field
1114
+ - *src-request-getter
1115
+ - *src-search-params
1116
+ - *src-url-search-params
1117
+ - *src-nest-param
1118
+ - *src-destructured-request
1119
+ - *dom-sources
1120
+ pattern-sanitizers: *js-sanitizers
1121
+ pattern-sinks:
1122
+ - patterns:
1123
+ - pattern-either:
1124
+ - pattern: eval($CODE)
1125
+ - pattern: new Function(..., $CODE)
1126
+ - pattern: Function(..., $CODE)
1127
+ - pattern: vm.runInThisContext($CODE, ...)
1128
+ - pattern: vm.runInNewContext($CODE, ...)
1129
+ - pattern: vm.runInContext($CODE, ...)
1130
+ - pattern: new vm.Script($CODE, ...)
1131
+ - pattern: setTimeout($CODE, ...)
1132
+ - pattern: setInterval($CODE, ...)
1133
+ - pattern-not: setTimeout((...) => {...}, ...)
1134
+ - pattern-not: setTimeout(function (...) {...}, ...)
1135
+ - pattern-not: setInterval((...) => {...}, ...)
1136
+ - pattern-not: setInterval(function (...) {...}, ...)
1137
+ - focus-metavariable: $CODE
1138
+
1139
+ - id: codewatch.js.ssrf
1140
+ mode: taint
1141
+ languages: [typescript, javascript]
1142
+ severity: ERROR
1143
+ message: >-
1144
+ Data from the request decides which URL the server fetches, so it can be pointed at internal services or
1145
+ cloud metadata endpoints. Fetch only from hosts on an exact allowlist, and resolve and block private addresses.
1146
+ metadata:
1147
+ category: security
1148
+ subcategory: [vuln]
1149
+ type: vulnerability
1150
+ title: Server-side request to a URL from the request
1151
+ cwe: ["CWE-918: Server-Side Request Forgery (SSRF)"]
1152
+ owasp: ["A01:2025 - Broken Access Control"]
1153
+ references:
1154
+ - https://cheatsheetseries.owasp.org/cheatsheets/Server_Side_Request_Forgery_Prevention_Cheat_Sheet.html
1155
+ pattern-sources: *js-sources
1156
+ pattern-sanitizers:
1157
+ - *san-numeric
1158
+ - *san-named
1159
+ - *san-allowlist-ternary
1160
+ - *san-guard
1161
+ - *san-signed
1162
+ - *san-file-content
1163
+ - *san-lookup-result
1164
+ # Only the path or query is user data when the scheme and host are fixed in front of it: a literal
1165
+ # "https://host/", or a constant base (PAYPAL_API_URL, process.env.X, config.x) then "/" (proshop-v2:
1166
+ # `${PAYPAL_API_URL}/v2/checkout/orders/${id}`).
1167
+ - patterns:
1168
+ - pattern: $URL
1169
+ - metavariable-pattern:
1170
+ metavariable: $URL
1171
+ patterns:
1172
+ - pattern: '`...`'
1173
+ - pattern-regex: '^`(https?://[^/`$]+|\$\{\s*([A-Z][A-Z0-9_]*|process\.env\.\w+|(this\.)?(config|env|conf|settings)(\.\w+)+)\s*\})/'
1174
+ - patterns:
1175
+ - pattern: $PREFIX + $X
1176
+ - metavariable-regex: {metavariable: $PREFIX, regex: '^[''"]https?://[^/''"]+/'}
1177
+ pattern-sinks:
1178
+ - patterns:
1179
+ - pattern-either:
1180
+ - pattern: fetch($URL, ...)
1181
+ - pattern: axios($URL, ...)
1182
+ - pattern: axios.$METHOD($URL, ...)
1183
+ - pattern: got($URL, ...)
1184
+ - pattern: got.$METHOD($URL, ...)
1185
+ - pattern: request($URL, ...)
1186
+ # The request library's verbs only: Semgrep resolves a function imported from a project's own
1187
+ # utils/request module as request.$NAME (immich: fromMaybeArray(req.headers[...])).
1188
+ - patterns:
1189
+ - pattern: request.$METHOD($URL, ...)
1190
+ - metavariable-regex: {metavariable: $METHOD, regex: '^(get|post|put|patch|del|delete|head|options)$'}
1191
+ - pattern: needle.get($URL, ...)
1192
+ - pattern: superagent.$METHOD($URL, ...)
1193
+ - pattern: http.get($URL, ...)
1194
+ - pattern: http.request($URL, ...)
1195
+ - pattern: https.get($URL, ...)
1196
+ - pattern: https.request($URL, ...)
1197
+ # With an options object only the host decides where it goes: a path or headers from the request don't
1198
+ # (linkwarden's SSRF-guard proxy connects to a checked IP with the request's path).
1199
+ - pattern-not: http.get({...}, ...)
1200
+ - pattern-not: http.request({...}, ...)
1201
+ - pattern-not: https.get({...}, ...)
1202
+ - pattern-not: https.request({...}, ...)
1203
+ - focus-metavariable: $URL
1204
+ - patterns:
1205
+ - pattern-either:
1206
+ - pattern: '$HTTP.$CALL({..., host: $URL, ...}, ...)'
1207
+ - pattern: '$HTTP.$CALL({..., hostname: $URL, ...}, ...)'
1208
+ - pattern: '$HTTP.$CALL({..., url: $URL, ...}, ...)'
1209
+ - metavariable-regex: {metavariable: $HTTP, regex: '^https?$'}
1210
+ - metavariable-regex: {metavariable: $CALL, regex: '^(get|request)$'}
1211
+ - focus-metavariable: $URL
1212
+ # Clients called directly, which javascript-taint.yml only matches through a method (superagent.get(url),
1213
+ # needle.get(url)): superagent(url), needle('get', url), ky(url).
1214
+ - patterns:
1215
+ - pattern-either:
1216
+ - pattern: superagent($URL, ...)
1217
+ - pattern: superagent($METHOD, $URL, ...)
1218
+ - pattern: needle($METHOD, $URL, ...)
1219
+ - pattern: needle.request($METHOD, $URL, ...)
1220
+ - pattern: ky($URL, ...)
1221
+ - patterns:
1222
+ - pattern-either:
1223
+ - pattern: needle.$VERB($URL, ...)
1224
+ - pattern: ky.$VERB($URL, ...)
1225
+ - metavariable-regex: {metavariable: $VERB, regex: '^(post|put|patch|delete|head)$'}
1226
+ - patterns:
1227
+ - pattern: ky.get($URL, ...)
1228
+ - pattern-not: superagent("$LITERAL", $URL, ...)
1229
+ - focus-metavariable: $URL
1230
+ # undici through its module object, or a name imported under another name: undici.request(url),
1231
+ # import { fetch as ufetch } from 'undici'. javascript-taint.yml's fetch(url) and request(url) cover the
1232
+ # plain names.
1233
+ - patterns:
1234
+ - pattern-either:
1235
+ - pattern-inside: |
1236
+ $U = require("undici");
1237
+ ...
1238
+ - pattern-inside: |
1239
+ import * as $U from "undici";
1240
+ ...
1241
+ - pattern-inside: |
1242
+ import $U from "undici";
1243
+ ...
1244
+ - pattern: $U.$FN($URL, ...)
1245
+ - metavariable-regex: {metavariable: $FN, regex: '^(request|fetch|stream|pipeline|connect)$'}
1246
+ - focus-metavariable: $URL
1247
+ - patterns:
1248
+ - pattern: require("undici").$FN($URL, ...)
1249
+ - metavariable-regex: {metavariable: $FN, regex: '^(request|fetch|stream|pipeline|connect)$'}
1250
+ - focus-metavariable: $URL
1251
+ - patterns:
1252
+ - pattern-either:
1253
+ - pattern-inside: |
1254
+ import { $IMP as $FN } from "undici";
1255
+ ...
1256
+ - pattern-inside: |
1257
+ const { $IMP: $FN } = require("undici");
1258
+ ...
1259
+ - pattern: $FN($URL, ...)
1260
+ - metavariable-regex: {metavariable: $IMP, regex: '^(request|fetch|stream|pipeline|connect)$'}
1261
+ - metavariable-regex: {metavariable: $FN, regex: '^(?!(request|fetch)$)'}
1262
+ - focus-metavariable: $URL
1263
+ - patterns:
1264
+ - pattern-either:
1265
+ - pattern-inside: |
1266
+ import { $FN } from "undici";
1267
+ ...
1268
+ - pattern-inside: |
1269
+ const { $FN } = require("undici");
1270
+ ...
1271
+ - pattern: $FN($URL, ...)
1272
+ - metavariable-regex: {metavariable: $FN, regex: '^(stream|pipeline|connect)$'}
1273
+ - focus-metavariable: $URL
1274
+
1275
+ - id: codewatch.js.unsafe-deserialization
1276
+ mode: taint
1277
+ languages: [typescript, javascript]
1278
+ severity: ERROR
1279
+ message: >-
1280
+ Data from the request is deserialized with a library that can run code embedded in it (node-serialize,
1281
+ funcster). Use JSON.parse, which only builds plain data.
1282
+ metadata:
1283
+ category: security
1284
+ subcategory: [vuln]
1285
+ type: vulnerability
1286
+ title: Request data deserialized unsafely
1287
+ cwe: ["CWE-502: Deserialization of Untrusted Data"]
1288
+ owasp: ["A08:2025 - Software or Data Integrity Failures"]
1289
+ references:
1290
+ - https://cheatsheetseries.owasp.org/cheatsheets/Deserialization_Cheat_Sheet.html
1291
+ pattern-sources: *js-sources
1292
+ pattern-sinks:
1293
+ - patterns:
1294
+ - pattern-either:
1295
+ - pattern: require('node-serialize').unserialize($DATA)
1296
+ - pattern: serialize.unserialize($DATA)
1297
+ - pattern: funcster.deepDeserialize($DATA)
1298
+ - patterns:
1299
+ - pattern: $LIB.unserialize($DATA)
1300
+ - pattern-inside: |
1301
+ $LIB = require('node-serialize')
1302
+ ...
1303
+ - focus-metavariable: $DATA
1304
+
1305
+ - id: codewatch.js.regex-injection
1306
+ mode: taint
1307
+ languages: [typescript, javascript]
1308
+ severity: WARNING
1309
+ message: >-
1310
+ Data from the request or the URL is compiled as a regular expression, so a user can send a pattern that
1311
+ takes exponential time to match and blocks the event loop (ReDoS). Escape its special characters first
1312
+ (lodash's escapeRegExp), or match literally with includes().
1313
+ metadata:
1314
+ category: security
1315
+ subcategory: [vuln]
1316
+ type: vulnerability
1317
+ title: Request data used as a regular expression
1318
+ cwe: ["CWE-730: OWASP Top Ten 2004 Category A9 - Denial of Service", "CWE-1333: Inefficient Regular Expression Complexity"]
1319
+ owasp: ["A05:2025 - Injection"]
1320
+ references:
1321
+ - https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS
1322
+ pattern-sources:
1323
+ - *src-request-field
1324
+ - *src-request-getter
1325
+ - *src-search-params
1326
+ - *src-url-search-params
1327
+ - *src-nest-param
1328
+ - *src-destructured-request
1329
+ pattern-sanitizers:
1330
+ - *san-numeric
1331
+ - *san-named
1332
+ - *san-allowlist-ternary
1333
+ - *san-guard
1334
+ - *san-signed
1335
+ # Its special characters escaped by hand: x.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') puts a backslash before
1336
+ # each match (habitica), so the pattern matches the text literally.
1337
+ - patterns:
1338
+ - pattern: $X.replace($RE, $ESCAPE)
1339
+ - metavariable-regex: {metavariable: $ESCAPE, regex: '^[''"`]\\\\\$&[''"`]$'}
1340
+ - *san-lookup-result
1341
+ - patterns:
1342
+ - pattern: $X.replace($RE, $WITH)
1343
+ - metavariable-regex: {metavariable: $WITH, regex: '\$\x26'}
1344
+ pattern-sinks:
1345
+ - patterns:
1346
+ - pattern-either:
1347
+ - pattern: new RegExp($PATTERN, ...)
1348
+ - pattern: RegExp($PATTERN, ...)
1349
+ - focus-metavariable: $PATTERN
1350
+
1351
+ - id: codewatch.js.stack-trace-exposure
1352
+ mode: taint
1353
+ languages: [typescript, javascript]
1354
+ severity: WARNING
1355
+ message: >-
1356
+ An error's stack trace is sent back in the response. It shows file paths and code to whoever made the
1357
+ request. Log it on the server and send a generic error message instead.
1358
+ metadata:
1359
+ category: security
1360
+ subcategory: [vuln]
1361
+ type: vulnerability
1362
+ title: Stack trace sent in the response
1363
+ interprocedural: false
1364
+ cwe: ["CWE-209: Generation of Error Message Containing Sensitive Information"]
1365
+ owasp: ["A10:2025 - Mishandling of Exceptional Conditions"]
1366
+ references:
1367
+ - https://cheatsheetseries.owasp.org/cheatsheets/Error_Handling_Cheat_Sheet.html
1368
+ - https://expressjs.com/en/guide/error-handling.html
1369
+ pattern-sources:
1370
+ - patterns:
1371
+ - pattern: $ERR.stack
1372
+ - metavariable-regex: {metavariable: $ERR, regex: '(?i)^(e|ex|exc|exception|\w*err(or)?)$'}
1373
+ # Only in development: if (process.env.NODE_ENV !== "production"), config.env === "development" && ...
1374
+ - pattern-not-inside: 'if (<... $C.NODE_ENV === $V ...>) { ... }'
1375
+ - pattern-not-inside: '<... $C.NODE_ENV === $V ...> ? $A : $B'
1376
+ - pattern-not-inside: '<... $C.NODE_ENV === $V ...> && $Y'
1377
+ - pattern-not-inside: 'if (<... $C.NODE_ENV !== $V ...>) { ... }'
1378
+ - pattern-not-inside: '<... $C.NODE_ENV !== $V ...> ? $A : $B'
1379
+ - pattern-not-inside: '<... $C.NODE_ENV !== $V ...> && $Y'
1380
+ - pattern-not-inside: 'if (<... $C.NODE_ENV == $V ...>) { ... }'
1381
+ - pattern-not-inside: '<... $C.NODE_ENV == $V ...> ? $A : $B'
1382
+ - pattern-not-inside: '<... $C.NODE_ENV == $V ...> && $Y'
1383
+ - pattern-not-inside: 'if (<... $C.NODE_ENV != $V ...>) { ... }'
1384
+ - pattern-not-inside: '<... $C.NODE_ENV != $V ...> ? $A : $B'
1385
+ - pattern-not-inside: '<... $C.NODE_ENV != $V ...> && $Y'
1386
+ - pattern-not-inside: 'if (<... $C.env === $V ...>) { ... }'
1387
+ - pattern-not-inside: '<... $C.env === $V ...> ? $A : $B'
1388
+ - pattern-not-inside: '<... $C.env === $V ...> && $Y'
1389
+ - pattern-not-inside: 'if (<... $C.env !== $V ...>) { ... }'
1390
+ - pattern-not-inside: '<... $C.env !== $V ...> ? $A : $B'
1391
+ - pattern-not-inside: '<... $C.env !== $V ...> && $Y'
1392
+ - pattern-not-inside: 'if (<... $C.env == $V ...>) { ... }'
1393
+ - pattern-not-inside: '<... $C.env == $V ...> ? $A : $B'
1394
+ - pattern-not-inside: '<... $C.env == $V ...> && $Y'
1395
+ - pattern-not-inside: 'if (<... $C.env != $V ...>) { ... }'
1396
+ - pattern-not-inside: '<... $C.env != $V ...> ? $A : $B'
1397
+ - pattern-not-inside: '<... $C.env != $V ...> && $Y'
1398
+ - pattern-not-inside: 'if (<... $APP.get("env") === $V ...>) { ... }'
1399
+ - pattern-not-inside: '<... $APP.get("env") === $V ...> ? $A : $B'
1400
+ - pattern-not-inside: '<... $APP.get("env") === $V ...> && $Y'
1401
+ - pattern-not-inside: 'if (<... $APP.get("env") !== $V ...>) { ... }'
1402
+ - pattern-not-inside: '<... $APP.get("env") !== $V ...> ? $A : $B'
1403
+ - pattern-not-inside: '<... $APP.get("env") !== $V ...> && $Y'
1404
+ - pattern-not-inside: 'if (<... $APP.get("env") == $V ...>) { ... }'
1405
+ - pattern-not-inside: '<... $APP.get("env") == $V ...> ? $A : $B'
1406
+ - pattern-not-inside: '<... $APP.get("env") == $V ...> && $Y'
1407
+ - pattern-not-inside: 'if (<... $APP.get("env") != $V ...>) { ... }'
1408
+ - pattern-not-inside: '<... $APP.get("env") != $V ...> ? $A : $B'
1409
+ - pattern-not-inside: '<... $APP.get("env") != $V ...> && $Y'
1410
+ - pattern-not-inside: 'if (<... $C.debug ...>) { ... }'
1411
+ - pattern-not-inside: '<... $C.debug ...> ? $A : $B'
1412
+ - pattern-not-inside: '<... $C.debug ...> && $Y'
1413
+ - pattern-not-inside: 'if (<... $C.DEBUG ...>) { ... }'
1414
+ - pattern-not-inside: '<... $C.DEBUG ...> ? $A : $B'
1415
+ - pattern-not-inside: '<... $C.DEBUG ...> && $Y'
1416
+ # Put in a response object that drops it again unless some condition holds (express-rest-boilerplate:
1417
+ # `if (env !== 'development') { delete response.stack; }`).
1418
+ - pattern-not-inside: |
1419
+ $OBJ = {..., stack: $ERR.stack, ...};
1420
+ ...
1421
+ if ($COND) { ... delete $OBJ.stack; ... }
1422
+ - pattern-not-inside: |
1423
+ const $OBJ = {..., stack: $ERR.stack, ...};
1424
+ ...
1425
+ if ($COND) { ... delete $OBJ.stack; ... }
1426
+ pattern-sinks:
1427
+ - patterns:
1428
+ - pattern-either:
1429
+ - pattern: $RES.$SEND(...)
1430
+ - pattern: $RES.status(...).$SEND(...)
1431
+ - metavariable-regex: {metavariable: $RES, regex: '^(res|response|reply)$'}
1432
+ - metavariable-regex: {metavariable: $SEND, regex: '^(send|json|jsonp|end|write|render)$'}
1433
+ - pattern: ctx.body = $BODY
1434
+
1435
+ - id: codewatch.js.template-injection
1436
+ mode: taint
1437
+ languages: [typescript, javascript]
1438
+ severity: ERROR
1439
+ message: >-
1440
+ Data from the request is compiled as a template, so a user can write template code that runs on the
1441
+ server. Pass request data as template variables, never as the template text.
1442
+ metadata:
1443
+ category: security
1444
+ subcategory: [vuln]
1445
+ type: vulnerability
1446
+ title: Request data compiled as a server-side template
1447
+ cwe: ["CWE-1336: Improper Neutralization of Special Elements Used in a Template Engine"]
1448
+ owasp: ["A05:2025 - Injection"]
1449
+ references:
1450
+ - https://portswigger.net/web-security/server-side-template-injection
1451
+ pattern-sources: *js-sources
1452
+ pattern-sanitizers:
1453
+ - *san-numeric
1454
+ - *san-named
1455
+ - *san-allowlist-ternary
1456
+ - *san-guard
1457
+ - *san-signed
1458
+ - *san-lookup-result
1459
+ pattern-sinks:
1460
+ - patterns:
1461
+ - pattern-either:
1462
+ - patterns:
1463
+ - pattern: $ENGINE.$COMPILE($TEMPLATE, ...)
1464
+ - metavariable-regex:
1465
+ metavariable: $ENGINE
1466
+ regex: '(?i)^(pug|jade|ejs|handlebars|hbs|nunjucks|_|lodash|dot|mustache|hogan|swig|dust|eta|velocity|velocityjs|liquid|liquidjs)$'
1467
+ - metavariable-regex:
1468
+ metavariable: $COMPILE
1469
+ regex: '^(render|compile|renderString|template|compileString|parseAndRender|parseAndRenderSync)$'
1470
+ - pattern: new nunjucks.Environment(...).renderString($TEMPLATE, ...)
1471
+ - pattern: new Liquid(...).parseAndRender($TEMPLATE, ...)
1472
+ - focus-metavariable: $TEMPLATE
1473
+
1474
+ - id: codewatch.js.ldap-injection
1475
+ mode: taint
1476
+ languages: [typescript, javascript]
1477
+ severity: ERROR
1478
+ message: >-
1479
+ Data from the request is built into an LDAP filter, so characters such as * ( ) can change what the
1480
+ search matches (and bypass a login check). Escape values for LDAP filters, or build the filter with
1481
+ ldapjs filter objects (new EqualityFilter({ attribute, value })).
1482
+ metadata:
1483
+ category: security
1484
+ subcategory: [vuln]
1485
+ type: vulnerability
1486
+ title: Request data built into an LDAP filter
1487
+ cwe: ["CWE-90: Improper Neutralization of Special Elements used in an LDAP Query ('LDAP Injection')"]
1488
+ owasp: ["A05:2025 - Injection"]
1489
+ references:
1490
+ - https://cheatsheetseries.owasp.org/cheatsheets/LDAP_Injection_Prevention_Cheat_Sheet.html
1491
+ pattern-sources: *js-sources
1492
+ pattern-sanitizers:
1493
+ - *san-numeric
1494
+ - *san-named
1495
+ - *san-allowlist-ternary
1496
+ - *san-guard
1497
+ - *san-signed
1498
+ - *san-lookup-result
1499
+ pattern-sinks:
1500
+ - patterns:
1501
+ - pattern-either:
1502
+ - pattern: '$CLIENT.search($BASE, {..., filter: $FILTER, ...}, ...)'
1503
+ - pattern: ldap.parseFilter($FILTER)
1504
+ - focus-metavariable: $FILTER
1505
+
1506
+ - id: codewatch.js.xpath-injection
1507
+ mode: taint
1508
+ languages: [typescript, javascript]
1509
+ severity: ERROR
1510
+ message: >-
1511
+ Data from the request is built into an XPath expression, so quotes and operators in it can change which
1512
+ nodes are selected (and bypass a check). Pass it as an XPath variable, or allow only expected values.
1513
+ metadata:
1514
+ category: security
1515
+ subcategory: [vuln]
1516
+ type: vulnerability
1517
+ title: Request data built into an XPath expression
1518
+ cwe: ["CWE-643: Improper Neutralization of Data within XPath Expressions ('XPath Injection')"]
1519
+ owasp: ["A05:2025 - Injection"]
1520
+ references:
1521
+ - https://owasp.org/www-community/attacks/XPATH_Injection
1522
+ pattern-sources: *js-sources
1523
+ pattern-sanitizers:
1524
+ - *san-numeric
1525
+ - *san-named
1526
+ - *san-allowlist-ternary
1527
+ - *san-guard
1528
+ - *san-signed
1529
+ - *san-lookup-result
1530
+ pattern-sinks:
1531
+ - patterns:
1532
+ - pattern-either:
1533
+ - pattern: xpath.select($EXPR, ...)
1534
+ - pattern: xpath.select1($EXPR, ...)
1535
+ - pattern: xpath.evaluate($EXPR, ...)
1536
+ - pattern: xpath.parse($EXPR)
1537
+ - pattern: document.evaluate($EXPR, ...)
1538
+ - pattern: $DOC.evaluate($EXPR, $NODE, ...)
1539
+ - focus-metavariable: $EXPR