heimdall-agent 1.1.0 → 1.4.0
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.
- package/README.md +101 -31
- package/README.pt-BR.md +124 -40
- package/agents/code-sentinel.md +7 -1
- package/agents/frontend-designer.md +6 -1
- package/agents/modernizer.md +8 -3
- package/agents/orchestrator.md +22 -8
- package/agents/reviewer.md +3 -1
- package/config/agents.json +177 -5
- package/config/mcp.json +1 -1
- package/config/mcp.resolved.json +74 -0
- package/config/mcp.template.json +85 -0
- package/config/models.json +70 -0
- package/config/profiles.json +4 -3
- package/config/skills.json +321 -93
- package/docs/SKILLS.md +158 -75
- package/docs/designs/old/2026-11-16 upstream-skill-sync-and-provenance-links.md +60 -0
- package/docs/runs/skill-audit/2026-11-12-compare-report.json +1028 -0
- package/docs/runs/skill-audit/2026-11-12-upstream-audit.json +275 -0
- package/doctrine/AGENTS.md +7 -4
- package/hooks/heimdall-hook.cjs +16 -1
- package/hooks/hooks.json +11 -0
- package/lib/catalog-sync.cjs +8 -3
- package/lib/model-context.cjs +50 -1
- package/lib/model-router.cjs +294 -0
- package/package.json +1 -1
- package/playbooks/01-interactive-grilling-gate.md +14 -10
- package/playbooks/03-adversarial-code-review.md +12 -4
- package/playbooks/05-canonical-plan-template.md +8 -13
- package/playbooks/06-model-registry-matrix.md +27 -19
- package/readme.html +1006 -0
- package/setup.mjs +317 -206
- package/skills/antislop-copywriting/SKILL.md +36 -1
- package/skills/brainstorming/SKILL.md +60 -38
- package/skills/codebase-design/DEEPENING.md +37 -0
- package/skills/codebase-design/DESIGN-IT-TWICE.md +44 -0
- package/skills/codebase-design/SKILL.md +114 -0
- package/skills/communication-doctrine/SKILL.md +2 -2
- package/skills/domain-modeling/ADR-FORMAT.md +47 -0
- package/skills/domain-modeling/GLOSSARY-FORMAT.md +60 -0
- package/skills/domain-modeling/SKILL.md +74 -0
- package/skills/executing-plans/SKILL.md +6 -4
- package/skills/grill-me/SKILL.md +65 -0
- package/skills/handoff/SKILL.md +77 -0
- package/skills/improve-codebase-architecture/HTML-REPORT.md +123 -0
- package/skills/improve-codebase-architecture/SKILL.md +71 -0
- package/skills/mcp-cleanup/SKILL.md +61 -0
- package/skills/mcp-sync/SKILL.md +58 -0
- package/skills/modern-web-guidance/SKILL.md +90 -0
- package/skills/owasp-security/reference/config-and-supply-chain.md +346 -344
- package/skills/owasp-security/reference/languages.md +378 -372
- package/skills/owasp-security/reference/owasp-report.md +1144 -1140
- package/skills/owasp-security/reference/review-checklist.md +134 -132
- package/skills/ruminate/SKILL.md +140 -0
- package/skills/subagent-driven-development/SKILL.md +7 -4
- package/skills/taste-skill/SKILL.md +367 -534
- package/skills/to-spec/SKILL.md +75 -0
- package/skills/to-tickets/SKILL.md +105 -0
- package/skills/upstream-skill-sync/SKILL.md +46 -0
- package/skills/wayfinder/SKILL.md +128 -0
- package/skills/writing-plans/SKILL.md +1 -1
|
@@ -1,372 +1,378 @@
|
|
|
1
|
-
# Language-Specific Security Quirks
|
|
2
|
-
|
|
3
|
-
> **Important:** The examples below are illustrative starting points, not exhaustive. When reviewing code, think like a senior security researcher: consider the language's memory model, type system, standard library pitfalls, ecosystem-specific attack vectors, and historical CVE patterns. Each language has deeper quirks beyond what's listed here.
|
|
4
|
-
|
|
5
|
-
Different languages have unique security pitfalls. This file covers the top 20 languages with key security considerations. **Go deeper for the specific language you're working in.**
|
|
6
|
-
|
|
7
|
-
## Contents
|
|
8
|
-
- [JavaScript / TypeScript](#javascript--typescript)
|
|
9
|
-
- [Python](#python)
|
|
10
|
-
- [Java](#java)
|
|
11
|
-
- [C#](#c)
|
|
12
|
-
- [PHP](#php)
|
|
13
|
-
- [Go](#go)
|
|
14
|
-
- [Ruby](#ruby)
|
|
15
|
-
- [Rust](#rust)
|
|
16
|
-
- [Swift](#swift)
|
|
17
|
-
- [Kotlin](#kotlin)
|
|
18
|
-
- [C / C++](#c--c)
|
|
19
|
-
- [Scala](#scala)
|
|
20
|
-
- [R](#r)
|
|
21
|
-
- [Perl](#perl)
|
|
22
|
-
- [Shell (Bash)](#shell-bash)
|
|
23
|
-
- [Lua](#lua)
|
|
24
|
-
- [Elixir](#elixir)
|
|
25
|
-
- [Dart / Flutter](#dart--flutter)
|
|
26
|
-
- [PowerShell](#powershell)
|
|
27
|
-
- [SQL (All Dialects)](#sql-all-dialects)
|
|
28
|
-
|
|
29
|
-
---
|
|
30
|
-
|
|
31
|
-
### JavaScript / TypeScript
|
|
32
|
-
**Main Risks:** Prototype pollution, XSS, eval injection
|
|
33
|
-
```javascript
|
|
34
|
-
// UNSAFE: Prototype pollution - the vector is RECURSIVE merge, not a shallow copy.
|
|
35
|
-
// Payload {"__proto__": {"isAdmin": true}} reaches Object.prototype for every object.
|
|
36
|
-
deepMerge(config, JSON.parse(body)) // lodash.merge
|
|
37
|
-
//
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
target[k] =
|
|
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
|
-
# UNSAFE:
|
|
167
|
-
|
|
168
|
-
# SAFE:
|
|
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
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
#
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
```
|
|
372
|
-
|
|
1
|
+
# Language-Specific Security Quirks
|
|
2
|
+
|
|
3
|
+
> **Important:** The examples below are illustrative starting points, not exhaustive. When reviewing code, think like a senior security researcher: consider the language's memory model, type system, standard library pitfalls, ecosystem-specific attack vectors, and historical CVE patterns. Each language has deeper quirks beyond what's listed here.
|
|
4
|
+
|
|
5
|
+
Different languages have unique security pitfalls. This file covers the top 20 languages with key security considerations. **Go deeper for the specific language you're working in.**
|
|
6
|
+
|
|
7
|
+
## Contents
|
|
8
|
+
- [JavaScript / TypeScript](#javascript--typescript)
|
|
9
|
+
- [Python](#python)
|
|
10
|
+
- [Java](#java)
|
|
11
|
+
- [C#](#c)
|
|
12
|
+
- [PHP](#php)
|
|
13
|
+
- [Go](#go)
|
|
14
|
+
- [Ruby](#ruby)
|
|
15
|
+
- [Rust](#rust)
|
|
16
|
+
- [Swift](#swift)
|
|
17
|
+
- [Kotlin](#kotlin)
|
|
18
|
+
- [C / C++](#c--c)
|
|
19
|
+
- [Scala](#scala)
|
|
20
|
+
- [R](#r)
|
|
21
|
+
- [Perl](#perl)
|
|
22
|
+
- [Shell (Bash)](#shell-bash)
|
|
23
|
+
- [Lua](#lua)
|
|
24
|
+
- [Elixir](#elixir)
|
|
25
|
+
- [Dart / Flutter](#dart--flutter)
|
|
26
|
+
- [PowerShell](#powershell)
|
|
27
|
+
- [SQL (All Dialects)](#sql-all-dialects)
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
### JavaScript / TypeScript
|
|
32
|
+
**Main Risks:** Prototype pollution, XSS, eval injection
|
|
33
|
+
```javascript
|
|
34
|
+
// UNSAFE: Prototype pollution - the vector is RECURSIVE merge, not a shallow copy.
|
|
35
|
+
// Payload {"__proto__": {"isAdmin": true}} reaches Object.prototype for every object.
|
|
36
|
+
deepMerge(config, JSON.parse(body)) // hand-rolled recursive merges; also lodash.merge / _.set
|
|
37
|
+
// on old Lodash (CVE-2018-3721, CVE-2018-16487, CVE-2020-8203).
|
|
38
|
+
// Current 4.17.x+ filters __proto__ and constructor.prototype:
|
|
39
|
+
// check the lockfile before flagging a Lodash call.
|
|
40
|
+
// SAFE: skip the dangerous keys at every depth (stripping only the top level misses
|
|
41
|
+
// {"a": {"__proto__": ...}}), or validate against a schema before merging
|
|
42
|
+
const BLOCKED = new Set(["__proto__", "constructor", "prototype"]);
|
|
43
|
+
function safeMerge(target, src) {
|
|
44
|
+
for (const k of Object.keys(src)) {
|
|
45
|
+
if (BLOCKED.has(k)) continue;
|
|
46
|
+
const v = src[k];
|
|
47
|
+
if (v && typeof v === "object" && !Array.isArray(v)) {
|
|
48
|
+
const cur = Object.hasOwn(target, k) ? target[k] : undefined;
|
|
49
|
+
if (!cur || typeof cur !== "object" || Array.isArray(cur)) target[k] = {};
|
|
50
|
+
safeMerge(target[k], v);
|
|
51
|
+
} else {
|
|
52
|
+
target[k] = v;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return target;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// UNSAFE: eval injection (and its aliases)
|
|
59
|
+
eval(userCode); new Function(userCode); setTimeout(userCode, 0);
|
|
60
|
+
// SAFE: Never build executable code from user input
|
|
61
|
+
```
|
|
62
|
+
**Watch for:** `eval()`, `new Function()`, string arguments to `setTimeout`/`setInterval`,
|
|
63
|
+
`innerHTML`, `outerHTML`, `insertAdjacentHTML`, `document.write()`, `dangerouslySetInnerHTML`,
|
|
64
|
+
`location`/`href` assignment from user input, `__proto__` and `constructor.prototype`,
|
|
65
|
+
`postMessage` handlers without an `origin` check.
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
### Python
|
|
70
|
+
**Main Risks:** Pickle deserialization, format string injection, SQL/shell injection
|
|
71
|
+
```python
|
|
72
|
+
# UNSAFE: Pickle RCE
|
|
73
|
+
pickle.loads(user_data)
|
|
74
|
+
# SAFE: Use JSON or validate source
|
|
75
|
+
json.loads(user_data)
|
|
76
|
+
|
|
77
|
+
# UNSAFE: SQL injection via string interpolation
|
|
78
|
+
query = "SELECT * FROM users WHERE name = '%s'" % user_input
|
|
79
|
+
# SAFE: Parameterized
|
|
80
|
+
cursor.execute("SELECT * FROM users WHERE name = %s", (user_input,))
|
|
81
|
+
|
|
82
|
+
# UNSAFE: Format string injection - user controls the TEMPLATE, not the argument.
|
|
83
|
+
# "{u.__class__.__init__.__globals__[SECRET]}" walks attributes and leaks module globals.
|
|
84
|
+
user_template.format(u=user)
|
|
85
|
+
# SAFE: template is a literal, user data is an argument
|
|
86
|
+
"Hello {name}".format(name=user_input)
|
|
87
|
+
```
|
|
88
|
+
**Watch for:** `pickle`, `yaml.load` without `SafeLoader`, `eval()`, `exec()`, `os.system()`,
|
|
89
|
+
`subprocess` with `shell=True`, user-controlled format templates, `jinja2.Template(user_input)`
|
|
90
|
+
(SSTI), `__import__`
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
### Java
|
|
95
|
+
**Main Risks:** Deserialization RCE, XXE, JNDI injection
|
|
96
|
+
```java
|
|
97
|
+
// UNSAFE: Arbitrary deserialization
|
|
98
|
+
ObjectInputStream ois = new ObjectInputStream(userStream);
|
|
99
|
+
Object obj = ois.readObject();
|
|
100
|
+
|
|
101
|
+
// SAFE: Use allowlist or JSON
|
|
102
|
+
ObjectMapper mapper = new ObjectMapper();
|
|
103
|
+
mapper.readValue(json, SafeClass.class);
|
|
104
|
+
```
|
|
105
|
+
**Watch for:** `ObjectInputStream`, `Runtime.exec()`, XML parsers without XXE protection, JNDI lookups
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
### C#
|
|
110
|
+
**Main Risks:** Deserialization, SQL injection, path traversal
|
|
111
|
+
```csharp
|
|
112
|
+
// UNSAFE: BinaryFormatter RCE
|
|
113
|
+
BinaryFormatter bf = new BinaryFormatter();
|
|
114
|
+
object obj = bf.Deserialize(stream);
|
|
115
|
+
|
|
116
|
+
// SAFE: Use System.Text.Json
|
|
117
|
+
var obj = JsonSerializer.Deserialize<SafeType>(json);
|
|
118
|
+
```
|
|
119
|
+
**Watch for:** `BinaryFormatter`, `JavaScriptSerializer`, `TypeNameHandling.All`, raw SQL strings
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
### PHP
|
|
124
|
+
**Main Risks:** Type juggling, file inclusion, object injection
|
|
125
|
+
```php
|
|
126
|
+
// UNSAFE: Type juggling - "magic hashes" like "0e123" == "0e456" both cast to float 0
|
|
127
|
+
if ($password == $stored_hash) { ... }
|
|
128
|
+
// SAFE: Verify against a password hash (constant-time, algorithm-aware)
|
|
129
|
+
if (password_verify($password, $stored_hash)) { ... }
|
|
130
|
+
// Store with password_hash(); never md5/sha1, never your own salt scheme
|
|
131
|
+
$hash = password_hash($password, PASSWORD_DEFAULT);
|
|
132
|
+
// Comparing two known strings (tokens, HMACs, webhook signatures):
|
|
133
|
+
if (hash_equals($expected_token, $provided_token)) { ... }
|
|
134
|
+
|
|
135
|
+
// UNSAFE: File inclusion
|
|
136
|
+
include($_GET['page'] . '.php');
|
|
137
|
+
// SAFE: Allowlist pages
|
|
138
|
+
$allowed = ['home', 'about']; include(in_array($page, $allowed) ? "$page.php" : 'home.php');
|
|
139
|
+
```
|
|
140
|
+
**Watch for:** `==` vs `===`, `include/require`, `unserialize()`, `preg_replace` with `/e`, `extract()`
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
### Go
|
|
145
|
+
**Main Risks:** Race conditions, template injection, slice bounds
|
|
146
|
+
```go
|
|
147
|
+
// UNSAFE: Race condition
|
|
148
|
+
go func() { counter++ }()
|
|
149
|
+
// SAFE: Use sync primitives
|
|
150
|
+
atomic.AddInt64(&counter, 1)
|
|
151
|
+
|
|
152
|
+
// UNSAFE: Template injection - template.HTML marks input trusted; text/template never escapes
|
|
153
|
+
template.HTML(userInput)
|
|
154
|
+
texttemplate.Must(texttemplate.New("page").Parse("<p>{{.UserInput}}</p>")) // text/template: XSS
|
|
155
|
+
// SAFE: html/template escapes {{.UserInput}} for the HTML, attribute, JS, or URL context it lands in
|
|
156
|
+
import "html/template"
|
|
157
|
+
template.Must(template.New("page").Parse("<p>{{.UserInput}}</p>"))
|
|
158
|
+
```
|
|
159
|
+
**Watch for:** Goroutine data races, `template.HTML()`, `text/template` rendering HTML, `unsafe` package, unchecked slice access
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
### Ruby
|
|
164
|
+
**Main Risks:** Mass assignment, YAML deserialization, regex DoS
|
|
165
|
+
```ruby
|
|
166
|
+
# UNSAFE: Mass assignment
|
|
167
|
+
User.new(params[:user])
|
|
168
|
+
# SAFE: Strong parameters
|
|
169
|
+
User.new(params.require(:user).permit(:name, :email))
|
|
170
|
+
|
|
171
|
+
# UNSAFE: YAML RCE
|
|
172
|
+
YAML.unsafe_load(user_input) # arbitrary objects on every Psych version
|
|
173
|
+
YAML.load(user_input) # RCE only on Psych < 4 (Ruby < 3.1); since Psych 4 it is safe_load
|
|
174
|
+
# SAFE: Use safe_load explicitly, so the result does not depend on the Psych version in Gemfile.lock
|
|
175
|
+
YAML.safe_load(user_input)
|
|
176
|
+
```
|
|
177
|
+
**Watch for:** YAML.unsafe_load, YAML.load on Psych < 4, Marshal.load, eval, send with user input, .permit!
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
### Rust
|
|
182
|
+
**Main Risks:** Unsafe blocks, FFI boundary issues, integer overflow in release
|
|
183
|
+
```rust
|
|
184
|
+
// CAUTION: Unsafe bypasses safety
|
|
185
|
+
unsafe { ptr::read(user_ptr) }
|
|
186
|
+
|
|
187
|
+
// CAUTION: Integer overflow panics in debug, wraps silently in release
|
|
188
|
+
// (a literal `255u8 + 1` is a compile error - this only bites on runtime values)
|
|
189
|
+
let x: u8 = parse_user_len(input);
|
|
190
|
+
let y = x + 1; // panic in debug; wraps to 0 in release (overflow-checks = off)
|
|
191
|
+
// SAFE: Be explicit about the overflow case
|
|
192
|
+
let y = x.checked_add(1).ok_or(Error::TooLarge)?;
|
|
193
|
+
```
|
|
194
|
+
**Watch for:** `unsafe` blocks, FFI calls, integer overflow in release builds, `.unwrap()` on untrusted input
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
### Swift
|
|
199
|
+
**Main Risks:** Force unwrapping crashes, Objective-C interop
|
|
200
|
+
```swift
|
|
201
|
+
// UNSAFE: Force unwrap on untrusted data
|
|
202
|
+
let value = jsonDict["key"]!
|
|
203
|
+
// SAFE: Safe unwrapping
|
|
204
|
+
guard let value = jsonDict["key"] else { return }
|
|
205
|
+
|
|
206
|
+
// UNSAFE: Format string
|
|
207
|
+
String(format: userInput, args)
|
|
208
|
+
// SAFE: Don't use user input as format
|
|
209
|
+
```
|
|
210
|
+
**Watch for:** force unwrap (!), try!, ObjC bridging, NSSecureCoding misuse
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
### Kotlin
|
|
215
|
+
**Main Risks:** Null safety bypass, Java interop, serialization
|
|
216
|
+
```kotlin
|
|
217
|
+
// UNSAFE: Platform type from Java
|
|
218
|
+
val len = javaString.length // NPE if null
|
|
219
|
+
// SAFE: Explicit null check
|
|
220
|
+
val len = javaString?.length ?: 0
|
|
221
|
+
|
|
222
|
+
// UNSAFE: Reflection
|
|
223
|
+
clazz.getDeclaredMethod(userInput)
|
|
224
|
+
// SAFE: Allowlist methods
|
|
225
|
+
```
|
|
226
|
+
**Watch for:** Java interop nulls (! operator), reflection, serialization, platform types
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
### C / C++
|
|
231
|
+
**Main Risks:** Buffer overflow, use-after-free, format string
|
|
232
|
+
```c
|
|
233
|
+
// UNSAFE: Buffer overflow
|
|
234
|
+
char buf[10]; strcpy(buf, userInput);
|
|
235
|
+
|
|
236
|
+
// ALSO UNSAFE: strncpy does NOT null-terminate when src >= n
|
|
237
|
+
strncpy(buf, userInput, sizeof(buf) - 1); // buf may be unterminated
|
|
238
|
+
|
|
239
|
+
// SAFE: snprintf always terminates and reports truncation
|
|
240
|
+
if (snprintf(buf, sizeof buf, "%s", userInput) >= (int)sizeof buf) {
|
|
241
|
+
/* input was truncated - decide explicitly, don't ignore */
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// UNSAFE: Format string
|
|
245
|
+
printf(userInput);
|
|
246
|
+
// SAFE: Always use format specifier
|
|
247
|
+
printf("%s", userInput);
|
|
248
|
+
```
|
|
249
|
+
**Watch for:** `strcpy`, `strncpy` (no null terminator), `sprintf`, `gets`, `alloca` with user size, pointer arithmetic, manual memory management, integer overflow in size calculations before `malloc`
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
### Scala
|
|
254
|
+
**Main Risks:** XML external entities, serialization, pattern matching exhaustiveness
|
|
255
|
+
```scala
|
|
256
|
+
// UNSAFE: XXE
|
|
257
|
+
val xml = XML.loadString(userInput)
|
|
258
|
+
// SAFE: Disable external entities
|
|
259
|
+
val factory = SAXParserFactory.newInstance()
|
|
260
|
+
factory.setFeature("http://xml.org/sax/features/external-general-entities", false)
|
|
261
|
+
```
|
|
262
|
+
**Watch for:** Java interop issues, XML parsing, `Serializable`, exhaustive pattern matching
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
### R
|
|
267
|
+
**Main Risks:** Code injection, file path manipulation
|
|
268
|
+
```r
|
|
269
|
+
# UNSAFE: eval injection
|
|
270
|
+
eval(parse(text = user_input))
|
|
271
|
+
# SAFE: Never parse user input as code
|
|
272
|
+
|
|
273
|
+
# UNSAFE: Path traversal
|
|
274
|
+
read.csv(paste0("data/", user_file))
|
|
275
|
+
# SAFE: Validate filename
|
|
276
|
+
if (grepl("^[a-zA-Z0-9]+\\.csv$", user_file)) read.csv(...)
|
|
277
|
+
```
|
|
278
|
+
**Watch for:** `eval()`, `parse()`, `source()`, `system()`, file path manipulation
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
### Perl
|
|
283
|
+
**Main Risks:** Regex injection, open() injection, taint mode bypass
|
|
284
|
+
```perl
|
|
285
|
+
# UNSAFE: Regex DoS
|
|
286
|
+
$input =~ /$user_pattern/;
|
|
287
|
+
# SAFE: Use quotemeta
|
|
288
|
+
$input =~ /\Q$user_pattern\E/;
|
|
289
|
+
|
|
290
|
+
# UNSAFE: open() command injection
|
|
291
|
+
open(FILE, $user_file);
|
|
292
|
+
# SAFE: Three-argument open
|
|
293
|
+
open(my $fh, '<', $user_file);
|
|
294
|
+
```
|
|
295
|
+
**Watch for:** Two-arg `open()`, regex from user input, backticks, `eval`, disabled taint mode
|
|
296
|
+
|
|
297
|
+
---
|
|
298
|
+
|
|
299
|
+
### Shell (Bash)
|
|
300
|
+
**Main Risks:** Command injection, word splitting, globbing
|
|
301
|
+
```bash
|
|
302
|
+
# UNSAFE: Unquoted variables
|
|
303
|
+
rm $user_file
|
|
304
|
+
# SAFE: Always quote
|
|
305
|
+
rm "$user_file"
|
|
306
|
+
|
|
307
|
+
# UNSAFE: eval
|
|
308
|
+
eval "$user_command"
|
|
309
|
+
# SAFE: Never eval user input
|
|
310
|
+
```
|
|
311
|
+
**Watch for:** Unquoted variables, `eval`, backticks, `$(...)` with user input, missing `set -euo pipefail`
|
|
312
|
+
|
|
313
|
+
---
|
|
314
|
+
|
|
315
|
+
### Lua
|
|
316
|
+
**Main Risks:** Sandbox escape, loadstring injection
|
|
317
|
+
```lua
|
|
318
|
+
-- UNSAFE: Code injection
|
|
319
|
+
loadstring(user_code)()
|
|
320
|
+
-- SAFE: Use sandboxed environment with restricted functions
|
|
321
|
+
```
|
|
322
|
+
**Watch for:** `loadstring`, `loadfile`, `dofile`, `os.execute`, `io` library, debug library
|
|
323
|
+
|
|
324
|
+
---
|
|
325
|
+
|
|
326
|
+
### Elixir
|
|
327
|
+
**Main Risks:** Atom exhaustion, code injection, ETS access
|
|
328
|
+
```elixir
|
|
329
|
+
# UNSAFE: Atom exhaustion DoS
|
|
330
|
+
String.to_atom(user_input)
|
|
331
|
+
# SAFE: Use existing atoms only
|
|
332
|
+
String.to_existing_atom(user_input)
|
|
333
|
+
|
|
334
|
+
# UNSAFE: Code injection
|
|
335
|
+
Code.eval_string(user_input)
|
|
336
|
+
# SAFE: Never eval user input
|
|
337
|
+
```
|
|
338
|
+
**Watch for:** `String.to_atom`, `Code.eval_string`, `:erlang.binary_to_term`, ETS public tables
|
|
339
|
+
|
|
340
|
+
---
|
|
341
|
+
|
|
342
|
+
### Dart / Flutter
|
|
343
|
+
**Main Risks:** Platform channel injection, insecure storage
|
|
344
|
+
```dart
|
|
345
|
+
// UNSAFE: Storing secrets in SharedPreferences
|
|
346
|
+
prefs.setString('auth_token', token);
|
|
347
|
+
// SAFE: Use flutter_secure_storage
|
|
348
|
+
secureStorage.write(key: 'auth_token', value: token);
|
|
349
|
+
```
|
|
350
|
+
**Watch for:** Platform channel data, `dart:mirrors`, `Function.apply`, insecure local storage
|
|
351
|
+
|
|
352
|
+
---
|
|
353
|
+
|
|
354
|
+
### PowerShell
|
|
355
|
+
**Main Risks:** Command injection, execution policy bypass
|
|
356
|
+
```powershell
|
|
357
|
+
# UNSAFE: Injection
|
|
358
|
+
Invoke-Expression $userInput
|
|
359
|
+
# SAFE: Avoid Invoke-Expression with user data
|
|
360
|
+
|
|
361
|
+
# UNSAFE: Unvalidated path
|
|
362
|
+
Get-Content $userPath
|
|
363
|
+
# SAFE: Validate path is within allowed directory
|
|
364
|
+
```
|
|
365
|
+
**Watch for:** `Invoke-Expression`, `& $userVar`, `Start-Process` with user args, `-ExecutionPolicy Bypass`
|
|
366
|
+
|
|
367
|
+
---
|
|
368
|
+
|
|
369
|
+
### SQL (All Dialects)
|
|
370
|
+
**Main Risks:** Injection, privilege escalation, data exfiltration
|
|
371
|
+
```sql
|
|
372
|
+
-- UNSAFE: String concatenation
|
|
373
|
+
"SELECT * FROM users WHERE id = " + userId
|
|
374
|
+
|
|
375
|
+
-- SAFE: Parameterized query (language-specific)
|
|
376
|
+
-- Use prepared statements in ALL cases
|
|
377
|
+
```
|
|
378
|
+
**Watch for:** Dynamic SQL, `EXECUTE IMMEDIATE`, stored procedures with dynamic queries, privilege grants
|