@arsh342/athena 0.2.4 → 0.3.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 (169) hide show
  1. package/README.md +132 -34
  2. package/dist/data/popular-crates.json +1 -0
  3. package/dist/data/popular-npm.json +1 -0
  4. package/dist/data/popular-nuget.json +1 -0
  5. package/dist/data/popular-packagist.json +1 -0
  6. package/dist/data/popular-pypi.json +1 -0
  7. package/dist/index.cjs +27682 -7864
  8. package/dist/models/fast/athena-detect-fast-0.1.0.bin +0 -0
  9. package/dist/models/fast/athena-detect-fast-0.1.0.json +259 -0
  10. package/dist/skills/.athena-builtin +1 -0
  11. package/dist/skills/ai-generated-code/SKILL.md +40 -0
  12. package/dist/skills/ai-generated-code/fixtures/safe/a.go +4 -0
  13. package/dist/skills/ai-generated-code/fixtures/safe/a.js +2 -0
  14. package/dist/skills/ai-generated-code/fixtures/safe/a.py +1 -0
  15. package/dist/skills/ai-generated-code/fixtures/vuln/a.go +4 -0
  16. package/dist/skills/ai-generated-code/fixtures/vuln/a.js +2 -0
  17. package/dist/skills/ai-generated-code/fixtures/vuln/a.py +1 -0
  18. package/dist/skills/ai-generated-code/rules.json +54 -0
  19. package/dist/skills/aspnet/SKILL.md +41 -0
  20. package/dist/skills/aspnet/fixtures/safe/Startup.cs +9 -0
  21. package/dist/skills/aspnet/fixtures/vuln/Startup.cs +9 -0
  22. package/dist/skills/aspnet/rules.json +46 -0
  23. package/dist/skills/audit-context/SKILL.md +38 -0
  24. package/dist/skills/auth-sessions/SKILL.md +39 -0
  25. package/dist/skills/auth-sessions/fixtures/safe/a.js +3 -0
  26. package/dist/skills/auth-sessions/fixtures/safe/a.py +2 -0
  27. package/dist/skills/auth-sessions/fixtures/vuln/a.js +3 -0
  28. package/dist/skills/auth-sessions/fixtures/vuln/a.py +2 -0
  29. package/dist/skills/auth-sessions/rules.json +95 -0
  30. package/dist/skills/c-memory-safety/SKILL.md +35 -0
  31. package/dist/skills/c-memory-safety/fixtures/safe/a.c +5 -0
  32. package/dist/skills/c-memory-safety/fixtures/vuln/a.c +6 -0
  33. package/dist/skills/c-memory-safety/rules.json +54 -0
  34. package/dist/skills/differential-review/SKILL.md +37 -0
  35. package/dist/skills/django/SKILL.md +42 -0
  36. package/dist/skills/django/fixtures/safe/settings.py +3 -0
  37. package/dist/skills/django/fixtures/vuln/settings.py +2 -0
  38. package/dist/skills/django/fixtures/vuln/views.py +4 -0
  39. package/dist/skills/django/rules.json +59 -0
  40. package/dist/skills/docker/SKILL.md +36 -0
  41. package/dist/skills/docker/fixtures/safe/Dockerfile +4 -0
  42. package/dist/skills/docker/fixtures/safe/Dockerfile.multi +6 -0
  43. package/dist/skills/docker/fixtures/safe/app.dockerfile +3 -0
  44. package/dist/skills/docker/fixtures/vuln/Dockerfile +3 -0
  45. package/dist/skills/docker/rules.json +82 -0
  46. package/dist/skills/efcore/SKILL.md +40 -0
  47. package/dist/skills/efcore/fixtures/safe/Repo.cs +6 -0
  48. package/dist/skills/efcore/fixtures/vuln/Repo.cs +6 -0
  49. package/dist/skills/efcore/rules.json +28 -0
  50. package/dist/skills/express/SKILL.md +42 -0
  51. package/dist/skills/express/fixtures/safe/app.js +8 -0
  52. package/dist/skills/express/fixtures/vuln/app.js +6 -0
  53. package/dist/skills/express/rules.json +102 -0
  54. package/dist/skills/false-positive-check/SKILL.md +38 -0
  55. package/dist/skills/fastapi/SKILL.md +40 -0
  56. package/dist/skills/fastapi/fixtures/safe/main.py +4 -0
  57. package/dist/skills/fastapi/fixtures/vuln/main.py +4 -0
  58. package/dist/skills/fastapi/rules.json +32 -0
  59. package/dist/skills/file-uploads/SKILL.md +38 -0
  60. package/dist/skills/file-uploads/fixtures/safe/up.js +5 -0
  61. package/dist/skills/file-uploads/fixtures/safe/up.py +6 -0
  62. package/dist/skills/file-uploads/fixtures/vuln/up.js +5 -0
  63. package/dist/skills/file-uploads/fixtures/vuln/up.py +5 -0
  64. package/dist/skills/file-uploads/rules.json +52 -0
  65. package/dist/skills/file-uploads/taint.json +21 -0
  66. package/dist/skills/flask/SKILL.md +41 -0
  67. package/dist/skills/flask/fixtures/safe/app.py +5 -0
  68. package/dist/skills/flask/fixtures/vuln/app.py +5 -0
  69. package/dist/skills/flask/rules.json +46 -0
  70. package/dist/skills/github-actions/SKILL.md +36 -0
  71. package/dist/skills/github-actions/fixtures/safe/.github/workflows/ci.yml +16 -0
  72. package/dist/skills/github-actions/fixtures/vuln/.github/workflows/ci.yml +12 -0
  73. package/dist/skills/github-actions/rules.json +85 -0
  74. package/dist/skills/go-web/SKILL.md +42 -0
  75. package/dist/skills/go-web/fixtures/safe/main.go +13 -0
  76. package/dist/skills/go-web/fixtures/vuln/main.go +8 -0
  77. package/dist/skills/go-web/rules.json +29 -0
  78. package/dist/skills/go-web/taint.json +14 -0
  79. package/dist/skills/gorm/SKILL.md +40 -0
  80. package/dist/skills/gorm/fixtures/safe/q.go +5 -0
  81. package/dist/skills/gorm/fixtures/vuln/q.go +5 -0
  82. package/dist/skills/gorm/rules.json +32 -0
  83. package/dist/skills/hibernate/SKILL.md +43 -0
  84. package/dist/skills/hibernate/fixtures/safe/Dao.java +6 -0
  85. package/dist/skills/hibernate/fixtures/vuln/Dao.java +6 -0
  86. package/dist/skills/hibernate/rules.json +28 -0
  87. package/dist/skills/insecure-defaults/SKILL.md +35 -0
  88. package/dist/skills/insecure-defaults-code/SKILL.md +37 -0
  89. package/dist/skills/insecure-defaults-code/fixtures/safe/a.js +2 -0
  90. package/dist/skills/insecure-defaults-code/fixtures/safe/a.py +2 -0
  91. package/dist/skills/insecure-defaults-code/fixtures/vuln/a.js +1 -0
  92. package/dist/skills/insecure-defaults-code/fixtures/vuln/a.py +2 -0
  93. package/dist/skills/insecure-defaults-code/rules.json +24 -0
  94. package/dist/skills/laravel/SKILL.md +41 -0
  95. package/dist/skills/laravel/fixtures/safe/User.php +5 -0
  96. package/dist/skills/laravel/fixtures/safe/app/Http/Middleware/VerifyCsrfToken.php +4 -0
  97. package/dist/skills/laravel/fixtures/safe/resources/views/a.blade.php +2 -0
  98. package/dist/skills/laravel/fixtures/vuln/User.php +5 -0
  99. package/dist/skills/laravel/fixtures/vuln/app/Http/Middleware/VerifyCsrfToken.php +4 -0
  100. package/dist/skills/laravel/fixtures/vuln/resources/views/a.blade.php +1 -0
  101. package/dist/skills/laravel/rules.json +62 -0
  102. package/dist/skills/lifecycle-and-races/SKILL.md +40 -0
  103. package/dist/skills/llm-app-security/SKILL.md +45 -0
  104. package/dist/skills/llm-app-security/fixtures/safe/a.js +6 -0
  105. package/dist/skills/llm-app-security/fixtures/safe/a.py +3 -0
  106. package/dist/skills/llm-app-security/fixtures/vuln/a.js +6 -0
  107. package/dist/skills/llm-app-security/fixtures/vuln/a.py +3 -0
  108. package/dist/skills/llm-app-security/rules.json +51 -0
  109. package/dist/skills/nestjs/SKILL.md +41 -0
  110. package/dist/skills/nestjs/fixtures/safe/main.ts +7 -0
  111. package/dist/skills/nestjs/fixtures/vuln/main.ts +5 -0
  112. package/dist/skills/nestjs/rules.json +47 -0
  113. package/dist/skills/nextjs/SKILL.md +41 -0
  114. package/dist/skills/nextjs/fixtures/safe/page.js +2 -0
  115. package/dist/skills/nextjs/fixtures/vuln/page.js +2 -0
  116. package/dist/skills/nextjs/rules.json +48 -0
  117. package/dist/skills/payments-webhooks/SKILL.md +35 -0
  118. package/dist/skills/payments-webhooks/fixtures/safe/hook.js +5 -0
  119. package/dist/skills/payments-webhooks/fixtures/vuln/hook.js +4 -0
  120. package/dist/skills/payments-webhooks/rules.json +33 -0
  121. package/dist/skills/php-hardening/SKILL.md +36 -0
  122. package/dist/skills/php-hardening/fixtures/safe/a.php +3 -0
  123. package/dist/skills/php-hardening/fixtures/vuln/a.php +3 -0
  124. package/dist/skills/php-hardening/rules.json +42 -0
  125. package/dist/skills/prisma/SKILL.md +41 -0
  126. package/dist/skills/prisma/fixtures/safe/q.js +2 -0
  127. package/dist/skills/prisma/fixtures/vuln/q.js +2 -0
  128. package/dist/skills/prisma/rules.json +28 -0
  129. package/dist/skills/react/SKILL.md +40 -0
  130. package/dist/skills/react/fixtures/safe/a.jsx +2 -0
  131. package/dist/skills/react/fixtures/vuln/a.jsx +2 -0
  132. package/dist/skills/react/rules.json +47 -0
  133. package/dist/skills/rust-unsafe-ffi/SKILL.md +35 -0
  134. package/dist/skills/rust-unsafe-ffi/fixtures/safe/a.rs +3 -0
  135. package/dist/skills/rust-unsafe-ffi/fixtures/vuln/a.rs +7 -0
  136. package/dist/skills/rust-unsafe-ffi/rules.json +41 -0
  137. package/dist/skills/rust-web/SKILL.md +45 -0
  138. package/dist/skills/rust-web/fixtures/safe/main.rs +4 -0
  139. package/dist/skills/rust-web/fixtures/vuln/main.rs +4 -0
  140. package/dist/skills/rust-web/rules.json +22 -0
  141. package/dist/skills/sharp-edges/SKILL.md +34 -0
  142. package/dist/skills/sharp-edges-code/SKILL.md +35 -0
  143. package/dist/skills/sharp-edges-code/fixtures/safe/a.py +3 -0
  144. package/dist/skills/sharp-edges-code/fixtures/vuln/a.py +2 -0
  145. package/dist/skills/sharp-edges-code/rules.json +23 -0
  146. package/dist/skills/shell-hardening/SKILL.md +35 -0
  147. package/dist/skills/shell-hardening/fixtures/safe/a.sh +3 -0
  148. package/dist/skills/shell-hardening/fixtures/vuln/a.sh +2 -0
  149. package/dist/skills/shell-hardening/rules.json +29 -0
  150. package/dist/skills/spec-vs-code/SKILL.md +34 -0
  151. package/dist/skills/spring/SKILL.md +45 -0
  152. package/dist/skills/spring/fixtures/safe/Sec.java +7 -0
  153. package/dist/skills/spring/fixtures/safe/src/main/resources/application.properties +1 -0
  154. package/dist/skills/spring/fixtures/vuln/Sec.java +8 -0
  155. package/dist/skills/spring/fixtures/vuln/src/main/resources/application.properties +1 -0
  156. package/dist/skills/spring/rules.json +75 -0
  157. package/dist/skills/sqlalchemy/SKILL.md +40 -0
  158. package/dist/skills/sqlalchemy/fixtures/safe/q.py +3 -0
  159. package/dist/skills/sqlalchemy/fixtures/vuln/q.py +3 -0
  160. package/dist/skills/sqlalchemy/rules.json +28 -0
  161. package/dist/skills/typeorm/SKILL.md +40 -0
  162. package/dist/skills/typeorm/fixtures/safe/q.ts +4 -0
  163. package/dist/skills/typeorm/fixtures/vuln/q.ts +4 -0
  164. package/dist/skills/typeorm/rules.json +32 -0
  165. package/dist/skills/variant-analysis/SKILL.md +38 -0
  166. package/package.json +11 -2
  167. package/null-pointer-font/NullPointer-8MpD.ttf +0 -0
  168. package/null-pointer-font/info.txt +0 -2
  169. package/null-pointer-font/misc/README.txt +0 -68
