torusguard 1.4.0 → 2.1.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 (160) hide show
  1. package/.torusguard/.manifest.json +50 -28
  2. package/.torusguard/auth.json +5 -0
  3. package/.torusguard/rules/container/TG-CONT-001-root-user-execution.md +50 -0
  4. package/.torusguard/rules/container/TG-CONT-002-docker-socket-mount.md +47 -0
  5. package/.torusguard/rules/container/TG-CONT-003-privileged-container-mode.md +53 -0
  6. package/.torusguard/rules/container/TG-CONT-004-build-arg-secret-exposure.md +43 -0
  7. package/.torusguard/rules/git/TG-GIT-001-historical-secret-in-git-commit.md +44 -0
  8. package/.torusguard/rules/git/TG-GIT-002-plaintext-credentials-in-git-config.md +41 -0
  9. package/.torusguard/rules/git/TG-GIT-003-sensitive-tracked-file-gitignore-breach.md +40 -0
  10. package/.torusguard/rules/rag/TG-RAG-001-untrusted-rag-context-injection.md +72 -0
  11. package/.torusguard/rules/rag/TG-RAG-002-autonomous-llm-tool-unsandboxed-call.md +51 -0
  12. package/.torusguard/rules/rag/TG-RAG-003-unpartitioned-vector-tenant-lookup.md +51 -0
  13. package/.torusguard/rules/redos/TG-REDOS-001-catastrophic-exponential-backtracking.md +46 -0
  14. package/.torusguard/rules/redos/TG-REDOS-002-unbounded-nested-quantifier.md +43 -0
  15. package/.torusguard/rules_catalog.json +338 -518
  16. package/.torusguard/scripts/__pycache__/apply_runner.cpython-314.pyc +0 -0
  17. package/.torusguard/scripts/__pycache__/audit_runner.cpython-314.pyc +0 -0
  18. package/.torusguard/scripts/__pycache__/harden_runner.cpython-314.pyc +0 -0
  19. package/.torusguard/scripts/__pycache__/html_reporter.cpython-314.pyc +0 -0
  20. package/.torusguard/scripts/__pycache__/manifest_builder.cpython-314.pyc +0 -0
  21. package/.torusguard/scripts/__pycache__/recipes_runner.cpython-314.pyc +0 -0
  22. package/.torusguard/scripts/__pycache__/report_sync.cpython-314.pyc +0 -0
  23. package/.torusguard/scripts/manifest_builder.py +1 -1
  24. package/.torusguard/skills/torusguard/SKILL.md +69 -24
  25. package/.torusguard/skills/torusguard/bootstrap.py +57 -24
  26. package/.torusguard/skills/torusguard-ai-guard/SKILL.md +95 -0
  27. package/.torusguard/skills/torusguard-apply/SKILL.md +60 -34
  28. package/.torusguard/skills/torusguard-audit/SKILL.md +73 -24
  29. package/.torusguard/skills/torusguard-authorize/SKILL.md +48 -6
  30. package/.torusguard/skills/torusguard-container/SKILL.md +94 -0
  31. package/.torusguard/skills/torusguard-exploit-check/SKILL.md +50 -6
  32. package/.torusguard/skills/torusguard-full/SKILL.md +62 -19
  33. package/.torusguard/skills/torusguard-git-mine/SKILL.md +92 -0
  34. package/.torusguard/skills/torusguard-harden/SKILL.md +81 -50
  35. package/.torusguard/skills/torusguard-init/SKILL.md +61 -14
  36. package/.torusguard/skills/torusguard-ocr-scan/SKILL.md +94 -0
  37. package/.torusguard/skills/torusguard-recheck/SKILL.md +71 -18
  38. package/.torusguard/skills/torusguard-redos/SKILL.md +91 -0
  39. package/.torusguard/skills/torusguard-report/SKILL.md +50 -9
  40. package/.torusguard/skills/torusguard-status/SKILL.md +63 -10
  41. package/.torusguard/skills/torusguard-verify/SKILL.md +52 -10
  42. package/.torusguard/skills/torusguard-web-validate/SKILL.md +53 -8
  43. package/.torusguard/snapshots/20260921-182638/go.mod.bak +11 -0
  44. package/.torusguard/snapshots/20260921-185213/file.go.bak +5 -0
  45. package/.torusguard/workflows/ai-guard.md +31 -0
  46. package/.torusguard/workflows/apply.md +32 -55
  47. package/.torusguard/workflows/audit.md +28 -46
  48. package/.torusguard/workflows/authorize.md +27 -50
  49. package/.torusguard/workflows/container.md +29 -0
  50. package/.torusguard/workflows/exploit-check.md +28 -50
  51. package/.torusguard/workflows/git-mine.md +25 -0
  52. package/.torusguard/workflows/harden.md +29 -48
  53. package/.torusguard/workflows/init.md +27 -50
  54. package/.torusguard/workflows/memory.md +18 -23
  55. package/.torusguard/workflows/ocr-scan.md +25 -0
  56. package/.torusguard/workflows/recheck.md +28 -46
  57. package/.torusguard/workflows/redos.md +27 -0
  58. package/.torusguard/workflows/report.md +33 -52
  59. package/.torusguard/workflows/status.md +31 -52
  60. package/.torusguard/workflows/verify.md +29 -49
  61. package/.torusguard/workflows/web-validate.md +22 -45
  62. package/README.md +336 -386
  63. package/package.json +1 -1
  64. package/skills/torusguard/SKILL.md +71 -24
  65. package/skills/torusguard/__pycache__/bootstrap.cpython-314.pyc +0 -0
  66. package/skills/torusguard/bootstrap.py +60 -71
  67. package/skills/torusguard/payload/.manifest.json +50 -28
  68. package/skills/torusguard/payload/TORUSGUARD.md +145 -145
  69. package/skills/torusguard/payload/agents/auditor.md +41 -41
  70. package/skills/torusguard/payload/agents/profiler.md +49 -49
  71. package/skills/torusguard/payload/agents/remediator.md +41 -41
  72. package/skills/torusguard/payload/agents/reviewer.md +39 -39
  73. package/skills/torusguard/payload/agents/validator.md +46 -46
  74. package/skills/torusguard/payload/config/scope.json +24 -24
  75. package/skills/torusguard/payload/references/csharp-security.md +41 -41
  76. package/skills/torusguard/payload/references/go-security.md +41 -41
  77. package/skills/torusguard/payload/references/java-security.md +40 -40
  78. package/skills/torusguard/payload/references/polyglot-security-matrix.md +25 -25
  79. package/skills/torusguard/payload/references/rust-security.md +40 -40
  80. package/skills/torusguard/payload/rules/container/TG-CONT-001-root-user-execution.md +50 -0
  81. package/skills/torusguard/payload/rules/container/TG-CONT-002-docker-socket-mount.md +47 -0
  82. package/skills/torusguard/payload/rules/container/TG-CONT-003-privileged-container-mode.md +53 -0
  83. package/skills/torusguard/payload/rules/container/TG-CONT-004-build-arg-secret-exposure.md +43 -0
  84. package/skills/torusguard/payload/rules/custom/.gitkeep +1 -1
  85. package/skills/torusguard/payload/rules/custom/README.md +30 -30
  86. package/skills/torusguard/payload/rules/git/TG-GIT-001-historical-secret-in-git-commit.md +44 -0
  87. package/skills/torusguard/payload/rules/git/TG-GIT-002-plaintext-credentials-in-git-config.md +41 -0
  88. package/skills/torusguard/payload/rules/git/TG-GIT-003-sensitive-tracked-file-gitignore-breach.md +40 -0
  89. package/skills/torusguard/payload/rules/rag/TG-RAG-001-untrusted-rag-context-injection.md +72 -0
  90. package/skills/torusguard/payload/rules/rag/TG-RAG-002-autonomous-llm-tool-unsandboxed-call.md +51 -0
  91. package/skills/torusguard/payload/rules/rag/TG-RAG-003-unpartitioned-vector-tenant-lookup.md +51 -0
  92. package/skills/torusguard/payload/rules/redos/TG-REDOS-001-catastrophic-exponential-backtracking.md +46 -0
  93. package/skills/torusguard/payload/rules/redos/TG-REDOS-002-unbounded-nested-quantifier.md +43 -0
  94. package/skills/torusguard/payload/rules_catalog.json +338 -518
  95. package/skills/torusguard/payload/scripts/__pycache__/term_ui.cpython-314.pyc +0 -0
  96. package/skills/torusguard/payload/scripts/manifest_builder.py +1 -1
  97. package/skills/torusguard/payload/scripts/rules_sync.py +321 -321
  98. package/skills/torusguard/payload/scripts/safety_gate.py +64 -64
  99. package/skills/torusguard/payload/skills/torusguard/SKILL.md +69 -24
  100. package/skills/torusguard/payload/skills/torusguard/bootstrap.py +57 -24
  101. package/skills/torusguard/payload/skills/torusguard-ai-guard/SKILL.md +95 -0
  102. package/skills/torusguard/payload/skills/torusguard-apply/SKILL.md +60 -34
  103. package/skills/torusguard/payload/skills/torusguard-audit/SKILL.md +73 -24
  104. package/skills/torusguard/payload/skills/torusguard-authorize/SKILL.md +48 -6
  105. package/skills/torusguard/payload/skills/torusguard-container/SKILL.md +94 -0
  106. package/skills/torusguard/payload/skills/torusguard-exploit-check/SKILL.md +50 -6
  107. package/skills/torusguard/payload/skills/torusguard-full/SKILL.md +62 -19
  108. package/skills/torusguard/payload/skills/torusguard-git-mine/SKILL.md +92 -0
  109. package/skills/torusguard/payload/skills/torusguard-harden/SKILL.md +81 -50
  110. package/skills/torusguard/payload/skills/torusguard-init/SKILL.md +61 -14
  111. package/skills/torusguard/payload/skills/torusguard-ocr-scan/SKILL.md +94 -0
  112. package/skills/torusguard/payload/skills/torusguard-recheck/SKILL.md +71 -18
  113. package/skills/torusguard/payload/skills/torusguard-redos/SKILL.md +91 -0
  114. package/skills/torusguard/payload/skills/torusguard-report/SKILL.md +50 -9
  115. package/skills/torusguard/payload/skills/torusguard-status/SKILL.md +63 -10
  116. package/skills/torusguard/payload/skills/torusguard-verify/SKILL.md +52 -10
  117. package/skills/torusguard/payload/skills/torusguard-web-validate/SKILL.md +53 -8
  118. package/skills/torusguard/payload/templates/audit-report.template.md +54 -54
  119. package/skills/torusguard/payload/templates/authorization.template.md +34 -34
  120. package/skills/torusguard/payload/templates/finding-card.template.md +32 -32
  121. package/skills/torusguard/payload/templates/remediation-bundle.template.md +35 -35
  122. package/skills/torusguard/payload/workflows/ai-guard.md +31 -0
  123. package/skills/torusguard/payload/workflows/apply.md +31 -62
  124. package/skills/torusguard/payload/workflows/audit.md +27 -51
  125. package/skills/torusguard/payload/workflows/authorize.md +27 -50
  126. package/skills/torusguard/payload/workflows/container.md +29 -0
  127. package/skills/torusguard/payload/workflows/exploit-check.md +28 -50
  128. package/skills/torusguard/payload/workflows/git-mine.md +25 -0
  129. package/skills/torusguard/payload/workflows/harden.md +28 -52
  130. package/skills/torusguard/payload/workflows/init.md +27 -56
  131. package/skills/torusguard/payload/workflows/memory.md +18 -23
  132. package/skills/torusguard/payload/workflows/ocr-scan.md +25 -0
  133. package/skills/torusguard/payload/workflows/recheck.md +28 -46
  134. package/skills/torusguard/payload/workflows/redos.md +27 -0
  135. package/skills/torusguard/payload/workflows/report.md +39 -62
  136. package/skills/torusguard/payload/workflows/status.md +31 -55
  137. package/skills/torusguard/payload/workflows/verify.md +29 -49
  138. package/skills/torusguard/payload/workflows/web-validate.md +22 -45
  139. package/skills/torusguard/references/csharp-security.md +41 -0
  140. package/skills/torusguard/references/go-security.md +41 -0
  141. package/skills/torusguard/references/java-security.md +40 -0
  142. package/skills/torusguard/references/polyglot-security-matrix.md +25 -0
  143. package/skills/torusguard/references/rust-security.md +40 -0
  144. package/skills/torusguard-ai-guard/SKILL.md +95 -0
  145. package/skills/torusguard-apply/SKILL.md +60 -34
  146. package/skills/torusguard-audit/SKILL.md +73 -24
  147. package/skills/torusguard-authorize/SKILL.md +48 -6
  148. package/skills/torusguard-container/SKILL.md +94 -0
  149. package/skills/torusguard-exploit-check/SKILL.md +50 -6
  150. package/skills/torusguard-full/SKILL.md +62 -19
  151. package/skills/torusguard-git-mine/SKILL.md +92 -0
  152. package/skills/torusguard-harden/SKILL.md +81 -50
  153. package/skills/torusguard-init/SKILL.md +61 -14
  154. package/skills/torusguard-ocr-scan/SKILL.md +94 -0
  155. package/skills/torusguard-recheck/SKILL.md +71 -18
  156. package/skills/torusguard-redos/SKILL.md +91 -0
  157. package/skills/torusguard-report/SKILL.md +50 -9
  158. package/skills/torusguard-status/SKILL.md +63 -10
  159. package/skills/torusguard-verify/SKILL.md +52 -10
  160. package/skills/torusguard-web-validate/SKILL.md +53 -8
