Repository navigation
Expand file tree
/
Copy pathjavascript-web-taint.yaml
More file actions
346 lines (330 loc) · 12.4 KB
/
Copy pathjavascript-web-taint.yaml
File metadata and controls
346 lines (330 loc) · 12.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
# ============================================================================
# Robusta Studio - JavaScript/TypeScript Web Application Security Rules
# Copyright (c) 2026 Robusta Studio. All rights reserved.
#
# Taint-tracking rules for Node.js/Express, React, and browser-side JS.
# Derived from 60,517 real-world CVE and HackerOne vulnerability records.
# Dataset: PentesterFlow/OffsecCyber
#
# Usage: semgrep --config javascript-web-taint.yaml /path/to/project
# ============================================================================
rules:
# -- CWE-79 | Cross-Site Scripting (XSS) -----------------------------------
- id: robusta-js-xss-taint-express
mode: taint
message: >
HTTP request parameter flows into an HTML response without encoding.
H1 pattern: search param reflected in page body → XSS.
PortSwigger: reflected into JS template literal → ${alert(1)}.
Use framework auto-escaping, or DOMPurify.sanitize() for rich HTML.
metadata:
cwe: ["CWE-79"]
owasp: ["A03:2021 Injection"]
confidence: HIGH
impact: HIGH
author: Robusta Studio
license: "MIT - Copyright (c) 2026 Robusta Studio. For the open-source community."
severity: ERROR
languages: [javascript, typescript]
pattern-sources:
- patterns:
- pattern-either:
- pattern: req.query.$PARAM
- pattern: req.params.$PARAM
- pattern: req.body.$PARAM
- pattern: req.headers[...]
- pattern: req.query[...]
- pattern: req.params[...]
- pattern: req.body[...]
pattern-sinks:
- patterns:
- pattern-either:
- pattern: res.send($DATA)
- pattern: res.write($DATA)
- pattern: $EL.innerHTML = $DATA
- pattern: $EL.outerHTML = $DATA
- pattern: document.write($DATA)
- pattern: document.writeln($DATA)
- focus-metavariable: $DATA
pattern-sanitizers:
- patterns:
- pattern-either:
- pattern: DOMPurify.sanitize(...)
- pattern: escapeHtml(...)
- pattern: escape(...)
- pattern: encodeURIComponent(...)
- pattern: $VALIDATOR.escape(...)
- pattern: xss(...)
# -- CWE-89 | SQL Injection ------------------------------------------------
- id: robusta-js-sqli-taint
mode: taint
message: >
HTTP input flows into a SQL query string. Use parameterized queries:
db.query("SELECT ... WHERE x = ?", [input]).
CVE-2024-9796: 't' param unsanitized in SQL → unauthenticated SQLi.
metadata:
cwe: ["CWE-89"]
owasp: ["A03:2021 Injection"]
confidence: HIGH
impact: HIGH
author: Robusta Studio
license: "MIT - Copyright (c) 2026 Robusta Studio. For the open-source community."
references:
- https://nvd.nist.gov/vuln/detail/CVE-2024-9796
severity: ERROR
languages: [javascript, typescript]
pattern-sources:
- patterns:
- pattern-either:
- pattern: req.query.$PARAM
- pattern: req.params.$PARAM
- pattern: req.body.$PARAM
- pattern: req.query[...]
- pattern: req.params[...]
- pattern: req.body[...]
pattern-sinks:
- patterns:
- pattern-either:
- pattern: $DB.query($Q, ...)
- pattern: $DB.raw($Q)
- pattern: $CONN.query($Q, ...)
- pattern: $POOL.query($Q, ...)
- pattern: $KNEX.raw($Q, ...)
- pattern: sequelize.query($Q, ...)
- pattern: $SEQ.literal($Q)
- focus-metavariable: $Q
pattern-sanitizers:
- patterns:
- pattern-either:
- pattern: parseInt(...)
- pattern: Number(...)
- pattern: $DB.escape(...)
- pattern: mysql.escape(...)
- pattern: $CONN.escapeId(...)
# -- CWE-78 | OS Command Injection -----------------------------------------
- id: robusta-js-cmdi-taint
mode: taint
message: >
HTTP request data reaches child_process.exec() (runs through shell).
Use child_process.execFile() or spawn() with an argument array.
metadata:
cwe: ["CWE-78"]
confidence: HIGH
impact: CRITICAL
author: Robusta Studio
license: "MIT - Copyright (c) 2026 Robusta Studio. For the open-source community."
severity: ERROR
languages: [javascript, typescript]
pattern-sources:
- patterns:
- pattern-either:
- pattern: req.query.$PARAM
- pattern: req.params.$PARAM
- pattern: req.body.$PARAM
- pattern: req.query[...]
- pattern: req.params[...]
- pattern: req.body[...]
pattern-sinks:
- patterns:
- pattern-either:
- pattern: child_process.exec($CMD, ...)
- pattern: exec($CMD, ...)
- pattern: execSync($CMD, ...)
- pattern: child_process.execSync($CMD, ...)
- focus-metavariable: $CMD
pattern-sanitizers:
- patterns:
- pattern-either:
- pattern: parseInt(...)
- pattern: Number(...)
- pattern: $RE.test(...)
# -- CWE-918 | Server-Side Request Forgery ----------------------------------
- id: robusta-js-ssrf-taint
mode: taint
message: >
User-supplied URL passed to a server-side HTTP client. Validate scheme,
resolve and reject private/link-local/metadata IPs before requesting.
metadata:
cwe: ["CWE-918"]
owasp: ["A10:2021 Server-Side Request Forgery"]
confidence: HIGH
impact: HIGH
author: Robusta Studio
license: "MIT - Copyright (c) 2026 Robusta Studio. For the open-source community."
severity: ERROR
languages: [javascript, typescript]
pattern-sources:
- patterns:
- pattern-either:
- pattern: req.query.$PARAM
- pattern: req.params.$PARAM
- pattern: req.body.$PARAM
- pattern: req.body[...]
- pattern: req.query[...]
pattern-sinks:
- patterns:
- pattern-either:
- pattern: fetch($URL, ...)
- pattern: axios.get($URL, ...)
- pattern: axios.post($URL, ...)
- pattern: axios.put($URL, ...)
- pattern: "axios.request({url: $URL, ...})"
- pattern: axios($URL, ...)
- pattern: got($URL, ...)
- pattern: got.get($URL, ...)
- pattern: needle.get($URL, ...)
- pattern: superagent.get($URL)
- pattern: http.get($URL, ...)
- pattern: https.get($URL, ...)
- pattern: undici.request($URL, ...)
- focus-metavariable: $URL
pattern-sanitizers:
- patterns:
- pattern-either:
- pattern: new URL(...)
- pattern: url.parse(...)
# -- CWE-1321 | Prototype Pollution ----------------------------------------
- id: robusta-js-prototype-pollution-deep-merge
patterns:
- pattern-either:
- pattern: |
function $MERGE($TARGET, $SOURCE) {
...
for (let $KEY in $SOURCE) {
...
$TARGET[$KEY] = ...
...
}
...
}
- pattern: |
function $MERGE($TARGET, $SOURCE) {
...
Object.keys($SOURCE).forEach($KEY => {
...
$TARGET[$KEY] = ...
...
})
...
}
message: >
Custom deep-merge without __proto__/constructor key rejection enables
prototype pollution. H1: mermaid directives → stored XSS, fastify-multipart → DoS.
Reject keys "__proto__", "constructor", "prototype" or use Map/Object.create(null).
metadata:
cwe: ["CWE-1321"]
confidence: HIGH
impact: HIGH
author: Robusta Studio
license: "MIT - Copyright (c) 2026 Robusta Studio. For the open-source community."
severity: ERROR
languages: [javascript, typescript]
- id: robusta-js-prototype-pollution-lodash-set
patterns:
- pattern-either:
- pattern: _.set($OBJ, $PATH, $VAL)
- pattern: _.setWith($OBJ, $PATH, $VAL, ...)
- pattern: _.merge($OBJ, $SOURCE)
- pattern: _.defaultsDeep($OBJ, $SOURCE)
- pattern-not: |
_.set($OBJ, "...", $VAL)
message: >
Lodash deep set/merge with user-controlled path enables prototype pollution.
Validate that the path does not contain "__proto__", "constructor", or "prototype".
metadata:
cwe: ["CWE-1321"]
confidence: MEDIUM
impact: HIGH
author: Robusta Studio
license: "MIT - Copyright (c) 2026 Robusta Studio. For the open-source community."
severity: WARNING
languages: [javascript, typescript]
# -- CWE-943 | NoSQL Injection ---------------------------------------------
- id: robusta-js-nosqli-taint
mode: taint
message: >
User input object passed directly to MongoDB query operator position.
Attack: {"password": {"$gt": ""}} bypasses auth. Validate input types
with mongo-sanitize or explicit type casting before query.
metadata:
cwe: ["CWE-943"]
confidence: HIGH
impact: HIGH
author: Robusta Studio
license: "MIT - Copyright (c) 2026 Robusta Studio. For the open-source community."
severity: ERROR
languages: [javascript, typescript]
pattern-sources:
- patterns:
- pattern-either:
- pattern: req.body
- pattern: req.body.$FIELD
- pattern: req.query
- pattern: req.query.$FIELD
pattern-sinks:
- patterns:
- pattern-either:
- pattern: $COLL.findOne($QUERY, ...)
- pattern: $COLL.find($QUERY, ...)
- pattern: $COLL.findOneAndUpdate($QUERY, ...)
- pattern: $COLL.findOneAndDelete($QUERY, ...)
- pattern: $COLL.updateOne($QUERY, ...)
- pattern: $COLL.updateMany($QUERY, ...)
- pattern: $COLL.deleteOne($QUERY, ...)
- pattern: $COLL.deleteMany($QUERY, ...)
- pattern: $MODEL.findOne($QUERY, ...)
- pattern: $MODEL.find($QUERY, ...)
- focus-metavariable: $QUERY
pattern-sanitizers:
- patterns:
- pattern-either:
- pattern: mongoSanitize(...)
- pattern: String(...)
- pattern: toString(...)
- pattern: parseInt(...)
# -- CWE-22 | Path Traversal -----------------------------------------------
- id: robusta-js-pathtraver-taint
mode: taint
message: >
User input flows into filesystem path. H1: lichess.org /assets/../build.sbt
leaked source code. Resolve with path.resolve() and verify the result starts
with the expected base directory.
metadata:
cwe: ["CWE-22"]
owasp: ["A01:2021 Broken Access Control"]
confidence: HIGH
impact: HIGH
author: Robusta Studio
license: "MIT - Copyright (c) 2026 Robusta Studio. For the open-source community."
severity: ERROR
languages: [javascript, typescript]
pattern-sources:
- patterns:
- pattern-either:
- pattern: req.query.$PARAM
- pattern: req.params.$PARAM
- pattern: req.body.$PARAM
- pattern: req.query[...]
- pattern: req.params[...]
pattern-sinks:
- patterns:
- pattern-either:
- pattern: fs.readFile($PATH, ...)
- pattern: fs.readFileSync($PATH, ...)
- pattern: fs.createReadStream($PATH, ...)
- pattern: fs.writeFile($PATH, ...)
- pattern: fs.writeFileSync($PATH, ...)
- pattern: fs.unlink($PATH, ...)
- pattern: fs.unlinkSync($PATH)
- pattern: fs.stat($PATH, ...)
- pattern: fs.statSync($PATH)
- pattern: fs.access($PATH, ...)
- pattern: res.sendFile($PATH, ...)
- pattern: res.download($PATH, ...)
- focus-metavariable: $PATH
pattern-sanitizers:
- patterns:
- pattern-either:
- pattern: path.basename(...)
- pattern: path.normalize(...)
- pattern: path.resolve(...)