@@ -0,0 +1,41 @@
1
+ ---
2
+ name: nextjs
3
+ description: 'Next.js: server secrets leaking into the client bundle and risky image settings.'
4
+ version: 1.0.0
5
+ license: MIT
6
+ author: Athena
7
+ appliesTo:
8
+ languages:
9
+ - js
10
+ frameworks:
11
+ - next
12
+ detect:
13
+ dependencies:
14
+ - next
15
+ imports:
16
+ - next
17
+ categories:
18
+ - config
19
+ ---
20
+
21
+ ## When this applies
22
+
23
+ Projects that depend on next.
24
+
25
+ ## How to investigate
26
+
27
+ Variables prefixed NEXT_PUBLIC_ are embedded in the browser bundle. Check route handlers and server actions for session checks.
28
+
29
+ ## Verification checklist
30
+
31
+ - Is any NEXT_PUBLIC_ variable a secret?
32
+ - Does each route handler check the session?
33
+
34
+ ## Fixes
35
+
36
+ Move secrets to server-only variables and read them in route handlers or server actions.
37
+
38
+ ## References
39
+
40
+ - https://nextjs.org/docs/app/building-your-application/configuring/environment-variables
41
+
@@ -0,0 +1,2 @@
1
+ export const key = process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY;
2
+ export const server = process.env.STRIPE_SECRET_KEY;
@@ -0,0 +1,2 @@
1
+ export const key = process.env.NEXT_PUBLIC_STRIPE_SECRET_KEY; // EXPECT nextjs.public-env-secret
2
+ module.exports = { images: { dangerouslyAllowSVG: true } }; // EXPECT nextjs.dangerously-allow-svg
@@ -0,0 +1,48 @@
1
+ {
2
+ "rules": [
3
+ {
4
+ "id": "nextjs.public-env-secret",
5
+ "title": "Secret exposed through a NEXT_PUBLIC_ variable",
6
+ "severity": "MEDIUM",
7
+ "cwe": [
8
+ 200,
9
+ 540
10
+ ],
11
+ "category": "config",
12
+ "why": "NEXT_PUBLIC_ values are inlined into client JavaScript, so anything secret in one is public.",
13
+ "fix": "Rename it without the NEXT_PUBLIC_ prefix and read it only on the server.",
14
+ "match": {
15
+ "kind": "line",
16
+ "line": "process\\.env\\.NEXT_PUBLIC_\\w*(?:SECRET|PRIVATE|PASSWORD|TOKEN|API_?KEY)",
17
+ "where": [
18
+ {
19
+ "op": "lineNotMatches",
20
+ "regex": "PUBLISHABLE|ANON"
21
+ }
22
+ ]
23
+ },
24
+ "families": [
25
+ "js"
26
+ ]
27
+ },
28
+ {
29
+ "id": "nextjs.dangerously-allow-svg",
30
+ "title": "SVG optimization enabled for untrusted images",
31
+ "severity": "LOW",
32
+ "cwe": [
33
+ 79
34
+ ],
35
+ "category": "xss",
36
+ "why": "dangerouslyAllowSVG lets crafted SVG files run script when opened directly.",
37
+ "fix": "Keep it off, or set a strict contentSecurityPolicy for images.",
38
+ "match": {
39
+ "kind": "line",
40
+ "line": "dangerouslyAllowSVG\\s*:\\s*true"
41
+ },
42
+ "families": [
43
+ "js"
44
+ ],
45
+ "confidence": "medium"
46
+ }
47
+ ]
48
+ }
@@ -0,0 +1,35 @@
1
+ ---
2
+ name: payments-webhooks
3
+ description: 'Payment webhooks: signature verification.'
4
+ version: 1.0.0
5
+ license: MIT
6
+ author: Athena
7
+ appliesTo:
8
+ languages:
9
+ - js
10
+ detect:
11
+ always: true
12
+ categories:
13
+ - authn
14
+ ---
15
+
16
+ ## When this applies
17
+
18
+ Code that receives webhooks from payment or SaaS providers.
19
+
20
+ ## How to investigate
21
+
22
+ Check that the raw body signature is verified before acting on the event, and that handlers are idempotent.
23
+
24
+ ## Verification checklist
25
+
26
+ - Is constructEvent (or an HMAC check) called before using the payload?
27
+
28
+ ## Fixes
29
+
30
+ Verify the signature with the provider SDK on the raw body; store processed event ids.
31
+
32
+ ## References
33
+
34
+ - https://stripe.com/docs/webhooks/signatures
35
+
@@ -0,0 +1,5 @@
1
+ app.post('/webhooks/stripe', express.raw({ type: '*/*' }), (req, res) => {
2
+ const event = stripe.webhooks.constructEvent(req.body, req.headers['stripe-signature'], secret);
3
+ handle(event);
4
+ res.sendStatus(200);
5
+ });
@@ -0,0 +1,4 @@
1
+ app.post('/webhooks/stripe', express.raw({ type: '*/*' }), (req, res) => { // EXPECT payments-webhooks.webhook-unauthenticated
2
+ handle(JSON.parse(req.body));
3
+ res.sendStatus(200);
4
+ });
@@ -0,0 +1,33 @@
1
+ {
2
+ "rules": [
3
+ {
4
+ "id": "payments-webhooks.webhook-unauthenticated",
5
+ "title": "Webhook route that never verifies a signature",
6
+ "severity": "HIGH",
7
+ "cwe": [
8
+ 345
9
+ ],
10
+ "category": "authn",
11
+ "why": "Without signature verification anyone can post fake payment events to the route.",
12
+ "fix": "Call stripe.webhooks.constructEvent (or the provider equivalent) on the raw body.",
13
+ "match": {
14
+ "kind": "call",
15
+ "callee": "^(?:app|router)\\.post$",
16
+ "where": [
17
+ {
18
+ "op": "argMatches",
19
+ "index": 0,
20
+ "regex": "webhook"
21
+ },
22
+ {
23
+ "op": "callTextNotMatches",
24
+ "regex": "constructEvent|verifyHeader|signature|hmac"
25
+ }
26
+ ]
27
+ },
28
+ "families": [
29
+ "js"
30
+ ]
31
+ }
32
+ ]
33
+ }
@@ -0,0 +1,36 @@
1
+ ---
2
+ name: php-hardening
3
+ description: 'PHP pitfalls: legacy eval-like regex flags and loose hash comparison.'
4
+ version: 1.0.0
5
+ license: MIT
6
+ author: Athena
7
+ appliesTo:
8
+ languages:
9
+ - php
10
+ detect:
11
+ always: true
12
+ categories:
13
+ - injection
14
+ - crypto
15
+ ---
16
+
17
+ ## When this applies
18
+
19
+ PHP code.
20
+
21
+ ## How to investigate
22
+
23
+ Search for preg_replace with /e, and for == comparisons between hashes ("magic hashes").
24
+
25
+ ## Verification checklist
26
+
27
+ - Is a hash compared with == instead of hash_equals?
28
+
29
+ ## Fixes
30
+
31
+ Use preg_replace_callback and hash_equals.
32
+
33
+ ## References
34
+
35
+ - https://www.php.net/manual/en/function.hash-equals.php
36
+
@@ -0,0 +1,3 @@
1
+ <?php
2
+ preg_replace_callback('/x/', fn($m) => strtoupper($m[0]), $s);
3
+ if (hash_equals($stored, hash('sha256', $pass))) { echo 1; }
@@ -0,0 +1,3 @@
1
+ <?php
2
+ preg_replace('/x/e', 'strtoupper(\\0)', $s); // EXPECT php-hardening.preg-replace-eval
3
+ if (md5($pass) == $stored) { echo 1; } // EXPECT php-hardening.loose-hash-compare
@@ -0,0 +1,42 @@
1
+ {
2
+ "rules": [
3
+ {
4
+ "id": "php-hardening.preg-replace-eval",
5
+ "title": "preg_replace with the /e modifier",
6
+ "severity": "HIGH",
7
+ "cwe": [
8
+ 95
9
+ ],
10
+ "category": "injection",
11
+ "why": "The /e modifier evaluates the replacement as PHP code.",
12
+ "fix": "Use preg_replace_callback.",
13
+ "match": {
14
+ "kind": "line",
15
+ "line": "preg_replace\\(\\s*[\\'\"][^\\'\"]*/[a-z]*e[a-z]*[\\'\"]"
16
+ },
17
+ "families": [
18
+ "php"
19
+ ]
20
+ },
21
+ {
22
+ "id": "php-hardening.loose-hash-compare",
23
+ "title": "Hash compared with ==",
24
+ "severity": "MEDIUM",
25
+ "cwe": [
26
+ 697,
27
+ 208
28
+ ],
29
+ "category": "crypto",
30
+ "why": "\"0e123\" == \"0e456\" is true in PHP (magic hashes), and == leaks timing.",
31
+ "fix": "Use hash_equals().",
32
+ "match": {
33
+ "kind": "line",
34
+ "line": "(?:md5|sha1|hash)\\(.*\\)\\s*(?:==|!=)\\s*[^=]"
35
+ },
36
+ "families": [
37
+ "php"
38
+ ],
39
+ "confidence": "medium"
40
+ }
41
+ ]
42
+ }
@@ -0,0 +1,41 @@
1
+ ---
2
+ name: prisma
3
+ description: 'Prisma: unsafe raw query APIs built from strings.'
4
+ version: 1.0.0
5
+ license: MIT
6
+ author: Athena
7
+ appliesTo:
8
+ languages:
9
+ - js
10
+ frameworks:
11
+ - prisma
12
+ detect:
13
+ dependencies:
14
+ - '@prisma/client'
15
+ - prisma
16
+ imports:
17
+ - '@prisma/client'
18
+ categories:
19
+ - injection
20
+ ---
21
+
22
+ ## When this applies
23
+
24
+ Projects that use prisma.
25
+
26
+ ## How to investigate
27
+
28
+ Find raw-query escape hatches and check every one for bound parameters.
29
+
30
+ ## Verification checklist
31
+
32
+ - Is the query text a literal? Are values bound separately?
33
+
34
+ ## Fixes
35
+
36
+ Use bound parameters or the query builder.
37
+
38
+ ## References
39
+
40
+ - https://owasp.org/www-community/attacks/SQL_Injection
41
+
@@ -0,0 +1,2 @@
1
+ await prisma.$queryRaw`SELECT * FROM users WHERE id = ${id}`;
2
+ await prisma.$queryRawUnsafe('SELECT 1');
@@ -0,0 +1,2 @@
1
+ const t = pickTable();
2
+ await prisma.$queryRawUnsafe('SELECT * FROM ' + t); // EXPECT prisma.unsafe-raw-concat
@@ -0,0 +1,28 @@
1
+ {
2
+ "rules": [
3
+ {
4
+ "id": "prisma.unsafe-raw-concat",
5
+ "title": "Prisma raw query built by concatenation",
6
+ "severity": "HIGH",
7
+ "cwe": [
8
+ 89
9
+ ],
10
+ "category": "injection",
11
+ "why": "$queryRawUnsafe/$executeRawUnsafe run the string as SQL; concatenating values into it is SQL injection.",
12
+ "fix": "Use the tagged template $queryRaw`...${value}` which binds values.",
13
+ "match": {
14
+ "kind": "call",
15
+ "callee": "\\.\\$(?:queryRawUnsafe|executeRawUnsafe)$",
16
+ "where": [
17
+ {
18
+ "op": "argIsConcat",
19
+ "index": 0
20
+ }
21
+ ]
22
+ },
23
+ "families": [
24
+ "js"
25
+ ]
26
+ }
27
+ ]
28
+ }
@@ -0,0 +1,40 @@
1
+ ---
2
+ name: react
3
+ description: 'React: unsafe link targets and tab-nabbing.'
4
+ version: 1.0.0
5
+ license: MIT
6
+ author: Athena
7
+ appliesTo:
8
+ languages:
9
+ - js
10
+ frameworks:
11
+ - react
12
+ detect:
13
+ dependencies:
14
+ - react
15
+ imports:
16
+ - react
17
+ categories:
18
+ - xss
19
+ ---
20
+
21
+ ## When this applies
22
+
23
+ Projects that use React.
24
+
25
+ ## How to investigate
26
+
27
+ Search JSX for dangerouslySetInnerHTML, javascript: URLs and target="_blank" links.
28
+
29
+ ## Verification checklist
30
+
31
+ - Is any URL taken from user data and used in href/src?
32
+
33
+ ## Fixes
34
+
35
+ Validate URL schemes (allow http, https, mailto) and add rel="noopener noreferrer".
36
+
37
+ ## References
38
+
39
+ - https://react.dev/reference/react-dom/components/common
40
+
@@ -0,0 +1,2 @@
1
+ export const A = () => <a href="https://x.test" target="_blank" rel="noopener noreferrer">x</a>;
2
+ export const B = () => <button onClick={() => go()}>y</button>;
@@ -0,0 +1,2 @@
1
+ export const A = () => <a href="https://x.test" target="_blank">x</a>; // EXPECT react.target-blank-no-rel
2
+ export const B = () => <a href="javascript:alert(1)">y</a>; // EXPECT react.javascript-url
@@ -0,0 +1,47 @@
1
+ {
2
+ "rules": [
3
+ {
4
+ "id": "react.target-blank-no-rel",
5
+ "title": "Link opens a new tab without rel=\"noopener\"",
6
+ "severity": "LOW",
7
+ "cwe": [
8
+ 1022
9
+ ],
10
+ "category": "xss",
11
+ "why": "A page opened with target=\"_blank\" can navigate the opener through window.opener (reverse tab-nabbing).",
12
+ "fix": "Add rel=\"noopener noreferrer\".",
13
+ "match": {
14
+ "kind": "line",
15
+ "line": "target\\s*=\\s*[\"\\']_blank[\"\\']",
16
+ "where": [
17
+ {
18
+ "op": "lineNotMatches",
19
+ "regex": "rel\\s*=\\s*[\"\\'{][^\"\\']*noopener"
20
+ }
21
+ ]
22
+ },
23
+ "families": [
24
+ "js"
25
+ ],
26
+ "confidence": "medium"
27
+ },
28
+ {
29
+ "id": "react.javascript-url",
30
+ "title": "javascript: URL in a link",
31
+ "severity": "MEDIUM",
32
+ "cwe": [
33
+ 79
34
+ ],
35
+ "category": "xss",
36
+ "why": "A javascript: URL runs script when clicked.",
37
+ "fix": "Use an onClick handler, or validate URL schemes.",
38
+ "match": {
39
+ "kind": "line",
40
+ "line": "(?:href|src|action)\\s*=\\s*\\{?[\"\\'`]javascript:"
41
+ },
42
+ "families": [
43
+ "js"
44
+ ]
45
+ }
46
+ ]
47
+ }
@@ -0,0 +1,35 @@
1
+ ---
2
+ name: rust-unsafe-ffi
3
+ description: 'Rust unsafe code and FFI: raw slices and uninitialized memory.'
4
+ version: 1.0.0
5
+ license: MIT
6
+ author: Athena
7
+ appliesTo:
8
+ languages:
9
+ - rust
10
+ detect:
11
+ always: true
12
+ categories:
13
+ - memory-safety
14
+ ---
15
+
16
+ ## When this applies
17
+
18
+ Rust code with unsafe blocks or FFI.
19
+
20
+ ## How to investigate
21
+
22
+ Check every from_raw_parts for a valid pointer/length proof and every uninitialized value for full initialization before read.
23
+
24
+ ## Verification checklist
25
+
26
+ - Is the invariant written next to the unsafe block?
27
+
28
+ ## Fixes
29
+
30
+ Wrap unsafe in a small safe function that checks its inputs.
31
+
32
+ ## References
33
+
34
+ - https://doc.rust-lang.org/nomicon/
35
+
@@ -0,0 +1,3 @@
1
+ fn f(data: &[u8]) -> &[u8] {
2
+ &data[..data.len().min(8)]
3
+ }
@@ -0,0 +1,7 @@
1
+ use std::slice;
2
+ fn f(p: *const u8, n: usize) -> &'static [u8] {
3
+ unsafe { slice::from_raw_parts(p, n) } // EXPECT rust-unsafe-ffi.from-raw-parts
4
+ }
5
+ fn g() -> u32 {
6
+ unsafe { std::mem::zeroed() } // EXPECT rust-unsafe-ffi.uninitialized-memory
7
+ }
@@ -0,0 +1,41 @@
1
+ {
2
+ "rules": [
3
+ {
4
+ "id": "rust-unsafe-ffi.from-raw-parts",
5
+ "title": "Slice built from a raw pointer and length",
6
+ "severity": "MEDIUM",
7
+ "cwe": [
8
+ 119
9
+ ],
10
+ "category": "memory-safety",
11
+ "why": "from_raw_parts requires a valid, aligned pointer and a length within the allocation; mistakes are memory corruption.",
12
+ "fix": "Prefer safe slices; if unavoidable, check the pointer and length first and document why they hold.",
13
+ "match": {
14
+ "kind": "call",
15
+ "callee": "(?:^|::)from_raw_parts(?:_mut)?$"
16
+ },
17
+ "families": [
18
+ "rust"
19
+ ]
20
+ },
21
+ {
22
+ "id": "rust-unsafe-ffi.uninitialized-memory",
23
+ "title": "Uninitialized memory",
24
+ "severity": "LOW",
25
+ "cwe": [
26
+ 908
27
+ ],
28
+ "category": "memory-safety",
29
+ "why": "mem::uninitialized / zeroed / MaybeUninit::uninit can expose invalid values if read before initialization.",
30
+ "fix": "Use MaybeUninit and write every field before assume_init, or use a default value.",
31
+ "match": {
32
+ "kind": "call",
33
+ "callee": "(?:^|::)(?:uninitialized|zeroed)$|MaybeUninit::uninit$"
34
+ },
35
+ "families": [
36
+ "rust"
37
+ ],
38
+ "confidence": "low"
39
+ }
40
+ ]
41
+ }
@@ -0,0 +1,45 @@
1
+ ---
2
+ name: rust-web
3
+ description: 'Rust web services: permissive CORS.'
4
+ version: 1.0.0
5
+ license: MIT
6
+ author: Athena
7
+ appliesTo:
8
+ languages:
9
+ - rust
10
+ frameworks:
11
+ - axum
12
+ - actix
13
+ detect:
14
+ dependencies:
15
+ - axum
16
+ - actix-web
17
+ - tower-http
18
+ imports:
19
+ - axum
20
+ - actix_web
21
+ - tower_http
22
+ categories:
23
+ - cors
24
+ ---
25
+
26
+ ## When this applies
27
+
28
+ Rust services using axum or actix-web.
29
+
30
+ ## How to investigate
31
+
32
+ Check CORS layers and extractor-based auth.
33
+
34
+ ## Verification checklist
35
+
36
+ - Is any CORS layer permissive in production?
37
+
38
+ ## Fixes
39
+
40
+ List origins explicitly.
41
+
42
+ ## References
43
+
44
+ - https://docs.rs/tower-http/latest/tower_http/cors/
45
+
@@ -0,0 +1,4 @@
1
+ use tower_http::cors::CorsLayer;
2
+ fn app() {
3
+ let layer = CorsLayer::new().allow_origin(origin);
4
+ }
@@ -0,0 +1,4 @@
1
+ use tower_http::cors::CorsLayer;
2
+ fn app() {
3
+ let layer = CorsLayer::permissive(); // EXPECT rust-web.permissive-cors
4
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "rules": [
3
+ {
4
+ "id": "rust-web.permissive-cors",
5
+ "title": "Permissive CORS layer",
6
+ "severity": "MEDIUM",
7
+ "cwe": [
8
+ 942
9
+ ],
10
+ "category": "cors",
11
+ "why": "permissive() allows any origin, method and header.",
12
+ "fix": "Configure allowed origins.",
13
+ "match": {
14
+ "kind": "line",
15
+ "line": "(?:Cors|CorsLayer)::permissive\\(\\)|allow_any_origin\\(\\)"
16
+ },
17
+ "families": [
18
+ "rust"
19
+ ]
20
+ }
21
+ ]
22
+ }
@@ -0,0 +1,34 @@
1
+ ---
2
+ name: sharp-edges
3
+ description: Error-prone APIs and configurations that look fine but behave dangerously.
4
+ version: 1.0.0
5
+ license: MIT
6
+ author: Athena
7
+ appliesTo:
8
+ detect:
9
+ always: true
10
+ categories:
11
+ - api-misuse
12
+ ---
13
+
14
+ ## When this applies
15
+
16
+ Reviewing use of APIs with surprising defaults (assert for security, loose comparisons, regex with user patterns).
17
+
18
+ ## How to investigate
19
+
20
+ List the language and framework APIs with surprising defaults and check each use against the safe form.
21
+
22
+ ## Verification checklist
23
+
24
+ - Is a security decision made by `assert`, loose equality or a type coercion?
25
+ - Is user input used as a pattern, format string or path?
26
+
27
+ ## Fixes
28
+
29
+ Replace with the explicit safe API and add a test for the dangerous input.
30
+
31
+ ## References
32
+
33
+ - https://owasp.org/
34
+