@@ -1,14 +1,14 @@
1
1
  ---
2
2
  name: torusguard-apply
3
3
  description: Apply governed remediation patches to disk with pre-apply rollback snapshots and Human Gate validation via CLI or AI Agent.
4
- version: 1.3.6
4
+ version: 2.0.0
5
5
  workflow: .torusguard/workflows/apply.md
6
6
  tools: Read, Grep, Glob, Write, replace_file_content, run_command
7
7
  scripts-binding:
8
- - .torusguard/scripts/report_sync.py
9
- - .torusguard/scripts/apply_runner.py
10
- - .torusguard/scripts/term_ui.py
11
- - .torusguard/scripts/memory_engine.py
8
+ - internal/apply/apply.go
9
+ - internal/apply/snapshot.go
10
+ - internal/apply/rollback.go
11
+ - cmd/torusguard/main.go
12
12
  ---
13
13
 
14
14
  # TorusGuard Apply — Governed Patch Application & Rollback Snapshot
@@ -18,41 +18,40 @@ Safely apply approved remediation bundles to disk source files, creating an auto
18
18
 
19
19
  ---
20
20
 
21
- ## Two Execution Modes
21
+ ## Tri-Mode Execution
22
22
 
23
23
  ### Mode A: Automated CLI Execution (Interactive or Non-Interactive)
