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,64 +1,64 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""
|
|
3
|
-
TorusGuard Runtime Safety Gate Evaluator
|
|
4
|
-
Evaluates prospective HTTP/browser validation probes against non-destruction policies.
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
import sys
|
|
8
|
-
import json
|
|
9
|
-
import argparse
|
|
10
|
-
from typing import Dict, Any, Tuple
|
|
11
|
-
|
|
12
|
-
def evaluate_safety_gate(method: str, path: str, body: str = "") -> Tuple[str, str]:
|
|
13
|
-
"""
|
|
14
|
-
Returns (decision, rationale)
|
|
15
|
-
Decisions:
|
|
16
|
-
- Auto-Allowed
|
|
17
|
-
- Approval Required
|
|
18
|
-
- Manual Only (Blocked)
|
|
19
|
-
"""
|
|
20
|
-
method_upper = method.upper()
|
|
21
|
-
|
|
22
|
-
# Block destructive verbs
|
|
23
|
-
if method_upper in ("DELETE", "DROP"):
|
|
24
|
-
return "Manual Only", f"Method '{method_upper}' is destructive and strictly blocked from automated runtime validation."
|
|
25
|
-
|
|
26
|
-
# Block sensitive administrative paths
|
|
27
|
-
destructive_keywords = ["/admin/delete", "/shutdown", "/drop-database", "/purge", "/reset-system"]
|
|
28
|
-
for kw in destructive_keywords:
|
|
29
|
-
if kw in path.lower():
|
|
30
|
-
return "Manual Only", f"Path '{path}' targets destructive administrative endpoint '{kw}'."
|
|
31
|
-
|
|
32
|
-
# Safe read methods
|
|
33
|
-
if method_upper in ("GET", "HEAD", "OPTIONS"):
|
|
34
|
-
return "Auto-Allowed", f"Read-only method '{method_upper}' with non-destructive path."
|
|
35
|
-
|
|
36
|
-
# State-changing methods (POST, PUT, PATCH)
|
|
37
|
-
if method_upper in ("POST", "PUT", "PATCH"):
|
|
38
|
-
# Check if safe canary marker exists
|
|
39
|
-
if "tg-canary" in body.lower() or "torusguard" in body.lower():
|
|
40
|
-
return "Approval Required", f"State-changing method '{method_upper}' contains benign TorusGuard test marker; requires user approval."
|
|
41
|
-
else:
|
|
42
|
-
return "Approval Required", f"State-changing method '{method_upper}' requires operator approval before execution."
|
|
43
|
-
|
|
44
|
-
return "Approval Required", f"Unknown probe profile for {method_upper} {path}."
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
def main():
|
|
48
|
-
parser = argparse.ArgumentParser(description="TorusGuard Safety Gate Evaluator")
|
|
49
|
-
parser.add_argument("--method", "-m", default="GET", help="HTTP Method")
|
|
50
|
-
parser.add_argument("--path", "-p", default="/api/test", help="Endpoint path")
|
|
51
|
-
parser.add_argument("--body", "-b", default="", help="Request payload body")
|
|
52
|
-
parser.add_argument("--json", action="store_true", help="Output JSON")
|
|
53
|
-
args = parser.parse_args()
|
|
54
|
-
|
|
55
|
-
decision, rationale = evaluate_safety_gate(args.method, args.path, args.body)
|
|
56
|
-
|
|
57
|
-
if args.json:
|
|
58
|
-
print(json.dumps({"decision": decision, "rationale": rationale}, indent=2))
|
|
59
|
-
else:
|
|
60
|
-
print(f"Safety Decision: {decision}")
|
|
61
|
-
print(f"Rationale: {rationale}")
|
|
62
|
-
|
|
63
|
-
if __name__ == "__main__":
|
|
64
|
-
main()
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
TorusGuard Runtime Safety Gate Evaluator
|
|
4
|
+
Evaluates prospective HTTP/browser validation probes against non-destruction policies.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import sys
|
|
8
|
+
import json
|
|
9
|
+
import argparse
|
|
10
|
+
from typing import Dict, Any, Tuple
|
|
11
|
+
|
|
12
|
+
def evaluate_safety_gate(method: str, path: str, body: str = "") -> Tuple[str, str]:
|
|
13
|
+
"""
|
|
14
|
+
Returns (decision, rationale)
|
|
15
|
+
Decisions:
|
|
16
|
+
- Auto-Allowed
|
|
17
|
+
- Approval Required
|
|
18
|
+
- Manual Only (Blocked)
|
|
19
|
+
"""
|
|
20
|
+
method_upper = method.upper()
|
|
21
|
+
|
|
22
|
+
# Block destructive verbs
|
|
23
|
+
if method_upper in ("DELETE", "DROP"):
|
|
24
|
+
return "Manual Only", f"Method '{method_upper}' is destructive and strictly blocked from automated runtime validation."
|
|
25
|
+
|
|
26
|
+
# Block sensitive administrative paths
|
|
27
|
+
destructive_keywords = ["/admin/delete", "/shutdown", "/drop-database", "/purge", "/reset-system"]
|
|
28
|
+
for kw in destructive_keywords:
|
|
29
|
+
if kw in path.lower():
|
|
30
|
+
return "Manual Only", f"Path '{path}' targets destructive administrative endpoint '{kw}'."
|
|
31
|
+
|
|
32
|
+
# Safe read methods
|
|
33
|
+
if method_upper in ("GET", "HEAD", "OPTIONS"):
|
|
34
|
+
return "Auto-Allowed", f"Read-only method '{method_upper}' with non-destructive path."
|
|
35
|
+
|
|
36
|
+
# State-changing methods (POST, PUT, PATCH)
|
|
37
|
+
if method_upper in ("POST", "PUT", "PATCH"):
|
|
38
|
+
# Check if safe canary marker exists
|
|
39
|
+
if "tg-canary" in body.lower() or "torusguard" in body.lower():
|
|
40
|
+
return "Approval Required", f"State-changing method '{method_upper}' contains benign TorusGuard test marker; requires user approval."
|
|
41
|
+
else:
|
|
42
|
+
return "Approval Required", f"State-changing method '{method_upper}' requires operator approval before execution."
|
|
43
|
+
|
|
44
|
+
return "Approval Required", f"Unknown probe profile for {method_upper} {path}."
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def main():
|
|
48
|
+
parser = argparse.ArgumentParser(description="TorusGuard Safety Gate Evaluator")
|
|
49
|
+
parser.add_argument("--method", "-m", default="GET", help="HTTP Method")
|
|
50
|
+
parser.add_argument("--path", "-p", default="/api/test", help="Endpoint path")
|
|
51
|
+
parser.add_argument("--body", "-b", default="", help="Request payload body")
|
|
52
|
+
parser.add_argument("--json", action="store_true", help="Output JSON")
|
|
53
|
+
args = parser.parse_args()
|
|
54
|
+
|
|
55
|
+
decision, rationale = evaluate_safety_gate(args.method, args.path, args.body)
|
|
56
|
+
|
|
57
|
+
if args.json:
|
|
58
|
+
print(json.dumps({"decision": decision, "rationale": rationale}, indent=2))
|
|
59
|
+
else:
|
|
60
|
+
print(f"Safety Decision: {decision}")
|
|
61
|
+
print(f"Rationale: {rationale}")
|
|
62
|
+
|
|
63
|
+
if __name__ == "__main__":
|
|
64
|
+
main()
|
|
@@ -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,54 +1,54 @@
|
|
|
1
|
-
# TorusGuard Security Audit & Runtime Verification Report
|
|
2
|
-
|
|
3
|
-
> **TorusGuard Version:** `{{torusguard_version}}`
|
|
4
|
-
> **Target:** `{{target_name}}`
|
|
5
|
-
> **Run ID:** `{{run_id}}`
|
|
6
|
-
> **Timestamp:** `{{timestamp}}`
|
|
7
|
-
|
|
8
|
-
---
|
|
9
|
-
|
|
10
|
-
## Detected Stack
|
|
11
|
-
- **Language:** {{stack_language}}
|
|
12
|
-
- **Framework:** {{stack_framework}}
|
|
13
|
-
- **Data Layer:** {{stack_data_layer}}
|
|
14
|
-
- **Dependency Files:** {{stack_dependency_files}}
|
|
15
|
-
- **Detection Confidence:** {{stack_confidence}}
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
## Executive Posture
|
|
20
|
-
**Posture:** {{posture_indicator}}
|
|
21
|
-
**Average Confidence Score:** `{{avg_confidence_score}}/100`
|
|
22
|
-
|
|
23
|
-
### Finding Summary
|
|
24
|
-
| Severity | Count | Confirmed | Needs Review | Remediated |
|
|
25
|
-
| :--- | :---: | :---: | :---: | :---: |
|
|
26
|
-
| 🔴 **Critical** | {{critical_count}} | {{critical_confirmed}} | {{critical_review}} | {{critical_fixed}} |
|
|
27
|
-
| 🟠 **High** | {{high_count}} | {{high_confirmed}} | {{high_review}} | {{high_fixed}} |
|
|
28
|
-
| 🟡 **Medium** | {{medium_count}} | {{medium_confirmed}} | {{medium_review}} | {{medium_fixed}} |
|
|
29
|
-
| 🔵 **Low** | {{low_count}} | {{low_confirmed}} | {{low_review}} | {{low_fixed}} |
|
|
30
|
-
|
|
31
|
-
---
|
|
32
|
-
|
|
33
|
-
## Root-Cause Clusters
|
|
34
|
-
{{cluster_summary_table}}
|
|
35
|
-
|
|
36
|
-
---
|
|
37
|
-
|
|
38
|
-
## Detailed Findings
|
|
39
|
-
{{finding_cards_section}}
|
|
40
|
-
|
|
41
|
-
---
|
|
42
|
-
|
|
43
|
-
## Governance & Safety Audit Statement
|
|
44
|
-
This execution complied with TorusGuard v0.8.0 governance rules:
|
|
45
|
-
- **Authorization Gate:** {{authorization_status}}
|
|
46
|
-
- **Patch Governance (Ponytail):** Additions $\le 35$, Deletions $\le 25$.
|
|
47
|
-
- **Token Redaction:** All captured authorization headers, bearer tokens, and passwords were redacted.
|
|
48
|
-
|
|
49
|
-
---
|
|
50
|
-
|
|
51
|
-
## Prioritized Next Steps
|
|
52
|
-
1. **Remediate Confirmed Sinks:** Run `/torusguard harden` to package remediation bundles.
|
|
53
|
-
2. **Apply Governed Fixes:** Run `/torusguard apply <bundle_id>` to apply targeted fixes.
|
|
54
|
-
3. **Verify Fixes:** Run `/torusguard recheck` to ensure no regressions exist.
|
|
1
|
+
# TorusGuard Security Audit & Runtime Verification Report
|
|
2
|
+
|
|
3
|
+
> **TorusGuard Version:** `{{torusguard_version}}`
|
|
4
|
+
> **Target:** `{{target_name}}`
|
|
5
|
+
> **Run ID:** `{{run_id}}`
|
|
6
|
+
> **Timestamp:** `{{timestamp}}`
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Detected Stack
|
|
11
|
+
- **Language:** {{stack_language}}
|
|
12
|
+
- **Framework:** {{stack_framework}}
|
|
13
|
+
- **Data Layer:** {{stack_data_layer}}
|
|
14
|
+
- **Dependency Files:** {{stack_dependency_files}}
|
|
15
|
+
- **Detection Confidence:** {{stack_confidence}}
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Executive Posture
|
|
20
|
+
**Posture:** {{posture_indicator}}
|
|
21
|
+
**Average Confidence Score:** `{{avg_confidence_score}}/100`
|
|
22
|
+
|
|
23
|
+
### Finding Summary
|
|
24
|
+
| Severity | Count | Confirmed | Needs Review | Remediated |
|
|
25
|
+
| :--- | :---: | :---: | :---: | :---: |
|
|
26
|
+
| 🔴 **Critical** | {{critical_count}} | {{critical_confirmed}} | {{critical_review}} | {{critical_fixed}} |
|
|
27
|
+
| 🟠 **High** | {{high_count}} | {{high_confirmed}} | {{high_review}} | {{high_fixed}} |
|
|
28
|
+
| 🟡 **Medium** | {{medium_count}} | {{medium_confirmed}} | {{medium_review}} | {{medium_fixed}} |
|
|
29
|
+
| 🔵 **Low** | {{low_count}} | {{low_confirmed}} | {{low_review}} | {{low_fixed}} |
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## Root-Cause Clusters
|
|
34
|
+
{{cluster_summary_table}}
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Detailed Findings
|
|
39
|
+
{{finding_cards_section}}
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Governance & Safety Audit Statement
|
|
44
|
+
This execution complied with TorusGuard v0.8.0 governance rules:
|
|
45
|
+
- **Authorization Gate:** {{authorization_status}}
|
|
46
|
+
- **Patch Governance (Ponytail):** Additions $\le 35$, Deletions $\le 25$.
|
|
47
|
+
- **Token Redaction:** All captured authorization headers, bearer tokens, and passwords were redacted.
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Prioritized Next Steps
|
|
52
|
+
1. **Remediate Confirmed Sinks:** Run `/torusguard harden` to package remediation bundles.
|
|
53
|
+
2. **Apply Governed Fixes:** Run `/torusguard apply <bundle_id>` to apply targeted fixes.
|
|
54
|
+
3. **Verify Fixes:** Run `/torusguard recheck` to ensure no regressions exist.
|