torusguard 0.9.2

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 (236) hide show
  1. package/.torusguard/.manifest.json +95 -0
  2. package/.torusguard/ARCHITECTURE.md +168 -0
  3. package/.torusguard/TORUSGUARD.md +145 -0
  4. package/.torusguard/agents/auditor.md +41 -0
  5. package/.torusguard/agents/profiler.md +49 -0
  6. package/.torusguard/agents/remediator.md +41 -0
  7. package/.torusguard/agents/reviewer.md +39 -0
  8. package/.torusguard/agents/validator.md +46 -0
  9. package/.torusguard/config/scope.json +24 -0
  10. package/.torusguard/config/slash-commands.json +102 -0
  11. package/.torusguard/config/torusguard.json +30 -0
  12. package/.torusguard/references/django-security.md +43 -0
  13. package/.torusguard/references/drf-security.md +20 -0
  14. package/.torusguard/references/express-security.md +103 -0
  15. package/.torusguard/references/fastapi-security.md +20 -0
  16. package/.torusguard/references/firebase-security.md +78 -0
  17. package/.torusguard/references/flask-security.md +20 -0
  18. package/.torusguard/references/nextjs-security.md +96 -0
  19. package/.torusguard/references/react-vite-security.md +97 -0
  20. package/.torusguard/references/sqlalchemy-security.md +16 -0
  21. package/.torusguard/references/supabase-security.md +84 -0
  22. package/.torusguard/rules/README.md +62 -0
  23. package/.torusguard/rules/TORUSGUARD.md +145 -0
  24. package/.torusguard/rules/active/.gitkeep +0 -0
  25. package/.torusguard/rules/active/TG-DIFF-001.md +20 -0
  26. package/.torusguard/rules/active/TG-DIFF-002.md +20 -0
  27. package/.torusguard/rules/active/TG-DIFF-003.md +19 -0
  28. package/.torusguard/runs/.gitkeep +0 -0
  29. package/.torusguard/schemas/authorization.schema.json +81 -0
  30. package/.torusguard/schemas/confidence.schema.json +72 -0
  31. package/.torusguard/schemas/evidence.schema.json +66 -0
  32. package/.torusguard/schemas/finding.schema.json +164 -0
  33. package/.torusguard/schemas/provenance.schema.json +46 -0
  34. package/.torusguard/schemas/remediation.schema.json +59 -0
  35. package/.torusguard/schemas/retest.schema.json +53 -0
  36. package/.torusguard/schemas/runtime-evidence.schema.json +72 -0
  37. package/.torusguard/scripts/__pycache__/diff_guard.cpython-311.pyc +0 -0
  38. package/.torusguard/scripts/__pycache__/monorepo_detector.cpython-311.pyc +0 -0
  39. package/.torusguard/scripts/diff_guard.py +171 -0
  40. package/.torusguard/scripts/finding_scorer.py +86 -0
  41. package/.torusguard/scripts/manifest_builder.py +130 -0
  42. package/.torusguard/scripts/monorepo_detector.py +164 -0
  43. package/.torusguard/scripts/run_manager.py +89 -0
  44. package/.torusguard/scripts/safety_gate.py +64 -0
  45. package/.torusguard/scripts/sarif_exporter.py +116 -0
  46. package/.torusguard/scripts/stack_detect.py +152 -0
  47. package/.torusguard/skills/torusguard/SKILL.md +37 -0
  48. package/.torusguard/skills/torusguard/bootstrap.py +158 -0
  49. package/.torusguard/skills/torusguard/references/auth-and-sessions.md +56 -0
  50. package/.torusguard/skills/torusguard/references/business-logic-and-abuse.md +23 -0
  51. package/.torusguard/skills/torusguard/references/cache-and-sensitive-responses.md +10 -0
  52. package/.torusguard/skills/torusguard/references/client-code-exposure.md +55 -0
  53. package/.torusguard/skills/torusguard/references/csrf-and-cross-origin.md +11 -0
  54. package/.torusguard/skills/torusguard/references/dependency-and-supply-chain.md +22 -0
  55. package/.torusguard/skills/torusguard/references/django-security.md +43 -0
  56. package/.torusguard/skills/torusguard/references/drf-security.md +20 -0
  57. package/.torusguard/skills/torusguard/references/fastapi-security.md +20 -0
  58. package/.torusguard/skills/torusguard/references/flask-security.md +20 -0
  59. package/.torusguard/skills/torusguard/references/frontend-no-db.md +53 -0
  60. package/.torusguard/skills/torusguard/references/graphql-security.md +12 -0
  61. package/.torusguard/skills/torusguard/references/input-and-injection.md +51 -0
  62. package/.torusguard/skills/torusguard/references/mass-assignment-and-property-auth.md +22 -0
  63. package/.torusguard/skills/torusguard/references/platform-hardening.md +56 -0
  64. package/.torusguard/skills/torusguard/references/python-dependencies.md +16 -0
  65. package/.torusguard/skills/torusguard/references/python-security-overview.md +12 -0
  66. package/.torusguard/skills/torusguard/references/rate-limit-and-abuse.md +57 -0
  67. package/.torusguard/skills/torusguard/references/secrets-and-config.md +64 -0
  68. package/.torusguard/skills/torusguard/references/sqlalchemy-security.md +16 -0
  69. package/.torusguard/skills/torusguard/references/ssrf-and-outbound-requests.md +46 -0
  70. package/.torusguard/skills/torusguard/references/webhook-security.md +15 -0
  71. package/.torusguard/skills/torusguard/references/websocket-security.md +12 -0
  72. package/.torusguard/skills/torusguard-apply/SKILL.md +46 -0
  73. package/.torusguard/skills/torusguard-audit/SKILL.md +70 -0
  74. package/.torusguard/skills/torusguard-authorize/SKILL.md +47 -0
  75. package/.torusguard/skills/torusguard-exploit-check/SKILL.md +64 -0
  76. package/.torusguard/skills/torusguard-full/SKILL.md +70 -0
  77. package/.torusguard/skills/torusguard-harden/SKILL.md +63 -0
  78. package/.torusguard/skills/torusguard-init/SKILL.md +52 -0
  79. package/.torusguard/skills/torusguard-recheck/SKILL.md +53 -0
  80. package/.torusguard/skills/torusguard-report/SKILL.md +54 -0
  81. package/.torusguard/skills/torusguard-status/SKILL.md +42 -0
  82. package/.torusguard/skills/torusguard-verify/SKILL.md +55 -0
  83. package/.torusguard/skills/torusguard-web-validate/SKILL.md +64 -0
  84. package/.torusguard/templates/audit-report.template.md +54 -0
  85. package/.torusguard/templates/authorization.template.md +34 -0
  86. package/.torusguard/templates/finding-card.template.md +32 -0
  87. package/.torusguard/templates/remediation-bundle.template.md +35 -0
  88. package/.torusguard/workflows/apply.md +95 -0
  89. package/.torusguard/workflows/audit.md +93 -0
  90. package/.torusguard/workflows/authorize.md +95 -0
  91. package/.torusguard/workflows/exploit-check.md +97 -0
  92. package/.torusguard/workflows/harden.md +93 -0
  93. package/.torusguard/workflows/init.md +95 -0
  94. package/.torusguard/workflows/recheck.md +95 -0
  95. package/.torusguard/workflows/report.md +95 -0
  96. package/.torusguard/workflows/status.md +95 -0
  97. package/.torusguard/workflows/verify.md +95 -0
  98. package/.torusguard/workflows/web-validate.md +95 -0
  99. package/LICENSE +21 -0
  100. package/README.md +319 -0
  101. package/bin/torusguard.js +110 -0
  102. package/install.py +98 -0
  103. package/package.json +48 -0
  104. package/skills/torusguard/SKILL.md +41 -0
  105. package/skills/torusguard/__pycache__/bootstrap.cpython-311.pyc +0 -0
  106. package/skills/torusguard/bootstrap.py +256 -0
  107. package/skills/torusguard/payload/.manifest.json +95 -0
  108. package/skills/torusguard/payload/ARCHITECTURE.md +168 -0
  109. package/skills/torusguard/payload/TORUSGUARD.md +145 -0
  110. package/skills/torusguard/payload/agents/auditor.md +41 -0
  111. package/skills/torusguard/payload/agents/profiler.md +49 -0
  112. package/skills/torusguard/payload/agents/remediator.md +41 -0
  113. package/skills/torusguard/payload/agents/reviewer.md +39 -0
  114. package/skills/torusguard/payload/agents/validator.md +46 -0
  115. package/skills/torusguard/payload/config/scope.json +24 -0
  116. package/skills/torusguard/payload/config/slash-commands.json +102 -0
  117. package/skills/torusguard/payload/config/torusguard.json +30 -0
  118. package/skills/torusguard/payload/references/django-security.md +43 -0
  119. package/skills/torusguard/payload/references/drf-security.md +20 -0
  120. package/skills/torusguard/payload/references/express-security.md +103 -0
  121. package/skills/torusguard/payload/references/fastapi-security.md +20 -0
  122. package/skills/torusguard/payload/references/firebase-security.md +78 -0
  123. package/skills/torusguard/payload/references/flask-security.md +20 -0
  124. package/skills/torusguard/payload/references/nextjs-security.md +96 -0
  125. package/skills/torusguard/payload/references/react-vite-security.md +97 -0
  126. package/skills/torusguard/payload/references/sqlalchemy-security.md +16 -0
  127. package/skills/torusguard/payload/references/supabase-security.md +84 -0
  128. package/skills/torusguard/payload/rules/README.md +62 -0
  129. package/skills/torusguard/payload/rules/TORUSGUARD.md +145 -0
  130. package/skills/torusguard/payload/rules/active/.gitkeep +0 -0
  131. package/skills/torusguard/payload/rules/active/TG-DIFF-001.md +20 -0
  132. package/skills/torusguard/payload/rules/active/TG-DIFF-002.md +20 -0
  133. package/skills/torusguard/payload/rules/active/TG-DIFF-003.md +19 -0
  134. package/skills/torusguard/payload/schemas/authorization.schema.json +81 -0
  135. package/skills/torusguard/payload/schemas/confidence.schema.json +72 -0
  136. package/skills/torusguard/payload/schemas/evidence.schema.json +66 -0
  137. package/skills/torusguard/payload/schemas/finding.schema.json +164 -0
  138. package/skills/torusguard/payload/schemas/provenance.schema.json +46 -0
  139. package/skills/torusguard/payload/schemas/remediation.schema.json +59 -0
  140. package/skills/torusguard/payload/schemas/retest.schema.json +53 -0
  141. package/skills/torusguard/payload/schemas/runtime-evidence.schema.json +72 -0
  142. package/skills/torusguard/payload/scripts/diff_guard.py +171 -0
  143. package/skills/torusguard/payload/scripts/finding_scorer.py +86 -0
  144. package/skills/torusguard/payload/scripts/manifest_builder.py +130 -0
  145. package/skills/torusguard/payload/scripts/monorepo_detector.py +164 -0
  146. package/skills/torusguard/payload/scripts/run_manager.py +89 -0
  147. package/skills/torusguard/payload/scripts/safety_gate.py +64 -0
  148. package/skills/torusguard/payload/scripts/sarif_exporter.py +116 -0
  149. package/skills/torusguard/payload/scripts/stack_detect.py +152 -0
  150. package/skills/torusguard/payload/skills/torusguard/SKILL.md +37 -0
  151. package/skills/torusguard/payload/skills/torusguard/bootstrap.py +158 -0
  152. package/skills/torusguard/payload/skills/torusguard/references/auth-and-sessions.md +56 -0
  153. package/skills/torusguard/payload/skills/torusguard/references/business-logic-and-abuse.md +23 -0
  154. package/skills/torusguard/payload/skills/torusguard/references/cache-and-sensitive-responses.md +10 -0
  155. package/skills/torusguard/payload/skills/torusguard/references/client-code-exposure.md +55 -0
  156. package/skills/torusguard/payload/skills/torusguard/references/csrf-and-cross-origin.md +11 -0
  157. package/skills/torusguard/payload/skills/torusguard/references/dependency-and-supply-chain.md +22 -0
  158. package/skills/torusguard/payload/skills/torusguard/references/django-security.md +43 -0
  159. package/skills/torusguard/payload/skills/torusguard/references/drf-security.md +20 -0
  160. package/skills/torusguard/payload/skills/torusguard/references/fastapi-security.md +20 -0
  161. package/skills/torusguard/payload/skills/torusguard/references/flask-security.md +20 -0
  162. package/skills/torusguard/payload/skills/torusguard/references/frontend-no-db.md +53 -0
  163. package/skills/torusguard/payload/skills/torusguard/references/graphql-security.md +12 -0
  164. package/skills/torusguard/payload/skills/torusguard/references/input-and-injection.md +51 -0
  165. package/skills/torusguard/payload/skills/torusguard/references/mass-assignment-and-property-auth.md +22 -0
  166. package/skills/torusguard/payload/skills/torusguard/references/platform-hardening.md +56 -0
  167. package/skills/torusguard/payload/skills/torusguard/references/python-dependencies.md +16 -0
  168. package/skills/torusguard/payload/skills/torusguard/references/python-security-overview.md +12 -0
  169. package/skills/torusguard/payload/skills/torusguard/references/rate-limit-and-abuse.md +57 -0
  170. package/skills/torusguard/payload/skills/torusguard/references/secrets-and-config.md +64 -0
  171. package/skills/torusguard/payload/skills/torusguard/references/sqlalchemy-security.md +16 -0
  172. package/skills/torusguard/payload/skills/torusguard/references/ssrf-and-outbound-requests.md +46 -0
  173. package/skills/torusguard/payload/skills/torusguard/references/webhook-security.md +15 -0
  174. package/skills/torusguard/payload/skills/torusguard/references/websocket-security.md +12 -0
  175. package/skills/torusguard/payload/skills/torusguard-apply/SKILL.md +46 -0
  176. package/skills/torusguard/payload/skills/torusguard-audit/SKILL.md +70 -0
  177. package/skills/torusguard/payload/skills/torusguard-authorize/SKILL.md +47 -0
  178. package/skills/torusguard/payload/skills/torusguard-exploit-check/SKILL.md +64 -0
  179. package/skills/torusguard/payload/skills/torusguard-full/SKILL.md +70 -0
  180. package/skills/torusguard/payload/skills/torusguard-harden/SKILL.md +63 -0
  181. package/skills/torusguard/payload/skills/torusguard-init/SKILL.md +52 -0
  182. package/skills/torusguard/payload/skills/torusguard-recheck/SKILL.md +53 -0
  183. package/skills/torusguard/payload/skills/torusguard-report/SKILL.md +54 -0
  184. package/skills/torusguard/payload/skills/torusguard-status/SKILL.md +42 -0
  185. package/skills/torusguard/payload/skills/torusguard-verify/SKILL.md +55 -0
  186. package/skills/torusguard/payload/skills/torusguard-web-validate/SKILL.md +64 -0
  187. package/skills/torusguard/payload/templates/audit-report.template.md +54 -0
  188. package/skills/torusguard/payload/templates/authorization.template.md +34 -0
  189. package/skills/torusguard/payload/templates/finding-card.template.md +32 -0
  190. package/skills/torusguard/payload/templates/remediation-bundle.template.md +35 -0
  191. package/skills/torusguard/payload/workflows/apply.md +95 -0
  192. package/skills/torusguard/payload/workflows/audit.md +93 -0
  193. package/skills/torusguard/payload/workflows/authorize.md +95 -0
  194. package/skills/torusguard/payload/workflows/exploit-check.md +97 -0
  195. package/skills/torusguard/payload/workflows/harden.md +93 -0
  196. package/skills/torusguard/payload/workflows/init.md +95 -0
  197. package/skills/torusguard/payload/workflows/recheck.md +95 -0
  198. package/skills/torusguard/payload/workflows/report.md +95 -0
  199. package/skills/torusguard/payload/workflows/status.md +95 -0
  200. package/skills/torusguard/payload/workflows/verify.md +95 -0
  201. package/skills/torusguard/payload/workflows/web-validate.md +95 -0
  202. package/skills/torusguard/references/auth-and-sessions.md +56 -0
  203. package/skills/torusguard/references/business-logic-and-abuse.md +23 -0
  204. package/skills/torusguard/references/cache-and-sensitive-responses.md +10 -0
  205. package/skills/torusguard/references/client-code-exposure.md +55 -0
  206. package/skills/torusguard/references/csrf-and-cross-origin.md +11 -0
  207. package/skills/torusguard/references/dependency-and-supply-chain.md +22 -0
  208. package/skills/torusguard/references/django-security.md +43 -0
  209. package/skills/torusguard/references/drf-security.md +20 -0
  210. package/skills/torusguard/references/fastapi-security.md +20 -0
  211. package/skills/torusguard/references/flask-security.md +20 -0
  212. package/skills/torusguard/references/frontend-no-db.md +53 -0
  213. package/skills/torusguard/references/graphql-security.md +12 -0
  214. package/skills/torusguard/references/input-and-injection.md +51 -0
  215. package/skills/torusguard/references/mass-assignment-and-property-auth.md +22 -0
  216. package/skills/torusguard/references/platform-hardening.md +56 -0
  217. package/skills/torusguard/references/python-dependencies.md +16 -0
  218. package/skills/torusguard/references/python-security-overview.md +12 -0
  219. package/skills/torusguard/references/rate-limit-and-abuse.md +57 -0
  220. package/skills/torusguard/references/secrets-and-config.md +64 -0
  221. package/skills/torusguard/references/sqlalchemy-security.md +16 -0
  222. package/skills/torusguard/references/ssrf-and-outbound-requests.md +46 -0
  223. package/skills/torusguard/references/webhook-security.md +15 -0
  224. package/skills/torusguard/references/websocket-security.md +12 -0
  225. package/skills/torusguard-apply/SKILL.md +46 -0
  226. package/skills/torusguard-audit/SKILL.md +70 -0
  227. package/skills/torusguard-authorize/SKILL.md +47 -0
  228. package/skills/torusguard-exploit-check/SKILL.md +64 -0
  229. package/skills/torusguard-full/SKILL.md +70 -0
  230. package/skills/torusguard-harden/SKILL.md +63 -0
  231. package/skills/torusguard-init/SKILL.md +52 -0
  232. package/skills/torusguard-recheck/SKILL.md +53 -0
  233. package/skills/torusguard-report/SKILL.md +54 -0
  234. package/skills/torusguard-status/SKILL.md +42 -0
  235. package/skills/torusguard-verify/SKILL.md +55 -0
  236. package/skills/torusguard-web-validate/SKILL.md +64 -0