24
24
  Run the governed patch applier from your terminal:
25
25
  ```bash
26
- # Interactive Human Gate review (prompts for each patch: [y]es / [n]o / [a]ll / [q]uit)
27
- npx torusguard apply
28
-
29
- # Non-interactive automated application
30
- npx torusguard apply --yes
31
-
32
- # Apply patches from a specific run ID
33
- npx torusguard apply --run run-20260910-121618-audit --yes
26
+ # Non-interactive automated application of unified diff or semantic patch
27
+ torusguard apply candidate.patch --yes
28
+ # or
29
+ torusguard apply patch.json --yes
34
30
 
35
31
  # Emergency rollback from pre-apply snapshot
36
- npx torusguard rollback
37
- # or
38
- npx torusguard apply --rollback
32
+ torusguard rollback
39
33
  ```
40
- **Under the Hood:** Executes `python .torusguard/scripts/apply_runner.py`.
41
- 1. Reads candidate bundles from `.torusguard/runs/<run_id>/bundles/`.
42
- 2. Creates `.bak` snapshot in `.torusguard/snapshots/<run_id>/<rel_path>.bak`.
34
+ **Under the Hood:** Executes compiled Go apply engine (`internal/apply`).
35
+ 1. Supports both unified diff files (`git apply`) and Semantic Reflection JSON patches (`harden.ReflectAndVerify`).
36
+ 2. Creates byte-for-byte snapshot in `.torusguard/snapshots/<run_id>/<rel_path>.bak`.
43
37
  3. Performs line-aware replacement without corrupting concurrent modifications.
44
- 4. Distills the applied fix into a **Golden Fix Recipe** registered in `.torusguard/memory/patterns.json`.
45
- 5. Emits `diff_summary.md` and `apply_plan.md` in the run directory.
46
- 6. Displays pixel-perfect 75-column terminal cards.
38
+ 4. Distills the applied fix into a **Golden Fix Recipe** registered in persistent memory.
39
+ 5. Displays pixel-perfect 75-column terminal cards.
47
40
 
48
41
  ### Mode B: In-Session AI Chat Agent Application
49
42
  When applying patches directly within an AI chat session:
50
- 1. **Human Gate Confirmation:** Present the unified diff to the operator and request explicit approval before editing code.
43
+ 1. **Human Gate Confirmation:** Present the semantic patch or unified diff to the operator and request explicit approval before editing code.
51
44
  2. **Pre-Apply Snapshot:** Ensure target file backup is created at `.torusguard/snapshots/<run_id>/<rel_path>.bak`.
52
- 3. **Execute Surgical Edit:** Use `replace_file_content` to apply only the approved lines. Strictly adhere to the formulated Ponytail diff.
53
- 4. **Syntax & Integrity Check:** Verify that the patched file is syntactically valid (e.g. `node --check <file>` or `python -m py_compile <file>`). If syntax fails, immediately restore from `.bak`.
45
+ 3. **Deterministic Reflection Execution:** Leverage Go CLI `torusguard apply <patch.json> --yes` or `replace_file_content` with exact verbatim strings.
46
+ 4. **Syntax & Integrity Check:** Verify that the patched file compiles and runs clean (`go test ./...`, `npm test`, or syntax linter). If syntax fails, immediately restore from `.bak`.
54
47
  5. **Memory Registration:** Update persistent memory events in `.torusguard/memory/events.json` with event `fix_applied`.
55
- 6. **Recommend Recheck:** Advise running `/torusguard recheck` or `npx torusguard recheck` to verify closure.
48
+ 6. **Recommend Recheck:** Advise running `/torusguard recheck` or `torusguard recheck` to verify closure.
49
+
50
+ ### Mode C: Native MCP Tool Integration
51
+ For autonomous AI coding agents (Antigravity, Cursor, Windsurf, Claude Code):
52
+ - **Remediation Validation:** First validate the patch via `torusguard_harden`.
53
+ - **Governed Application:** Autonomous tools respect the **Human Gate Invariant**; agents invoke terminal command `torusguard apply candidate.patch --yes` upon receiving explicit user confirmation.
54
+ - **Rollback Safety:** If any test fails, run `torusguard rollback` to restore pre-apply `.bak` snapshots instantly.
56
55
 
