torusguard 2.1.0 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.torusguard/.manifest.json +55 -5
- package/.torusguard/core/__init__.py +146 -0
- package/.torusguard/core/agent_roles.py +104 -0
- package/.torusguard/core/ast_walker.py +283 -0
- package/.torusguard/core/authorization.py +218 -0
- package/.torusguard/core/browser_verifier.py +128 -0
- package/.torusguard/core/bundle.py +141 -0
- package/.torusguard/core/call_graph.py +184 -0
- package/.torusguard/core/clustering.py +275 -0
- package/.torusguard/core/confidence.py +120 -0
- package/.torusguard/core/cross_file_taint.py +101 -0
- package/.torusguard/core/exploit_checker.py +317 -0
- package/.torusguard/core/formatter.py +351 -0
- package/.torusguard/core/governance.py +210 -0
- package/.torusguard/core/identity.py +104 -0
- package/.torusguard/core/import_resolver.py +91 -0
- package/.torusguard/core/incremental.py +102 -0
- package/.torusguard/core/lifecycle.py +137 -0
- package/.torusguard/core/models.py +425 -0
- package/.torusguard/core/parallel.py +56 -0
- package/.torusguard/core/parser.py +202 -0
- package/.torusguard/core/rechecker.py +107 -0
- package/.torusguard/core/replay_trace.py +178 -0
- package/.torusguard/core/rules_registry.py +131 -0
- package/.torusguard/core/run_folder.py +60 -0
- package/.torusguard/core/run_manager.py +163 -0
- package/.torusguard/core/runtime_evidence.py +175 -0
- package/.torusguard/core/runtime_validator.py +246 -0
- package/.torusguard/core/safety_gate.py +139 -0
- package/.torusguard/core/sarif.py +189 -0
- package/.torusguard/core/stack_profiler.py +184 -0
- package/.torusguard/core/symbol_table.py +91 -0
- package/.torusguard/core/taint.py +133 -0
- package/.torusguard/core/taint_graph.py +235 -0
- package/.torusguard/core/taint_rules.py +268 -0
- package/.torusguard/core/v070_reporter.py +102 -0
- package/.torusguard/core/v070_workflow.py +339 -0
- package/.torusguard/core/v6_reporter.py +180 -0
- package/.torusguard/core/v6_workflow.py +221 -0
- package/.torusguard/core/watcher.py +58 -0
- package/.torusguard/custom_rules/README.md +24 -0
- package/.torusguard/rules/TG-INPUT-007-unvalidated-redirect.md +53 -0
- package/.torusguard/rules/TG-INPUT-008-insecure-deserialization.md +52 -0
- package/.torusguard/scripts/__pycache__/audit_runner.cpython-314.pyc +0 -0
- package/.torusguard/scripts/__pycache__/finding_scorer.cpython-314.pyc +0 -0
- package/.torusguard/scripts/__pycache__/manifest_builder.cpython-314.pyc +0 -0
- package/.torusguard/scripts/__pycache__/rules_sync.cpython-314.pyc +0 -0
- package/.torusguard/scripts/audit_runner.py +108 -10
- package/.torusguard/scripts/deliberation_tournament.py +136 -0
- package/.torusguard/scripts/finding_scorer.py +43 -13
- package/.torusguard/scripts/reachability_analyzer.py +165 -0
- package/.torusguard/scripts/skill_profiler.py +26 -0
- package/.torusguard/scripts/stride_generator.py +198 -0
- package/.torusguard/skills/torusguard/SKILL.md +6 -2
- package/.torusguard/skills/torusguard-audit/SKILL.md +109 -84
- package/.torusguard/skills/torusguard-review/SKILL.md +27 -0
- package/.torusguard/skills/torusguard-threatmodel/SKILL.md +27 -0
- package/.torusguard/workflows/audit.md +21 -17
- package/.torusguard/workflows/review.md +11 -0
- package/.torusguard/workflows/threatmodel.md +9 -0
- package/README.md +149 -48
- package/package.json +10 -2
- package/skills/torusguard/SKILL.md +6 -2
- package/skills/torusguard/__pycache__/bootstrap.cpython-314.pyc +0 -0
- package/skills/torusguard/bootstrap.py +3 -3
- package/skills/torusguard/payload/.manifest.json +56 -7
- package/skills/torusguard/payload/core/__init__.py +146 -0
- package/skills/torusguard/payload/core/agent_roles.py +104 -0
- package/skills/torusguard/payload/core/ast_walker.py +283 -0
- package/skills/torusguard/payload/core/authorization.py +218 -0
- package/skills/torusguard/payload/core/browser_verifier.py +128 -0
- package/skills/torusguard/payload/core/bundle.py +141 -0
- package/skills/torusguard/payload/core/call_graph.py +184 -0
- package/skills/torusguard/payload/core/clustering.py +275 -0
- package/skills/torusguard/payload/core/confidence.py +120 -0
- package/skills/torusguard/payload/core/cross_file_taint.py +101 -0
- package/skills/torusguard/payload/core/exploit_checker.py +317 -0
- package/skills/torusguard/payload/core/formatter.py +351 -0
- package/skills/torusguard/payload/core/governance.py +210 -0
- package/skills/torusguard/payload/core/identity.py +104 -0
- package/skills/torusguard/payload/core/import_resolver.py +91 -0
- package/skills/torusguard/payload/core/incremental.py +102 -0
- package/skills/torusguard/payload/core/lifecycle.py +137 -0
- package/skills/torusguard/payload/core/models.py +425 -0
- package/skills/torusguard/payload/core/parallel.py +56 -0
- package/skills/torusguard/payload/core/parser.py +202 -0
- package/skills/torusguard/payload/core/rechecker.py +107 -0
- package/skills/torusguard/payload/core/replay_trace.py +178 -0
- package/skills/torusguard/payload/core/rules_registry.py +131 -0
- package/skills/torusguard/payload/core/run_folder.py +60 -0
- package/skills/torusguard/payload/core/run_manager.py +163 -0
- package/skills/torusguard/payload/core/runtime_evidence.py +175 -0
- package/skills/torusguard/payload/core/runtime_validator.py +246 -0
- package/skills/torusguard/payload/core/safety_gate.py +139 -0
- package/skills/torusguard/payload/core/sarif.py +189 -0
- package/skills/torusguard/payload/core/stack_profiler.py +184 -0
- package/skills/torusguard/payload/core/symbol_table.py +91 -0
- package/skills/torusguard/payload/core/taint.py +133 -0
- package/skills/torusguard/payload/core/taint_graph.py +235 -0
- package/skills/torusguard/payload/core/taint_rules.py +268 -0
- package/skills/torusguard/payload/core/v070_reporter.py +102 -0
- package/skills/torusguard/payload/core/v070_workflow.py +339 -0
- package/skills/torusguard/payload/core/v6_reporter.py +180 -0
- package/skills/torusguard/payload/core/v6_workflow.py +221 -0
- package/skills/torusguard/payload/core/watcher.py +58 -0
- package/skills/torusguard/payload/custom_rules/README.md +15 -0
- package/skills/torusguard/payload/rules/TG-INPUT-007-unvalidated-redirect.md +53 -0
- package/skills/torusguard/payload/rules/TG-INPUT-008-insecure-deserialization.md +52 -0
- package/skills/torusguard/payload/rules/container/TG-CONT-001-root-user-execution.md +50 -50
- package/skills/torusguard/payload/rules/container/TG-CONT-002-docker-socket-mount.md +47 -47
- package/skills/torusguard/payload/rules/container/TG-CONT-003-privileged-container-mode.md +53 -53
- package/skills/torusguard/payload/rules/container/TG-CONT-004-build-arg-secret-exposure.md +43 -43
- package/skills/torusguard/payload/rules/git/TG-GIT-001-historical-secret-in-git-commit.md +44 -44
- package/skills/torusguard/payload/rules/git/TG-GIT-002-plaintext-credentials-in-git-config.md +41 -41
- package/skills/torusguard/payload/rules/git/TG-GIT-003-sensitive-tracked-file-gitignore-breach.md +40 -40
- package/skills/torusguard/payload/rules/rag/TG-RAG-001-untrusted-rag-context-injection.md +72 -72
- package/skills/torusguard/payload/rules/rag/TG-RAG-002-autonomous-llm-tool-unsandboxed-call.md +51 -51
- package/skills/torusguard/payload/rules/rag/TG-RAG-003-unpartitioned-vector-tenant-lookup.md +51 -51
- package/skills/torusguard/payload/rules/redos/TG-REDOS-001-catastrophic-exponential-backtracking.md +46 -46
- package/skills/torusguard/payload/rules/redos/TG-REDOS-002-unbounded-nested-quantifier.md +43 -43
- package/skills/torusguard/payload/scripts/audit_runner.py +108 -10
- package/skills/torusguard/payload/scripts/deliberation_tournament.py +127 -0
- package/skills/torusguard/payload/scripts/finding_scorer.py +43 -13
- package/skills/torusguard/payload/scripts/reachability_analyzer.py +164 -0
- package/skills/torusguard/payload/scripts/stride_generator.py +196 -0
- package/skills/torusguard/payload/skills/torusguard/SKILL.md +6 -2
- package/skills/torusguard/payload/skills/torusguard/bootstrap.py +3 -3
- package/skills/torusguard/payload/skills/torusguard-ai-guard/SKILL.md +95 -95
- package/skills/torusguard/payload/skills/torusguard-audit/SKILL.md +109 -84
- package/skills/torusguard/payload/skills/torusguard-container/SKILL.md +94 -94
- package/skills/torusguard/payload/skills/torusguard-git-mine/SKILL.md +92 -92
- package/skills/torusguard/payload/skills/torusguard-ocr-scan/SKILL.md +94 -94
- package/skills/torusguard/payload/skills/torusguard-redos/SKILL.md +91 -91
- package/skills/torusguard/payload/skills/torusguard-review/SKILL.md +27 -0
- package/skills/torusguard/payload/skills/torusguard-threatmodel/SKILL.md +27 -0
- package/skills/torusguard/payload/workflows/ai-guard.md +31 -31
- package/skills/torusguard/payload/workflows/audit.md +21 -17
- package/skills/torusguard/payload/workflows/container.md +29 -29
- package/skills/torusguard/payload/workflows/git-mine.md +25 -25
- package/skills/torusguard/payload/workflows/ocr-scan.md +25 -25
- package/skills/torusguard/payload/workflows/redos.md +27 -27
- package/skills/torusguard/payload/workflows/review.md +11 -0
- package/skills/torusguard/payload/workflows/threatmodel.md +9 -0
- package/skills/torusguard/payload/workflows/torusguard-audit.md +35 -55
- package/skills/torusguard/references/csharp-security.md +41 -41
- package/skills/torusguard/references/go-security.md +41 -41
- package/skills/torusguard/references/java-security.md +40 -40
- package/skills/torusguard/references/polyglot-security-matrix.md +25 -25
- package/skills/torusguard/references/rust-security.md +40 -40
- package/skills/torusguard-audit/SKILL.md +107 -83
- package/skills/torusguard-review/SKILL.md +27 -0
- package/skills/torusguard-threatmodel/SKILL.md +27 -0
|
@@ -1,55 +1,47 @@
|
|
|
1
1
|
---
|
|
2
|
-
description:
|
|
3
|
-
tools: Read, Grep, Glob, Bash, Write
|
|
4
|
-
version:
|
|
2
|
+
description: Taint-aware static security AST scanning, cross-file interprocedural dataflow, 86+ rules across 22 families, and 7-signal calibrated confidence scoring.
|
|
3
|
+
tools: Read, Grep, Glob, Bash, Write, run_command
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
agent: auditor
|
|
6
6
|
lifecycle-phase: Phase 2 (Static Audit & Clustering)
|
|
7
7
|
required-skills:
|
|
8
8
|
- torusguard-audit
|
|
9
9
|
scripts-binding:
|
|
10
10
|
- .torusguard/scripts/audit_runner.py
|
|
11
|
-
- .torusguard/scripts/report_sync.py
|
|
12
|
-
- .torusguard/scripts/run_manager.py
|
|
13
11
|
- .torusguard/scripts/finding_scorer.py
|
|
12
|
+
- .torusguard/core/cross_file_taint.py
|
|
13
|
+
- .torusguard/core/confidence.py
|
|
14
|
+
- .torusguard/core/incremental.py
|
|
14
15
|
---
|
|
15
16
|
|
|
16
|
-
# /torusguard audit — Static Security Code Scan & Clustering
|
|
17
|
+
# /torusguard audit — Deep Taint-Aware Static Security Code Scan & Clustering
|
|
17
18
|
|
|
18
19
|
$ARGUMENTS
|
|
19
20
|
|
|
20
21
|
---
|
|
21
22
|
|
|
22
23
|
## Objective
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
Supported CLI flags:
|
|
26
|
-
- `npx torusguard audit [--target <dir>]` : Specify project root directory
|
|
27
|
-
- `npx torusguard audit --watch` / `-w` : Continuous watch mode, re-scanning on file change
|
|
28
|
-
- `npx torusguard audit --sarif` : Automatically export OASIS SARIF v2.1.0 log
|
|
29
|
-
- `npx torusguard audit --severity <critical|high|medium|low>` : Floor filter for findings
|
|
24
|
+
Execute deep taint-aware static AST analysis across polyglot project files, evaluate code against 86+ canonical security rules across 22 families, trace interprocedural source-to-sink dataflows, assign stable line-shift invariant fingerprints, cluster architectural root causes, synchronize findings with `security_report.md`, and score findings with auditable 7-signal evidence-chain confidence ratings.
|
|
30
25
|
|
|
31
26
|
---
|
|
32
27
|
|
|
33
|
-
##
|
|
28
|
+
## Tri-Mode Execution
|
|
34
29
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
5. **Syntax Check:** Check for syntax errors before parsing ASTs.
|
|
30
|
+
| Mode | Command / Tool | Execution Method |
|
|
31
|
+
| :--- | :--- | :--- |
|
|
32
|
+
| **Mode A: Terminal CLI** | `torusguard audit [--incremental] [--watch] [--json]` | Shell execution of TorusGuard audit engine. |
|
|
33
|
+
| **Mode B: AI Chat Slash** | `/torusguard audit` | Conversational guided audit with bounded context inspection. |
|
|
34
|
+
| **Mode C: Native MCP Tool** | `torusguard_audit` | Autonomous agent tool invocation via stdio JSON-RPC. |
|
|
41
35
|
|
|
42
36
|
---
|
|
43
37
|
|
|
44
|
-
##
|
|
38
|
+
## Mandatory Pre-Flight Context Inspection
|
|
45
39
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
| Live endpoint or runtime probing | Run `/torusguard web-validate` |
|
|
52
|
-
| Differential check after patch | Run `/torusguard recheck` |
|
|
40
|
+
Inspect workspace prerequisites before launching static audit:
|
|
41
|
+
1. **Init State (`torusguard.json`):** Assert repository is initialized or run `torusguard init`.
|
|
42
|
+
2. **Active Rules (`rules/`):** Confirm rule definitions exist across the 22 architectural families.
|
|
43
|
+
3. **Exclusions:** Assert `node_modules/`, `.venv/`, `dist/`, `.git/` are skipped.
|
|
44
|
+
4. **Syntax Check:** Check for syntax errors before parsing ASTs.
|
|
53
45
|
|
|
54
46
|
---
|
|
55
47
|
|
|
@@ -57,31 +49,19 @@ Inspect workspace prerequisites before launching static audit:
|
|
|
57
49
|
- Audit discoveries automatically synchronize to `security_report.md` at workspace root.
|
|
58
50
|
- Findings transition into `OPEN 🔴` status with stable invariant fingerprints.
|
|
59
51
|
|
|
60
|
-
## Execution Steps
|
|
61
|
-
|
|
62
|
-
1. **Allocate Run Folder:** Run `python .torusguard/scripts/run_manager.py create audit`.
|
|
63
|
-
2. **Scan Codebase ASTs:** Match active rules against source trees.
|
|
64
|
-
3. **Compute Stable Fingerprints:** Hash AST context to produce stable IDs.
|
|
65
|
-
4. **Cluster Root Causes:** Group findings sharing identical sinks.
|
|
66
|
-
5. **Score Confidence (0–100):** Run `python .torusguard/scripts/finding_scorer.py --run <run_dir>`.
|
|
67
|
-
6. **Emit Artifacts:** Write `findings.md`, `findings.json`, and `summary.md`.
|
|
68
|
-
|
|
69
52
|
---
|
|
70
53
|
|
|
71
|
-
##
|
|
72
|
-
|
|
73
|
-
- **Zero Rules Active:** Re-run `/torusguard init` to activate rules.
|
|
74
|
-
- **AST Parse Error:** Log syntax error on malformed file, skip, and continue.
|
|
75
|
-
- **Scorer Failure:** Ensure Python 3.10+; verify finding JSON structure.
|
|
76
|
-
- **Halt Trigger:** Abort if run folder cannot be allocated or disk write fails.
|
|
77
|
-
|
|
78
|
-
---
|
|
79
|
-
|
|
80
|
-
## Hallucination Guard
|
|
54
|
+
## Execution Steps
|
|
81
55
|
|
|
82
|
-
|
|
83
|
-
-
|
|
84
|
-
-
|
|
56
|
+
1. **Launch Audit Scan:**
|
|
57
|
+
- **Mode A (CLI):** Run `torusguard audit` (or `python .torusguard/scripts/audit_runner.py`). Use `--incremental` for fast diffs.
|
|
58
|
+
- **Mode B (Chat):** Parse AST sinks and trace sources to sinks using `core.taint_graph` and bounded context windows.
|
|
59
|
+
- **Mode C (MCP):** Call `torusguard_audit` with `{"target": "."}`.
|
|
60
|
+
2. **Scan Codebase ASTs:** Match 86+ canonical rules across 22 families against source trees.
|
|
61
|
+
3. **Trace Taint Dataflows:** Follow untrusted inputs from sources to dangerous sinks across module boundaries.
|
|
62
|
+
4. **Compute Stable Fingerprints:** Hash AST context to produce stable line-shift invariant IDs (`TG-XXX-<hash12>`).
|
|
63
|
+
5. **Cluster Root Causes:** Group findings into the 22 canonical architectural root causes.
|
|
64
|
+
6. **Synchronize Ground Truth:** Update `security_report.md` at workspace root.
|
|
85
65
|
|
|
86
66
|
---
|
|
87
67
|
|
|
@@ -89,12 +69,12 @@ Inspect workspace prerequisites before launching static audit:
|
|
|
89
69
|
|
|
90
70
|
```markdown
|
|
91
71
|
### 🔎 TorusGuard Static Audit Results
|
|
92
|
-
- **
|
|
93
|
-
- **
|
|
72
|
+
- **Files Scanned:** [Count] source files ([Changed] changed)
|
|
73
|
+
- **Taint Paths Confirmed:** [Count] verified dataflows
|
|
94
74
|
- **Total Findings:** [Count] ([Critical] Critical, [High] High)
|
|
95
75
|
- **Root Cause Clusters:** [Count] architectural issues
|
|
96
|
-
- **Confidence:** [Score]/100
|
|
97
|
-
- **
|
|
76
|
+
- **Confidence:** [Score]/100 (Evidence-Chain Calibrated)
|
|
77
|
+
- **Living Report:** `security_report.md`
|
|
98
78
|
```
|
|
99
79
|
|
|
100
80
|
---
|
|
@@ -102,4 +82,4 @@ Inspect workspace prerequisites before launching static audit:
|
|
|
102
82
|
## Next Steps
|
|
103
83
|
|
|
104
84
|
1. Run `/torusguard verify` to validate exploitability and review evidence.
|
|
105
|
-
2. Run `/torusguard harden` to generate minimal surgical remediation plans.
|
|
85
|
+
2. Run `/torusguard harden` to generate minimal surgical remediation plans conforming to the Ponytail protocol (<= 35 additions, <= 25 deletions).
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
# TorusGuard Skill Reference: C# & ASP.NET Core Security
|
|
2
|
-
|
|
3
|
-
> **Loaded When:** A project is identified as a C# / .NET application (`*.csproj`, `*.sln`, ASP.NET Core detected).
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## 🛡️ Key Inspection Areas & Rules
|
|
8
|
-
|
|
9
|
-
### 1. Authentication & Authorization
|
|
10
|
-
* `TG-AUTH-001`: Ensure controllers and endpoints have `[Authorize]` attributes.
|
|
11
|
-
* Prohibit unvetted `[AllowAnonymous]` on sensitive business logic or user data endpoints.
|
|
12
|
-
|
|
13
|
-
### 2. Entity Framework Core & SQL Injection
|
|
14
|
-
* `TG-INPUT-002`: Use LINQ expressions or `FromSqlInterpolated` with interpolated string syntax (EF Core converts parameters automatically).
|
|
15
|
-
* Prohibit raw `FromSqlRaw` with un-parameterized string concatenations.
|
|
16
|
-
* `TG-DB-004`: Configure Global Query Filters (`HasQueryFilter(e => e.TenantId == _currentTenant)`) for multi-tenant safety.
|
|
17
|
-
|
|
18
|
-
### 3. Anti-Forgery & TLS
|
|
19
|
-
* `TG-CSRF-001`: Ensure `[ValidateAntiForgeryToken]` or `[AutoValidateAntiforgeryToken]` is applied to POST/PUT/DELETE actions.
|
|
20
|
-
* Prohibit `DangerousAcceptAnyServerCertificateValidator`.
|
|
21
|
-
|
|
22
|
-
---
|
|
23
|
-
|
|
24
|
-
## 🛠️ Safe Patterns Summary
|
|
25
|
-
|
|
26
|
-
```csharp
|
|
27
|
-
// Safe Entity Framework Parameterized Query
|
|
28
|
-
var user = await context.Users
|
|
29
|
-
.Where(u => u.Id == userId && u.TenantId == currentTenantId)
|
|
30
|
-
.FirstOrDefaultAsync();
|
|
31
|
-
|
|
32
|
-
// Safe Global Query Filter in DbContext
|
|
33
|
-
modelBuilder.Entity<Invoice>()
|
|
34
|
-
.HasQueryFilter(i => i.TenantId == _tenantProvider.GetTenantId());
|
|
35
|
-
|
|
36
|
-
// Safe Controller Security
|
|
37
|
-
[Authorize]
|
|
38
|
-
[ApiController]
|
|
39
|
-
[Route("api/[controller]")]
|
|
40
|
-
public class InvoicesController : ControllerBase { ... }
|
|
41
|
-
```
|
|
1
|
+
# TorusGuard Skill Reference: C# & ASP.NET Core Security
|
|
2
|
+
|
|
3
|
+
> **Loaded When:** A project is identified as a C# / .NET application (`*.csproj`, `*.sln`, ASP.NET Core detected).
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 🛡️ Key Inspection Areas & Rules
|
|
8
|
+
|
|
9
|
+
### 1. Authentication & Authorization
|
|
10
|
+
* `TG-AUTH-001`: Ensure controllers and endpoints have `[Authorize]` attributes.
|
|
11
|
+
* Prohibit unvetted `[AllowAnonymous]` on sensitive business logic or user data endpoints.
|
|
12
|
+
|
|
13
|
+
### 2. Entity Framework Core & SQL Injection
|
|
14
|
+
* `TG-INPUT-002`: Use LINQ expressions or `FromSqlInterpolated` with interpolated string syntax (EF Core converts parameters automatically).
|
|
15
|
+
* Prohibit raw `FromSqlRaw` with un-parameterized string concatenations.
|
|
16
|
+
* `TG-DB-004`: Configure Global Query Filters (`HasQueryFilter(e => e.TenantId == _currentTenant)`) for multi-tenant safety.
|
|
17
|
+
|
|
18
|
+
### 3. Anti-Forgery & TLS
|
|
19
|
+
* `TG-CSRF-001`: Ensure `[ValidateAntiForgeryToken]` or `[AutoValidateAntiforgeryToken]` is applied to POST/PUT/DELETE actions.
|
|
20
|
+
* Prohibit `DangerousAcceptAnyServerCertificateValidator`.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## 🛠️ Safe Patterns Summary
|
|
25
|
+
|
|
26
|
+
```csharp
|
|
27
|
+
// Safe Entity Framework Parameterized Query
|
|
28
|
+
var user = await context.Users
|
|
29
|
+
.Where(u => u.Id == userId && u.TenantId == currentTenantId)
|
|
30
|
+
.FirstOrDefaultAsync();
|
|
31
|
+
|
|
32
|
+
// Safe Global Query Filter in DbContext
|
|
33
|
+
modelBuilder.Entity<Invoice>()
|
|
34
|
+
.HasQueryFilter(i => i.TenantId == _tenantProvider.GetTenantId());
|
|
35
|
+
|
|
36
|
+
// Safe Controller Security
|
|
37
|
+
[Authorize]
|
|
38
|
+
[ApiController]
|
|
39
|
+
[Route("api/[controller]")]
|
|
40
|
+
public class InvoicesController : ControllerBase { ... }
|
|
41
|
+
```
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
# TorusGuard Skill Reference: Go Security
|
|
2
|
-
|
|
3
|
-
> **Loaded When:** A project is identified as a Go application (`go.mod`, `go.sum`, or Go source files detected).
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## 🛡️ Key Inspection Areas & Rules
|
|
8
|
-
|
|
9
|
-
### 1. Database & SQL Injection
|
|
10
|
-
* `TG-INPUT-002`: Ensure raw queries use parameterized placeholders (`?`, `$1`), never `fmt.Sprintf` or string concatenation.
|
|
11
|
-
* `TG-DB-004`: Enforce tenant isolation in GORM queries (`db.Where("tenant_id = ?", tenantID)`).
|
|
12
|
-
|
|
13
|
-
### 2. TLS & Network Security
|
|
14
|
-
* `TG-DIFF-001`: Prohibit `InsecureSkipVerify: true` in `tls.Config`. Always use valid root CA pools.
|
|
15
|
-
* `TG-SSRF-001`: Validate outbound URLs before issuing `http.Get` or `http.Post`.
|
|
16
|
-
|
|
17
|
-
### 3. Concurrency & Goroutine Safety
|
|
18
|
-
* `TG-BIZ-001`: Ensure context cancellation propagation (`ctx.Done()`) to prevent goroutine leaks.
|
|
19
|
-
* Use mutexes or channels to prevent data races on shared state.
|
|
20
|
-
|
|
21
|
-
### 4. Input Validation & Path Traversal
|
|
22
|
-
* `TG-INPUT-006`: Sanitize file paths with `filepath.Clean` and check `strings.HasPrefix(cleanPath, baseDir)`.
|
|
23
|
-
|
|
24
|
-
---
|
|
25
|
-
|
|
26
|
-
## 🛠️ Safe Patterns Summary
|
|
27
|
-
|
|
28
|
-
```go
|
|
29
|
-
// Safe Parameterized Query
|
|
30
|
-
row := db.QueryRowContext(ctx, "SELECT id, email FROM users WHERE id = ? AND tenant_id = ?", userID, tenantID)
|
|
31
|
-
|
|
32
|
-
// Safe GORM Scoping
|
|
33
|
-
var invoice Invoice
|
|
34
|
-
result := db.Where("id = ? AND tenant_id = ?", invoiceID, currentTenantID).First(&invoice)
|
|
35
|
-
|
|
36
|
-
// Safe TLS Client
|
|
37
|
-
tlsConfig := &tls.Config{
|
|
38
|
-
MinVersion: tls.VersionTLS13,
|
|
39
|
-
}
|
|
40
|
-
client := &http.Client{Transport: &http.Transport{TLSClientConfig: tlsConfig}}
|
|
41
|
-
```
|
|
1
|
+
# TorusGuard Skill Reference: Go Security
|
|
2
|
+
|
|
3
|
+
> **Loaded When:** A project is identified as a Go application (`go.mod`, `go.sum`, or Go source files detected).
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 🛡️ Key Inspection Areas & Rules
|
|
8
|
+
|
|
9
|
+
### 1. Database & SQL Injection
|
|
10
|
+
* `TG-INPUT-002`: Ensure raw queries use parameterized placeholders (`?`, `$1`), never `fmt.Sprintf` or string concatenation.
|
|
11
|
+
* `TG-DB-004`: Enforce tenant isolation in GORM queries (`db.Where("tenant_id = ?", tenantID)`).
|
|
12
|
+
|
|
13
|
+
### 2. TLS & Network Security
|
|
14
|
+
* `TG-DIFF-001`: Prohibit `InsecureSkipVerify: true` in `tls.Config`. Always use valid root CA pools.
|
|
15
|
+
* `TG-SSRF-001`: Validate outbound URLs before issuing `http.Get` or `http.Post`.
|
|
16
|
+
|
|
17
|
+
### 3. Concurrency & Goroutine Safety
|
|
18
|
+
* `TG-BIZ-001`: Ensure context cancellation propagation (`ctx.Done()`) to prevent goroutine leaks.
|
|
19
|
+
* Use mutexes or channels to prevent data races on shared state.
|
|
20
|
+
|
|
21
|
+
### 4. Input Validation & Path Traversal
|
|
22
|
+
* `TG-INPUT-006`: Sanitize file paths with `filepath.Clean` and check `strings.HasPrefix(cleanPath, baseDir)`.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## 🛠️ Safe Patterns Summary
|
|
27
|
+
|
|
28
|
+
```go
|
|
29
|
+
// Safe Parameterized Query
|
|
30
|
+
row := db.QueryRowContext(ctx, "SELECT id, email FROM users WHERE id = ? AND tenant_id = ?", userID, tenantID)
|
|
31
|
+
|
|
32
|
+
// Safe GORM Scoping
|
|
33
|
+
var invoice Invoice
|
|
34
|
+
result := db.Where("id = ? AND tenant_id = ?", invoiceID, currentTenantID).First(&invoice)
|
|
35
|
+
|
|
36
|
+
// Safe TLS Client
|
|
37
|
+
tlsConfig := &tls.Config{
|
|
38
|
+
MinVersion: tls.VersionTLS13,
|
|
39
|
+
}
|
|
40
|
+
client := &http.Client{Transport: &http.Transport{TLSClientConfig: tlsConfig}}
|
|
41
|
+
```
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
# TorusGuard Skill Reference: Java & Spring Security
|
|
2
|
-
|
|
3
|
-
> **Loaded When:** A project is identified as a Java/Kotlin application (`pom.xml`, `build.gradle`, Spring Boot detected).
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## 🛡️ Key Inspection Areas & Rules
|
|
8
|
-
|
|
9
|
-
### 1. Spring Security & CSRF
|
|
10
|
-
* `TG-CSRF-001`: Prohibit `.csrf().disable()` or `AbstractHttpConfigurer::disable` on state-changing browser routes.
|
|
11
|
-
* `TG-PLATFORM-001`: Avoid `@CrossOrigin(origins = "*")` with `allowCredentials = "true"`.
|
|
12
|
-
|
|
13
|
-
### 2. JPA & Hibernate SQL Injection
|
|
14
|
-
* `TG-INPUT-002`: Use named parameters (`:param`) or `CriteriaBuilder`. Never concatenate strings into JPQL queries.
|
|
15
|
-
* `TG-DB-004`: Enforce tenant isolation via `@Filter` or explicit where clauses.
|
|
16
|
-
|
|
17
|
-
### 3. Insecure Deserialization & XML
|
|
18
|
-
* Prohibit `ObjectInputStream.readObject()` on untrusted input without look-ahead verification.
|
|
19
|
-
* Disable external entity resolution (`setFeature("http://apache.org/xml/features/disallow-doctype-decl", true)`).
|
|
20
|
-
|
|
21
|
-
---
|
|
22
|
-
|
|
23
|
-
## 🛠️ Safe Patterns Summary
|
|
24
|
-
|
|
25
|
-
```java
|
|
26
|
-
// Safe JPA Query
|
|
27
|
-
@Query("SELECT u FROM User u WHERE u.id = :id AND u.tenantId = :tenantId")
|
|
28
|
-
Optional<User> findByIdAndTenantId(@Param("id") Long id, @Param("tenantId") String tenantId);
|
|
29
|
-
|
|
30
|
-
// Safe Spring Security Configuration
|
|
31
|
-
@Bean
|
|
32
|
-
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
33
|
-
http
|
|
34
|
-
.authorizeHttpRequests(auth -> auth
|
|
35
|
-
.requestMatchers("/public/**").permitAll()
|
|
36
|
-
.anyRequest().authenticated()
|
|
37
|
-
);
|
|
38
|
-
return http.build();
|
|
39
|
-
}
|
|
40
|
-
```
|
|
1
|
+
# TorusGuard Skill Reference: Java & Spring Security
|
|
2
|
+
|
|
3
|
+
> **Loaded When:** A project is identified as a Java/Kotlin application (`pom.xml`, `build.gradle`, Spring Boot detected).
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 🛡️ Key Inspection Areas & Rules
|
|
8
|
+
|
|
9
|
+
### 1. Spring Security & CSRF
|
|
10
|
+
* `TG-CSRF-001`: Prohibit `.csrf().disable()` or `AbstractHttpConfigurer::disable` on state-changing browser routes.
|
|
11
|
+
* `TG-PLATFORM-001`: Avoid `@CrossOrigin(origins = "*")` with `allowCredentials = "true"`.
|
|
12
|
+
|
|
13
|
+
### 2. JPA & Hibernate SQL Injection
|
|
14
|
+
* `TG-INPUT-002`: Use named parameters (`:param`) or `CriteriaBuilder`. Never concatenate strings into JPQL queries.
|
|
15
|
+
* `TG-DB-004`: Enforce tenant isolation via `@Filter` or explicit where clauses.
|
|
16
|
+
|
|
17
|
+
### 3. Insecure Deserialization & XML
|
|
18
|
+
* Prohibit `ObjectInputStream.readObject()` on untrusted input without look-ahead verification.
|
|
19
|
+
* Disable external entity resolution (`setFeature("http://apache.org/xml/features/disallow-doctype-decl", true)`).
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 🛠️ Safe Patterns Summary
|
|
24
|
+
|
|
25
|
+
```java
|
|
26
|
+
// Safe JPA Query
|
|
27
|
+
@Query("SELECT u FROM User u WHERE u.id = :id AND u.tenantId = :tenantId")
|
|
28
|
+
Optional<User> findByIdAndTenantId(@Param("id") Long id, @Param("tenantId") String tenantId);
|
|
29
|
+
|
|
30
|
+
// Safe Spring Security Configuration
|
|
31
|
+
@Bean
|
|
32
|
+
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
33
|
+
http
|
|
34
|
+
.authorizeHttpRequests(auth -> auth
|
|
35
|
+
.requestMatchers("/public/**").permitAll()
|
|
36
|
+
.anyRequest().authenticated()
|
|
37
|
+
);
|
|
38
|
+
return http.build();
|
|
39
|
+
}
|
|
40
|
+
```
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
# TorusGuard Universal Polyglot Security Matrix
|
|
2
|
-
|
|
3
|
-
> **Loaded When:** Any language or framework is detected. Maps universal security invariants across major programming language ecosystems.
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## 🛡️ Cross-Language Invariant Mappings
|
|
8
|
-
|
|
9
|
-
| Rule Family | Python | TypeScript / Node.js | Go | Rust | Java / Kotlin | C# / .NET |
|
|
10
|
-
|---|---|---|---|---|---|---|
|
|
11
|
-
| **TG-SEC (Secrets)** | `os.environ["KEY"]` | `process.env.KEY` | `os.Getenv("KEY")` | `std::env::var("KEY")` | `System.getenv("KEY")` | `Environment.GetEnvironmentVariable()` |
|
|
12
|
-
| **TG-DB (SQL Injection)** | `%s` / ORM bound | `$1` / Prisma / Drizzle | `?` / `$1` / GORM `?` | `sqlx::query!` / Diesel | Named parameters `:param` | `@p0` / `FromSqlInterpolated` |
|
|
13
|
-
| **TG-DB-004 (Tenant Scope)** | `.filter(tenant=...)` | `where: { tenantId }` | `.Where("tenant_id = ?", tid)` | `filter(tenant_id.eq(tid))` | `WHERE e.tenantId = :tid` | `.Where(x => x.TenantId == tid)` |
|
|
14
|
-
| **TG-AUTH (Access Control)** | `@login_required` / Depends | Middleware auth / Guards | Middleware handlers | Tower layer / extractors | `@PreAuthorize` / Spring Sec | `[Authorize]` attributes |
|
|
15
|
-
| **TG-CSRF (Request Forgery)** | CSRF Middleware | SameSite / csurf | Gorilla CSRF | Anti-CSRF token middleware | Spring Security CSRF | `[ValidateAntiForgeryToken]` |
|
|
16
|
-
| **TG-DIFF (Bypass Comments)** | No `# nosec` | No `// nosec` | No `/* nosec */` | No `#![allow(unsafe)]` | No `@SuppressWarnings` | No pragma disable |
|
|
17
|
-
| **TG-DIFF (TLS Verification)** | No `verify=False` | No `rejectUnauthorized:false` | No `InsecureSkipVerify: true` | No `danger_accept_invalid_certs`| No `TrustAllStrategy` | No `DangerousAcceptAny...` |
|
|
18
|
-
|
|
19
|
-
---
|
|
20
|
-
|
|
21
|
-
## 🚀 Polyglot Hardening Rules of Thumb
|
|
22
|
-
|
|
23
|
-
1. **Parameterize Everything:** Never concatenate raw user input into SQL, shell commands, LDAP filters, or template strings, regardless of language.
|
|
24
|
-
2. **Fail Closed on Auth:** Default all endpoints to authenticated; explicitly mark public routes rather than remembering to protect private ones.
|
|
25
|
-
3. **Strict Bounds:** Keep remediation diffs minimal ($\le 35$ additions, $\le 25$ deletions) to ensure auditability across all codebases.
|
|
1
|
+
# TorusGuard Universal Polyglot Security Matrix
|
|
2
|
+
|
|
3
|
+
> **Loaded When:** Any language or framework is detected. Maps universal security invariants across major programming language ecosystems.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 🛡️ Cross-Language Invariant Mappings
|
|
8
|
+
|
|
9
|
+
| Rule Family | Python | TypeScript / Node.js | Go | Rust | Java / Kotlin | C# / .NET |
|
|
10
|
+
|---|---|---|---|---|---|---|
|
|
11
|
+
| **TG-SEC (Secrets)** | `os.environ["KEY"]` | `process.env.KEY` | `os.Getenv("KEY")` | `std::env::var("KEY")` | `System.getenv("KEY")` | `Environment.GetEnvironmentVariable()` |
|
|
12
|
+
| **TG-DB (SQL Injection)** | `%s` / ORM bound | `$1` / Prisma / Drizzle | `?` / `$1` / GORM `?` | `sqlx::query!` / Diesel | Named parameters `:param` | `@p0` / `FromSqlInterpolated` |
|
|
13
|
+
| **TG-DB-004 (Tenant Scope)** | `.filter(tenant=...)` | `where: { tenantId }` | `.Where("tenant_id = ?", tid)` | `filter(tenant_id.eq(tid))` | `WHERE e.tenantId = :tid` | `.Where(x => x.TenantId == tid)` |
|
|
14
|
+
| **TG-AUTH (Access Control)** | `@login_required` / Depends | Middleware auth / Guards | Middleware handlers | Tower layer / extractors | `@PreAuthorize` / Spring Sec | `[Authorize]` attributes |
|
|
15
|
+
| **TG-CSRF (Request Forgery)** | CSRF Middleware | SameSite / csurf | Gorilla CSRF | Anti-CSRF token middleware | Spring Security CSRF | `[ValidateAntiForgeryToken]` |
|
|
16
|
+
| **TG-DIFF (Bypass Comments)** | No `# nosec` | No `// nosec` | No `/* nosec */` | No `#![allow(unsafe)]` | No `@SuppressWarnings` | No pragma disable |
|
|
17
|
+
| **TG-DIFF (TLS Verification)** | No `verify=False` | No `rejectUnauthorized:false` | No `InsecureSkipVerify: true` | No `danger_accept_invalid_certs`| No `TrustAllStrategy` | No `DangerousAcceptAny...` |
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 🚀 Polyglot Hardening Rules of Thumb
|
|
22
|
+
|
|
23
|
+
1. **Parameterize Everything:** Never concatenate raw user input into SQL, shell commands, LDAP filters, or template strings, regardless of language.
|
|
24
|
+
2. **Fail Closed on Auth:** Default all endpoints to authenticated; explicitly mark public routes rather than remembering to protect private ones.
|
|
25
|
+
3. **Strict Bounds:** Keep remediation diffs minimal ($\le 35$ additions, $\le 25$ deletions) to ensure auditability across all codebases.
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
# TorusGuard Skill Reference: Rust Security
|
|
2
|
-
|
|
3
|
-
> **Loaded When:** A project is identified as a Rust application (`Cargo.toml` or `.rs` files detected).
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## 🛡️ Key Inspection Areas & Rules
|
|
8
|
-
|
|
9
|
-
### 1. Memory Safety & Unsafe Blocks
|
|
10
|
-
* `TG-INPUT-003`: Audit and restrict `unsafe { ... }` blocks. Must include a `// SAFETY:` rationale comment.
|
|
11
|
-
* Never disable standard borrow checker lints via `#![allow(unsafe_code)]`.
|
|
12
|
-
|
|
13
|
-
### 2. Database & SQL Queries
|
|
14
|
-
* `TG-INPUT-002`: Use compile-time checked `sqlx::query!` or Diesel query builder methods.
|
|
15
|
-
* `TG-DB-004`: Enforce tenant filtering in queries (`filter(tenant_id.eq(current_tenant_id))`).
|
|
16
|
-
|
|
17
|
-
### 3. Outbound Requests & TLS
|
|
18
|
-
* `TG-DIFF-001`: Prohibit `danger_accept_invalid_certs(true)` in `reqwest::ClientBuilder`.
|
|
19
|
-
* `TG-SSRF-001`: Enforce IP allowlists before dispatching network calls.
|
|
20
|
-
|
|
21
|
-
---
|
|
22
|
-
|
|
23
|
-
## 🛠️ Safe Patterns Summary
|
|
24
|
-
|
|
25
|
-
```rust
|
|
26
|
-
// Safe sqlx Parameterized Query
|
|
27
|
-
let user = sqlx::query_as!(
|
|
28
|
-
User,
|
|
29
|
-
"SELECT id, email FROM users WHERE id = $1 AND tenant_id = $2",
|
|
30
|
-
user_id,
|
|
31
|
-
current_tenant_id
|
|
32
|
-
)
|
|
33
|
-
.fetch_one(&pool)
|
|
34
|
-
.await?;
|
|
35
|
-
|
|
36
|
-
// Safe reqwest Client (Strict TLS)
|
|
37
|
-
let client = reqwest::Client::builder()
|
|
38
|
-
.timeout(std::time::Duration::from_secs(10))
|
|
39
|
-
.build()?;
|
|
40
|
-
```
|
|
1
|
+
# TorusGuard Skill Reference: Rust Security
|
|
2
|
+
|
|
3
|
+
> **Loaded When:** A project is identified as a Rust application (`Cargo.toml` or `.rs` files detected).
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 🛡️ Key Inspection Areas & Rules
|
|
8
|
+
|
|
9
|
+
### 1. Memory Safety & Unsafe Blocks
|
|
10
|
+
* `TG-INPUT-003`: Audit and restrict `unsafe { ... }` blocks. Must include a `// SAFETY:` rationale comment.
|
|
11
|
+
* Never disable standard borrow checker lints via `#![allow(unsafe_code)]`.
|
|
12
|
+
|
|
13
|
+
### 2. Database & SQL Queries
|
|
14
|
+
* `TG-INPUT-002`: Use compile-time checked `sqlx::query!` or Diesel query builder methods.
|
|
15
|
+
* `TG-DB-004`: Enforce tenant filtering in queries (`filter(tenant_id.eq(current_tenant_id))`).
|
|
16
|
+
|
|
17
|
+
### 3. Outbound Requests & TLS
|
|
18
|
+
* `TG-DIFF-001`: Prohibit `danger_accept_invalid_certs(true)` in `reqwest::ClientBuilder`.
|
|
19
|
+
* `TG-SSRF-001`: Enforce IP allowlists before dispatching network calls.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 🛠️ Safe Patterns Summary
|
|
24
|
+
|
|
25
|
+
```rust
|
|
26
|
+
// Safe sqlx Parameterized Query
|
|
27
|
+
let user = sqlx::query_as!(
|
|
28
|
+
User,
|
|
29
|
+
"SELECT id, email FROM users WHERE id = $1 AND tenant_id = $2",
|
|
30
|
+
user_id,
|
|
31
|
+
current_tenant_id
|
|
32
|
+
)
|
|
33
|
+
.fetch_one(&pool)
|
|
34
|
+
.await?;
|
|
35
|
+
|
|
36
|
+
// Safe reqwest Client (Strict TLS)
|
|
37
|
+
let client = reqwest::Client::builder()
|
|
38
|
+
.timeout(std::time::Duration::from_secs(10))
|
|
39
|
+
.build()?;
|
|
40
|
+
```
|