@arsh342/athena 0.2.5 → 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 +133 -36
  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 +27692 -8009
  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,5 @@
1
+ package m
2
+ import "gorm.io/gorm"
3
+ func f(db *gorm.DB, col string) {
4
+ db.Raw("SELECT * FROM users ORDER BY " + col) // EXPECT gorm.raw-concat
5
+ }
@@ -0,0 +1,32 @@
1
+ {
2
+ "rules": [
3
+ {
4
+ "id": "gorm.raw-concat",
5
+ "title": "GORM raw SQL built by concatenation",
6
+ "severity": "HIGH",
7
+ "cwe": [
8
+ 89
9
+ ],
10
+ "category": "injection",
11
+ "why": "Raw/Exec/Where with a formatted string is SQL injection.",
12
+ "fix": "Use placeholders: Where(\"id = ?\", id).",
13
+ "match": {
14
+ "kind": "call",
15
+ "callee": "\\.(?:Raw|Exec|Where)$",
16
+ "where": [
17
+ {
18
+ "op": "argIsConcat",
19
+ "index": 0
20
+ },
21
+ {
22
+ "op": "fileTextMatches",
23
+ "regex": "gorm\\.io"
24
+ }
25
+ ]
26
+ },
27
+ "families": [
28
+ "go"
29
+ ]
30
+ }
31
+ ]
32
+ }
@@ -0,0 +1,43 @@
1
+ ---
2
+ name: hibernate
3
+ description: 'Hibernate/JPA: HQL and native queries built from strings.'
4
+ version: 1.0.0
5
+ license: MIT
6
+ author: Athena
7
+ appliesTo:
8
+ languages:
9
+ - java
10
+ frameworks:
11
+ - hibernate
12
+ detect:
13
+ dependencies:
14
+ - hibernate
15
+ - spring-data-jpa
16
+ imports:
17
+ - org.hibernate
18
+ - javax.persistence
19
+ - jakarta.persistence
20
+ categories:
21
+ - injection
22
+ ---
23
+
24
+ ## When this applies
25
+
26
+ Projects that use hibernate.
27
+
28
+ ## How to investigate
29
+
30
+ Find raw-query escape hatches and check every one for bound parameters.
31
+
32
+ ## Verification checklist
33
+
34
+ - Is the query text a literal? Are values bound separately?
35
+
36
+ ## Fixes
37
+
38
+ Use bound parameters or the query builder.
39
+
40
+ ## References
41
+
42
+ - https://owasp.org/www-community/attacks/SQL_Injection
43
+
@@ -0,0 +1,6 @@
1
+ import javax.persistence.EntityManager;
2
+ class Dao {
3
+ Object f(EntityManager em, long id) {
4
+ return em.createQuery("from User where id = :id").setParameter("id", id);
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ import javax.persistence.EntityManager;
2
+ class Dao {
3
+ Object f(EntityManager em, String order) {
4
+ return em.createQuery("from User order by " + order); // EXPECT hibernate.query-concat
5
+ }
6
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "rules": [
3
+ {
4
+ "id": "hibernate.query-concat",
5
+ "title": "HQL/JPQL query built by concatenation",
6
+ "severity": "HIGH",
7
+ "cwe": [
8
+ 89
9
+ ],
10
+ "category": "injection",
11
+ "why": "createQuery with concatenated values is injectable.",
12
+ "fix": "Use named parameters (:name) and setParameter.",
13
+ "match": {
14
+ "kind": "call",
15
+ "callee": "\\.createQuery$",
16
+ "where": [
17
+ {
18
+ "op": "argIsConcat",
19
+ "index": 0
20
+ }
21
+ ]
22
+ },
23
+ "families": [
24
+ "java"
25
+ ]
26
+ }
27
+ ]
28
+ }
@@ -0,0 +1,35 @@
1
+ ---
2
+ name: insecure-defaults
3
+ description: 'Find fail-open behavior: code that runs insecurely when configuration is missing, such as a fallback secret or disabled auth.'
4
+ version: 1.0.0
5
+ license: MIT
6
+ author: Athena
7
+ appliesTo:
8
+ detect:
9
+ always: true
10
+ categories:
11
+ - config
12
+ - authn
13
+ ---
14
+
15
+ ## When this applies
16
+
17
+ Reviewing configuration loading, secrets handling and feature flags.
18
+
19
+ ## How to investigate
20
+
21
+ Look for values read from the environment with a hard-coded fallback, auth or TLS that turns off when a setting is absent, and defaults that differ between dev and prod.
22
+
23
+ ## Verification checklist
24
+
25
+ - Does the application start without the secret/config? It should refuse to.
26
+ - Is the fallback usable in production?
27
+
28
+ ## Fixes
29
+
30
+ Fail closed: require the setting at startup and exit with a clear error.
31
+
32
+ ## References
33
+
34
+ - https://cwe.mitre.org/data/definitions/1188.html
35
+
@@ -0,0 +1,37 @@
1
+ ---
2
+ name: insecure-defaults-code
3
+ description: 'Fail-open defaults in code: secrets that fall back to a hard-coded value when the environment variable is missing.'
4
+ version: 1.0.0
5
+ license: MIT
6
+ author: Athena
7
+ appliesTo:
8
+ languages:
9
+ - js
10
+ - python
11
+ detect:
12
+ always: true
13
+ categories:
14
+ - config
15
+ - authn
16
+ ---
17
+
18
+ ## When this applies
19
+
20
+ Any code that reads secrets or keys from the environment.
21
+
22
+ ## How to investigate
23
+
24
+ Search for `process.env.X || "literal"`, `os.environ.get("X", "literal")` and similar fallbacks.
25
+
26
+ ## Verification checklist
27
+
28
+ - Does the app start in production without the secret set? It must not.
29
+
30
+ ## Fixes
31
+
32
+ Remove the fallback and fail at startup when the variable is missing.
33
+
34
+ ## References
35
+
36
+ - https://cwe.mitre.org/data/definitions/1188.html
37
+
@@ -0,0 +1,2 @@
1
+ const secret = process.env.JWT_SECRET;
2
+ if (!secret) throw new Error('JWT_SECRET is required');
@@ -0,0 +1,2 @@
1
+ import os
2
+ SECRET = os.environ['SECRET_KEY']
@@ -0,0 +1 @@
1
+ const secret = process.env.JWT_SECRET || 'dev-secret-change-me'; // EXPECT insecure-defaults-code.env-secret-fallback
@@ -0,0 +1,2 @@
1
+ import os
2
+ SECRET = os.environ.get('SECRET_KEY', 'changeme-in-prod') # EXPECT insecure-defaults-code.env-secret-fallback
@@ -0,0 +1,24 @@
1
+ {
2
+ "rules": [
3
+ {
4
+ "id": "insecure-defaults-code.env-secret-fallback",
5
+ "title": "Secret falls back to a hard-coded value",
6
+ "severity": "HIGH",
7
+ "cwe": [
8
+ 1188,
9
+ 798
10
+ ],
11
+ "category": "config",
12
+ "why": "If the environment variable is missing the app silently uses a known value, so anyone can forge tokens or sessions.",
13
+ "fix": "Require the variable and exit with a clear error when it is absent.",
14
+ "match": {
15
+ "kind": "line",
16
+ "line": "(?:process\\.env\\.\\w*(?:SECRET|KEY|TOKEN|PASSWORD)\\w*|os\\.environ\\.get\\([\\'\"]\\w*(?:SECRET|KEY|TOKEN|PASSWORD)\\w*[\\'\"])\\s*(?:\\|\\||\\?\\?|,)\\s*[`\\'\"][^`\\'\"]{3,}"
17
+ },
18
+ "families": [
19
+ "js",
20
+ "python"
21
+ ]
22
+ }
23
+ ]
24
+ }
@@ -0,0 +1,41 @@
1
+ ---
2
+ name: laravel
3
+ description: 'Laravel: mass assignment, CSRF exceptions and unescaped Blade output.'
4
+ version: 1.0.0
5
+ license: MIT
6
+ author: Athena
7
+ appliesTo:
8
+ languages:
9
+ - php
10
+ frameworks:
11
+ - laravel
12
+ detect:
13
+ dependencies:
14
+ - laravel/framework
15
+ imports:
16
+ - Illuminate
17
+ categories:
18
+ - authz
19
+ - xss
20
+ ---
21
+
22
+ ## When this applies
23
+
24
+ Projects that depend on laravel/framework.
25
+
26
+ ## How to investigate
27
+
28
+ Check Eloquent $fillable/$guarded, VerifyCsrfToken exceptions and {!! !!} in Blade views.
29
+
30
+ ## Verification checklist
31
+
32
+ - Is $guarded an empty array?
33
+
34
+ ## Fixes
35
+
36
+ Use $fillable lists and {{ }} escaping.
37
+
38
+ ## References
39
+
40
+ - https://laravel.com/docs/eloquent#mass-assignment
41
+
@@ -0,0 +1,5 @@
1
+ <?php
2
+ use Illuminate\Database\Eloquent\Model;
3
+ class User extends Model {
4
+ protected $fillable = ['name', 'email'];
5
+ }
@@ -0,0 +1,4 @@
1
+ <?php
2
+ class VerifyCsrfToken {
3
+ protected $except = ['webhooks/stripe'];
4
+ }
@@ -0,0 +1,2 @@
1
+ <p>{{ $comment }}</p>
2
+ <p>{!! e($comment) !!}</p>
@@ -0,0 +1,5 @@
1
+ <?php
2
+ use Illuminate\Database\Eloquent\Model;
3
+ class User extends Model {
4
+ protected $guarded = []; // EXPECT laravel.guarded-empty
5
+ }
@@ -0,0 +1,4 @@
1
+ <?php
2
+ class VerifyCsrfToken {
3
+ protected $except = ['*']; // EXPECT laravel.csrf-except-wildcard
4
+ }
@@ -0,0 +1 @@
1
+ <p>{!! $comment !!}</p> {{-- EXPECT laravel.blade-unescaped-output --}}
@@ -0,0 +1,62 @@
1
+ {
2
+ "rules": [
3
+ {
4
+ "id": "laravel.guarded-empty",
5
+ "title": "Eloquent model with no mass-assignment protection",
6
+ "severity": "HIGH",
7
+ "cwe": [
8
+ 915
9
+ ],
10
+ "category": "authz",
11
+ "why": "$guarded = [] allows every attribute (role, is_admin) to be set from request data.",
12
+ "fix": "Use an explicit $fillable list.",
13
+ "match": {
14
+ "kind": "line",
15
+ "line": "\\$guarded\\s*=\\s*\\[\\s*\\]"
16
+ },
17
+ "families": [
18
+ "php"
19
+ ]
20
+ },
21
+ {
22
+ "id": "laravel.csrf-except-wildcard",
23
+ "title": "CSRF verification disabled for every route",
24
+ "severity": "MEDIUM",
25
+ "cwe": [
26
+ 352
27
+ ],
28
+ "category": "session",
29
+ "why": "$except = [\"*\"] turns CSRF protection off.",
30
+ "fix": "List only the webhook routes that need it.",
31
+ "match": {
32
+ "kind": "line",
33
+ "line": "\\$except\\s*=\\s*\\[\\s*[\\'\"]\\*[\\'\"]"
34
+ },
35
+ "families": [
36
+ "php"
37
+ ]
38
+ },
39
+ {
40
+ "id": "laravel.blade-unescaped-output",
41
+ "title": "Unescaped Blade output",
42
+ "severity": "MEDIUM",
43
+ "cwe": [
44
+ 79
45
+ ],
46
+ "category": "xss",
47
+ "why": "{!! $x !!} prints raw HTML; user data in it is an XSS hole.",
48
+ "fix": "Use {{ $x }} or sanitize first.",
49
+ "match": {
50
+ "kind": "file",
51
+ "files": "\\.blade\\.php$",
52
+ "line": "\\{!!\\s*\\$",
53
+ "where": [
54
+ {
55
+ "op": "lineNotMatches",
56
+ "regex": "e\\(|htmlspecialchars|Purifier"
57
+ }
58
+ ]
59
+ }
60
+ }
61
+ ]
62
+ }
@@ -0,0 +1,40 @@
1
+ ---
2
+ name: lifecycle-and-races
3
+ description: 'Resources, cleanup, failure paths and concurrency: leaks, late cleanup handlers, swallowed errors, check-then-act races.'
4
+ version: 1.0.0
5
+ license: MIT
6
+ author: Athena
7
+ appliesTo:
8
+ detect:
9
+ always: true
10
+ categories:
11
+ - lifecycle
12
+ - race-condition
13
+ ---
14
+
15
+ ## When this applies
16
+
17
+ Reviewing long-lived connections, background jobs, token and session handling, and anything that reads then writes shared state.
18
+
19
+ ## How to investigate
20
+
21
+ - Acquire without release on every path (including errors).
22
+ - Registration then await then cleanup handler: a disconnect during the await leaks.
23
+ - Success status written but not the failure status.
24
+ - A catch that returns an empty value that callers read as success.
25
+ - Read a row, decide, then update by id only: two requests can both pass.
26
+
27
+ ## Verification checklist
28
+
29
+ - Is the update conditional (`WHERE id = $1 AND used = false`) and its row count checked?
30
+ - Is cleanup attached before the first await?
31
+ - Does every exit path record an outcome?
32
+
33
+ ## Fixes
34
+
35
+ Make updates conditional or transactional, attach cleanup first, and record failures explicitly.
36
+
37
+ ## References
38
+
39
+ - https://cwe.mitre.org/data/definitions/367.html
40
+
@@ -0,0 +1,45 @@
1
+ ---
2
+ name: llm-app-security
3
+ description: 'Applications that call LLMs: prompt injection paths and model output reaching dangerous sinks (OWASP LLM Top 10).'
4
+ version: 1.0.0
5
+ license: MIT
6
+ author: Athena
7
+ appliesTo:
8
+ languages:
9
+ - js
10
+ - python
11
+ detect:
12
+ imports:
13
+ - openai
14
+ - '@anthropic-ai/sdk'
15
+ - anthropic
16
+ - langchain
17
+ - '@langchain'
18
+ - ollama
19
+ - '@google/generative-ai'
20
+ - google.generativeai
21
+ categories:
22
+ - llm
23
+ ---
24
+
25
+ ## When this applies
26
+
27
+ Code that imports an LLM SDK.
28
+
29
+ ## How to investigate
30
+
31
+ Trace model output to sinks (eval, shell, SQL, innerHTML) and user input into system prompts and tool arguments.
32
+
33
+ ## Verification checklist
34
+
35
+ - Is model output executed or rendered as HTML?
36
+ - Do tools run with more authority than the user has?
37
+
38
+ ## Fixes
39
+
40
+ Treat model output as untrusted input: validate against a schema, never eval/exec it, sandbox tools, keep user text out of the system prompt.
41
+
42
+ ## References
43
+
44
+ - https://owasp.org/www-project-top-10-for-large-language-model-applications/
45
+
@@ -0,0 +1,6 @@
1
+ const openai = require('openai');
2
+ async function f(client) {
3
+ const completion = await client.chat.completions.create({});
4
+ const plan = JSON.parse(completion.choices[0].message.content);
5
+ const m = [{ role: 'system', content: 'You are a helpful assistant.' }, { role: 'user', content: input }];
6
+ }
@@ -0,0 +1,3 @@
1
+ import openai
2
+ def f(client, text):
3
+ m = [{"role": "system", "content": "You are helpful."}, {"role": "user", "content": text}]
@@ -0,0 +1,6 @@
1
+ const openai = require('openai');
2
+ async function f(client) {
3
+ const completion = await client.chat.completions.create({});
4
+ eval(completion.choices[0].message.content); // EXPECT llm-app-security.model-output-executed
5
+ const m = [{ role: 'system', content: `You are ${userRole}` }]; // EXPECT llm-app-security.user-text-in-system-prompt
6
+ }
@@ -0,0 +1,3 @@
1
+ import openai
2
+ def f(client, role):
3
+ m = [{"role": "system", "content": f"You are {role}"}] # EXPECT llm-app-security.user-text-in-system-prompt
@@ -0,0 +1,51 @@
1
+ {
2
+ "rules": [
3
+ {
4
+ "id": "llm-app-security.model-output-executed",
5
+ "title": "Model output passed to eval or a shell",
6
+ "severity": "HIGH",
7
+ "cwe": [
8
+ 94,
9
+ 78
10
+ ],
11
+ "category": "llm",
12
+ "why": "An LLM can be steered by prompt injection to return code or commands; executing its output hands that control to whoever can influence the prompt.",
13
+ "fix": "Never execute model output. Parse a constrained format and map it to allow-listed actions.",
14
+ "match": {
15
+ "kind": "call",
16
+ "callee": "^(?:eval|exec|execSync|child_process\\.exec|os\\.system|subprocess\\.run)$",
17
+ "where": [
18
+ {
19
+ "op": "argMatches",
20
+ "index": 0,
21
+ "regex": "(?:completion|response|message|output|reply|answer)\\w*(?:\\.choices|\\.content|\\.text|\\[0\\])"
22
+ }
23
+ ]
24
+ },
25
+ "families": [
26
+ "js",
27
+ "python"
28
+ ]
29
+ },
30
+ {
31
+ "id": "llm-app-security.user-text-in-system-prompt",
32
+ "title": "User text interpolated into a system prompt",
33
+ "severity": "MEDIUM",
34
+ "cwe": [
35
+ 77
36
+ ],
37
+ "category": "llm",
38
+ "why": "Putting user text in the system role lets it override your instructions (prompt injection).",
39
+ "fix": "Keep the system prompt constant and pass user text as a user message.",
40
+ "match": {
41
+ "kind": "line",
42
+ "line": "role[\\'\"]?\\s*[:=]\\s*[\\'\"]system[\\'\"]\\s*,\\s*[\\'\"]?content[\\'\"]?\\s*[:=]\\s*(?:f[\\'\"]|[`\\'\"][^`\\'\"]*\\$\\{|[^`\\'\"\\n,]*\\+)"
43
+ },
44
+ "families": [
45
+ "js",
46
+ "python"
47
+ ],
48
+ "confidence": "low"
49
+ }
50
+ ]
51
+ }
@@ -0,0 +1,41 @@
1
+ ---
2
+ name: nestjs
3
+ description: 'NestJS: validation pipe and CORS defaults.'
4
+ version: 1.0.0
5
+ license: MIT
6
+ author: Athena
7
+ appliesTo:
8
+ languages:
9
+ - js
10
+ frameworks:
11
+ - nestjs
12
+ detect:
13
+ dependencies:
14
+ - '@nestjs/core'
15
+ imports:
16
+ - '@nestjs/core'
17
+ categories:
18
+ - validation
19
+ - cors
20
+ ---
21
+
22
+ ## When this applies
23
+
24
+ Projects that depend on @nestjs/core.
25
+
26
+ ## How to investigate
27
+
28
+ Check main.ts for a global ValidationPipe and enableCors options; check controllers for guards.
29
+
30
+ ## Verification checklist
31
+
32
+ - Is a global ValidationPipe (whitelist: true) registered?
33
+
34
+ ## Fixes
35
+
36
+ Register ValidationPipe with whitelist and forbidNonWhitelisted; list CORS origins.
37
+
38
+ ## References
39
+
40
+ - https://docs.nestjs.com/security/cors
41
+
@@ -0,0 +1,7 @@
1
+ import { NestFactory } from '@nestjs/core';
2
+ import { ValidationPipe } from '@nestjs/common';
3
+ async function main() {
4
+ const app = await NestFactory.create(AppModule);
5
+ app.useGlobalPipes(new ValidationPipe({ whitelist: true }));
6
+ app.enableCors({ origin: ['https://app.example.org'] });
7
+ }
@@ -0,0 +1,5 @@
1
+ import { NestFactory } from '@nestjs/core';
2
+ async function main() {
3
+ const app = await NestFactory.create(AppModule); // EXPECT nestjs.validation-pipe-missing
4
+ app.enableCors(); // EXPECT nestjs.cors-open
5
+ }
@@ -0,0 +1,47 @@
1
+ {
2
+ "rules": [
3
+ {
4
+ "id": "nestjs.validation-pipe-missing",
5
+ "title": "NestJS app without a global ValidationPipe",
6
+ "severity": "LOW",
7
+ "cwe": [
8
+ 20
9
+ ],
10
+ "category": "validation",
11
+ "why": "Without ValidationPipe, DTO decorators are not enforced and request bodies are used as sent.",
12
+ "fix": "app.useGlobalPipes(new ValidationPipe({ whitelist: true })).",
13
+ "match": {
14
+ "kind": "line",
15
+ "line": "NestFactory\\.create\\(",
16
+ "where": [
17
+ {
18
+ "op": "fileTextNotMatches",
19
+ "regex": "ValidationPipe"
20
+ }
21
+ ]
22
+ },
23
+ "families": [
24
+ "js"
25
+ ],
26
+ "confidence": "low"
27
+ },
28
+ {
29
+ "id": "nestjs.cors-open",
30
+ "title": "enableCors() with no origin list",
31
+ "severity": "MEDIUM",
32
+ "cwe": [
33
+ 942
34
+ ],
35
+ "category": "cors",
36
+ "why": "enableCors() without options allows every origin.",
37
+ "fix": "Pass an explicit origin list.",
38
+ "match": {
39
+ "kind": "line",
40
+ "line": "\\.enableCors\\(\\s*\\)"
41
+ },
42
+ "families": [
43
+ "js"
44
+ ]
45
+ }
46
+ ]
47
+ }