57
56
  ---
58
57
 
@@ -60,10 +59,7 @@ When applying patches directly within an AI chat session:
60
59
  If an applied patch introduces unexpected runtime behavior or breaks tests:
61
60
  ```bash
62
61
  # Instant one-command rollback of the latest applied run:
63
- npx torusguard rollback
64
-
65
- # Or rollback a specific run:
66
- npx torusguard rollback --run run-20260910-121618-audit
62
+ torusguard rollback
67
63
  ```
68
64
  All affected files are restored byte-for-byte from `.torusguard/snapshots/<run_id>/`.
69
65
 
@@ -75,10 +71,40 @@ All affected files are restored byte-for-byte from `.torusguard/snapshots/<run_i
75
71
  - **Target File:** `server/index.js:9`
76
72
  - **Rule ID:** `TG-SEC-001` (Hardcoded JWT secret)
77
73
  - **Ponytail Churn:** +1 / -1
74
+ - **Engine:** Line-Level Reflection Match (Alibaba OpenCodeReview Hybrid Pipeline)
78
75
  - **Rollback Snapshot:** `.torusguard/snapshots/<run_id>/server/index.js.bak`
79
76
  - **Golden Recipe:** Distilled into persistent memory
80
- - **Next Step:** Run `npx torusguard recheck` or `/torusguard recheck` to verify closure
77
+ - **Next Step:** Run `torusguard recheck` or `/torusguard recheck` to verify closure
81
78
  ```
82
79
 
83
- ## Living Report Ground Truth
84
- - Read `security_report.md` in the workspace root before taking any action. Update the relevant finding card after completing remediation.
80
+ ---
81
+
82
+ ## 🚨 LLM Trap Table
83
+
84
+ | Pattern | What AI Does Wrong | What Is Actually Correct |
85
+ | :--- | :--- | :--- |
86
+ | **Skipping Pre-Apply Snapshot** | Modifies files on disk before creating a `.bak` backup in `.torusguard/snapshots/`. | Always capture a byte-for-byte snapshot before writing any modified content. |
87
+ | **Bypassing Human Gate** | Applies changes to disk without presenting the diff preview to the operator. | Require explicit confirmation or `--yes` flag before altering source code. |
88
+ | **Blind Unified Diff Rejection** | Uses standard `git apply` which fails on CRLF/LF line-ending differences or offset drift. | Use the Line-Level Reflection Module (`SemanticPatch`) with exact substring replacement. |
89
+ | **Leaving Broken Build Unchecked** | Leaves file modified even if project tests or compilation fails after patch. | Run immediate integrity checks; trigger `torusguard rollback` if regression is introduced. |
90
+
91
+ ---
92
+
93
+ ## ✅ Pre-Flight Self-Audit
94
+
95
+ Before modifying code on disk, verify:
96
+ - [ ] Did the operator provide explicit approval for this specific change?
97
+ - [ ] Has a pre-apply `.bak` backup been saved in `.torusguard/snapshots/<run_id>/`?
98
+ - [ ] Does the edit strictly touch only the vulnerable lines without unrelated changes?
99
+ - [ ] Did I verify line matches using the Line-Level Reflection Module?
100
+ - [ ] Is there an instant rollback path ready if tests fail?
101
+
102
+ ---
103
+
104
+ ## 🔁 VBC Protocol (Verify → Build → Confirm)
105
+
106
+ ```
107
+ VERIFY: Confirm operator approval and verify target file snapshot is captured on disk.
108
+ BUILD: Apply surgical replacement via torusguard apply or exact replace_file_content.
109
+ CONFIRM: Run project test suite; execute torusguard recheck to mark finding Confirmed Fixed.
110
+ ```
@@ -1,41 +1,39 @@
1
1
  ---
2
2
  name: torusguard-audit
3
3
  description: Static AST security scanning, line-shift invariant fingerprinting, root-cause clustering, and 0-100 confidence scoring via CLI or AI Agent.
4
- version: 1.3.6
4
+ version: 2.0.0
5
5
  workflow: .torusguard/workflows/audit.md
6
6
  tools: Read, Grep, Glob, Write, run_command
7
7
  scripts-binding:
8
- - .torusguard/scripts/report_sync.py
9
- - .torusguard/scripts/audit_runner.py
10
- - .torusguard/scripts/term_ui.py
11
- - .torusguard/scripts/finding_scorer.py
8
+ - internal/scanner/scanner.go
9
+ - cmd/torusguard/main.go
12
10
  ---
13
11
 
14
12
  # TorusGuard Audit — Static Code Security Analysis
15
13
 
16
14
  ## Objective
17
- Execute static AST analysis across polyglot project files, evaluate code against 74 canonical security rules across 11 families, assign stable line-shift invariant fingerprints, cluster architectural root causes, and score findings with auditable 0–100 confidence ratings.
15
+ Execute static AST analysis across polyglot project files, evaluate code against 74 canonical security rules across 18 families, assign stable line-shift invariant fingerprints, cluster architectural root causes, synchronize findings with `security_report.md`, and score findings with auditable 0–100 confidence ratings.
18
16
 
19
17
  ---
20
18
 
21
- ## Two Execution Modes
19
+ ## Tri-Mode Execution
22
20
 
23
21
  ### Mode A: Automated CLI Execution
24
22
  Run the static security audit from your terminal:
25
23
  ```bash
26
24
  # Scan current repository
27
- npx torusguard audit
25
+ torusguard audit
28
26
 
29
27
  # Scan specific directory or example app
30
- npx torusguard audit ./examples/vulnerable-react-express
28
+ torusguard audit ./examples/vulnerable-react-express
31
29
 
32
30
  # Include test fixtures and spec directories
33
- npx torusguard audit --include-tests
31
+ torusguard audit --include-tests
34
32
 
35
33
  # Output machine-readable JSON
36
- npx torusguard audit --json
34
+ torusguard audit --json
37
35
  ```
38
- **Under the Hood:** Executes `python .torusguard/scripts/audit_runner.py`.
36
+ **Under the Hood:** Executes compiled Go static analysis engine (`internal/scanner`).
39
37
  - Auto-detects repository stack and skips build/cache directories (`node_modules`, `.git`, `.venv`, `dist`, `build`).
