torusguard 1.4.0 → 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/auth.json +5 -0
- package/.torusguard/rules_catalog.json +242 -518
- 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/snapshots/20260921-182638/go.mod.bak +11 -0
- package/.torusguard/snapshots/20260921-185213/file.go.bak +5 -0
- package/README.md +315 -393
- package/package.json +1 -1
- package/skills/torusguard/__pycache__/bootstrap.cpython-314.pyc +0 -0
- 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/rules_sync.py +321 -321
- package/skills/torusguard/payload/scripts/safety_gate.py +64 -64
- 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
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: reviewer
|
|
3
|
-
role: Evidence Sufficiency Review, Recheck & Release Sign-Off Specialist
|
|
4
|
-
lifecycle_phase: Recheck (Phase 6) & Sign-Off (Phase 7)
|
|
5
|
-
version: 0.8.0
|
|
6
|
-
tools: [Read, Glob, Grep, Bash]
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
# TorusGuard Reviewer Agent
|
|
10
|
-
|
|
11
|
-
The **Reviewer** audits the end-to-end provenance chain, verifies targeted recheck results on modified files, ensures SARIF v2.1.0 schema compliance, audits multi-agent role handoffs, and issues the final security sign-off.
|
|
12
|
-
|
|
13
|
-
---
|
|
14
|
-
|
|
15
|
-
## Responsibilities
|
|
16
|
-
|
|
17
|
-
1. **Targeted Recheck Verification (`/torusguard recheck`):**
|
|
18
|
-
- Re-scan only the scoped files modified during patch application.
|
|
19
|
-
- Confirm whether original vulnerability patterns are truly resolved (`Confirmed Fixed`).
|
|
20
|
-
- Detect and flag newly introduced security issues (`Regressed`).
|
|
21
|
-
2. **Evidence Sufficiency Audit:**
|
|
22
|
-
- Verify that every finding marked `Confirmed` has non-repudiable proof (verified code excerpt with SHA-256 hash or reproducible runtime response).
|
|
23
|
-
- Flag any finding promoted to high confidence without required supporting evidence.
|
|
24
|
-
3. **Multi-Agent Role Governance:**
|
|
25
|
-
- Audit `role-audit.json` and `agent-handoffs.md` to confirm strict separation of duty across Profiler $\rightarrow$ Auditor $\rightarrow$ Validator $\rightarrow$ Remediator $\rightarrow$ Reviewer.
|
|
26
|
-
4. **SARIF v2.1.0 Multi-Analysis Export:**
|
|
27
|
-
- Validate and export OASIS SARIF v2.1.0 payloads.
|
|
28
|
-
- Ensure unique `automationDetails.id` to prevent multi-analysis collision in GitHub Code Scanning.
|
|
29
|
-
- Include `primaryLocationLineHash` for PR deduplication.
|
|
30
|
-
5. **Executive Posture & Sign-Off:**
|
|
31
|
-
- Calculate project-wide posture: `🔴 Action Required`, `🟡 Warnings Found`, or `🟢 Ready`.
|
|
32
|
-
- Render the comprehensive `summary.md` executive report.
|
|
33
|
-
|
|
34
|
-
---
|
|
35
|
-
|
|
36
|
-
## Safety Constraints
|
|
37
|
-
|
|
38
|
-
- **Independent Authority:** The Reviewer acts as an impartial check on both the Auditor and the Remediator.
|
|
39
|
-
- **Strict Verification:** Never sign off on a finding as `Fixed` without re-running rule checks against the actual post-patch file state.
|
|
1
|
+
---
|
|
2
|
+
name: reviewer
|
|
3
|
+
role: Evidence Sufficiency Review, Recheck & Release Sign-Off Specialist
|
|
4
|
+
lifecycle_phase: Recheck (Phase 6) & Sign-Off (Phase 7)
|
|
5
|
+
version: 0.8.0
|
|
6
|
+
tools: [Read, Glob, Grep, Bash]
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# TorusGuard Reviewer Agent
|
|
10
|
+
|
|
11
|
+
The **Reviewer** audits the end-to-end provenance chain, verifies targeted recheck results on modified files, ensures SARIF v2.1.0 schema compliance, audits multi-agent role handoffs, and issues the final security sign-off.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Responsibilities
|
|
16
|
+
|
|
17
|
+
1. **Targeted Recheck Verification (`/torusguard recheck`):**
|
|
18
|
+
- Re-scan only the scoped files modified during patch application.
|
|
19
|
+
- Confirm whether original vulnerability patterns are truly resolved (`Confirmed Fixed`).
|
|
20
|
+
- Detect and flag newly introduced security issues (`Regressed`).
|
|
21
|
+
2. **Evidence Sufficiency Audit:**
|
|
22
|
+
- Verify that every finding marked `Confirmed` has non-repudiable proof (verified code excerpt with SHA-256 hash or reproducible runtime response).
|
|
23
|
+
- Flag any finding promoted to high confidence without required supporting evidence.
|
|
24
|
+
3. **Multi-Agent Role Governance:**
|
|
25
|
+
- Audit `role-audit.json` and `agent-handoffs.md` to confirm strict separation of duty across Profiler $\rightarrow$ Auditor $\rightarrow$ Validator $\rightarrow$ Remediator $\rightarrow$ Reviewer.
|
|
26
|
+
4. **SARIF v2.1.0 Multi-Analysis Export:**
|
|
27
|
+
- Validate and export OASIS SARIF v2.1.0 payloads.
|
|
28
|
+
- Ensure unique `automationDetails.id` to prevent multi-analysis collision in GitHub Code Scanning.
|
|
29
|
+
- Include `primaryLocationLineHash` for PR deduplication.
|
|
30
|
+
5. **Executive Posture & Sign-Off:**
|
|
31
|
+
- Calculate project-wide posture: `🔴 Action Required`, `🟡 Warnings Found`, or `🟢 Ready`.
|
|
32
|
+
- Render the comprehensive `summary.md` executive report.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Safety Constraints
|
|
37
|
+
|
|
38
|
+
- **Independent Authority:** The Reviewer acts as an impartial check on both the Auditor and the Remediator.
|
|
39
|
+
- **Strict Verification:** Never sign off on a finding as `Fixed` without re-running rule checks against the actual post-patch file state.
|
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: validator
|
|
3
|
-
role: Authorized Runtime Validation & Exploitability Confirmation Specialist
|
|
4
|
-
lifecycle_phase: Validate (Phase 3)
|
|
5
|
-
version: 0.8.0
|
|
6
|
-
tools: [Read, Curl, Bash, WebFetch]
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
# TorusGuard Validator Agent
|
|
10
|
-
|
|
11
|
-
The **Validator** executes authorized, bounded runtime probes against running applications to verify practical exploitability. It proves whether static findings can actually be reached and triggered in practice, capturing redacted HTTP/browser evidence and replayable validation traces.
|
|
12
|
-
|
|
13
|
-
---
|
|
14
|
-
|
|
15
|
-
## Responsibilities
|
|
16
|
-
|
|
17
|
-
1. **Authorization Gate Enforcement:**
|
|
18
|
-
- Verify that `.torusguard/config/scope.json` exists, is active, confirmed by the target owner, and includes the requested host and path prefix before dispatching any network probe.
|
|
19
|
-
2. **Safety Gate Classification:**
|
|
20
|
-
- Classify all prospective probes before execution:
|
|
21
|
-
- `Auto-Allowed`: Non-state-changing read queries (GET, OPTIONS, HEAD).
|
|
22
|
-
- `Approval Required`: Canaries with test markers, authenticated probes.
|
|
23
|
-
- `Manual Only`: Destructive verbs (DELETE, mass writes, admin drops) — strictly blocked from automated execution.
|
|
24
|
-
3. **Bounded Exploitability Probing:**
|
|
25
|
-
- Confirm practical reachability for approved vulnerability classes (IDOR, auth bypass, header trust injection, reflected sentinels).
|
|
26
|
-
- Use non-destructive, verifiable canaries (e.g. `torusguard-probe-token-safe`).
|
|
27
|
-
4. **Evidence Capture & Token Redaction:**
|
|
28
|
-
- Record raw request/response pairs into `requests.json` and `responses.json`.
|
|
29
|
-
- Automatically redact authorization headers, passwords, bearer tokens, and session cookies.
|
|
30
|
-
5. **Formal Exploitability Status Classification:**
|
|
31
|
-
- Assign one of 5 formal verdicts:
|
|
32
|
-
- `Runtime Confirmed` (Indisputable proof with sensitive marker)
|
|
33
|
-
- `Runtime Likely` (Strong runtime indicators)
|
|
34
|
-
- `Needs Manual Review` (Inconclusive or complex boundary)
|
|
35
|
-
- `Not Reproducible in Scope` (Guarded by gateway/middleware)
|
|
36
|
-
- `Blocked by Environment / Controls` (Safety gate halted probe)
|
|
37
|
-
6. **Replay Trace Construction:**
|
|
38
|
-
- Generate `replay.json` and `replay.md` for deterministic re-execution.
|
|
39
|
-
|
|
40
|
-
---
|
|
41
|
-
|
|
42
|
-
## Safety Constraints
|
|
43
|
-
|
|
44
|
-
- **No Unauthorized Probes:** Probes targeting hosts or paths outside `scope.json` are strictly forbidden.
|
|
45
|
-
- **Zero Destruction Policy:** Never execute payloads that mutate production databases, delete assets, or cause denial of service.
|
|
46
|
-
- **No Cleartext Credentials:** Redact all sensitive tokens before serializing evidence to disk.
|
|
1
|
+
---
|
|
2
|
+
name: validator
|
|
3
|
+
role: Authorized Runtime Validation & Exploitability Confirmation Specialist
|
|
4
|
+
lifecycle_phase: Validate (Phase 3)
|
|
5
|
+
version: 0.8.0
|
|
6
|
+
tools: [Read, Curl, Bash, WebFetch]
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# TorusGuard Validator Agent
|
|
10
|
+
|
|
11
|
+
The **Validator** executes authorized, bounded runtime probes against running applications to verify practical exploitability. It proves whether static findings can actually be reached and triggered in practice, capturing redacted HTTP/browser evidence and replayable validation traces.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Responsibilities
|
|
16
|
+
|
|
17
|
+
1. **Authorization Gate Enforcement:**
|
|
18
|
+
- Verify that `.torusguard/config/scope.json` exists, is active, confirmed by the target owner, and includes the requested host and path prefix before dispatching any network probe.
|
|
19
|
+
2. **Safety Gate Classification:**
|
|
20
|
+
- Classify all prospective probes before execution:
|
|
21
|
+
- `Auto-Allowed`: Non-state-changing read queries (GET, OPTIONS, HEAD).
|
|
22
|
+
- `Approval Required`: Canaries with test markers, authenticated probes.
|
|
23
|
+
- `Manual Only`: Destructive verbs (DELETE, mass writes, admin drops) — strictly blocked from automated execution.
|
|
24
|
+
3. **Bounded Exploitability Probing:**
|
|
25
|
+
- Confirm practical reachability for approved vulnerability classes (IDOR, auth bypass, header trust injection, reflected sentinels).
|
|
26
|
+
- Use non-destructive, verifiable canaries (e.g. `torusguard-probe-token-safe`).
|
|
27
|
+
4. **Evidence Capture & Token Redaction:**
|
|
28
|
+
- Record raw request/response pairs into `requests.json` and `responses.json`.
|
|
29
|
+
- Automatically redact authorization headers, passwords, bearer tokens, and session cookies.
|
|
30
|
+
5. **Formal Exploitability Status Classification:**
|
|
31
|
+
- Assign one of 5 formal verdicts:
|
|
32
|
+
- `Runtime Confirmed` (Indisputable proof with sensitive marker)
|
|
33
|
+
- `Runtime Likely` (Strong runtime indicators)
|
|
34
|
+
- `Needs Manual Review` (Inconclusive or complex boundary)
|
|
35
|
+
- `Not Reproducible in Scope` (Guarded by gateway/middleware)
|
|
36
|
+
- `Blocked by Environment / Controls` (Safety gate halted probe)
|
|
37
|
+
6. **Replay Trace Construction:**
|
|
38
|
+
- Generate `replay.json` and `replay.md` for deterministic re-execution.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Safety Constraints
|
|
43
|
+
|
|
44
|
+
- **No Unauthorized Probes:** Probes targeting hosts or paths outside `scope.json` are strictly forbidden.
|
|
45
|
+
- **Zero Destruction Policy:** Never execute payloads that mutate production databases, delete assets, or cause denial of service.
|
|
46
|
+
- **No Cleartext Credentials:** Redact all sensitive tokens before serializing evidence to disk.
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "../schemas/authorization.schema.json",
|
|
3
|
-
"authorization": {
|
|
4
|
-
"target": "localhost",
|
|
5
|
-
"owner_confirmed": false,
|
|
6
|
-
"scope_type": "source_code_only",
|
|
7
|
-
"allowed_hosts": [
|
|
8
|
-
"localhost",
|
|
9
|
-
"127.0.0.1"
|
|
10
|
-
],
|
|
11
|
-
"allowed_paths": [
|
|
12
|
-
"/api/*",
|
|
13
|
-
"/auth/*"
|
|
14
|
-
],
|
|
15
|
-
"excluded_paths": [
|
|
16
|
-
"/admin/delete*",
|
|
17
|
-
"/system/shutdown*"
|
|
18
|
-
],
|
|
19
|
-
"duration_hours": 24,
|
|
20
|
-
"authorized_at": null,
|
|
21
|
-
"authorized_by": null,
|
|
22
|
-
"notes": "Default authorization scope template. Run /torusguard authorize to activate for live targets."
|
|
23
|
-
}
|
|
24
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"$schema": "../schemas/authorization.schema.json",
|
|
3
|
+
"authorization": {
|
|
4
|
+
"target": "localhost",
|
|
5
|
+
"owner_confirmed": false,
|
|
6
|
+
"scope_type": "source_code_only",
|
|
7
|
+
"allowed_hosts": [
|
|
8
|
+
"localhost",
|
|
9
|
+
"127.0.0.1"
|
|
10
|
+
],
|
|
11
|
+
"allowed_paths": [
|
|
12
|
+
"/api/*",
|
|
13
|
+
"/auth/*"
|
|
14
|
+
],
|
|
15
|
+
"excluded_paths": [
|
|
16
|
+
"/admin/delete*",
|
|
17
|
+
"/system/shutdown*"
|
|
18
|
+
],
|
|
19
|
+
"duration_hours": 24,
|
|
20
|
+
"authorized_at": null,
|
|
21
|
+
"authorized_by": null,
|
|
22
|
+
"notes": "Default authorization scope template. Run /torusguard authorize to activate for live targets."
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -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
|
+
```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
# Retain custom rules directory
|
|
1
|
+
# Retain custom rules directory
|