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