40
38
  - Evaluates files across 18 canonical security families:
41
39
  - `TG-SEC-*`: Hardcoded credentials, private keys, JWT secrets, client env leaks.
@@ -43,19 +41,33 @@ npx torusguard audit --json
43
41
  - `TG-DB-*`: Missing tenant isolation, service role keys in client code.
44
42
  - `TG-AUTH-*`: Plaintext passwords, missing cookie security flags (httpOnly, secure, sameSite).
45
43
  - `TG-PLATFORM-*`: Permissive wildcard CORS with credentials, missing security headers.
46
- - `TG-DIFF-*`: Disabled TLS verification (`verify=False`, `rejectUnauthorized: false`).
47
- - Generates run directory: `.torusguard/runs/run-YYYYMMDD-HHMMSS-audit/`.
48
- - Writes `findings.json`, `findings.md`, and `manifest.json`.
44
+ - `TG-DIFF-*`: Disabled TLS verification (`verify=False`, `InsecureSkipVerify: true`).
45
+ - `TG-NPE-*`: Null-pointer exceptions, unchecked nil error dereferences.
46
+ - `TG-CONC-*`: Concurrency hazards, goroutine loop variable capture.
47
+ - Writes findings directly to `security_report.md` at workspace root.
49
48
  - Displays standardized 75-column terminal cards.
50
- - Returns exit code `1` if findings are discovered, `0` if clean.
51
49
 
52
50
  ### Mode B: In-Session AI Chat Agent Scan
53
51
  When auditing files directly in AI chat:
54
52
  1. **Discover Sinks:** Use `grep_search` and `view_file` to search for dangerous patterns across server and client code.
55
53
  2. **Cluster Root Causes:** Group findings by causal architecture (e.g. `cluster-tenant-isolation`, `cluster-credentials-exposure`, `cluster-injection`).
56
54
  3. **Audit Evidence Sufficiency:** Ensure that user-controlled input reaches the vulnerable sink without prior sanitization or schema validation.
57
- 4. **Present Actionable Findings:** Display finding cards with severity, rule ID, file, line, and remediation recommendation.
58
- 5. **Prompt Next Phase:** Guide the operator to `/torusguard harden` or `npx torusguard harden`.
55
+ 4. **Context Minimization (1/9th Token Strategy):** Inspect only bounded AST context windows ($\pm 3$ lines) via `scanner.ExtractContext` rather than ingesting entire files.
56
+ 5. **Present Actionable Findings:** Display finding cards with severity, rule ID, file, line, and remediation recommendation.
57
+ 6. **Prompt Next Phase:** Guide the operator to `/torusguard harden` or `torusguard harden`.
58
+
59
+ ### Mode C: Native MCP Tool Execution
60
+ For autonomous AI coding agents (Antigravity, Cursor, Windsurf, Claude Code):
61
+ - **Tool Invocation:** Call `torusguard_audit` with target arguments:
62
+ ```json
63
+ {
64
+ "target": ".",
65
+ "include_ocr": true,
66
+ "max_image_mb": 10
67
+ }
68
+ ```
69
+ - **Programmatic Return:** Receives formatted finding summaries, active rule counts, and confirmation that `security_report.md` is updated on disk.
70
+ - **Resource Companion:** Inspect the living report via resource `torusguard://security_report` or rules catalog via `torusguard://rules_catalog`.
59
71
 
60
72
  ---
61
73
 
@@ -67,7 +79,9 @@ When auditing files directly in AI chat:
67
79
  | **TG-DB** | Database & Tenant Scoping | Unscoped `.objects.get(id=...)`, Prisma missing `tenantId` |
68
80
  | **TG-AUTH** | Authentication & Cookies | Insecure cookies (missing httpOnly/secure/sameSite) |
69
81
  | **TG-PLATFORM** | Server & Platform Config | Wildcard CORS (`origin: '*'`) with credentials |
70
- | **TG-DIFF** | Security Bypasses | Disabled TLS verification (`verify=False`) |
82
+ | **TG-DIFF** | Security Bypasses | Disabled TLS verification (`verify=False`, `# nosec`) |
83
+ | **TG-NPE** | Null Dereference / NPE | Unchecked optional chaining, unhandled nil error returns |
84
+ | **TG-CONC** | Concurrency & Thread-Safety | Goroutine loop variable capture, unmutexed map mutations |
71
85
 
72
86
  ---
73
87
 
@@ -75,13 +89,48 @@ When auditing files directly in AI chat:
75
89
  ```markdown
76
90
  ### 🛡️ TorusGuard Static Security Audit Completed
77
91
  - **Run ID:** `run-20260910-121618-audit`
78
- - **Scope:** 7 files evaluated across 11 canonical families
92
+ - **Scope:** 7 files evaluated across 18 canonical families
79
93
  - **Status:** ✖ CRITICAL FINDINGS DETECTED
80
94
  - **Findings:** 2 Critical, 2 High, 2 Medium/Low (6 total)
81
95
  - **Clusters:** 3 architectural root causes identified
82
- - **Artifacts:** `.torusguard/runs/<run_id>/findings.json`
83
- - **Next Action:** Run `npx torusguard harden` or `/torusguard harden`
96
+ - **Artifacts:** `security_report.md`
97
+ - **Next Action:** Run `torusguard harden` or `/torusguard harden`
84
98
  ```
85
99
 