@@ -0,0 +1,12 @@
1
+ # TorusGuard Skill Reference: Python Security Overview
2
+
3
+ > **Loaded When:** Any Python project is detected (`requirements.txt`, `pyproject.toml`, `Pipfile`, `.py` source files).
4
+
5
+ ---
6
+
7
+ ## ๐Ÿ Python Platform Security Principles
8
+
9
+ 1. **Explicit Boundaries Over Dynamic Magic:** Avoid unpacking arbitrary user dictionaries directly into database ORM models or data structures (`**req.dict()`, `**request.json`).
10
+ 2. **Server-Side Authorization First:** Route decorators (`@login_required`) verify identity, but database queries must verify resource ownership (`user_id == current_user.id`).
11
+ 3. **Outbound Request Bounding (SSRF):** Always validate scheme, resolve DNS, and block private CIDR blocks before calling `requests.get()` or `httpx.get()`.
12
+ 4. **Deterministic Environments:** Always maintain virtual environment isolation and commit cryptographically verifiable lockfiles (`poetry.lock`, `uv.lock`, `requirements.lock`).
@@ -0,0 +1,57 @@
1
+ # Rate Limiting and Abuse Prevention
2
+
3
+ ## When to load
4
+
5
+ Load during `/TorusGuard check rate-limit`, auth endpoint reviews, or public API design.
6
+
7
+ ## Linked rules
8
+
9
+ - [TG-RATE-001](../../rules/TG-RATE-001-unlimited-auth-endpoint.md) โ€” Unlimited Auth Endpoint (High)
10
+ - [TG-RATE-002](../../rules/TG-RATE-002-unlimited-public-write-endpoint.md) โ€” Unlimited Public Write (Medium)
11
+ - [TG-RATE-003](../../rules/TG-RATE-003-unbounded-resource-consumption.md) โ€” Unbounded Resource Use (High)
12
+
13
+ ## Hard bans
14
+
15
+ - Never rely only on frontend throttling
16
+ - Never leave login, reset, OTP, or contact endpoints unlimited in production
17
+ - Never use in-memory-only rate limits as sole protection in distributed production
18
+
19
+ ## Configurable default limits
20
+
21
+ | Endpoint | Suggested starting point |
22
+ |----------|-------------------------|
23
+ | Login | 5 / IP / 15 min + account backoff |
24
+ | Password reset | 3 / email / hour |
25
+ | OTP | 3 / identifier / 15 min |
26
+ | Contact/feedback | 5 / IP / hour |
27
+ | Public API | 60 / IP / minute |
28
+ | Search | 30 / IP / minute |
29
+ | Upload | 10 / IP / hour + size limits |
30
+ | AI/LLM | Per-user and per-IP cost limits |
31
+
32
+ Adjust for your traffic profile โ€” these are defaults, not universal values.
33
+
34
+ ## Safe defaults
35
+
36
+ - Per-IP limits on public endpoints
37
+ - Per-account limits on auth flows
38
+ - HTTP 429 with `Retry-After` when practical
39
+ - Body, upload, and pagination caps (TG-RATE-003)
40
+ - Timeouts and concurrency limits on expensive endpoints
41
+ - Shared store (Redis) for multi-instance deployments
42
+
43
+ ## Audit checklist
44
+
45
+ - [ ] Auth endpoints rate-limited (TG-RATE-001)
46
+ - [ ] Public write/AI endpoints protected (TG-RATE-002)
47
+ - [ ] Body/upload/pagination limits set (TG-RATE-003)
48
+
49
+ ## Manual review
50
+
51
+ - Webhook endpoints (signature + IP limits)
52
+ - GraphQL complexity/depth limits
53
+ - Spend alerts for metered third-party APIs
54
+
55
+ ## Related rules
56
+
57
+ TG-AUTH-005, TG-PLATFORM-004, TG-INPUT-004
@@ -0,0 +1,64 @@
1
+ # Secrets and Environment Configuration
2
+
3
+ ## When to load
4
+
5
+ Load during `/TorusGuard check secrets`, secret-related audits, or before adding environment variables, CI config, or deployment secrets.
6
+
7
+ ## Linked rules
8
+
9
+ - [TG-SEC-001](../../rules/TG-SEC-001-hardcoded-secrets.md) โ€” Hardcoded Secret (Critical)
10
+ - [TG-SEC-002](../../rules/TG-SEC-002-public-environment-secrets.md) โ€” Public Environment Secret (Critical)
11
+ - [TG-SEC-003](../../rules/TG-SEC-003-tracked-env-file.md) โ€” Tracked Environment File (High)
12
+ - [TG-SEC-004](../../rules/TG-SEC-004-sensitive-logging.md) โ€” Sensitive Data Logging (Medium)
13
+
14
+ ## Hard bans
15
+
16
+ - Never hardcode database URLs, JWT secrets, passwords, or API keys in source
17
+ - Never expose service-role or admin credentials to the browser
18
+ - Never put secrets in `VITE_*`, `NEXT_PUBLIC_*`, or `REACT_APP_*` variables
19
+ - Never log passwords, tokens, session IDs, API keys, or full authorization headers
20
+ - Never commit `.env`, credentials JSON, or private key files
21
+
22
+ ## Frontend env prefixes are public
23
+
24
+ | Prefix | Reaches browser? |
25
+ |--------|------------------|
26
+ | `VITE_` | Yes |
27
+ | `NEXT_PUBLIC_` | Yes |
28
+ | `REACT_APP_` | Yes |
29
+ | (no prefix) | Server only |
30
+
31
+ Only intentionally public configuration may use client prefixes.
32
+
33
+ ## Safe defaults
34
+
35
+ 1. Server-only env for all secrets
36
+ 2. `.env` in `.gitignore`
37
+ 3. `.env.example` with placeholder values only
38
+ 4. Rotate/revoke any discovered leaked secret immediately
39
+ 5. Separate dev/test/production secret stores where applicable
40
+
41
+ ## Audit checklist
42
+
43
+ - [ ] No real secrets in tracked source (TG-SEC-001)
44
+ - [ ] No sensitive values in public env vars (TG-SEC-002)
45
+ - [ ] `.env` not tracked by Git (TG-SEC-003)
46
+ - [ ] Logs redact auth material (TG-SEC-004)
47
+ - [ ] `.env.example` exists with safe placeholders
48
+
49
+ ## Framework notes
50
+
51
+ - **Vite/CRA/Next public vars** โ€” treat as published in the client bundle
52
+ - **Supabase** โ€” anon key in browser OK; service-role server-only
53
+ - **Firebase** โ€” client config public; Admin SDK credentials server-only
54
+ - **CI/CD** โ€” use platform secret stores, not plaintext in workflow files
55
+
56
+ ## Manual review
57
+
58
+ - Verify secret rotation after any exposure
59
+ - Review CI logs for accidental secret echo
60
+ - Confirm production secrets differ from development
61
+
62
+ ## Related rules
63
+
64
+ TG-DB-002, TG-DB-003, TG-CLIENT-002
@@ -0,0 +1,16 @@
1
+ # TorusGuard Skill Reference: SQLAlchemy Security
2
+
3
+ > **Loaded When:** Project uses `sqlalchemy` dependencies or imports.
4
+
5
+ ---
6
+
7
+ ## ๐Ÿ›ก๏ธ Key Inspection Areas & Rules
8
+
9
+ ### 1. SQL Injection in Raw Query Clauses
10
+ * `TG-INPUT-003`: Search for `text(f"...")`, `text("..." + ...)`, or `.format()` inside `text()` constructs. Ensure parameter mapping `text("... WHERE col = :val")` is used.
11
+
12
+ ### 2. Tenant Scoping & Object Ownership
13
+ * `TG-AUTH-007`: Verify queries on tenant-isolated tables include tenant/user ID predicates in `.filter()` or `.filter_by()`.
14
+
15
+ ### 3. Mass Assignment via Bulk Updates
16
+ * `TG-AUTH-006`: Inspect `.update(dict)` calls to ensure input dictionaries are filtered against permitted field allowlists.
@@ -0,0 +1,46 @@
1
+ # SSRF and Outbound Requests
2
+
3
+ ## When the reference applies
4
+ Applies to any endpoint that fetches a URL.
5
+
6
+ ## User-controlled URL detection
7
+ Always check if the URL is user-controlled.
8
+
9
+ ## URL scheme validation
10
+ Only allow expected schemes.
11
+
12
+ ## Hostname and IP validation
13
+ Validate hostnames carefully.
14
+
15
+ ## Private-network blocking
16
+ Block internal IP addresses.
17
+
18
+ ## Cloud metadata protection
19
+ Block 169.254.169.254 and similar.
20
+
21
+ ## Redirect handling
22
+ Disable redirects or validate them.
23
+
24
+ ## DNS rebinding considerations
25
+ Check DNS at resolution time.
26
+
27
+ ## Timeout and response-size limits
28
+ Enforce timeouts and max response sizes.
29
+
30
+ ## Network isolation
31
+ Run fetches from isolated networks if possible.
32
+
33
+ ## Safe logging
34
+ Avoid logging raw URLs with credentials.
35
+
36
+ ## Manual-review checklist
37
+ - [ ] Is the outbound URL user-controlled?
38
+ - [ ] Is HTTPS required?
39
+ - [ ] Is the hostname allowlisted?
40
+ - [ ] Are loopback and private IPs blocked?
41
+ - [ ] Are cloud metadata endpoints blocked?
42
+ - [ ] Are redirects disabled or revalidated?
43
+ - [ ] Is DNS resolution checked safely?
44
+ - [ ] Is there a timeout?
45
+ - [ ] Is response size limited?
46
+ - [ ] Is the server isolated from sensitive networks?
@@ -0,0 +1,15 @@
1
+ # Webhook Security
2
+
3
+ - Signature verification over the raw request body.
4
+ - Timestamp tolerance.
5
+ - Replay protection.
6
+ - Event-type allowlisting.
7
+ - Payload schema validation.
8
+ - Idempotency keys or event IDs.
9
+ - Safe retry behavior.
10
+ - Rate and size limits.
11
+ - Generic response errors.
12
+ - No trust in event fields before signature verification.
13
+
14
+ ## Workflow
15
+ Receive raw body โ†’ Verify signature โ†’ Verify timestamp โ†’ Check event ID/idempotency โ†’ Validate event schema โ†’ Authorize event source/tenant โ†’ Process within transaction โ†’ Return safe response
@@ -0,0 +1,12 @@
1
+ # WebSocket Security
2
+
3
+ - Authentication during handshake.
4
+ - Re-authentication or token expiry.
5
+ - Origin validation.
6
+ - Per-room and per-channel authorization.
7
+ - Message schema validation.
8
+ - Message-size limits.
9
+ - Connection and subscription limits.
10
+ - Tenant isolation.
11
+ - Disconnect behavior.
12
+ - Logging and abuse detection.
@@ -0,0 +1,46 @@
1
+ ---
2
+ name: torusguard-apply
3
+ description: Apply governed remediation patches to disk with pre-apply rollback snapshots and Human Gate validation.
4
+ version: 0.9.2
5
+ workflow: .torusguard/workflows/apply.md
6
+ tools: Read, Grep, Glob, Bash, Edit, Write
7
+ scripts-binding:
8
+ - .torusguard/scripts/run_manager.py
9
+ - .torusguard/scripts/diff_guard.py
10
+ ---
11
+
12
+ # TorusGuard Apply โ€” Governed Patch Application & Rollback Snapshot
13
+
14
+ ## Objective
15
+ Safely apply approved remediation bundles to disk source files, capturing a byte-for-byte pre-apply backup snapshot and asserting syntax validity post-patch.
16
+
17
+ ---
18
+
19
+ ## Execution Steps
20
+
21
+ 1. **Load Bundle:** Read `patch.diff` and metadata from `.torusguard/runs/<run_id>/remediation/<finding_id>/`.
22
+ 2. **Pre-Apply Snapshot:** Save exact backup to `.torusguard/runs/<run_id>/pre_apply/<filename>.bak`.
23
+ 3. **Obtain Human Gate:** Confirm user approval for proposed diff.
24
+ 4. **Apply Patch:** Execute surgical modification using `replace_file_content` or `patch`.
25
+ 5. **Assert Integrity:** Verify modified file compiles cleanly without syntax errors.
26
+ 6. **Record Ledger:** Log timestamp, file path, and post-patch SHA-256 in `apply-log.json`.
27
+
28
+ ---
29
+
30
+ ## Governance & Safety Rules
31
+ - Hard limit: additions $\le 35$, deletions $\le 25$ lines.
32
+ - Always create a rollback snapshot before modifying disk code.
33
+ - If compile or syntax error occurs, instantly restore from `.bak`.
34
+ - Require explicit operator confirmation before writing changes.
35
+
36
+ ---
37
+
38
+ ## Output Format
39
+ ```markdown
40
+ ๐Ÿš€ [TorusGuard] Patch Applied Successfully
41
+ - Finding Target: <Finding ID> | File: <Path>
42
+ - Churn: +<Additions> / -<Deletions>
43
+ - Rollback Backup: `.torusguard/runs/<run_id>/pre_apply/<file>.bak`
44
+ - Compile Check: PASSED
45
+ Next: Run `/torusguard recheck` to verify vulnerability is closed.
46
+ ```
@@ -0,0 +1,70 @@
1
+ ---
2
+ name: torusguard-audit
3
+ description: Static security AST scanning, stable fingerprinting, root-cause clustering, and 0โ€“100 confidence scoring.
4
+ version: 0.9.2
5
+ workflow: .torusguard/workflows/audit.md
6
+ tools: Read, Grep, Glob, Write
7
+ scripts-binding:
8
+ - .torusguard/scripts/finding_scorer.py
9
+ - .torusguard/scripts/run_manager.py
10
+ ---
11
+
12
+ # TorusGuard Audit โ€” Static Code Analysis & Finding Clustering
13
+
14
+ ## Objective
15
+ Execute static analysis across ASTs, generate line-shift invariant fingerprints, group findings into root causes, compute 0โ€“100 confidence scores, and persist findings to `.torusguard/runs/`.
16
+
17
+ ---
18
+
19
+ ## Execution Steps
20
+
21
+ 1. **Setup Run Directory:** Initialize `.torusguard/runs/run-YYYYMMDD-HHMMSS-audit/` via `run_manager.py`.
22
+ 2. **Load Active Rules:** Load rules from `.torusguard/rules/active/` and thresholds from `torusguard.json`.
23
+ 3. **AST Scan Sinks:** Match files against active rules:
24
+ - `TG-SEC-*`: Leaked API keys, secrets.
25
+ - `TG-INPUT-*`: Unescaped SQL or unvalidated payloads.
26
+ - `TG-DB-*`: Unscoped queries omitting tenant filters (`Model.get(id=id)`).
27
+ - `TG-AUTH-*`: Missing `HttpOnly`/`Secure` flags; open CORS.
28
+ - `TG-CLIENT-*`: Admin credentials in client bundles.
29
+ 4. **Stable Fingerprinting:** Compute SHA-256 hash of normalized 3 surrounding AST lines.
30
+ 5. **Root-Cause Clustering:** Group findings by root cause (`cluster-tenant-isolation`, `cluster-raw-sql-sink`).
31
+ 6. **Confidence Scoring:** Calculate 0โ€“100 score across 5-factor rubric via `finding_scorer.py`.
32
+ 7. **Write Run Artifacts:** Persist `findings.md`, `findings.json`, and `summary.md`.
33
+
34
+ ---
35
+
36
+ ## Confidence Scoring Rubric
37
+ - **1. Evidence (35):** AST flow (35), regex match (20), indirect (10).
38
+ - **2. Reproduction (25):** Deterministic test (25), simulated (15), hypothesis (0).
39
+ - **3. Corroboration (15):** >=3 files (15), 2 files (10), single (5).
40
+ - **4. Environment (15):** Explicit route (15), minor ambiguity (8), unknown (0).
41
+ - **5. Review Status (10):** Human verified (10), agent consensus (5), auto (0).
42
+ - **Bands:** 90โ€“100 (`Confirmed`), 70โ€“89 (`High`), 50โ€“69 (`Medium`), <50 (`Review`).
43
+
44
+ ---
45
+
46
+ ## Finding Card Format
47
+ ```markdown
48
+ ### [TG-DB-004] Missing Tenant Scoping in /invoices/
49
+ - **Severity**: High | **Confidence**: 90/100 (Confirmed)
50
+ - **File**: `views.py:42` | **Cluster**: `cluster-tenant-isolation`
51
+ - **Evidence**: Unscoped query leaks records.
52
+ - **Remediation**: Scope by `tenant=request.user.tenant`.
53
+ ```
54
+
55
+ ---
56
+
57
+ ## Safety Constraints
58
+ - Read-only execution; zero code modifications.
59
+ - Exclude build folders (`node_modules/`, `.venv/`, `dist/`).
60
+ - Redact secrets before saving to `findings.md`.
61
+
62
+ ---
63
+
64
+ ## Output Format
65
+ ```markdown
66
+ ๐Ÿ›ก๏ธ [TorusGuard] Static Code Audit Completed
67
+ - Run ID: run-YYYYMMDD-HHMMSS-audit | Files: <Count> | Findings: <Count>
68
+ - Clusters: <Count> identified | Posture: ACTION REQUIRED
69
+ Next: Run `/torusguard harden` to formulate surgical fixes.
70
+ ```
@@ -0,0 +1,47 @@
1
+ ---
2
+ name: torusguard-authorize
3
+ description: Register and validate runtime target authorization boundaries โ€” scope boundaries, ownership proofs, TTL expiration, and Safety Gate enforcement.
4
+ version: 0.9.2
5
+ workflow: .torusguard/workflows/authorize.md
6
+ tools: Read, Grep, Glob, Write
7
+ scripts-binding:
8
+ - .torusguard/scripts/safety_gate.py
9
+ ---
10
+
11
+ # TorusGuard Authorize โ€” Legal Scope & Safety Gate Registration
12
+
13
+ ## Objective
14
+ Define and validate legal runtime authorization boundaries, verify target ownership, enforce maximum rate limits, and persist a cryptographically auditable `.torusguard/config/scope.json`.
15
+
16
+ ---
17
+
18
+ ## Execution Steps
19
+
20
+ 1. **Capture Scope Parameters:** Collect target host URL, allowed path prefixes, forbidden prefixes, and session TTL.
21
+ 2. **Validate Environment:** Assert target is local (`localhost`, `127.0.0.1`) or staging (`*.staging.*`). Block production targets without explicit override.
22
+ 3. **Verify Host Ownership:** Confirm ownership token or local process socket binding.
23
+ 4. **Invoke Safety Gate:**
24
+ ```bash
25
+ python .torusguard/scripts/safety_gate.py check --url <target_url>
26
+ ```
27
+ 5. **Write Scope Record:** Persist authorized targets, rate limits, and expiration timestamp into `.torusguard/config/scope.json`.
28
+ 6. **Validate Schema:** Confirm `scope.json` adheres to `auth-boundary.schema.json`.
29
+
30
+ ---
31
+
32
+ ## Safety Constraints
33
+ - Never authorize wildcard hosts (`*`) or third-party domains.
34
+ - State-changing destructive actions (`DELETE`, bulk drops) are disabled by default.
35
+ - Set strict TTL (default 4 hours, maximum 24 hours).
36
+
37
+ ---
38
+
39
+ ## Output Format
40
+ ```markdown
41
+ ๐Ÿ”’ [TorusGuard] Target Scope Authorized
42
+ - Target Host: <Host URL> | Environment: <Local / Staging>
43
+ - Allowed Paths: <Prefixes> | Rate Limit: <Max Req/sec>
44
+ - Expiration TTL: <Timestamp>
45
+ - Scope File: `.torusguard/config/scope.json`
46
+ Next: Run `/torusguard web-validate` to begin safe runtime probing.
47
+ ```
@@ -0,0 +1,64 @@
1
+ ---
2
+ name: torusguard-exploit-check
3
+ description: Safe, non-destructive confirmation of exploitability using inert canary tokens and sentinels.
4
+ version: 0.9.2
5
+ workflow: .torusguard/workflows/exploit-check.md
6
+ tools: Read, Grep, Glob, Bash, Write
7
+ scripts-binding:
8
+ - .torusguard/scripts/safety_gate.py
9
+ - .torusguard/scripts/finding_scorer.py
10
+ ---
11
+
12
+ # TorusGuard Exploit Check โ€” Bounded Exploitability Confirmation
13
+
14
+ ## Objective
15
+ Confirm whether candidate findings are practically exploitable using safe, single-step sentinel canaries without data loss or weaponized execution.
16
+
17
+ ---
18
+
19
+ ## Authorization Gate Check
20
+ Before dispatching any exploitability probe:
21
+ 1. Verify target route is explicitly authorized in `.torusguard/config/scope.json`.
22
+ 2. Verify authorization TTL has not expired.
23
+ 3. Assert probe passes `.torusguard/scripts/safety_gate.py`.
24
+
25
+ ---
26
+
27
+ ## Bounded Probe Strategies
28
+ - **SQLi:** Mathematical identity canary (`' OR 1=1--`) asserting differential response without altering data.
29
+ - **XSS:** Inert HTML marker tag (`<tg-canary-tag>`) checking unescaped reflection in DOM.
30
+ - **IDOR:** Cross-tenant GET using secondary tenant session; assert 403 vs leak.
31
+ - **Auth:** Omit auth header on protected route; assert 401.
32
+
33
+ ---
34
+
35
+ ## Execution Steps
36
+
37
+ 1. **Verify Scope:** Read `scope.json`; assert authorized endpoint.
38
+ 2. **Select Canary:** Choose matching non-destructive probe strategy.
39
+ 3. **Dispatch Probe:** Send request with header `X-TorusGuard-AuthID`.
40
+ 4. **Classify Status:** Transition finding into one of 5 canonical outcomes:
41
+ - `Confirmed`: Canary reflected or secondary tenant data leaked.
42
+ - `Not Reproducible`: Endpoint responded with 401/403 or sanitized input.
43
+ - `Needs Review`: Ambiguous status code or incomplete response.
44
+ - `Blocked by Controls`: WAF or rate limiter stopped probe.
45
+ - `Out of Scope`: Target endpoint is not authorized.
46
+ 5. **Record Evidence:** Save trace in `.torusguard/runs/<run_id>/exploit-evidence.md`.
47
+
48
+ ---
49
+
50
+ ## Safety Constraints
51
+ - Zero destructive payloads (`DROP`, `DELETE`, `UPDATE`).
52
+ - No denial-of-service or continuous fuzzing loops.
53
+ - Redact tokens before recording traces.
54
+
55
+ ---
56
+
57
+ ## Output Format
58
+ ```markdown
59
+ ๐ŸŽฏ [TorusGuard] Exploitability Confirmation
60
+ - Finding ID: <Finding ID> | Target: <Route>
61
+ - Status: <Confirmed / Not Reproducible / Blocked>
62
+ - Evidence: <Response snippet or status code>
63
+ Next: Run `/torusguard harden` to formulate surgical remediation bundle.
64
+ ```
@@ -0,0 +1,70 @@
1
+ ---
2
+ name: torusguard-full
3
+ description: Master 7-stage security pipeline orchestrator โ€” coordinates discovery, authorization, static audit, runtime validation, governed remediation, recheck, and reporting.
4
+ version: 0.9.2
5
+ workflow: .torusguard/workflows/audit.md
6
+ tools: Read, Grep, Glob, Bash, Edit, Write
7
+ scripts-binding:
8
+ - .torusguard/scripts/stack_detect.py
9
+ - .torusguard/scripts/safety_gate.py
10
+ - .torusguard/scripts/finding_scorer.py
11
+ - .torusguard/scripts/run_manager.py
12
+ - .torusguard/scripts/sarif_exporter.py
13
+ ---
14
+
15
+ # TorusGuard Full โ€” Master 7-Stage Pipeline Orchestrator
16
+
17
+ ## Objective
18
+ Execute the full, closed-loop TorusGuard security lifecycle from stack discovery through static scanning, runtime validation, Ponytail remediation, differential re-check, and SARIF export under strict governance.
19
+
20
+ ---
21
+
22
+ ## 7-Stage Security Pipeline
23
+ 0. Init (Baseline) โ”€โ”€โ–บ 1. Authorize (Scope) โ”€โ”€โ–บ 2. Audit (AST Scan) โ”€โ”€โ–บ 3. Validate (Evidence/Exploit) โ”€โ”€โ–บ 4. Harden (Ponytail Patch) โ”€โ”€โ–บ 5. Apply (Backup & Edit) โ”€โ”€โ–บ 6. Recheck (Regression) โ”€โ”€โ–บ 7. Report (SARIF)
24
+
25
+ ---
26
+
27
+ ## Specialist Skill Routing
28
+ - **Phase 0:** `torusguard-init` (`profiler`)
29
+ - **Phase 1:** `torusguard-authorize` (`reviewer`)
30
+ - **Phase 2:** `torusguard-audit` (`auditor`)
31
+ - **Phase 3:** `torusguard-verify` / `torusguard-exploit-check` (`validator`)
32
+ - **Phase 4:** `torusguard-harden` (`remediator`)
33
+ - **Phase 5:** `torusguard-apply` (`remediator`)
34
+ - **Phase 6:** `torusguard-recheck` (`reviewer`)
35
+ - **Phase 7:** `torusguard-report` (`reviewer`)
36
+
37
+ ---
38
+
39
+ ## Pipeline Execution Instructions
40
+ 1. **Init:** Detect stack via `stack_detect.py` and activate rules in `.torusguard/rules/active/`.
41
+ 2. **Authorize:** Verify target ownership and TTL in `.torusguard/config/scope.json`.
42
+ 3. **Audit:** Scan ASTs; assign fingerprints; cluster root causes; compute confidence scores.
43
+ 4. **Validate:** Audit evidence sufficiency; optionally send bounded probe canary.
44
+ 5. **Harden:** Formulate surgical diffs bound by Ponytail limits ($\le 35$ add, $\le 25$ del).
45
+ 6. **Apply:** Save `.bak` snapshot in `pre_apply/`; obtain Human Gate; apply patch.
46
+ 7. **Recheck:** Re-scan modified files; assert findings are `Fixed` with zero regressions.
47
+ 8. **Report:** Export OASIS SARIF v2.1.0 and emit signed markdown summary.
48
+
49
+ ---
50
+
51
+ ## Confidence Scoring Rubric
52
+ Evaluates Evidence (35 pts), Reproduction (25 pts), Corroboration (15 pts), Environment (15 pts), and Review Status (10 pts) into 4 bands: Confirmed (90โ€“100), High (70โ€“89), Medium (50โ€“69), Needs Review (<50).
53
+
54
+ ---
55
+
56
+ ## Safety & Governance
57
+ - Human Gate mandatory before code modifications in Phase 5.
58
+ - Enforce Ponytail line bounds ($\le 35$ additions, $\le 25$ deletions).
59
+ - Never dispatch network probes outside authorized scope in `scope.json`.
60
+
61
+ ---
62
+
63
+ ## Output Format
64
+ ```markdown
65
+ ๐Ÿ† [TorusGuard] 7-Stage Security Pipeline Complete
66
+ - Run ID: run-YYYYMMDD-HHMMSS | Status: SECURE / AUDITED
67
+ - Findings: <Total> (<Fixed> Fixed ยท <Open> Remaining)
68
+ - SARIF Log: `.torusguard/runs/<run_id>/results.sarif`
69
+ - Report: `.torusguard/runs/<run_id>/report.md`
70
+ ```
@@ -0,0 +1,63 @@
1
+ ---
2
+ name: torusguard-harden
3
+ description: Package surgical remediation bundles conforming to the Ponytail Protocol (<= 35 additions, <= 25 deletions).
4
+ version: 0.9.2
5
+ workflow: .torusguard/workflows/harden.md
6
+ tools: Read, Grep, Glob, Write
7
+ scripts-binding:
8
+ - .torusguard/scripts/run_manager.py
9
+ - .torusguard/scripts/diff_guard.py
10
+ ---
11
+
12
+ # TorusGuard Harden โ€” Governed Remediation & Bundle Packaging
13
+
14
+ ## Objective
15
+ Formulate minimal, surgical code fixes bound by the Ponytail Protocol ($\le 35$ additions, $\le 25$ deletions), packaging unified diffs into auditable 4-artifact remediation bundles ready for review.
16
+
17
+ ---
18
+
19
+ ## The Ponytail Protocol
20
+ - **Limits:** Additions $\le 35$, Deletions $\le 25$ lines per bundle.
21
+ - **Invariants:** Zero full-file rewrites; preserve public APIs and tests.
22
+ - **Overflow:** Partition into sequential sub-bundles.
23
+
24
+ ---
25
+
26
+ ## Bundle Directory Structure
27
+ ```
28
+ .torusguard/runs/<run_id>/remediation/<finding_id>/
29
+ โ”œโ”€โ”€ patch.diff # Standard unified diff with line numbers
30
+ โ”œโ”€โ”€ plan.md # Rationale and root-cause breakdown
31
+ โ”œโ”€โ”€ verification.md # Test instructions proving fix works
32
+ โ””โ”€โ”€ rollback.md # Command or steps to revert patch
33
+ ```
34
+
35
+ ---
36
+
37
+ ## Execution Steps
38
+
39
+ 1. **Select Finding:** Choose prioritized verified flaw from active run's `findings.md`.
40
+ 2. **Read AST Context:** View target file surrounding lines (ยฑ15) using `view_file`.
41
+ 3. **Formulate Minimal Fix:** Parameterize SQL, add tenant filters, insert validation schemas.
42
+ 4. **Validate Line Churn:** Assert additions $\le 35$ and deletions $\le 25$.
43
+ 5. **Package Bundle:** Write 4 artifacts (`patch.diff`, `plan.md`, `verification.md`, `rollback.md`).
44
+ 6. **Flag Sensitive Paths:** Mark changes touching auth or billing with `Requires Sensitive-Path Sign-Off`.
45
+
46
+ ---
47
+
48
+ ## Safety Constraints
49
+ - Dry-run only; do NOT apply modifications to source code during harden.
50
+ - Keep surrounding formatting and comments intact.
51
+ - Never touch files outside the targeted vulnerable sink.
52
+
53
+ ---
54
+
55
+ ## Output Format
56
+ ```markdown
57
+ ๐Ÿ› ๏ธ [TorusGuard] Remediation Bundle Packaged
58
+ - Finding Target: <Finding ID> | File: <Path>
59
+ - Line Churn: +<Additions> / -<Deletions> (Ponytail: PASS)
60
+ - Sensitive Path: <Yes/No>
61
+ - Bundle Path: `.torusguard/runs/<run_id>/remediation/<finding_id>/`
62
+ Next: Run `/torusguard apply` to review diff and apply with rollback backup.
63
+ ```
@@ -0,0 +1,52 @@
1
+ ---
2
+ name: torusguard-init
3
+ description: Initialize TorusGuard workspace โ€” detect project stack, activate tailored TG-* security rules, and generate SECURITY.md baseline.
4
+ version: 0.9.2
5
+ workflow: .torusguard/workflows/init.md
6
+ tools: Read, Grep, Glob, Write
7
+ scripts-binding:
8
+ - .torusguard/scripts/stack_detect.py
9
+ ---
10
+
11
+ # TorusGuard Init โ€” Project Stack Discovery & Rule Activation
12
+
13
+ ## Objective
14
+ Auto-detect repository technology stack via indicators or `stack_detect.py`, activate framework-tailored `TG-*` security rules into `.torusguard/rules/active/`, and provision `torusguard.json` and `SECURITY.md`.
15
+
16
+ ---
17
+
18
+ ## Pre-Flight Check
19
+ 1. Verify `.torusguard/` layout (`config/`, `rules/active/`, `runs/`, `scripts/`, `workflows/`, `templates/`, `schemas/`).
20
+ 2. If missing, unpack via `python skills/torusguard/bootstrap.py --target .`.
21
+ 3. Check existing `.torusguard/config/torusguard.json` before overwriting.
22
+
23
+ ---
24
+
25
+ ## Execution Steps
26
+
27
+ 1. **Stack Detection:** Run `python .torusguard/scripts/stack_detect.py .` to detect:
28
+ - Python: Django (`manage.py`), FastAPI (`fastapi`), Flask (`flask`), SQLAlchemy.
29
+ - Node: Next.js (`"next"`), Express (`"express"`), React/Vite (`"vite"`).
30
+ - BaaS: Supabase (`@supabase/supabase-js`), Firebase (`firebase-admin`).
31
+ 2. **Emit Stack Record:** Log detected language, framework, ORM, and client SDKs.
32
+ 3. **Activate Tailored Rules:** Copy matching `TG-*` rules from `.torusguard/rules/` into `.torusguard/rules/active/`.
33
+ 4. **Provision Policy:** Create `SECURITY.md` if absent, configuring responsible disclosure contacts.
34
+ 5. **Write Configuration:** Persist detected stack and active rules count to `.torusguard/config/torusguard.json`.
35
+
36
+ ---
37
+
38
+ ## Safety Constraints
39
+ - Never overwrite custom rules in `.torusguard/rules/active/` without prompt.
40
+ - Retain existing `SECURITY.md` if already established by repository owners.
41
+ - Strictly read-only detection against source files.
42
+
43
+ ---
44
+
45
+ ## Output Format
46
+ ```markdown
47
+ ๐Ÿ›ก๏ธ [TorusGuard] Workspace Initialized
48
+ - Primary Stack: <Detected Stack> | Components: <Backend/Frontend/DB>
49
+ - Active Rules: <Count> rules enabled in `.torusguard/rules/active/`
50
+ - Configuration: `.torusguard/config/torusguard.json` written
51
+ Next: Run `/torusguard audit` to execute static security scan.
52
+ ```