torusguard 1.4.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.torusguard/.manifest.json +50 -28
- package/.torusguard/auth.json +5 -0
- package/.torusguard/rules/container/TG-CONT-001-root-user-execution.md +50 -0
- package/.torusguard/rules/container/TG-CONT-002-docker-socket-mount.md +47 -0
- package/.torusguard/rules/container/TG-CONT-003-privileged-container-mode.md +53 -0
- package/.torusguard/rules/container/TG-CONT-004-build-arg-secret-exposure.md +43 -0
- package/.torusguard/rules/git/TG-GIT-001-historical-secret-in-git-commit.md +44 -0
- package/.torusguard/rules/git/TG-GIT-002-plaintext-credentials-in-git-config.md +41 -0
- package/.torusguard/rules/git/TG-GIT-003-sensitive-tracked-file-gitignore-breach.md +40 -0
- package/.torusguard/rules/rag/TG-RAG-001-untrusted-rag-context-injection.md +72 -0
- package/.torusguard/rules/rag/TG-RAG-002-autonomous-llm-tool-unsandboxed-call.md +51 -0
- package/.torusguard/rules/rag/TG-RAG-003-unpartitioned-vector-tenant-lookup.md +51 -0
- package/.torusguard/rules/redos/TG-REDOS-001-catastrophic-exponential-backtracking.md +46 -0
- package/.torusguard/rules/redos/TG-REDOS-002-unbounded-nested-quantifier.md +43 -0
- package/.torusguard/rules_catalog.json +338 -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/scripts/manifest_builder.py +1 -1
- package/.torusguard/skills/torusguard/SKILL.md +69 -24
- package/.torusguard/skills/torusguard/bootstrap.py +57 -24
- package/.torusguard/skills/torusguard-ai-guard/SKILL.md +95 -0
- package/.torusguard/skills/torusguard-apply/SKILL.md +60 -34
- package/.torusguard/skills/torusguard-audit/SKILL.md +73 -24
- package/.torusguard/skills/torusguard-authorize/SKILL.md +48 -6
- package/.torusguard/skills/torusguard-container/SKILL.md +94 -0
- package/.torusguard/skills/torusguard-exploit-check/SKILL.md +50 -6
- package/.torusguard/skills/torusguard-full/SKILL.md +62 -19
- package/.torusguard/skills/torusguard-git-mine/SKILL.md +92 -0
- package/.torusguard/skills/torusguard-harden/SKILL.md +81 -50
- package/.torusguard/skills/torusguard-init/SKILL.md +61 -14
- package/.torusguard/skills/torusguard-ocr-scan/SKILL.md +94 -0
- package/.torusguard/skills/torusguard-recheck/SKILL.md +71 -18
- package/.torusguard/skills/torusguard-redos/SKILL.md +91 -0
- package/.torusguard/skills/torusguard-report/SKILL.md +50 -9
- package/.torusguard/skills/torusguard-status/SKILL.md +63 -10
- package/.torusguard/skills/torusguard-verify/SKILL.md +52 -10
- package/.torusguard/skills/torusguard-web-validate/SKILL.md +53 -8
- package/.torusguard/snapshots/20260921-182638/go.mod.bak +11 -0
- package/.torusguard/snapshots/20260921-185213/file.go.bak +5 -0
- package/.torusguard/workflows/ai-guard.md +31 -0
- package/.torusguard/workflows/apply.md +32 -55
- package/.torusguard/workflows/audit.md +28 -46
- package/.torusguard/workflows/authorize.md +27 -50
- package/.torusguard/workflows/container.md +29 -0
- package/.torusguard/workflows/exploit-check.md +28 -50
- package/.torusguard/workflows/git-mine.md +25 -0
- package/.torusguard/workflows/harden.md +29 -48
- package/.torusguard/workflows/init.md +27 -50
- package/.torusguard/workflows/memory.md +18 -23
- package/.torusguard/workflows/ocr-scan.md +25 -0
- package/.torusguard/workflows/recheck.md +28 -46
- package/.torusguard/workflows/redos.md +27 -0
- package/.torusguard/workflows/report.md +33 -52
- package/.torusguard/workflows/status.md +31 -52
- package/.torusguard/workflows/verify.md +29 -49
- package/.torusguard/workflows/web-validate.md +22 -45
- package/README.md +336 -386
- package/package.json +1 -1
- package/skills/torusguard/SKILL.md +71 -24
- package/skills/torusguard/__pycache__/bootstrap.cpython-314.pyc +0 -0
- package/skills/torusguard/bootstrap.py +60 -71
- package/skills/torusguard/payload/.manifest.json +50 -28
- 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/container/TG-CONT-001-root-user-execution.md +50 -0
- package/skills/torusguard/payload/rules/container/TG-CONT-002-docker-socket-mount.md +47 -0
- package/skills/torusguard/payload/rules/container/TG-CONT-003-privileged-container-mode.md +53 -0
- package/skills/torusguard/payload/rules/container/TG-CONT-004-build-arg-secret-exposure.md +43 -0
- package/skills/torusguard/payload/rules/custom/.gitkeep +1 -1
- package/skills/torusguard/payload/rules/custom/README.md +30 -30
- package/skills/torusguard/payload/rules/git/TG-GIT-001-historical-secret-in-git-commit.md +44 -0
- package/skills/torusguard/payload/rules/git/TG-GIT-002-plaintext-credentials-in-git-config.md +41 -0
- package/skills/torusguard/payload/rules/git/TG-GIT-003-sensitive-tracked-file-gitignore-breach.md +40 -0
- package/skills/torusguard/payload/rules/rag/TG-RAG-001-untrusted-rag-context-injection.md +72 -0
- package/skills/torusguard/payload/rules/rag/TG-RAG-002-autonomous-llm-tool-unsandboxed-call.md +51 -0
- package/skills/torusguard/payload/rules/rag/TG-RAG-003-unpartitioned-vector-tenant-lookup.md +51 -0
- package/skills/torusguard/payload/rules/redos/TG-REDOS-001-catastrophic-exponential-backtracking.md +46 -0
- package/skills/torusguard/payload/rules/redos/TG-REDOS-002-unbounded-nested-quantifier.md +43 -0
- package/skills/torusguard/payload/rules_catalog.json +338 -518
- package/skills/torusguard/payload/scripts/__pycache__/term_ui.cpython-314.pyc +0 -0
- package/skills/torusguard/payload/scripts/manifest_builder.py +1 -1
- 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/SKILL.md +69 -24
- package/skills/torusguard/payload/skills/torusguard/bootstrap.py +57 -24
- package/skills/torusguard/payload/skills/torusguard-ai-guard/SKILL.md +95 -0
- package/skills/torusguard/payload/skills/torusguard-apply/SKILL.md +60 -34
- package/skills/torusguard/payload/skills/torusguard-audit/SKILL.md +73 -24
- package/skills/torusguard/payload/skills/torusguard-authorize/SKILL.md +48 -6
- package/skills/torusguard/payload/skills/torusguard-container/SKILL.md +94 -0
- package/skills/torusguard/payload/skills/torusguard-exploit-check/SKILL.md +50 -6
- package/skills/torusguard/payload/skills/torusguard-full/SKILL.md +62 -19
- package/skills/torusguard/payload/skills/torusguard-git-mine/SKILL.md +92 -0
- package/skills/torusguard/payload/skills/torusguard-harden/SKILL.md +81 -50
- package/skills/torusguard/payload/skills/torusguard-init/SKILL.md +61 -14
- package/skills/torusguard/payload/skills/torusguard-ocr-scan/SKILL.md +94 -0
- package/skills/torusguard/payload/skills/torusguard-recheck/SKILL.md +71 -18
- package/skills/torusguard/payload/skills/torusguard-redos/SKILL.md +91 -0
- package/skills/torusguard/payload/skills/torusguard-report/SKILL.md +50 -9
- package/skills/torusguard/payload/skills/torusguard-status/SKILL.md +63 -10
- package/skills/torusguard/payload/skills/torusguard-verify/SKILL.md +52 -10
- package/skills/torusguard/payload/skills/torusguard-web-validate/SKILL.md +53 -8
- package/skills/torusguard/payload/templates/audit-report.template.md +54 -54
- package/skills/torusguard/payload/templates/authorization.template.md +34 -34
- package/skills/torusguard/payload/templates/finding-card.template.md +32 -32
- package/skills/torusguard/payload/templates/remediation-bundle.template.md +35 -35
- package/skills/torusguard/payload/workflows/ai-guard.md +31 -0
- package/skills/torusguard/payload/workflows/apply.md +31 -62
- package/skills/torusguard/payload/workflows/audit.md +27 -51
- package/skills/torusguard/payload/workflows/authorize.md +27 -50
- package/skills/torusguard/payload/workflows/container.md +29 -0
- package/skills/torusguard/payload/workflows/exploit-check.md +28 -50
- package/skills/torusguard/payload/workflows/git-mine.md +25 -0
- package/skills/torusguard/payload/workflows/harden.md +28 -52
- package/skills/torusguard/payload/workflows/init.md +27 -56
- package/skills/torusguard/payload/workflows/memory.md +18 -23
- package/skills/torusguard/payload/workflows/ocr-scan.md +25 -0
- package/skills/torusguard/payload/workflows/recheck.md +28 -46
- package/skills/torusguard/payload/workflows/redos.md +27 -0
- package/skills/torusguard/payload/workflows/report.md +39 -62
- package/skills/torusguard/payload/workflows/status.md +31 -55
- package/skills/torusguard/payload/workflows/verify.md +29 -49
- package/skills/torusguard/payload/workflows/web-validate.md +22 -45
- package/skills/torusguard/references/csharp-security.md +41 -0
- package/skills/torusguard/references/go-security.md +41 -0
- package/skills/torusguard/references/java-security.md +40 -0
- package/skills/torusguard/references/polyglot-security-matrix.md +25 -0
- package/skills/torusguard/references/rust-security.md +40 -0
- package/skills/torusguard-ai-guard/SKILL.md +95 -0
- package/skills/torusguard-apply/SKILL.md +60 -34
- package/skills/torusguard-audit/SKILL.md +73 -24
- package/skills/torusguard-authorize/SKILL.md +48 -6
- package/skills/torusguard-container/SKILL.md +94 -0
- package/skills/torusguard-exploit-check/SKILL.md +50 -6
- package/skills/torusguard-full/SKILL.md +62 -19
- package/skills/torusguard-git-mine/SKILL.md +92 -0
- package/skills/torusguard-harden/SKILL.md +81 -50
- package/skills/torusguard-init/SKILL.md +61 -14
- package/skills/torusguard-ocr-scan/SKILL.md +94 -0
- package/skills/torusguard-recheck/SKILL.md +71 -18
- package/skills/torusguard-redos/SKILL.md +91 -0
- package/skills/torusguard-report/SKILL.md +50 -9
- package/skills/torusguard-status/SKILL.md +63 -10
- package/skills/torusguard-verify/SKILL.md +52 -10
- package/skills/torusguard-web-validate/SKILL.md +53 -8
|
@@ -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
|
+
```
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# TG-CONT-001: Root User Execution in Container
|
|
2
|
+
|
|
3
|
+
## Severity
|
|
4
|
+
High. Running container processes as root increases the blast radius of any remote code execution (RCE) flaw, enabling container breakout and host compromise.
|
|
5
|
+
|
|
6
|
+
## Applies To
|
|
7
|
+
- `Dockerfile`, `Dockerfile.*`, `Containerfile`
|
|
8
|
+
- Docker Compose (`docker-compose.yml`, `compose.yaml`)
|
|
9
|
+
- Kubernetes PodSpecs
|
|
10
|
+
|
|
11
|
+
## Why It Matters
|
|
12
|
+
By default, Docker executes container entrypoints as the `root` user (UID 0). If an application vulnerability (e.g., path traversal, command injection, or memory corruption) is exploited, the attacker immediately possesses root privileges within the container, facilitating kernel exploits, namespace escapes, and host file access.
|
|
13
|
+
|
|
14
|
+
## What TorusGuard Looks For
|
|
15
|
+
1. Dockerfiles lacking an explicit non-root `USER <user>` directive.
|
|
16
|
+
2. Explicit `USER root` or `USER 0` declarations without dropping privileges.
|
|
17
|
+
3. Compose services declaring `user: "0"` or `user: "root"`.
|
|
18
|
+
|
|
19
|
+
## Unsafe Example
|
|
20
|
+
```dockerfile
|
|
21
|
+
# UNSAFE: No USER declared; runs as root
|
|
22
|
+
FROM node:20-alpine
|
|
23
|
+
WORKDIR /app
|
|
24
|
+
COPY package*.json ./
|
|
25
|
+
RUN npm install
|
|
26
|
+
COPY . .
|
|
27
|
+
CMD ["node", "server.js"]
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Safe Example
|
|
31
|
+
```dockerfile
|
|
32
|
+
# SAFE: Dedicated unprivileged non-root user
|
|
33
|
+
FROM node:20-alpine
|
|
34
|
+
WORKDIR /app
|
|
35
|
+
COPY package*.json ./
|
|
36
|
+
RUN npm install
|
|
37
|
+
COPY . .
|
|
38
|
+
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
|
|
39
|
+
USER appuser
|
|
40
|
+
CMD ["node", "server.js"]
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Remediation
|
|
44
|
+
1. Declare a non-privileged user and group (`USER appuser` or `USER 10001:10001`).
|
|
45
|
+
2. Ensure file permissions allow the non-root user to read necessary application files.
|
|
46
|
+
3. In Compose files, set `user: "10001:10001"`.
|
|
47
|
+
|
|
48
|
+
## Related Rules
|
|
49
|
+
- `TG-CONT-002`: Dangerous Docker Socket Mount
|
|
50
|
+
- `TG-CONT-003`: Privileged Container Mode
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# TG-CONT-002: Dangerous Docker Socket Mount
|
|
2
|
+
|
|
3
|
+
## Severity
|
|
4
|
+
Critical. Mounting `/var/run/docker.sock` grants the container full root control over the host Docker daemon, enabling trivial container breakout and host root takeover.
|
|
5
|
+
|
|
6
|
+
## Applies To
|
|
7
|
+
- `docker-compose.yml`, `docker-compose.yaml`, `compose.yml`, `compose.yaml`
|
|
8
|
+
- Kubernetes PodSpecs, Helm charts, Docker run scripts
|
|
9
|
+
|
|
10
|
+
## Why It Matters
|
|
11
|
+
The Docker UNIX socket (`/var/run/docker.sock`) is the management API for the Docker daemon. Any process that can communicate with this socket can issue API calls to spawn new containers with host root filesystem mounts (`-v /:/host`), inspect all container secrets, and execute code directly on the host machine.
|
|
12
|
+
|
|
13
|
+
## What TorusGuard Looks For
|
|
14
|
+
1. Volume bindings referencing `/var/run/docker.sock:/var/run/docker.sock`.
|
|
15
|
+
2. Mounting the Docker socket in read-write or read-only mode without a hardening proxy.
|
|
16
|
+
|
|
17
|
+
## Unsafe Example
|
|
18
|
+
```yaml
|
|
19
|
+
# UNSAFE: Exposes host Docker daemon to the container
|
|
20
|
+
version: '3.8'
|
|
21
|
+
services:
|
|
22
|
+
app:
|
|
23
|
+
image: my-app:latest
|
|
24
|
+
volumes:
|
|
25
|
+
- /var/run/docker.sock:/var/run/docker.sock
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Safe Example
|
|
29
|
+
```yaml
|
|
30
|
+
# SAFE: Remove Docker socket mount; use dedicated APIs or rootless sidecars
|
|
31
|
+
version: '3.8'
|
|
32
|
+
services:
|
|
33
|
+
app:
|
|
34
|
+
image: my-app:latest
|
|
35
|
+
volumes:
|
|
36
|
+
- app-data:/data
|
|
37
|
+
volumes:
|
|
38
|
+
app-data:
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Remediation
|
|
42
|
+
1. Remove `/var/run/docker.sock` volume bindings from application containers.
|
|
43
|
+
2. If Docker commands are required, use unprivileged rootless container tooling (e.g., Kaniko for image builds) or a restricted Docker socket proxy that denies container-creation privileges.
|
|
44
|
+
|
|
45
|
+
## Related Rules
|
|
46
|
+
- `TG-CONT-001`: Root User Execution in Container
|
|
47
|
+
- `TG-CONT-003`: Privileged Container Mode
|