86
- ## Living Report Ground Truth
87
- - Read `security_report.md` in the workspace root before taking any action. Update the relevant finding card after completing remediation.
100
+ ---
101
+
102
+ ## 🏛️ OpenCodeReview Precision & Context Minimization
103
+ - **1/9th Token Minimization:** Use `scanner.ExtractContext` to extract only the bounded $\pm 3$ lines context window instead of ingesting entire files.
104
+ - **Line-Level Pinning:** Every finding is reported with exact 1-indexed line numbers, line content, severity, and suggested remediation.
105
+
106
+ ---
107
+
108
+ ## 🚨 LLM Trap Table
109
+
110
+ | Pattern | What AI Does Wrong | What Is Actually Correct |
111
+ | :--- | :--- | :--- |
112
+ | **Unbounded File Reading** | Reads entire 800+ line files to diagnose a 1-line vulnerability. | Read only the bounded context ($\pm 3$ lines) around the finding's line number. |
113
+ | **Ignoring NPE / Concurrency** | Focuses only on secrets and misses thread-safety and null-pointer hazards. | Enforce `TG-NPE-001` and `TG-CONC-001` checks during audit review. |
114
+ | **False Positive Escalation** | Flags documentation strings or mock test fixtures as production vulnerabilities. | Skip test files (`*_test.go`, `.test.ts`) and verify sink exploitability before reporting. |
115
+ | **Missing Sync to Ground Truth** | Produces analysis in chat without checking or updating `security_report.md`. | Always reconcile against `security_report.md` at workspace root. |
116
+
117
+ ---
118
+
119
+ ## ✅ Pre-Flight Self-Audit
120
+
121
+ Before completing an audit pass, verify:
122
+ - [ ] Did I run `torusguard audit` or inspect `security_report.md` first?
123
+ - [ ] Are all reported findings pinned to precise line numbers?
124
+ - [ ] Did I verify user input reaches the sink without prior validation?
125
+ - [ ] Did I extract only the minimal AST context window ($\pm 3$ lines) to conserve tokens?
126
+ - [ ] Did I evaluate against all 18 families including NPE and concurrency rules?
127
+
128
+ ---
129
+
130
+ ## 🔁 VBC Protocol (Verify → Build → Confirm)
131
+
132
+ ```
133
+ VERIFY: Scan source code and image assets using torusguard audit or torusguard_audit MCP tool.
134
+ BUILD: Synthesize findings clustered by root cause with exact line numbers and bounded AST snippets.
135
+ CONFIRM: Synchronize living findings into security_report.md and guide operator to /torusguard harden.
136
+ ```
@@ -1,10 +1,11 @@
1
1
  ---
2
2
  name: torusguard-authorize
3
3
  description: Register and validate runtime target authorization boundaries — scope boundaries, ownership proofs, TTL expiration, and Safety Gate enforcement.
4
- version: 1.3.6
4
+ version: 2.0.0
5
5
  workflow: .torusguard/workflows/authorize.md
6
6
  tools: Read, Grep, Glob, Write, run_command
7
7
  scripts-binding:
8
+ - internal/scanner/scanner.go
8
9
  - .torusguard/scripts/report_sync.py
9
10
  - .torusguard/scripts/safety_gate.py
10
11
  ---
@@ -16,18 +17,27 @@ Define and validate legal runtime authorization boundaries, verify target owners
16
17
 
17
18
  ---
18
19
 
20
+ ## Tri-Mode Parity
21
+
22
+ | Mode | Command / Tool | Governed Behavior |
23
+ | :--- | :--- | :--- |
24
+ | **Mode A: CLI Terminal** | `torusguard authorize` | Interactive boundary setup, generates cryptographically signed scope tokens. |
25
+ | **Mode B: AI Chat Slash** | `/torusguard authorize` | Conversational parameter collection, validates host ownership and environment. |
26
+ | **Mode C: Native MCP Tool**| — | Administrative gatekeeper ensuring strict safety boundaries before probes. |
27
+
28
+ ---
29
+
19
30
  ## Execution Steps
20
31
 
21
32
  1. **Capture Scope Parameters:** Collect target host URL, allowed path prefixes, forbidden prefixes, and session TTL.
22
- 2. **Validate Environment:** Assert target is local (`localhost`, `127.0.0.1`) or staging (`*.staging.*`). Block production targets without explicit override.
33
+ 2. **Validate Environment:** Assert target is local (`localhost`, `127.0.0.1`) or staging (`*.staging.*`). Block production targets without explicit cryptographic override.
23
34
  3. **Verify Host Ownership:** Confirm ownership token or local process socket binding.
24
35
  4. **Invoke Safety Gate:**
25
36
  ```bash
26
- python .torusguard/scripts/safety_gate.py check --url <target_url>
37
+ torusguard authorize --url <target_url>
27
38
  ```
28
- 5. **Handle CLI Failures:** If `safety_gate.py` fails or is unavailable, YOU must manually verify the safety invariants and generate the JSON structure below.
29
- 6. **Write Scope Record:** Persist authorized targets, rate limits, and expiration timestamp into `.torusguard/config/scope.json`.
30
- 7. **Validate Schema:** Confirm `scope.json` adheres to `auth-boundary.schema.json`.
39
+ 5. **Write Scope Record:** Persist authorized targets, rate limits, and expiration timestamp into `.torusguard/config/scope.json`.
40
+ 6. **Validate Schema:** Confirm `scope.json` adheres to `auth-boundary.schema.json`.
31
41
 
32
42
  ---
33
43
 
@@ -39,6 +49,7 @@ Define and validate legal runtime authorization boundaries, verify target owners
39
49
  - Never authorize wildcard hosts (`*`) or third-party domains.
40
50
  - State-changing destructive actions (`DELETE`, bulk drops) are disabled by default.
41
51
  - Set strict TTL (default 4 hours, maximum 24 hours).
52
+ - Fail-Closed Cryptography: Authorization token generation must panic on entropy failure. No hardcoded fallback tokens are permitted.
42
53
 
43
54
  ---
44
55
 
@@ -51,3 +62,34 @@ Define and validate legal runtime authorization boundaries, verify target owners
51
62
  - Scope File: `.torusguard/config/scope.json`
52
63
  Next: Run `/torusguard web-validate` to begin safe runtime probing.
