torusguard 1.3.6 โ 2.0.0-alpha
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.
- package/.torusguard/.manifest.json +9 -8
- package/.torusguard/auth.json +5 -0
- package/.torusguard/rules_catalog.json +242 -518
- package/.torusguard/runs/report-latest.html +3529 -364
- package/.torusguard/runs/run-20260918-105940-audit/manifest.json +2 -1
- package/.torusguard/runs/run-20260918-105940-audit/remediation.md +7 -0
- package/.torusguard/runs/run-20260919-145701-audit/findings.json +1 -0
- package/.torusguard/runs/run-20260919-145701-audit/findings.md +8 -0
- package/.torusguard/runs/run-20260919-145701-audit/manifest.json +12 -0
- package/.torusguard/runs/run-20260919-145701-audit/summary.md +5 -0
- package/.torusguard/runs/run-20260919-151729-audit/findings.json +1 -0
- package/.torusguard/runs/run-20260919-151729-audit/findings.md +8 -0
- package/.torusguard/runs/run-20260919-151729-audit/manifest.json +13 -0
- package/.torusguard/runs/run-20260919-151729-audit/remediation.md +7 -0
- package/.torusguard/runs/run-20260919-151729-audit/summary.md +5 -0
- package/.torusguard/runs/run-20260919-152340-audit/findings.json +1 -0
- package/.torusguard/runs/run-20260919-152340-audit/findings.md +8 -0
- package/.torusguard/runs/run-20260919-152340-audit/manifest.json +12 -0
- package/.torusguard/runs/run-20260919-152340-audit/summary.md +5 -0
- package/.torusguard/runs/run-20260919-152345-audit/findings.json +1 -0
- package/.torusguard/runs/run-20260919-152345-audit/findings.md +8 -0
- package/.torusguard/runs/run-20260919-152345-audit/manifest.json +12 -0
- package/.torusguard/runs/run-20260919-152345-audit/summary.md +5 -0
- package/.torusguard/runs/run-20260919-153500-audit/findings.json +1 -0
- package/.torusguard/runs/run-20260919-153500-audit/findings.md +8 -0
- package/.torusguard/runs/run-20260919-153500-audit/manifest.json +12 -0
- package/.torusguard/runs/run-20260919-153500-audit/summary.md +5 -0
- package/.torusguard/scripts/__pycache__/apply_runner.cpython-314.pyc +0 -0
- package/.torusguard/scripts/__pycache__/audit_runner.cpython-314.pyc +0 -0
- package/.torusguard/scripts/__pycache__/harden_runner.cpython-314.pyc +0 -0
- package/.torusguard/scripts/__pycache__/html_reporter.cpython-314.pyc +0 -0
- package/.torusguard/scripts/__pycache__/manifest_builder.cpython-314.pyc +0 -0
- package/.torusguard/scripts/__pycache__/recipes_runner.cpython-314.pyc +0 -0
- package/.torusguard/scripts/__pycache__/report_sync.cpython-314.pyc +0 -0
- package/.torusguard/scripts/apply_runner.py +101 -8
- package/.torusguard/scripts/audit_runner.py +116 -11
- package/.torusguard/scripts/harden_runner.py +122 -68
- package/.torusguard/scripts/html_reporter.py +1170 -253
- package/.torusguard/scripts/manifest_builder.py +2 -0
- package/.torusguard/scripts/recheck_runner.py +2 -1
- package/.torusguard/scripts/recipes_runner.py +91 -8
- package/.torusguard/scripts/report_sync.py +134 -7
- package/.torusguard/scripts/status_runner.py +267 -0
- package/.torusguard/snapshots/20260921-182638/go.mod.bak +11 -0
- package/.torusguard/snapshots/20260921-185213/file.go.bak +5 -0
- package/README.md +314 -364
- package/bin/torusguard.js +190 -20
- package/package.json +6 -2
- package/skills/torusguard/__pycache__/bootstrap.cpython-314.pyc +0 -0
- package/skills/torusguard/bootstrap.py +45 -6
- package/skills/torusguard/payload/.manifest.json +29 -14
- package/skills/torusguard/payload/TORUSGUARD.md +145 -145
- package/skills/torusguard/payload/agents/auditor.md +41 -41
- package/skills/torusguard/payload/agents/profiler.md +49 -49
- package/skills/torusguard/payload/agents/remediator.md +41 -41
- package/skills/torusguard/payload/agents/reviewer.md +39 -39
- package/skills/torusguard/payload/agents/validator.md +46 -46
- package/skills/torusguard/payload/config/scope.json +24 -24
- package/skills/torusguard/payload/references/csharp-security.md +41 -41
- package/skills/torusguard/payload/references/go-security.md +41 -41
- package/skills/torusguard/payload/references/java-security.md +40 -40
- package/skills/torusguard/payload/references/polyglot-security-matrix.md +25 -25
- package/skills/torusguard/payload/references/rust-security.md +40 -40
- package/skills/torusguard/payload/rules/custom/.gitkeep +1 -1
- package/skills/torusguard/payload/rules/custom/README.md +30 -30
- package/skills/torusguard/payload/scripts/__pycache__/audit_runner.cpython-314.pyc +0 -0
- package/skills/torusguard/payload/scripts/__pycache__/html_reporter.cpython-314.pyc +0 -0
- package/skills/torusguard/payload/scripts/__pycache__/report_sync.cpython-314.pyc +0 -0
- package/skills/torusguard/payload/scripts/__pycache__/sarif_exporter.cpython-314.pyc +0 -0
- package/skills/torusguard/payload/scripts/__pycache__/term_ui.cpython-314.pyc +0 -0
- package/skills/torusguard/payload/scripts/apply_runner.py +101 -8
- package/skills/torusguard/payload/scripts/audit_runner.py +116 -11
- package/skills/torusguard/payload/scripts/harden_runner.py +122 -68
- package/skills/torusguard/payload/scripts/html_reporter.py +1170 -253
- package/skills/torusguard/payload/scripts/manifest_builder.py +2 -0
- package/skills/torusguard/payload/scripts/recheck_runner.py +2 -1
- package/skills/torusguard/payload/scripts/recipes_runner.py +91 -8
- package/skills/torusguard/payload/scripts/report_sync.py +134 -7
- package/skills/torusguard/payload/scripts/rules_sync.py +321 -321
- package/skills/torusguard/payload/scripts/safety_gate.py +64 -64
- package/skills/torusguard/payload/scripts/status_runner.py +267 -0
- package/skills/torusguard/payload/skills/torusguard/references/csharp-security.md +41 -41
- package/skills/torusguard/payload/skills/torusguard/references/go-security.md +41 -41
- package/skills/torusguard/payload/skills/torusguard/references/java-security.md +40 -40
- package/skills/torusguard/payload/skills/torusguard/references/polyglot-security-matrix.md +25 -25
- package/skills/torusguard/payload/skills/torusguard/references/rust-security.md +40 -40
- package/skills/torusguard/payload/templates/audit-report.template.md +54 -54
- package/skills/torusguard/payload/templates/authorization.template.md +34 -34
- package/skills/torusguard/payload/templates/finding-card.template.md +32 -32
- package/skills/torusguard/payload/templates/remediation-bundle.template.md +35 -35
- package/skills/torusguard/payload/workflows/apply.md +9 -1
- package/skills/torusguard/payload/workflows/audit.md +8 -2
- package/skills/torusguard/payload/workflows/harden.md +6 -1
- package/skills/torusguard/payload/workflows/init.md +7 -1
- package/skills/torusguard/payload/workflows/recipes.md +55 -0
- package/skills/torusguard/payload/workflows/report.md +59 -55
- package/skills/torusguard/payload/workflows/status.md +4 -1
- package/skills/torusguard/payload/workflows/torusguard-apply.md +110 -0
- package/skills/torusguard/payload/workflows/torusguard-audit.md +105 -0
- package/skills/torusguard/payload/workflows/torusguard-authorize.md +96 -0
- package/skills/torusguard/payload/workflows/torusguard-exploit-check.md +98 -0
- package/skills/torusguard/payload/workflows/torusguard-harden.md +104 -0
- package/skills/torusguard/payload/workflows/torusguard-init.md +106 -0
- package/skills/torusguard/payload/workflows/torusguard-recheck.md +101 -0
- package/skills/torusguard/payload/workflows/torusguard-recipes.md +55 -0
- package/skills/torusguard/payload/workflows/torusguard-report.md +105 -0
- package/skills/torusguard/payload/workflows/torusguard-status.md +103 -0
- package/skills/torusguard/payload/workflows/torusguard-verify.md +100 -0
- package/skills/torusguard/payload/workflows/torusguard-web-validate.md +96 -0
- package/skills/torusguard/payload/workflows/torusguard.md +19 -0
package/README.md
CHANGED
|
@@ -1,476 +1,426 @@
|
|
|
1
|
-
<
|
|
2
|
-
<img src="TorusGuard.png" alt="TorusGuard
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
<
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="TorusGuard.png" alt="TorusGuard Logo" width="200" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">TorusGuard</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<strong>The Hybrid Governance Security Engine for AI-built web applications.</strong><br>
|
|
9
|
+
<em>Pairs the intelligence of your AI Agent with a deterministic Go CLI to enforce strict security boundaries and patch limits.</em>
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
<p align="center">
|
|
13
|
+
<a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="License: MIT"></a>
|
|
14
|
+
<a href="https://github.com/githubmofo/TorusGuard/releases"><img src="https://img.shields.io/badge/version-2.0.0--alpha-orange.svg" alt="Version"></a>
|
|
15
|
+
<a href="https://www.npmjs.com/package/torusguard"><img src="https://img.shields.io/badge/npm-v2.0.0--alpha-CB3837?logo=npm&logoColor=white" alt="npm: v2.0.0-alpha"></a>
|
|
16
|
+
<img src="https://img.shields.io/badge/Privacy-Local_First-success" alt="Privacy: Local First">
|
|
17
|
+
<img src="https://img.shields.io/badge/Dependencies-Zero-brightgreen" alt="Dependencies: Zero">
|
|
18
|
+
<img src="https://img.shields.io/badge/SARIF-v2.1.0-6C3483" alt="SARIF">
|
|
19
|
+
<img src="https://img.shields.io/badge/OWASP-Top_10-000000?logo=owasp&logoColor=white" alt="OWASP">
|
|
20
|
+
</p>
|
|
21
|
+
|
|
22
|
+
<p align="center">
|
|
23
|
+
<img src="https://img.shields.io/badge/Unit%20Tests-100%25%20Passing-brightgreen?logo=go&logoColor=white" alt="Unit Tests: 100% Passing">
|
|
24
|
+
<img src="https://img.shields.io/badge/Polyglot%20Tests-36%2F36%20Repos%20Passed-brightgreen?logo=checkmarx&logoColor=white" alt="Polyglot Tests: 36/36 Repos Passed">
|
|
25
|
+
<img src="https://img.shields.io/badge/Tri--Mode%20E2E-16%2F16%20Verified-blue?logo=checkmarx&logoColor=white" alt="Tri-Mode E2E: 16/16 Verified">
|
|
26
|
+
<img src="https://img.shields.io/badge/Vision%20OCR-Tested%20%26%20Verified-blueviolet?logo=tesseract&logoColor=white" alt="Vision OCR: Tested & Verified">
|
|
27
|
+
<img src="https://img.shields.io/badge/Rules%20Verified-74%2F74%20Rules-success" alt="Rules: 74/74 Verified">
|
|
28
|
+
</p>
|
|
29
|
+
|
|
30
|
+
<p align="center">
|
|
31
|
+
<img src="https://img.shields.io/badge/Tri--Mode-CLI%20%7C%20Chat%20%7C%20MCP-blue" alt="Tri-Mode Parity">
|
|
32
|
+
<img src="https://img.shields.io/badge/Go-1.25-00ADD8?logo=go&logoColor=white" alt="Go">
|
|
33
|
+
<img src="https://img.shields.io/badge/Node.js-18+-339933?logo=nodedotjs&logoColor=white" alt="Node.js">
|
|
34
|
+
<img src="https://img.shields.io/badge/Python-3.10+-3776AB?logo=python&logoColor=white" alt="Python">
|
|
35
|
+
<img src="https://img.shields.io/badge/TypeScript-5.0+-3178C6?logo=typescript&logoColor=white" alt="TypeScript">
|
|
36
|
+
<img src="https://img.shields.io/badge/Rust-2021-DEA584?logo=rust&logoColor=white" alt="Rust">
|
|
37
|
+
</p>
|
|
26
38
|
|
|
27
39
|
---
|
|
28
40
|
|
|
29
|
-
##
|
|
41
|
+
## Table of Contents
|
|
42
|
+
|
|
43
|
+
- [What Is TorusGuard?](#what-is-torusguard)
|
|
44
|
+
- [Features](#-features)
|
|
45
|
+
- [Autonomous Architecture](#-autonomous-architecture)
|
|
46
|
+
- [Prerequisites](#-prerequisites)
|
|
47
|
+
- [Installation](#-installation)
|
|
48
|
+
- [Usage](#-usage)
|
|
49
|
+
- [Commands](#-commands)
|
|
50
|
+
- [Project Structure](#-project-structure)
|
|
51
|
+
- [Security Rules (74 Rules, 18 Families)](#-security-rules-74-rules-18-families)
|
|
52
|
+
- [AI Agent Integration](#-ai-agent-integration)
|
|
53
|
+
- [Verified Test Suite & Benchmarks](#-verified-test-suite--mass-benchmarks)
|
|
54
|
+
- [Non-Negotiable Invariants](#-non-negotiable-invariants)
|
|
55
|
+
- [Contributing](#-contributing)
|
|
56
|
+
- [License](#-license)
|
|
57
|
+
- [Documentation](#-documentation)
|
|
30
58
|
|
|
31
|
-
|
|
59
|
+
---
|
|
32
60
|
|
|
33
|
-
|
|
34
|
-
flowchart LR
|
|
35
|
-
subgraph Torus ["๐ 360ยฐ Closed-Loop Torus Lifecycle"]
|
|
36
|
-
direction LR
|
|
37
|
-
Detect["1. Detect (74 AST Rules)"] --> Verify["2. Verify (Evidence & Fingerprints)"]
|
|
38
|
-
Verify --> Harden["3. Harden (Ponytail Protocol)"]
|
|
39
|
-
Harden --> Apply["4. Apply (Human Gate & Snapshots)"]
|
|
40
|
-
Apply --> Recheck["5. Recheck (Differential Closure)"]
|
|
41
|
-
Recheck --> Memory["6. Memory (Golden Fix Recipes)"]
|
|
42
|
-
Memory -.->|Continuous Guardrail| Detect
|
|
43
|
-
end
|
|
61
|
+
## What Is TorusGuard?
|
|
44
62
|
|
|
45
|
-
|
|
46
|
-
direction TB
|
|
47
|
-
Inv1["Browser-Code Truth: Zero Client Secrets"]
|
|
48
|
-
Inv2["Tenant Partitioning: Scoped Lookups"]
|
|
49
|
-
Inv3["Zero Bypasses: No verify=False"]
|
|
50
|
-
Inv4["Living Source of Truth: security_report.md"]
|
|
51
|
-
end
|
|
63
|
+
TorusGuard is a **zero-dependency, single-binary security engine** that scans, hardens, and validates AI-generated codebases. It enforces 74 security rules across 18 architectural families and works in two complementary modes:
|
|
52
64
|
|
|
53
|
-
|
|
54
|
-
|
|
65
|
+
- **CLI Mode (Go Binary)** โ A deterministic scanner and enforcer that runs in your terminal or CI/CD pipeline.
|
|
66
|
+
- **AI Agent Mode** โ Integrates natively with Antigravity, Cursor, Claude Code, Windsurf, VS Code, and other AI coding assistants via slash commands.
|
|
55
67
|
|
|
56
|
-
|
|
57
|
-
> **TorusGuard forms an unbroken local guardrail around your codebase.** It audits static ASTs, runtime-verifies exploitability with inert canaries, synthesizes minimal surgical diffs adhering to the **Ponytail Protocol** ($\le 35$ additions, $\le 25$ deletions), and eliminates hallucinations by maintaining a verifiable single source of truth in `security_report.md`.
|
|
68
|
+
TorusGuard ensures that the code your AI assistant writes is secure *before* it reaches production.
|
|
58
69
|
|
|
59
70
|
---
|
|
60
71
|
|
|
61
|
-
##
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
10
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
15. [License](#-license)
|
|
72
|
+
## โจ Features
|
|
73
|
+
|
|
74
|
+
- **74 Security Rules** across 18 families (Secrets, Auth, SQL Injection, SSRF, CSRF, GraphQL, Supply Chain, and more)
|
|
75
|
+
- **Heuristic AST Scanner** โ Polyglot static analysis for Go, JavaScript, TypeScript, and Python
|
|
76
|
+
- **Ponytail Protocol** โ Surgical patch bounds (โค35 additions, โค25 deletions) to prevent full-file rewrites
|
|
77
|
+
- **Pre-Apply Snapshots** โ Automatic `.bak` rollback snapshots before every code modification
|
|
78
|
+
- **SARIF v2.1.0 Export** โ Standards-compliant output for GitHub Advanced Security, VS Code, and other SARIF consumers
|
|
79
|
+
- **Dark-Mode HTML Reports** โ Single-file visual posture dashboards
|
|
80
|
+
- **Golden Fix Recipes** โ Persistent memory of verified security patterns for reuse
|
|
81
|
+
- **SSRF Defense** โ Built-in private IP blocking and AWS metadata protection in the web validator
|
|
82
|
+
- **Fail-Closed Cryptography** โ No fallback tokens; panics on entropy failure
|
|
83
|
+
- **DoS Resilience** โ 10,000-file scan limit and 5-minute context timeout to prevent resource exhaustion
|
|
84
|
+
- **16+ Language Stack Detection** โ Go, Rust, Java, C#, PHP, Ruby, Kotlin, Elixir, Dart, Swift, Python, TypeScript, and more
|
|
85
|
+
- **Multi-Modal Vision OCR** โ Scans architecture diagrams, mockups, and screenshots (`.png`, `.jpg`, `.webp`) via Tesseract OCR to detect leaked keys, tokens, and credentials
|
|
86
|
+
- **Native MCP Server (Model Context Protocol)** โ Exposes standard JSON-RPC 2.0 stdio tools and resources for direct agent integration
|
|
87
|
+
- **Tri-Mode Parity** โ Terminal CLI, AI Chat slash commands, and Native MCP Tools share identical governance workflows
|
|
78
88
|
|
|
79
89
|
---
|
|
80
90
|
|
|
81
|
-
##
|
|
82
|
-
|
|
83
|
-
When developers use AI coding agents to write features, models optimize for *getting the code to run* rather than *defensive architecture*. Common failure modes include:
|
|
84
|
-
- **Exposing Private Credentials:** Leaking `process.env.SUPABASE_SERVICE_ROLE_KEY` or master database connection strings into Next.js `'use client'` bundles.
|
|
85
|
-
- **Dropping Tenant Boundaries:** Querying Prisma or Mongoose by record ID without scoping by tenant (`where: { id }` instead of `where: { id, tenantId }`).
|
|
86
|
-
- **Prompt Injection Vulnerabilities:** Interpolating untrusted user chat messages directly into system prompts.
|
|
87
|
-
- **Destructive AI Rewrites:** When asked to fix a minor bug, AI models rewrite entire 500-line files, introducing fresh regressions and breaking surrounding business logic.
|
|
91
|
+
## ๐งช Proven Compatibility
|
|
88
92
|
|
|
89
|
-
|
|
90
|
-
- **Zero-Egress Local Execution:** 100% of scanning and patching happens on your machine. Zero code or tokens are transmitted to external servers.
|
|
91
|
-
- **Zero Pip Dependencies:** Pure Python standard library (`pathlib`, `re`, `json`, `difflib`, `shutil`). No virtualenv conflicts or broken build wheels.
|
|
92
|
-
- **Ponytail Churn Bounds:** Patches are constrained strictly to $\le 35$ additions and $\le 25$ deletions. Surrounding business logic is never rewritten.
|
|
93
|
-
- **Human Gate & Instant Undo:** Every change requires interactive approval with syntax-highlighted diffs, backed up byte-for-byte in `.torusguard/snapshots/` with instant 1-command rollback.
|
|
93
|
+
TorusGuardโs static scanner and enforcement binary have been rigorously tested and confirmed compatible across **20 major technology stacks and frameworks**:
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
| Ecosystem | Tested Frameworks & Runtimes |
|
|
96
|
+
|-----------|------------------------------|
|
|
97
|
+
| **JavaScript / TypeScript** | React, Next.js, Express, Vue, Angular, SvelteKit, NestJS |
|
|
98
|
+
| **Python** | Django, Flask, FastAPI, raw Python scripts |
|
|
99
|
+
| **Go** | Gin |
|
|
100
|
+
| **Java / C# (.NET)** | Spring Boot, ASP.NET Core, .NET Core Middleware |
|
|
101
|
+
| **Ruby** | Ruby on Rails, Sinatra |
|
|
102
|
+
| **PHP** | Laravel, Symfony |
|
|
103
|
+
| **Rust** | Actix Web |
|
|
98
104
|
|
|
99
105
|
---
|
|
100
106
|
|
|
101
|
-
##
|
|
107
|
+
## ๐๏ธ Autonomous Architecture
|
|
102
108
|
|
|
103
|
-
|
|
109
|
+
TorusGuard uses a **tri-track architecture** where intelligence, deterministic enforcement, and agent tool execution are cleanly separated across three unified operational modes:
|
|
104
110
|
|
|
105
111
|
```mermaid
|
|
106
112
|
flowchart TD
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
C1["Hardened Production Code (Zero Regressions)"]
|
|
127
|
-
C2["Self-Contained Dark-Mode HTML Dashboard"]
|
|
128
|
-
C3["OASIS SARIF v2.1.0 for CI/CD Pipeline"]
|
|
129
|
-
C4["Auto-Synced AI Rules (.cursorrules, CLAUDE.md, etc.)"]
|
|
113
|
+
User([Developer / CI / AI Coding Assistant])
|
|
114
|
+
|
|
115
|
+
User --> ModeA[Mode A: Terminal CLI<br/><code>torusguard <cmd></code><br/>Deterministic Go Binary]
|
|
116
|
+
User --> ModeB[Mode B: AI Chat Slash Command<br/><code>/torusguard <cmd></code><br/>Chat Prompt & Workflow Bridge]
|
|
117
|
+
User --> ModeC[Mode C: Native MCP Protocol<br/><code>torusguard_audit / ocr_scan</code><br/>Stdio JSON-RPC 2.0 Agent Tools]
|
|
118
|
+
|
|
119
|
+
ModeA --> Router[Command Router & Dispatcher<br/>cmd/torusguard]
|
|
120
|
+
ModeB --> Router
|
|
121
|
+
ModeC --> Router
|
|
122
|
+
|
|
123
|
+
Router --> Engine
|
|
124
|
+
|
|
125
|
+
subgraph Engine[TorusGuard Core Engine]
|
|
126
|
+
Scanner[Polyglot AST & Heuristic Scanner<br/>74 Rules across 18 Families]
|
|
127
|
+
OCR[Multi-Modal Vision OCR Engine<br/>Tesseract Optical Analysis ≤10MB]
|
|
128
|
+
Harden[Harden Engine<br/>Ponytail Protocol ≤35 add, ≤25 del]
|
|
129
|
+
Apply[Snapshot & Apply Engine<br/>Byte-for-byte Rollback Backups]
|
|
130
|
+
Validate[Runtime Web Validator<br/>SSRF Defense & Audit Probing]
|
|
131
|
+
Recheck[Differential Recheck Engine<br/>Fix Closure Verification]
|
|
130
132
|
end
|
|
131
|
-
|
|
132
|
-
|
|
133
|
+
|
|
134
|
+
Engine --> Ledger[Living Security Ground Truth<br/><code>security_report.md</code>]
|
|
135
|
+
Engine --> Workspace[(.torusguard/ Workspace State<br/>rules/ • schemas/ • memory/ • snapshots/)]
|
|
133
136
|
```
|
|
134
137
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
+
**Key design decisions:**
|
|
139
|
+
- **Tri-Mode Parity:** The CLI (Mode A), Chat Slash Commands (Mode B), and Native MCP Tools (Mode C) share the exact same underlying governance and validation rules.
|
|
140
|
+
- **Multi-Modal Vision OCR:** Images, architecture diagrams, and screenshots are automatically scanned for leaked secrets using Tesseract OCR, bounded by strict 10MB memory safety limits.
|
|
141
|
+
- **Deterministic Enforcement:** The **Go binary** handles all deterministic operations (AST scanning, bounds checking, snapshotting, reporting).
|
|
142
|
+
- **AI Intelligence:** The **AI agent** handles intelligence-requiring tasks (patch generation, root-cause analysis, remediation formulation).
|
|
143
|
+
- **Living Ground Truth:** All modes synchronize with `security_report.md` to prevent finding drift or hallucination.
|
|
144
|
+
- **Zero-Bypass Guardrails:** Neither human nor AI can bypass Ponytail Protocol bounds (โค35 additions, โค25 deletions) or the Human Gate before modifying code.
|
|
138
145
|
|
|
139
|
-
| Security Dimension | Traditional SAST (SonarQube, Snyk) | Raw AI Coding Agents | TorusGuard v1.3.6 Engine |
|
|
140
|
-
|:---|:---:|:---:|:---:|
|
|
141
|
-
| **Target Architecture** | Human-written legacy codebases | High-churn AI code generation | **AI-built full-stack applications** |
|
|
142
|
-
| **Remediation Model** | PDF reports & Jira tickets | Destructive full-file rewrites | **Ponytail Protocol** ($\le 35$ add, $\le 25$ del) |
|
|
143
|
-
| **Fix Preservation** | None (scans from scratch) | Forgets context across chats | **Adaptive Security Memory** & Golden Recipes |
|
|
144
|
-
| **Editor Sync** | Heavy background language daemons | Bloated prompt context ($> 2,000$ tokens) | **Stack-Adaptive Rules** ($\le 300$ prompt tokens) |
|
|
145
|
-
| **Ground-Truth State** | External proprietary web dashboard | Ephemeral chat context (hallucinates) | **Living Security Ledger** (`security_report.md`) |
|
|
146
|
-
| **Pre-Commit Defense** | Slow server-side webhooks | None (commits insecure code) | **Git Pre-Commit Diff Guard** ($< 200\text{ ms}$) |
|
|
147
|
-
| **Privacy & Telemetry** | Cloud code upload / SaaS | Third-party cloud LLMs | **100% Local, Zero-Egress Guarantee** |
|
|
148
146
|
|
|
149
147
|
---
|
|
150
148
|
|
|
151
|
-
##
|
|
152
|
-
|
|
153
|
-
TorusGuard is designed to be effortless to adopt in any project. There are no configuration servers, databases, or complex background daemons.
|
|
154
|
-
|
|
155
|
-
### ๐ Prerequisites
|
|
156
|
-
- **Node.js:** 18.0.0 or higher
|
|
157
|
-
- **Python:** 3.10 or higher (**Pure standard library** โ **zero `pip` dependencies required**)
|
|
149
|
+
## ๐ Prerequisites
|
|
158
150
|
|
|
159
|
-
|
|
160
|
-
|
|
151
|
+
- **Go 1.25+** (to build from source)
|
|
152
|
+
- **Git** (for `git apply` patch operations)
|
|
153
|
+
- **Node.js 18+** (for npm package installation)
|
|
161
154
|
|
|
162
155
|
---
|
|
163
156
|
|
|
164
|
-
|
|
165
|
-
|
|
157
|
+
## ๐ Installation
|
|
158
|
+
|
|
159
|
+
### Option 1: npm (Primary)
|
|
166
160
|
|
|
167
161
|
```bash
|
|
168
|
-
|
|
169
|
-
npx torusguard init
|
|
170
|
-
npx torusguard audit
|
|
171
|
-
npx torusguard status
|
|
162
|
+
npm install -g torusguard
|
|
172
163
|
```
|
|
173
164
|
|
|
174
|
-
|
|
175
|
-
Lock TorusGuard into your project's `package.json` for all team members and CI/CD pipelines:
|
|
165
|
+
Or use directly without installing:
|
|
176
166
|
|
|
177
167
|
```bash
|
|
178
|
-
|
|
168
|
+
npx torusguard init
|
|
179
169
|
```
|
|
180
170
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
"scripts": {
|
|
185
|
-
"security:audit": "torusguard audit",
|
|
186
|
-
"security:harden": "torusguard harden",
|
|
187
|
-
"security:recheck": "torusguard recheck",
|
|
188
|
-
"security:status": "torusguard status"
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
```
|
|
171
|
+
<a href="https://www.npmjs.com/package/torusguard">
|
|
172
|
+
<img src="https://img.shields.io/badge/npm-v2.0.0--alpha-CB3837?logo=npm&logoColor=white" alt="npm package">
|
|
173
|
+
</a>
|
|
192
174
|
|
|
193
|
-
###
|
|
194
|
-
If you prefer having the `torusguard` binary available system-wide across all terminal sessions:
|
|
175
|
+
### Option 2: Build from Source (Recommended for Contributors)
|
|
195
176
|
|
|
196
177
|
```bash
|
|
197
|
-
|
|
178
|
+
git clone https://github.com/githubmofo/TorusGuard.git
|
|
179
|
+
cd TorusGuard
|
|
180
|
+
go build -o torusguard ./cmd/torusguard
|
|
198
181
|
```
|
|
199
182
|
|
|
200
|
-
###
|
|
201
|
-
Install TorusGuard as a native AI assistant skill for Cursor, Claude Code, Cline, or Antigravity:
|
|
183
|
+
### Option 3: Go Install
|
|
202
184
|
|
|
203
185
|
```bash
|
|
204
|
-
|
|
186
|
+
go install github.com/torusguard/torusguard/cmd/torusguard@latest
|
|
205
187
|
```
|
|
206
188
|
|
|
207
189
|
---
|
|
208
190
|
|
|
209
|
-
|
|
210
|
-
When you execute `npx torusguard init` in your repository:
|
|
211
|
-
1. **Polyglot Profiling:** Automatically detects 16+ languages (Go, Rust, Java, C#, PHP, Python, TypeScript) and 30+ frameworks without manual configuration.
|
|
212
|
-
2. **Scaffolding:** Creates a local `.torusguard/` directory containing active security rules, schemas, and runners.
|
|
213
|
-
3. **Editor Rules Synchronization:** Automatically compiles compact, language-specific guardrails into `.cursorrules`, `CLAUDE.md`, `.agent/rules/torusguard.md`, and `.windsurfrules` ($\le 300$ prompt tokens).
|
|
214
|
-
4. **Living Ledger Initialization:** Creates `security_report.md` at workspace root to track finding states without hallucination.
|
|
215
|
-
5. **Baseline Policy:** Emits a production-ready `SECURITY.md` for responsible disclosure.
|
|
216
|
-
|
|
217
|
-
---
|
|
218
|
-
|
|
219
|
-
## โก Quickstart: The 5-Step Core Lifecycle
|
|
191
|
+
## ๐ป Usage
|
|
220
192
|
|
|
221
|
-
|
|
193
|
+
### Quick Start
|
|
222
194
|
|
|
223
195
|
```bash
|
|
224
|
-
#
|
|
225
|
-
|
|
196
|
+
# Initialize TorusGuard in your project
|
|
197
|
+
torusguard init
|
|
226
198
|
|
|
227
|
-
#
|
|
228
|
-
|
|
199
|
+
# Run a full security audit
|
|
200
|
+
torusguard audit
|
|
229
201
|
|
|
230
|
-
#
|
|
231
|
-
|
|
202
|
+
# Check workspace posture
|
|
203
|
+
torusguard status
|
|
232
204
|
|
|
233
|
-
#
|
|
234
|
-
|
|
205
|
+
# Generate an HTML report
|
|
206
|
+
torusguard report --html
|
|
235
207
|
|
|
236
|
-
#
|
|
237
|
-
|
|
208
|
+
# Generate a SARIF report
|
|
209
|
+
torusguard report --sarif
|
|
238
210
|
```
|
|
239
211
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
---
|
|
243
|
-
|
|
244
|
-
## โจ๏ธ Dual-Strategy Command Matrix (CLI & AI Chat Parity)
|
|
245
|
-
|
|
246
|
-
TorusGuard guarantees **100% operational parity** between terminal CLI execution and AI chat slash commands. Terminal outputs strictly adhere to a **75-column visual width** with Unicode emojis and ANSI stripping.
|
|
212
|
+
### Remediation Workflow
|
|
247
213
|
|
|
248
|
-
|
|
214
|
+
```bash
|
|
215
|
+
# Validate a candidate patch against Ponytail bounds
|
|
216
|
+
torusguard harden fix.patch
|
|
249
217
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
| **1. Init** | `npx torusguard init` | `/torusguard init` | Profiles workspace, activates rules, initializes `.torusguard/` |
|
|
253
|
-
| **2. Audit** | `npx torusguard audit` | `/torusguard audit` | 74-rule AST scan, line-shift fingerprints, updates `security_report.md` |
|
|
254
|
-
| **3. Harden** | `npx torusguard harden` | `/torusguard harden` | Synthesizes Ponytail diffs ($\le 35$ add, $\le 25$ del) into candidate bundles |
|
|
255
|
-
| **4. Apply** | `npx torusguard apply [--yes]` | `/torusguard apply` | Human Gate, pre-apply `.bak` snapshots, Golden Fix distillation |
|
|
256
|
-
| **5. Rollback**| `npx torusguard rollback` | `/torusguard rollback` | Instant restoration from pre-apply snapshots in `.torusguard/snapshots/` |
|
|
257
|
-
| **6. Recheck** | `npx torusguard recheck` | `/torusguard recheck` | Differential AST re-scan; marks findings `RESOLVED ๐ข` in living report |
|
|
218
|
+
# Apply the patch with rollback snapshot (requires --yes for Human Gate)
|
|
219
|
+
torusguard apply --yes fix.patch
|
|
258
220
|
|
|
259
|
-
|
|
221
|
+
# Verify the fix was applied correctly
|
|
222
|
+
torusguard recheck
|
|
260
223
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
| **Recipes** | `npx torusguard recipes` | `/torusguard recipes` | Explores verified Golden Fix patterns stored in `.torusguard/memory/` |
|
|
265
|
-
| **Report** | `npx torusguard report --html` | `/torusguard report` | Emits single-file dark-mode HTML posture report & OASIS SARIF v2.1.0 |
|
|
266
|
-
| **Rules Sync**| `npx torusguard rules sync` | `/torusguard rules sync`| Synchronizes prompt guardrails across Cursor, Claude, Antigravity, Windsurf |
|
|
267
|
-
| **Diff Guard**| `npx torusguard diff-guard` | `/torusguard diff-guard`| Audits git diffs for security bypasses; `--install-hook` binds pre-commit |
|
|
224
|
+
# Roll back if something went wrong
|
|
225
|
+
torusguard rollback
|
|
226
|
+
```
|
|
268
227
|
|
|
269
|
-
###
|
|
228
|
+
### Runtime Validation
|
|
270
229
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
| **Verify** | `npx torusguard verify` | `/torusguard verify` | Asserts evidence sufficiency & live disk line-shift fingerprint matches |
|
|
275
|
-
| **Validate** | `npx torusguard web-validate` | `/torusguard web-validate`| Authorized non-destructive HTTP probing with transparent audit headers |
|
|
276
|
-
| **Exploit** | `npx torusguard exploit-check`| `/torusguard exploit-check`| Bounded single-step exploitability confirmation using inert sentinels |
|
|
230
|
+
```bash
|
|
231
|
+
# Generate authorization token for runtime probing
|
|
232
|
+
torusguard authorize
|
|
277
233
|
|
|
278
|
-
|
|
234
|
+
# Probe a running application for security headers
|
|
235
|
+
torusguard web-validate
|
|
279
236
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
TorusGuard's AST scanner inspects polyglot source trees across 74 canonical security rules organized into **6 core security pillars** across 18 families:
|
|
283
|
-
|
|
284
|
-
```text
|
|
285
|
-
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
286
|
-
โ 74 CANONICAL RULES ACROSS 6 PILLARS โ
|
|
287
|
-
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
288
|
-
1. Secrets & Identity โโโบ TG-SEC (7) ยท TG-AUTH (8) ยท TG-CLIENT (2)
|
|
289
|
-
2. Data & Injection Defense โโโบ TG-DB (4) ยท TG-INPUT (6) ยท TG-CSRF (2)
|
|
290
|
-
3. AI Agent & LLM Security โโโบ TG-AGENT (4)
|
|
291
|
-
4. Network & Real-Time โโโบ TG-SSRF (4) ยท TG-WEBHOOK (4) ยท TG-WS (4)
|
|
292
|
-
5. Platform & API Limits โโโบ TG-RATE (3) ยท TG-GQL (4) ยท TG-PLATFORM (4)
|
|
293
|
-
TG-CACHE (3) ยท TG-EDGE (2)
|
|
294
|
-
6. Supply Chain & Governanceโโโบ TG-SUPPLY (6) ยท TG-BIZ (4) ยท TG-DIFF (3)
|
|
237
|
+
# Send bounded inert payloads to test input handling
|
|
238
|
+
torusguard exploit-check
|
|
295
239
|
```
|
|
296
240
|
|
|
297
|
-
| Pillar | Family Prefix | Rules | Critical Invariant Enforced |
|
|
298
|
-
|:---|:---|:---:|:---|
|
|
299
|
-
| **๐ Secrets & Client Bundles** | `TG-SEC`, `TG-CLIENT` | **9** | Zero hardcoded API keys, JWT secrets, private certificates, or server keys in client bundles. |
|
|
300
|
-
| **๐ก๏ธ Authentication & Sessions** | `TG-AUTH`, `TG-CSRF` | **10** | Timing-safe string compares, strong password hashing, algorithm verification, SameSite cookies. |
|
|
301
|
-
| **๐๏ธ Database & Input Safety** | `TG-DB`, `TG-INPUT` | **10** | Parameterized SQL queries, multi-tenant isolation (`where: { tenantId }`), path sanitization. |
|
|
302
|
-
| **๐ค AI Agent & LLM Guardrails** | `TG-AGENT` | **4** | Structural user prompt isolation, delimiter wrapping, shell tool sandboxing, MCP least-privilege. |
|
|
303
|
-
| **๐ Network, Webhooks & WS** | `TG-SSRF`, `TG-WEBHOOK`, `TG-WS` | **12** | Private IP range blocking (`169.254.169.254`), HMAC-SHA256 signature checks, WS origin validation. |
|
|
304
|
-
| **โก Platform, Edge & Governance** | `TG-RATE`, `TG-GQL`, `TG-PLATFORM`, `TG-CACHE`, `TG-EDGE`, `TG-SUPPLY`, `TG-BIZ`, `TG-DIFF` | **29** | Auth rate limiting, GraphQL depth bounds, Helmet headers, lockfile integrity, zero `# nosec` bypasses. |
|
|
305
|
-
|
|
306
|
-
<details>
|
|
307
|
-
<summary><strong>๐ Click to expand full 18-family catalog breakdown</strong></summary>
|
|
308
|
-
|
|
309
|
-
<br>
|
|
310
|
-
|
|
311
|
-
- **`TG-SEC` (Secrets & API Tokens โ 7 rules):** Detects hardcoded JWT secrets, private certificates, cloud API keys, environment variable leakage, and secrets in URL queries or logs.
|
|
312
|
-
- **`TG-AUTH` (Authentication & Access Control โ 8 rules):** Enforces constant-time string comparisons, strong password hashing (`bcrypt`/`argon2`), JWT algorithm pinning, mass assignment prevention, and server-side role verification.
|
|
313
|
-
- **`TG-DB` (Database Partitioning & Injection โ 4 rules):** Mandates tenant-scoped queries across Prisma, Mongoose, SQLAlchemy, and GORM; eliminates raw SQL string concatenation.
|
|
314
|
-
- **`TG-INPUT` (Input Validation & Traversal โ 6 rules):** Enforces safe path sanitization (`path.basename`), command argument escaping, safe DOM text assignments, and server-side file upload bounds.
|
|
315
|
-
- **`TG-RATE` (Rate Limiting & Resource Protection โ 3 rules):** Enforces rate-limiting middleware on authentication routes, pagination bounds, and request payload size limits.
|
|
316
|
-
- **`TG-AGENT` (AI Agent & LLM Defense โ 4 rules):** Enforces structural separation of user prompts from system instructions, inert XML delimiters, and containerized tool execution.
|
|
317
|
-
- **`TG-SSRF` (Server-Side Request Forgery โ 4 rules):** Restricts dynamic outbound HTTP calls, blocks AWS/cloud metadata access (`169.254.169.254`), and enforces request timeouts.
|
|
318
|
-
- **`TG-WEBHOOK` (Webhook Verification โ 4 rules):** Mandates cryptographic HMAC-SHA256 signature validation before body parsing, replay prevention, and timestamp expiration.
|
|
319
|
-
- **`TG-WS` (WebSocket Security โ 4 rules):** Enforces handshake authentication, origin validation, channel-level authorization, and frame size caps.
|
|
320
|
-
- **`TG-CSRF` (Cross-Site Request Forgery โ 2 rules):** Enforces anti-CSRF tokens on state-changing operations and `SameSite` cookie attributes.
|
|
321
|
-
- **`TG-GQL` (GraphQL Protection โ 4 rules):** Enforces query depth limiting, production introspection suppression, and field-level resolver authorization.
|
|
322
|
-
- **`TG-SUPPLY` (Supply Chain Integrity โ 6 rules):** Audits dependency lockfile presence, checks against known CVEs, prevents `--no-audit` build flags, and inspects build scripts.
|
|
323
|
-
- **`TG-BIZ` (Business Logic Bounds โ 4 rules):** Validates negative quantity inputs, coupon/discount boundaries, and race-condition transaction locks.
|
|
324
|
-
- **`TG-CACHE` (Cache Isolation โ 3 rules):** Enforces `Cache-Control: no-store, private` on authenticated responses and sanitizes unkeyed request headers.
|
|
325
|
-
- **`TG-CLIENT` (Client Bundle Hygiene โ 2 rules):** Forbids importing private server environment variables into browser bundles and suppresses production source maps.
|
|
326
|
-
- **`TG-PLATFORM` (Server Hardening โ 4 rules):** Enforces Helmet HTTP security headers, CORS origin whitelisting, cookie `secure` flags, and debug mode suppression.
|
|
327
|
-
- **`TG-DIFF` (Polyglot Diff Integrity โ 3 rules):** Intercepts security bypass comments (`# nosec`, `InsecureSkipVerify: true`) and asserts Ponytail patch budgets.
|
|
328
|
-
- **`TG-EDGE` (Edge & Serverless Limits โ 2 rules):** Prevents cross-request memory leaks in Cloudflare Workers and enforces subrequest fan-out limits.
|
|
329
|
-
|
|
330
|
-
</details>
|
|
331
|
-
|
|
332
241
|
---
|
|
333
242
|
|
|
334
|
-
##
|
|
243
|
+
## ๐ง Commands
|
|
244
|
+
|
|
245
|
+
| Command | Description |
|
|
246
|
+
| :--------------- | :------------------------------------------------------------- |
|
|
247
|
+
| `init` | Scaffold `.torusguard/` workspace, detect stack, activate rules |
|
|
248
|
+
| `status` | Diagnostic overview of posture, stack, and active rules |
|
|
249
|
+
| `audit` | Static heuristic security scan against active TG-* rules |
|
|
250
|
+
| `verify` | Live disk line match audit and evidence sufficiency check |
|
|
251
|
+
| `harden` | Validate patches against Ponytail Protocol bounds |
|
|
252
|
+
| `apply` | Apply patches with pre-apply `.bak` rollback snapshots |
|
|
253
|
+
| `rollback` | Instant restoration from pre-apply snapshots |
|
|
254
|
+
| `recheck` | Differential re-scan on modified files |
|
|
255
|
+
| `report` | Generate HTML (`--html`) or SARIF (`--sarif`) posture reports |
|
|
256
|
+
| `recipes` | Manage the Golden Fix recipe library |
|
|
257
|
+
| `authorize` | Generate cryptographic auth tokens for runtime probing |
|
|
258
|
+
| `web-validate` | Authorized HTTP probing with `X-TorusGuard-Audit` headers |
|
|
259
|
+
| `ocr-scan` | Run Tesseract OCR secret scan on images/diagrams (<10MB) |
|
|
260
|
+
| `mcp` | Run native Model Context Protocol (MCP) server over stdio |
|
|
261
|
+
| `update` | Self-update the TorusGuard engine |
|
|
262
|
+
| `help` | Show interactive command guide |
|
|
335
263
|
|
|
336
|
-
|
|
264
|
+
---
|
|
337
265
|
|
|
338
|
-
|
|
266
|
+
## ๐ Project Structure
|
|
339
267
|
|
|
340
|
-
### ๐ก๏ธ Pre-Apply Rollback Snapshots
|
|
341
|
-
Before modifying a single file on disk, `apply_runner.py` creates a byte-for-byte backup:
|
|
342
|
-
```text
|
|
343
|
-
.torusguard/snapshots/<run_id>/<target_file>.bak
|
|
344
268
|
```
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
269
|
+
TorusGuard/
|
|
270
|
+
โโโ cmd/torusguard/ # CLI entry point, command router & MCP server
|
|
271
|
+
โ โโโ main.go # CLI command router
|
|
272
|
+
โ โโโ mcp.go # Model Context Protocol (MCP) JSON-RPC 2.0 stdio server
|
|
273
|
+
โโโ internal/
|
|
274
|
+
โ โโโ apply/ # Patch application + pre-apply snapshot engine
|
|
275
|
+
โ โโโ harden/ # Ponytail Protocol bounds enforcement
|
|
276
|
+
โ โโโ memory/ # Golden Fix recipe persistence
|
|
277
|
+
โ โโโ recheck/ # Differential re-scan engine
|
|
278
|
+
โ โโโ report/ # SARIF v2.1.0 + dark-mode HTML generators
|
|
279
|
+
โ โโโ rules/ # TG-* rule catalog loader
|
|
280
|
+
โ โโโ scanner/ # Heuristic polyglot security scanner + Tesseract OCR
|
|
281
|
+
โ โ โโโ scanner.go # Polyglot code AST & heuristic scanner
|
|
282
|
+
โ โ โโโ ocr.go # Multi-modal Vision OCR secret detection
|
|
283
|
+
โ โโโ termui/ # 75-column terminal UI formatting
|
|
284
|
+
โ โโโ validate/ # authorize / web-validate / exploit-check / verify
|
|
285
|
+
โ โโโ workspace/ # init + polyglot stack detection
|
|
286
|
+
โโโ .torusguard/ # Generated workspace state
|
|
287
|
+
โ โโโ rules/ # Active security rule definitions
|
|
288
|
+
โ โโโ schemas/ # JSON schemas for findings, recipes, etc.
|
|
289
|
+
โ โโโ memory/ # Persistent security context
|
|
290
|
+
โ โโโ snapshots/ # Pre-apply rollback backups
|
|
291
|
+
โโโ docs/ # Architecture and usage documentation
|
|
292
|
+
โโโ bin/ # npm package CLI wrapper
|
|
293
|
+
โโโ go.mod # Go module (github.com/torusguard/torusguard)
|
|
294
|
+
โโโ package.json # npm package definition
|
|
349
295
|
```
|
|
350
|
-
All affected files are immediately restored to their exact pre-patch byte state.
|
|
351
296
|
|
|
352
297
|
---
|
|
353
298
|
|
|
354
|
-
##
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
$$\text{Score} = \max(0, \min(100, 100 - \text{Penalty}))$$
|
|
377
|
-
|
|
378
|
-
*When all findings are verified closed via differential recheck, the repository achieves **Health Score: 100/100 ๐ข Hardened & Secure**.*
|
|
299
|
+
## ๐ Security Rules (74 Rules, 18 Families)
|
|
300
|
+
|
|
301
|
+
| Family | Domain | Rules | Core Invariant |
|
|
302
|
+
| :------------- | :------------------------------- | :---: | :------------------------------------------------------- |
|
|
303
|
+
| `TG-SEC` | Core Secrets & API Tokens | 7 | Zero hardcoded API keys or JWT secrets in source |
|
|
304
|
+
| `TG-AUTH` | Authentication & Sessions | 8 | Timing-safe compares, strong hashing, algorithm verify |
|
|
305
|
+
| `TG-DB` | Database Isolation & Injection | 4 | Parameterized queries and tenant partition scoping |
|
|
306
|
+
| `TG-INPUT` | Input Sanitization & Traversal | 6 | Strict path sanitization, safe DOM assignments |
|
|
307
|
+
| `TG-RATE` | Rate Limiting & Resources | 3 | Rate-limiting on auth endpoints, payload size bounds |
|
|
308
|
+
| `TG-AGENT` | AI Agent & LLM Injection | 4 | Structural prompt isolation, tool call schema validation |
|
|
309
|
+
| `TG-SSRF` | Server-Side Request Forgery | 4 | Hostname whitelisting, private IP range blocking |
|
|
310
|
+
| `TG-WEBHOOK` | Inbound Webhook Verification | 4 | HMAC-SHA256 signature verification, replay prevention |
|
|
311
|
+
| `TG-WS` | WebSocket & Real-Time | 4 | Origin verification, handshake auth, frame size limits |
|
|
312
|
+
| `TG-CSRF` | Cross-Site Request Forgery | 2 | SameSite cookies, anti-CSRF token verification |
|
|
313
|
+
| `TG-GQL` | GraphQL Safety | 4 | Query depth limiting, introspection suppression |
|
|
314
|
+
| `TG-SUPPLY` | Supply Chain & Dependencies | 6 | Lockfile integrity, known CVE audits |
|
|
315
|
+
| `TG-BIZ` | Business Logic & Workflows | 4 | Negative amount validation, transaction locks |
|
|
316
|
+
| `TG-CACHE` | Cache Poisoning & Timing | 3 | Cache-control headers, unkeyed header sanitization |
|
|
317
|
+
| `TG-CLIENT` | Client Bundle & Frontend | 2 | Zero private env vars in client bundles |
|
|
318
|
+
| `TG-PLATFORM` | Server Hardening & Headers | 4 | Helmet headers, debug suppression, cookie secure flags |
|
|
319
|
+
| `TG-DIFF` | Polyglot Bypass & Churn | 3 | Block `# nosec`, `InsecureSkipVerify`, churn bounds |
|
|
320
|
+
| `TG-EDGE` | Edge Computing & Serverless | 2 | Subrequest fan-out limits, execution timeouts |
|
|
379
321
|
|
|
380
322
|
---
|
|
381
323
|
|
|
382
|
-
##
|
|
324
|
+
## ๐ค AI Agent Integration
|
|
383
325
|
|
|
384
|
-
|
|
385
|
-
```bash
|
|
386
|
-
npx torusguard report --html
|
|
387
|
-
```
|
|
388
|
-
- **SVG Circular Posture Gauge:** Animated visual health score ($0-100$).
|
|
389
|
-
- **7-Stage Closed-Loop Pipeline:** Visual state timeline across all lifecycle phases.
|
|
390
|
-
- **Golden Fix Recipes Grid:** Syntax-highlighted unified diffs with Ponytail metrics.
|
|
391
|
-
- **Zero-CDN Architecture:** Completely offline-ready; embeds all styles and assets inline.
|
|
326
|
+
TorusGuard works natively inside AI coding assistants. Add the configuration file to your project root and your AI agent automatically enforces TorusGuard security invariants.
|
|
392
327
|
|
|
393
|
-
|
|
394
|
-
```bash
|
|
395
|
-
npx torusguard report > results.sarif
|
|
396
|
-
```
|
|
328
|
+
### Supported Agents
|
|
397
329
|
|
|
398
|
-
|
|
330
|
+
| Agent | Configuration File | Status |
|
|
331
|
+
| :------------------- | :-------------------- | :----- |
|
|
332
|
+
| Antigravity (Gemini) | `AGENTS.md` | โ
Full support |
|
|
333
|
+
| Claude Code | `CLAUDE.md` | โ
Full support |
|
|
334
|
+
| Cursor | `.cursorrules` | โ
Full support |
|
|
335
|
+
| Windsurf | `.windsurfrules` | โ
Full support |
|
|
336
|
+
| VS Code Copilot | `AGENTS.md` | โ
Full support |
|
|
337
|
+
| Kimi | `SKILL.md` | โ
Full support |
|
|
399
338
|
|
|
400
|
-
|
|
339
|
+
### Slash Commands (AI Chat Mode)
|
|
401
340
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
341
|
+
```
|
|
342
|
+
/torusguard init # Initialize workspace
|
|
343
|
+
/torusguard audit # Run security + OCR scan; sync security_report.md
|
|
344
|
+
/torusguard ocr-scan # Scan diagram or image assets for leaked credentials
|
|
345
|
+
/torusguard harden # Formulate remediation patches
|
|
346
|
+
/torusguard apply # Apply patches with Human Gate
|
|
347
|
+
/torusguard recheck # Verify fix closure
|
|
348
|
+
/torusguard report # Generate posture report
|
|
349
|
+
/torusguard status # Check posture overview
|
|
350
|
+
/torusguard full # End-to-end 7-stage pipeline
|
|
405
351
|
```
|
|
406
352
|
|
|
407
|
-
###
|
|
408
|
-
- **Cursor:** Injects non-destructive rules into `.cursorrules`
|
|
409
|
-
- **Claude Code:** Injects non-destructive rules into `CLAUDE.md`
|
|
410
|
-
- **Antigravity IDE:** Injects non-destructive rules into `.agent/rules/torusguard.md`
|
|
411
|
-
- **Windsurf:** Injects non-destructive rules into `.windsurfrules`
|
|
412
|
-
|
|
413
|
-
*All rules are compiled under a strict overhead ceiling of $\le 300$ prompt tokens to preserve AI reasoning context.*
|
|
414
|
-
|
|
415
|
-
---
|
|
353
|
+
### Native MCP Tools (Agent Toolkit Mode)
|
|
416
354
|
|
|
417
|
-
|
|
355
|
+
When configured with `.agents/mcp_config.json` or `mcp_config.json`, AI coding agents gain native tool calling:
|
|
418
356
|
|
|
419
|
-
|
|
420
|
-
-
|
|
421
|
-
-
|
|
422
|
-
-
|
|
357
|
+
- `torusguard_audit`: Deep static AST scan + Vision OCR; writes `security_report.md`
|
|
358
|
+
- `torusguard_ocr_scan`: Dedicated image credential analysis via Tesseract (5-10MB bounds)
|
|
359
|
+
- `torusguard_harden`: Validates remediation diff against Ponytail Protocol bounds
|
|
360
|
+
- `torusguard_recheck`: Differential re-scan confirming fix closure
|
|
361
|
+
- `torusguard_status`: Workspace posture and tech stack inspection
|
|
362
|
+
- `torusguard://security_report`: MCP Resource reading the living security report
|
|
423
363
|
|
|
424
364
|
---
|
|
425
365
|
|
|
426
|
-
## ๐งช
|
|
366
|
+
## ๐งช Verified Test Suite & Mass Benchmarks
|
|
427
367
|
|
|
428
|
-
|
|
429
|
-
TorusGuard enforces a strict **100% pass requirement across 120 test suites** before every release.
|
|
430
|
-
The test harness runs with **zero third-party dependencies** via standard Python 3:
|
|
368
|
+
TorusGuard undergoes rigorous automated multi-tier testing across polyglot stacks, multi-modal vision assets, and agent communication protocols:
|
|
431
369
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
370
|
+
| Testing Tier | Scope & Target Stacks | Pass Rate | Verified Capabilities |
|
|
371
|
+
| :--- | :--- | :---: | :--- |
|
|
372
|
+
| **Go Engine & Unit Tests** | `cmd/torusguard`, `internal/scanner`, `internal/*` | **100% Passing** | Deterministic AST matching, 74 rule patterns, JSON-RPC 2.0 MCP protocol. |
|
|
373
|
+
| **Mass Polyglot Benchmarks** | **20 Enterprise Tech Stacks** (Go, Python, Java, Node, Rust, PHP, C#, Ruby, Svelte, Vue, Angular) | **20/20 Passed** | Framework auto-profiling, heuristic AST analysis, finding deduplication. |
|
|
374
|
+
| **Tri-Mode & Vision E2E** | **16 Diverse Framework Repos** (React, Next.js, Express, Django, FastAPI, Spring Boot, etc.) | **16/16 Passed** | Mode A (CLI) + Mode B (Slash Commands) + Mode C (Native MCP Tools) + Multi-Modal Vision OCR. |
|
|
375
|
+
| **Multi-Modal Vision OCR** | Diagram & Image assets (`.png`, `.jpg`, etc.) via Tesseract v5.4.0 | **100% Recall** | Secrets detection (`TG-SEC-001` - `TG-SEC-007`), 10MB DoS bounding, OCR character substitution tolerance. |
|
|
376
|
+
| **Ponytail Churn Limits** | Surgical patch validation across all 74 rules | **Bounded** | Line bounds (โค35 additions, โค25 deletions), zero-bypass verification (`TG-DIFF-001`). |
|
|
436
377
|
|
|
437
|
-
|
|
438
|
-
```bash
|
|
439
|
-
npm test
|
|
440
|
-
```
|
|
441
|
-
The test harness invokes `python harness/runner.py` directly using the Python standard library. It systematically verifies:
|
|
442
|
-
1. **JSON Schema Validity:** 10 formal schemas (`finding`, `evidence`, `remediation`, `rule`, `lifecycle`, `provenance`, etc.).
|
|
443
|
-
2. **74-Rule Catalog Integrity:** AST detection accuracy across all 18 security families.
|
|
444
|
-
3. **Line-Shift Fingerprinting:** Stable anchor matching across file edits without line number drift.
|
|
445
|
-
4. **Secret Redaction:** Stripe secret keys and JWT tokens safely masked.
|
|
446
|
-
5. **Deterministic Replay:** 3-pass differential validation across Django, DRF, FastAPI, Flask, and SQLAlchemy fixtures.
|
|
447
|
-
6. **Ponytail Patch Churn Bounds:** Verifying line budgets ($\le 35$ additions, $\le 25$ deletions).
|
|
448
|
-
7. **Living Security Report State Transitions:** Discovery (`OPEN ๐ด`), Candidate (`CANDIDATE ๐ก`), Applied (`APPLIED ๐ต`), and Verified Closure (`RESOLVED ๐ข`).
|
|
378
|
+
All test environments are completely sandboxed, verified with byte-for-byte assertions, and cleaned up automatically.
|
|
449
379
|
|
|
450
|
-
|
|
451
|
-
# Run formal TorusGuard test harness
|
|
452
|
-
npm test
|
|
380
|
+
---
|
|
453
381
|
|
|
454
|
-
|
|
455
|
-
# ================================================================================
|
|
456
|
-
# SUMMARY: 120 Passed | 0 Failed
|
|
457
|
-
# ================================================================================
|
|
458
|
-
```
|
|
382
|
+
## ๐ก๏ธ Non-Negotiable Invariants
|
|
459
383
|
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
384
|
+
1. **Browser-Code Truth:** Never expose secrets in frontend bundles.
|
|
385
|
+
2. **Multi-Tenant Isolation:** Always scope DB lookups by tenant/user ownership.
|
|
386
|
+
3. **Ponytail Churn Bounds:** Patches โค35 additions, โค25 deletions. No full-file rewrites.
|
|
387
|
+
4. **Zero Security Bypasses:** Never insert `# nosec`, `verify=False`, `InsecureSkipVerify: true`.
|
|
388
|
+
5. **Snapshots Before Edits:** Mandatory `.bak` backup before every modification.
|
|
389
|
+
6. **Fail-Closed Cryptography:** Panic on entropy failure. No fallback tokens.
|
|
390
|
+
7. **SSRF Boundary Enforcement:** Block private IPs and cloud metadata before probing.
|
|
391
|
+
8. **DoS Resilience:** 10,000-file max, 5-minute timeout.
|
|
464
392
|
|
|
465
393
|
---
|
|
466
394
|
|
|
467
|
-
##
|
|
395
|
+
## ๐ค Contributing
|
|
468
396
|
|
|
469
|
-
|
|
397
|
+
1. Fork the repository
|
|
398
|
+
2. Create a feature branch: `git checkout -b feat/your-feature`
|
|
399
|
+
3. Commit changes: `git commit -m "feat: add your feature"`
|
|
400
|
+
4. Push to branch: `git push origin feat/your-feature`
|
|
401
|
+
5. Open a Pull Request
|
|
402
|
+
|
|
403
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines and [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) for community standards.
|
|
470
404
|
|
|
471
405
|
---
|
|
472
406
|
|
|
473
407
|
## ๐ License
|
|
474
408
|
|
|
475
|
-
|
|
476
|
-
|
|
409
|
+
[MIT](LICENSE) ยฉ 2026 Jenish Lad
|
|
410
|
+
|
|
411
|
+
---
|
|
412
|
+
|
|
413
|
+
## ๐ Documentation
|
|
414
|
+
|
|
415
|
+
| Document | Description |
|
|
416
|
+
| :-------------------------------------------------------- | :--------------------------------------- |
|
|
417
|
+
| [Architecture](docs/architecture/ARCHITECTURE.md) | System design and module relationships |
|
|
418
|
+
| [Security Architecture](docs/architecture/SECURITY_ARCHITECTURE.md) | Threat model and security design |
|
|
419
|
+
| [Detection Engine](docs/architecture/DETECTION_ENGINE.md) | Scanner internals and rule matching |
|
|
420
|
+
| [API Specification](docs/architecture/API_SPECIFICATION.md) | CLI argument specification |
|
|
421
|
+
| [Security Philosophy](docs/overview/security-philosophy.md) | Core design principles |
|
|
422
|
+
| [Testing Playbook](docs/usage/testing-playbook.md) | Testing guide and CI integration |
|
|
423
|
+
| [Demo Guide](docs/demo.md) | Quick start and full lifecycle demo |
|
|
424
|
+
| [Roadmap](docs/roadmap.md) | Feature roadmap and release planning |
|
|
425
|
+
| [SECURITY.md](SECURITY.md) | Vulnerability disclosure policy |
|
|
426
|
+
| [CHANGELOG.md](CHANGELOG.md) | Version history and release notes |
|