53
64
  ```
65
+
66
+ ---
67
+
68
+ ## 🚨 LLM Trap Table
69
+
70
+ | Pattern | What AI Does Wrong | What Is Actually Correct |
71
+ | :--- | :--- | :--- |
72
+ | **Wildcard Scope Authorization** | Accepts `*` or wide domain patterns like `*.com`, enabling unbounded network probes. | Strictly enforce exact domain/port matching (`http://localhost:3000`, `https://staging.internal`). |
73
+ | **Infinite TTL** | Omits `expires_at` or sets multi-year expiration timestamps. | Enforce TTL bound of maximum 24 hours (default 4 hours) to prevent lingering test permissions. |
74
+ | **Production Probe Authorization** | Authorizes live production domains without ownership challenge or manual user confirmation. | Reject production domains unless explicit cryptographic ownership challenge succeeds. |
75
+ | **Destructive Method Inclusion** | Allows `DELETE`, `PUT /bulk`, or `DROP` routes in `allowed_paths`. | Blacklist state-altering destructive paths; confine runtime validation to safe, non-destructive probes. |
76
+
77
+ ---
78
+
79
+ ## ✅ Pre-Flight Self-Audit
80
+
81
+ Before authorizing any runtime scope:
82
+ - [ ] Is the target host local (`localhost`, `127.0.0.1`) or an authorized staging environment?
83
+ - [ ] Are wildcards (`*`) strictly rejected?
84
+ - [ ] Is the TTL strictly bounded (≤24 hours)?
85
+ - [ ] Are destructive routes and SQL operations explicitly forbidden?
86
+
87
+ ---
88
+
89
+ ## 🔁 VBC Protocol (Verify → Build → Confirm)
90
+
91
+ ```
92
+ VERIFY: Check target URL, environment, and ownership proof against safety boundaries.
93
+ BUILD: Construct scope.json record with explicit allowed paths and TTL bounds.
94
+ CONFIRM: Validate JSON against auth-boundary.schema.json and persist to .torusguard/config/scope.json.
95
+ ```
@@ -0,0 +1,94 @@
1
+ ---
2
+ name: torusguard-container
3
+ description: Audits Dockerfiles, Containerfiles, and Docker Compose configurations for root users, exposed docker sockets, privileged mode, and embedded secrets via CLI, Chat, or MCP.
4
+ version: 2.0.0
5
+ workflow: .torusguard/workflows/container.md
6
+ tools: Read, Grep, Glob, Write, run_command
7
+ scripts-binding:
8
+ - internal/scanner/container.go
9
+ - cmd/torusguard/main.go
10
+ - cmd/torusguard/mcp.go
11
+ ---
12
+
13
+ # TorusGuard Container & Docker Security Audit
14
+
15
+ ## Objective
16
+ Detect and remediate critical container runtime and build-time security vulnerabilities across `Dockerfile`, `Containerfile`, `docker-compose.yml`, and `compose.yaml` files. Enforces non-root execution, privilege containment, socket isolation, and BuildKit secret mounts.
17
+
18
+ ---
19
+
20
+ ## Tri-Mode Execution
21
+
22
+ ### Mode A: Automated CLI Execution
23
+ Run container audits against current directory or specific target project:
24
+ ```bash
25
+ # Scan container files in current directory
26
+ torusguard container
27
+
28
+ # Scan container files in specific workspace target
29
+ torusguard container --target ./deployments/docker
30
+ ```
31
+
32
+ ### Mode B: In-Session AI Chat Slash Command
33
+ Run `/torusguard container` in chat.
34
+ The agent invokes the native Go scanner or MCP tool to inspect container definitions, audit user permissions, and report structural container misconfigurations.
35
+
36
+ ### Mode C: Native MCP Tool Call
37
+ MCP-enabled coding agents (Antigravity, Cursor, Windsurf, Claude Code) call:
38
+ ```json
39
+ {
40
+ "tool": "torusguard_container",
41
+ "arguments": {
42
+ "target": "."
43
+ }
44
+ }
45
+ ```
46
+
47
+ ---
48
+
49
+ ## Supported Patterns & Invariants
50
+ - **TG-CONT-001 (Root Execution Default):** Detects omission of explicit `USER <non-root>` instruction or explicit `USER root` declarations in production container stages.
51
+ - **TG-CONT-002 (Docker Socket Exposure):** Detects dangerous mounting of the host daemon socket (`/var/run/docker.sock`), which grants unconfined root privileges over the host.
52
+ - **TG-CONT-003 (Privileged Container Flag):** Detects `privileged: true`, `seccomp:unconfined`, or `SYS_ADMIN` capability grants that defeat Linux namespace and cgroup boundaries.
53
+ - **TG-CONT-004 (Build-Time Secret Injection):** Flags embedding sensitive tokens, passwords, or keys via `ARG` or `ENV` directives in Dockerfiles rather than BuildKit secret mounts.
54
+
55
+ ---
56
+
57
+ ## 🏛️ OpenCodeReview Hybrid Architecture Integration
58
+ - **Deterministic Dockerfile & Compose Parser:** Pattern extraction is executed by Go AST/regex parsers without external Docker daemon dependencies.
59
+ - **Token Efficiency:** Only flagged container directives and minimal surrounding context are returned to the agent context.
60
+ - **Ponytail Bounds:** Remediation patches must add dedicated non-root users (`USER appuser`) or switch secrets to `--mount=type=secret` without full container file rewrites (≤35 additions, ≤25 deletions).
61
+
62
+ ---
63
+
64
+ ## 🚨 LLM Trap Table
65
+
66
+ | Pattern | What AI Does Wrong | What Is Actually Correct |
67
+ | :--- | :--- | :--- |
68
+ | **Default Root Execution** | Forgets that Docker executes as UID 0 (`root`) unless a non-root `USER` is declared. | Always declare `RUN adduser -D appuser && USER appuser` before the entrypoint. |
69
+ | **Secrets in Build Arguments** | Recommends `ARG API_KEY` or `ENV DB_PASSWORD`, leaving keys baked into image layers. | Use Docker BuildKit secret mounts: `RUN --mount=type=secret,id=mysecret ...`. |
70
+ | **Permissive Privileged Mode** | Adds `privileged: true` or `cap_add: [ALL]` to resolve permission or port binding errors. | Grant only specific minimal Linux capabilities (e.g. `NET_BIND_SERVICE`) or fix file ownership. |
71
+ | **Docker Socket Mounting** | Mounts `/var/run/docker.sock` inside container to run Docker commands inside Docker. | Use Docker-in-Docker (dind) rootless or ephemeral CI runners with isolated daemons. |
72
+ | **Full File Rewrites** | Rewrites entire multi-stage Dockerfile destroying cached layer order. | Formulate surgical diffs replacing or inserting only the missing `USER` or mount flag. |
73
+
74
+ ---
75
+
76
+ ## ✅ Pre-Flight Self-Audit
77
+
78
+ Before concluding a container security review, verify:
79
+ - [ ] Did I scan all Dockerfiles (`Dockerfile`, `Dockerfile.*`, `Containerfile`)?
80
+ - [ ] Did I scan all compose files (`docker-compose.yml`, `compose.yaml`)?
81
+ - [ ] Is there an unprivileged non-root user defined before `ENTRYPOINT` or `CMD`?
82
+ - [ ] Are sensitive environment variables passed via runtime `.env` / secret managers instead of `ARG` / `ENV`?
83
+ - [ ] Is `/var/run/docker.sock` completely absent from compose volumes?
84
+ - [ ] Are all proposed fixes within Ponytail churn bounds (≤35 additions, ≤25 deletions)?
85
+
86
+ ---
87
+
88
+ ## 🔁 VBC Protocol (Verify → Build → Confirm)
89
+
90
+ ```
91
+ VERIFY: Identify Dockerfiles and Compose files in the workspace.
92
+ BUILD: Execute torusguard container or torusguard_container to locate container privilege and secret flaws.
93
+ CONFIRM: Formulate surgical remediation patch introducing non-root users and removing dangerous mounts, rechecking with torusguard recheck.
94
+ ```
@@ -1,10 +1,11 @@
1
1
  ---
2
2
  name: torusguard-exploit-check
3
3
  description: Safe, non-destructive confirmation of exploitability using inert canary tokens and sentinels.
4
- version: 1.3.6
4
+ version: 2.0.0
5
5
  workflow: .torusguard/workflows/exploit-check.md
6
6
  tools: Read, Grep, Glob, Bash, Write, run_command
7
7
  scripts-binding:
8
+ - internal/scanner/scanner.go
8
9
  - .torusguard/scripts/report_sync.py
9
10
  - .torusguard/scripts/safety_gate.py
10
11
  - .torusguard/scripts/finding_scorer.py
@@ -17,11 +18,21 @@ Confirm whether candidate findings are practically exploitable using safe, singl
17
18
 
18
19
  ---
19
20
 
21
+ ## Tri-Mode Parity
22
+
23
+ | Mode | Command / Tool | Governed Behavior |
24
+ | :--- | :--- | :--- |
25
+ | **Mode A: CLI Terminal** | `torusguard exploit-check` | Dispatches single-step sentinel canaries, confirms exploitability safely. |
26
+ | **Mode B: AI Chat Slash** | `/torusguard exploit-check` | Evaluates reproduction traces and classifies findings into 5 statuses. |
27
+ | **Mode C: Native MCP Tool**| — | Bounded execution guarded by safety gate and inert payloads. |
28
+
29
+ ---
30
+
20
31
  ## Authorization Gate Check
21
32
  Before dispatching any exploitability probe:
22
33
  1. Verify target route is explicitly authorized in `.torusguard/config/scope.json`.
23
34
  2. Verify authorization TTL has not expired.
24
- 3. Assert probe passes `.torusguard/scripts/safety_gate.py`.
35
+ 3. Assert probe passes safety boundaries.
25
36
 
26
37
  ---
27
38
 
@@ -37,15 +48,17 @@ Before dispatching any exploitability probe:
37
48
 
38
49
  1. **Verify Scope:** Read `scope.json`; assert authorized endpoint.
39
50
  2. **Select Canary:** Choose matching non-destructive probe strategy.
40
- 3. **Handle Automation Failure:** If automated exploit check scripts fail, YOU must manually construct the safe HTTP request (using `curl` or `fetch`) and inspect the response.
41
- 4. **Dispatch Probe:** Send request with header `X-TorusGuard-AuthID`.
42
- 5. **Classify Status:** Transition finding into one of 5 canonical outcomes:
51
+ 3. **Dispatch Probe:** Send request with header `X-TorusGuard-AuthID`:
52
+ ```bash
53
+ torusguard exploit-check --finding TG-SEC-001
54
+ ```
55
+ 4. **Classify Status:** Transition finding into one of 5 canonical outcomes:
43
56
  - `Confirmed`: Canary reflected or secondary tenant data leaked.
44
57
  - `Not Reproducible`: Endpoint responded with 401/403 or sanitized input.
45
58
  - `Needs Review`: Ambiguous status code or incomplete response.
46
59
  - `Blocked by Controls`: WAF or rate limiter stopped probe.
47
60
  - `Out of Scope`: Target endpoint is not authorized.
48
- 6. **Record Evidence:** Save trace in `.torusguard/runs/<run_id>/exploit-evidence.md`.
61
+ 5. **Record Evidence:** Save trace in `.torusguard/runs/<run_id>/exploit-evidence.md`.
49
62
 
50
63
  ---
51
64
 
@@ -68,3 +81,34 @@ Before dispatching any exploitability probe:
68
81
  - Evidence: <Response snippet or status code>
69
82
  Next: Run `/torusguard harden` to formulate surgical remediation bundle.
70
83
  ```
84
+
85
+ ---
86
+
87
+ ## 🚨 LLM Trap Table
88
+
89
+ | Pattern | What AI Does Wrong | What Is Actually Correct |
90
+ | :--- | :--- | :--- |
91
+ | **Destructive Payloads** | Generates real data-altering payloads (`'; DROP TABLE users;--`, `<script>evil()</script>`). | Use strictly inert canaries (`' OR 1=1--`, `<tg-canary-tag>`) that cannot destroy state or exfiltrate data. |
92
+ | **Fuzzing Floods** | Runs recursive wordlist fuzzing or multi-hundred request automated attacks. | Enforce single-step bounded confirmation (1-2 deterministic probe requests max). |
93
+ | **False Confirmation** | Declares finding "Confirmed" based on a generic HTTP 500 error without validating the canary reflection. | Require differential response evidence (e.g. reflection of exact sentinel tag or tenant leak). |
94
+ | **Missing Scope Check** | Probes external auth providers (OAuth Google/GitHub) during auth validation. | Confine probes strictly to internal endpoints authorized in `scope.json`. |
95
+
96
+ ---
97
+
98
+ ## ✅ Pre-Flight Self-Audit
99
+
100
+ Before dispatching an exploitability check:
101
+ - [ ] Is the probe payload completely inert and non-destructive?
102
+ - [ ] Is the route explicitly in scope and within TTL?
103
+ - [ ] Is the `X-TorusGuard-AuthID` header attached?
104
+ - [ ] Is the outcome classification mapped to one of the 5 canonical statuses?
105
+
106
+ ---
107
+
108
+ ## 🔁 VBC Protocol (Verify → Build → Confirm)
109
+
110
+ ```
111
+ VERIFY: Check route authorization in scope.json and confirm finding AST context.
112
+ BUILD: Select inert canary token (e.g. <tg-canary-tag>) and construct probe.
113
+ CONFIRM: Evaluate response for differential proof, classify status, and record trace.
114
+ ```