torusguard 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.torusguard/.manifest.json +95 -0
- package/.torusguard/ARCHITECTURE.md +168 -0
- package/.torusguard/TORUSGUARD.md +145 -0
- package/.torusguard/agents/auditor.md +41 -0
- package/.torusguard/agents/profiler.md +49 -0
- package/.torusguard/agents/remediator.md +41 -0
- package/.torusguard/agents/reviewer.md +39 -0
- package/.torusguard/agents/validator.md +46 -0
- package/.torusguard/config/scope.json +24 -0
- package/.torusguard/config/slash-commands.json +102 -0
- package/.torusguard/config/torusguard.json +30 -0
- package/.torusguard/references/django-security.md +43 -0
- package/.torusguard/references/drf-security.md +20 -0
- package/.torusguard/references/express-security.md +103 -0
- package/.torusguard/references/fastapi-security.md +20 -0
- package/.torusguard/references/firebase-security.md +78 -0
- package/.torusguard/references/flask-security.md +20 -0
- package/.torusguard/references/nextjs-security.md +96 -0
- package/.torusguard/references/react-vite-security.md +97 -0
- package/.torusguard/references/sqlalchemy-security.md +16 -0
- package/.torusguard/references/supabase-security.md +84 -0
- package/.torusguard/rules/README.md +62 -0
- package/.torusguard/rules/TORUSGUARD.md +145 -0
- package/.torusguard/rules/active/.gitkeep +0 -0
- package/.torusguard/rules/active/TG-DIFF-001.md +20 -0
- package/.torusguard/rules/active/TG-DIFF-002.md +20 -0
- package/.torusguard/rules/active/TG-DIFF-003.md +19 -0
- package/.torusguard/runs/.gitkeep +0 -0
- package/.torusguard/schemas/authorization.schema.json +81 -0
- package/.torusguard/schemas/confidence.schema.json +72 -0
- package/.torusguard/schemas/evidence.schema.json +66 -0
- package/.torusguard/schemas/finding.schema.json +164 -0
- package/.torusguard/schemas/provenance.schema.json +46 -0
- package/.torusguard/schemas/remediation.schema.json +59 -0
- package/.torusguard/schemas/retest.schema.json +53 -0
- package/.torusguard/schemas/runtime-evidence.schema.json +72 -0
- package/.torusguard/scripts/__pycache__/diff_guard.cpython-311.pyc +0 -0
- package/.torusguard/scripts/__pycache__/monorepo_detector.cpython-311.pyc +0 -0
- package/.torusguard/scripts/diff_guard.py +171 -0
- package/.torusguard/scripts/finding_scorer.py +86 -0
- package/.torusguard/scripts/manifest_builder.py +130 -0
- package/.torusguard/scripts/monorepo_detector.py +164 -0
- package/.torusguard/scripts/run_manager.py +89 -0
- package/.torusguard/scripts/safety_gate.py +64 -0
- package/.torusguard/scripts/sarif_exporter.py +116 -0
- package/.torusguard/scripts/stack_detect.py +152 -0
- package/.torusguard/skills/torusguard/SKILL.md +37 -0
- package/.torusguard/skills/torusguard/bootstrap.py +158 -0
- package/.torusguard/skills/torusguard/references/auth-and-sessions.md +56 -0
- package/.torusguard/skills/torusguard/references/business-logic-and-abuse.md +23 -0
- package/.torusguard/skills/torusguard/references/cache-and-sensitive-responses.md +10 -0
- package/.torusguard/skills/torusguard/references/client-code-exposure.md +55 -0
- package/.torusguard/skills/torusguard/references/csrf-and-cross-origin.md +11 -0
- package/.torusguard/skills/torusguard/references/dependency-and-supply-chain.md +22 -0
- package/.torusguard/skills/torusguard/references/django-security.md +43 -0
- package/.torusguard/skills/torusguard/references/drf-security.md +20 -0
- package/.torusguard/skills/torusguard/references/fastapi-security.md +20 -0
- package/.torusguard/skills/torusguard/references/flask-security.md +20 -0
- package/.torusguard/skills/torusguard/references/frontend-no-db.md +53 -0
- package/.torusguard/skills/torusguard/references/graphql-security.md +12 -0
- package/.torusguard/skills/torusguard/references/input-and-injection.md +51 -0
- package/.torusguard/skills/torusguard/references/mass-assignment-and-property-auth.md +22 -0
- package/.torusguard/skills/torusguard/references/platform-hardening.md +56 -0
- package/.torusguard/skills/torusguard/references/python-dependencies.md +16 -0
- package/.torusguard/skills/torusguard/references/python-security-overview.md +12 -0
- package/.torusguard/skills/torusguard/references/rate-limit-and-abuse.md +57 -0
- package/.torusguard/skills/torusguard/references/secrets-and-config.md +64 -0
- package/.torusguard/skills/torusguard/references/sqlalchemy-security.md +16 -0
- package/.torusguard/skills/torusguard/references/ssrf-and-outbound-requests.md +46 -0
- package/.torusguard/skills/torusguard/references/webhook-security.md +15 -0
- package/.torusguard/skills/torusguard/references/websocket-security.md +12 -0
- package/.torusguard/skills/torusguard-apply/SKILL.md +46 -0
- package/.torusguard/skills/torusguard-audit/SKILL.md +70 -0
- package/.torusguard/skills/torusguard-authorize/SKILL.md +47 -0
- package/.torusguard/skills/torusguard-exploit-check/SKILL.md +64 -0
- package/.torusguard/skills/torusguard-full/SKILL.md +70 -0
- package/.torusguard/skills/torusguard-harden/SKILL.md +63 -0
- package/.torusguard/skills/torusguard-init/SKILL.md +52 -0
- package/.torusguard/skills/torusguard-recheck/SKILL.md +53 -0
- package/.torusguard/skills/torusguard-report/SKILL.md +54 -0
- package/.torusguard/skills/torusguard-status/SKILL.md +42 -0
- package/.torusguard/skills/torusguard-verify/SKILL.md +55 -0
- package/.torusguard/skills/torusguard-web-validate/SKILL.md +64 -0
- package/.torusguard/templates/audit-report.template.md +54 -0
- package/.torusguard/templates/authorization.template.md +34 -0
- package/.torusguard/templates/finding-card.template.md +32 -0
- package/.torusguard/templates/remediation-bundle.template.md +35 -0
- package/.torusguard/workflows/apply.md +95 -0
- package/.torusguard/workflows/audit.md +93 -0
- package/.torusguard/workflows/authorize.md +95 -0
- package/.torusguard/workflows/exploit-check.md +97 -0
- package/.torusguard/workflows/harden.md +93 -0
- package/.torusguard/workflows/init.md +95 -0
- package/.torusguard/workflows/recheck.md +95 -0
- package/.torusguard/workflows/report.md +95 -0
- package/.torusguard/workflows/status.md +95 -0
- package/.torusguard/workflows/verify.md +95 -0
- package/.torusguard/workflows/web-validate.md +95 -0
- package/LICENSE +21 -0
- package/README.md +319 -0
- package/bin/torusguard.js +110 -0
- package/install.py +98 -0
- package/package.json +48 -0
- package/skills/torusguard/SKILL.md +41 -0
- package/skills/torusguard/__pycache__/bootstrap.cpython-311.pyc +0 -0
- package/skills/torusguard/bootstrap.py +256 -0
- package/skills/torusguard/payload/.manifest.json +95 -0
- package/skills/torusguard/payload/ARCHITECTURE.md +168 -0
- package/skills/torusguard/payload/TORUSGUARD.md +145 -0
- package/skills/torusguard/payload/agents/auditor.md +41 -0
- package/skills/torusguard/payload/agents/profiler.md +49 -0
- package/skills/torusguard/payload/agents/remediator.md +41 -0
- package/skills/torusguard/payload/agents/reviewer.md +39 -0
- package/skills/torusguard/payload/agents/validator.md +46 -0
- package/skills/torusguard/payload/config/scope.json +24 -0
- package/skills/torusguard/payload/config/slash-commands.json +102 -0
- package/skills/torusguard/payload/config/torusguard.json +30 -0
- package/skills/torusguard/payload/references/django-security.md +43 -0
- package/skills/torusguard/payload/references/drf-security.md +20 -0
- package/skills/torusguard/payload/references/express-security.md +103 -0
- package/skills/torusguard/payload/references/fastapi-security.md +20 -0
- package/skills/torusguard/payload/references/firebase-security.md +78 -0
- package/skills/torusguard/payload/references/flask-security.md +20 -0
- package/skills/torusguard/payload/references/nextjs-security.md +96 -0
- package/skills/torusguard/payload/references/react-vite-security.md +97 -0
- package/skills/torusguard/payload/references/sqlalchemy-security.md +16 -0
- package/skills/torusguard/payload/references/supabase-security.md +84 -0
- package/skills/torusguard/payload/rules/README.md +62 -0
- package/skills/torusguard/payload/rules/TORUSGUARD.md +145 -0
- package/skills/torusguard/payload/rules/active/.gitkeep +0 -0
- package/skills/torusguard/payload/rules/active/TG-DIFF-001.md +20 -0
- package/skills/torusguard/payload/rules/active/TG-DIFF-002.md +20 -0
- package/skills/torusguard/payload/rules/active/TG-DIFF-003.md +19 -0
- package/skills/torusguard/payload/schemas/authorization.schema.json +81 -0
- package/skills/torusguard/payload/schemas/confidence.schema.json +72 -0
- package/skills/torusguard/payload/schemas/evidence.schema.json +66 -0
- package/skills/torusguard/payload/schemas/finding.schema.json +164 -0
- package/skills/torusguard/payload/schemas/provenance.schema.json +46 -0
- package/skills/torusguard/payload/schemas/remediation.schema.json +59 -0
- package/skills/torusguard/payload/schemas/retest.schema.json +53 -0
- package/skills/torusguard/payload/schemas/runtime-evidence.schema.json +72 -0
- package/skills/torusguard/payload/scripts/diff_guard.py +171 -0
- package/skills/torusguard/payload/scripts/finding_scorer.py +86 -0
- package/skills/torusguard/payload/scripts/manifest_builder.py +130 -0
- package/skills/torusguard/payload/scripts/monorepo_detector.py +164 -0
- package/skills/torusguard/payload/scripts/run_manager.py +89 -0
- package/skills/torusguard/payload/scripts/safety_gate.py +64 -0
- package/skills/torusguard/payload/scripts/sarif_exporter.py +116 -0
- package/skills/torusguard/payload/scripts/stack_detect.py +152 -0
- package/skills/torusguard/payload/skills/torusguard/SKILL.md +37 -0
- package/skills/torusguard/payload/skills/torusguard/bootstrap.py +158 -0
- package/skills/torusguard/payload/skills/torusguard/references/auth-and-sessions.md +56 -0
- package/skills/torusguard/payload/skills/torusguard/references/business-logic-and-abuse.md +23 -0
- package/skills/torusguard/payload/skills/torusguard/references/cache-and-sensitive-responses.md +10 -0
- package/skills/torusguard/payload/skills/torusguard/references/client-code-exposure.md +55 -0
- package/skills/torusguard/payload/skills/torusguard/references/csrf-and-cross-origin.md +11 -0
- package/skills/torusguard/payload/skills/torusguard/references/dependency-and-supply-chain.md +22 -0
- package/skills/torusguard/payload/skills/torusguard/references/django-security.md +43 -0
- package/skills/torusguard/payload/skills/torusguard/references/drf-security.md +20 -0
- package/skills/torusguard/payload/skills/torusguard/references/fastapi-security.md +20 -0
- package/skills/torusguard/payload/skills/torusguard/references/flask-security.md +20 -0
- package/skills/torusguard/payload/skills/torusguard/references/frontend-no-db.md +53 -0
- package/skills/torusguard/payload/skills/torusguard/references/graphql-security.md +12 -0
- package/skills/torusguard/payload/skills/torusguard/references/input-and-injection.md +51 -0
- package/skills/torusguard/payload/skills/torusguard/references/mass-assignment-and-property-auth.md +22 -0
- package/skills/torusguard/payload/skills/torusguard/references/platform-hardening.md +56 -0
- package/skills/torusguard/payload/skills/torusguard/references/python-dependencies.md +16 -0
- package/skills/torusguard/payload/skills/torusguard/references/python-security-overview.md +12 -0
- package/skills/torusguard/payload/skills/torusguard/references/rate-limit-and-abuse.md +57 -0
- package/skills/torusguard/payload/skills/torusguard/references/secrets-and-config.md +64 -0
- package/skills/torusguard/payload/skills/torusguard/references/sqlalchemy-security.md +16 -0
- package/skills/torusguard/payload/skills/torusguard/references/ssrf-and-outbound-requests.md +46 -0
- package/skills/torusguard/payload/skills/torusguard/references/webhook-security.md +15 -0
- package/skills/torusguard/payload/skills/torusguard/references/websocket-security.md +12 -0
- package/skills/torusguard/payload/skills/torusguard-apply/SKILL.md +46 -0
- package/skills/torusguard/payload/skills/torusguard-audit/SKILL.md +70 -0
- package/skills/torusguard/payload/skills/torusguard-authorize/SKILL.md +47 -0
- package/skills/torusguard/payload/skills/torusguard-exploit-check/SKILL.md +64 -0
- package/skills/torusguard/payload/skills/torusguard-full/SKILL.md +70 -0
- package/skills/torusguard/payload/skills/torusguard-harden/SKILL.md +63 -0
- package/skills/torusguard/payload/skills/torusguard-init/SKILL.md +52 -0
- package/skills/torusguard/payload/skills/torusguard-recheck/SKILL.md +53 -0
- package/skills/torusguard/payload/skills/torusguard-report/SKILL.md +54 -0
- package/skills/torusguard/payload/skills/torusguard-status/SKILL.md +42 -0
- package/skills/torusguard/payload/skills/torusguard-verify/SKILL.md +55 -0
- package/skills/torusguard/payload/skills/torusguard-web-validate/SKILL.md +64 -0
- package/skills/torusguard/payload/templates/audit-report.template.md +54 -0
- package/skills/torusguard/payload/templates/authorization.template.md +34 -0
- package/skills/torusguard/payload/templates/finding-card.template.md +32 -0
- package/skills/torusguard/payload/templates/remediation-bundle.template.md +35 -0
- package/skills/torusguard/payload/workflows/apply.md +95 -0
- package/skills/torusguard/payload/workflows/audit.md +93 -0
- package/skills/torusguard/payload/workflows/authorize.md +95 -0
- package/skills/torusguard/payload/workflows/exploit-check.md +97 -0
- package/skills/torusguard/payload/workflows/harden.md +93 -0
- package/skills/torusguard/payload/workflows/init.md +95 -0
- package/skills/torusguard/payload/workflows/recheck.md +95 -0
- package/skills/torusguard/payload/workflows/report.md +95 -0
- package/skills/torusguard/payload/workflows/status.md +95 -0
- package/skills/torusguard/payload/workflows/verify.md +95 -0
- package/skills/torusguard/payload/workflows/web-validate.md +95 -0
- package/skills/torusguard/references/auth-and-sessions.md +56 -0
- package/skills/torusguard/references/business-logic-and-abuse.md +23 -0
- package/skills/torusguard/references/cache-and-sensitive-responses.md +10 -0
- package/skills/torusguard/references/client-code-exposure.md +55 -0
- package/skills/torusguard/references/csrf-and-cross-origin.md +11 -0
- package/skills/torusguard/references/dependency-and-supply-chain.md +22 -0
- package/skills/torusguard/references/django-security.md +43 -0
- package/skills/torusguard/references/drf-security.md +20 -0
- package/skills/torusguard/references/fastapi-security.md +20 -0
- package/skills/torusguard/references/flask-security.md +20 -0
- package/skills/torusguard/references/frontend-no-db.md +53 -0
- package/skills/torusguard/references/graphql-security.md +12 -0
- package/skills/torusguard/references/input-and-injection.md +51 -0
- package/skills/torusguard/references/mass-assignment-and-property-auth.md +22 -0
- package/skills/torusguard/references/platform-hardening.md +56 -0
- package/skills/torusguard/references/python-dependencies.md +16 -0
- package/skills/torusguard/references/python-security-overview.md +12 -0
- package/skills/torusguard/references/rate-limit-and-abuse.md +57 -0
- package/skills/torusguard/references/secrets-and-config.md +64 -0
- package/skills/torusguard/references/sqlalchemy-security.md +16 -0
- package/skills/torusguard/references/ssrf-and-outbound-requests.md +46 -0
- package/skills/torusguard/references/webhook-security.md +15 -0
- package/skills/torusguard/references/websocket-security.md +12 -0
- package/skills/torusguard-apply/SKILL.md +46 -0
- package/skills/torusguard-audit/SKILL.md +70 -0
- package/skills/torusguard-authorize/SKILL.md +47 -0
- package/skills/torusguard-exploit-check/SKILL.md +64 -0
- package/skills/torusguard-full/SKILL.md +70 -0
- package/skills/torusguard-harden/SKILL.md +63 -0
- package/skills/torusguard-init/SKILL.md +52 -0
- package/skills/torusguard-recheck/SKILL.md +53 -0
- package/skills/torusguard-report/SKILL.md +54 -0
- package/skills/torusguard-status/SKILL.md +42 -0
- package/skills/torusguard-verify/SKILL.md +55 -0
- package/skills/torusguard-web-validate/SKILL.md +64 -0
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
{
|
|
2
|
+
"commands": [
|
|
3
|
+
{
|
|
4
|
+
"name": "/torusguard init",
|
|
5
|
+
"description": "Initialize TorusGuard in the workspace: detect project stack, activate tailored TG-* rules, and verify SECURITY.md.",
|
|
6
|
+
"usage": "/torusguard init",
|
|
7
|
+
"workflow": ".torusguard/workflows/init.md",
|
|
8
|
+
"agent": "profiler",
|
|
9
|
+
"modifies_code": false
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"name": "/torusguard authorize",
|
|
13
|
+
"description": "Capture target ownership, allowed hosts, permitted endpoints, and write scope.json for runtime validation.",
|
|
14
|
+
"usage": "/torusguard authorize [target_url]",
|
|
15
|
+
"workflow": ".torusguard/workflows/authorize.md",
|
|
16
|
+
"agent": "reviewer",
|
|
17
|
+
"modifies_code": false
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"name": "/torusguard audit",
|
|
21
|
+
"description": "Execute static AST code audit against active rules, assign Stable Fingerprints, cluster findings, and score confidence.",
|
|
22
|
+
"usage": "/torusguard audit [target_dir]",
|
|
23
|
+
"workflow": ".torusguard/workflows/audit.md",
|
|
24
|
+
"agent": "auditor",
|
|
25
|
+
"modifies_code": false
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"name": "/torusguard verify",
|
|
29
|
+
"description": "Validate evidence sufficiency, audit AST source matches, and compute 0–100 confidence score.",
|
|
30
|
+
"usage": "/torusguard verify [finding_id]",
|
|
31
|
+
"workflow": ".torusguard/workflows/verify.md",
|
|
32
|
+
"agent": "validator",
|
|
33
|
+
"modifies_code": false
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"name": "/torusguard web-validate",
|
|
37
|
+
"description": "Dispatch authorized HTTP and API runtime probes with token redaction to test practical reachability.",
|
|
38
|
+
"usage": "/torusguard web-validate [target_url]",
|
|
39
|
+
"workflow": ".torusguard/workflows/web-validate.md",
|
|
40
|
+
"agent": "validator",
|
|
41
|
+
"modifies_code": false,
|
|
42
|
+
"requires_authorization": true
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"name": "/torusguard exploit-check",
|
|
46
|
+
"description": "Execute bounded, safe exploitability confirmation for approved vulnerability classes (SQLi, SSRF, XSS, auth bypass).",
|
|
47
|
+
"usage": "/torusguard exploit-check [target_url]",
|
|
48
|
+
"workflow": ".torusguard/workflows/exploit-check.md",
|
|
49
|
+
"agent": "validator",
|
|
50
|
+
"modifies_code": false,
|
|
51
|
+
"requires_authorization": true
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"name": "/torusguard harden",
|
|
55
|
+
"description": "Generate structured remediation bundles with framework-native before/after diffs enriched by runtime findings.",
|
|
56
|
+
"usage": "/torusguard harden [run_id]",
|
|
57
|
+
"workflow": ".torusguard/workflows/harden.md",
|
|
58
|
+
"agent": "remediator",
|
|
59
|
+
"modifies_code": false
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"name": "/torusguard apply",
|
|
63
|
+
"description": "Apply surgical, governed patches with strict line addition (<=35) and deletion (<=25) boundaries.",
|
|
64
|
+
"usage": "/torusguard apply [bundle_id]",
|
|
65
|
+
"workflow": ".torusguard/workflows/apply.md",
|
|
66
|
+
"agent": "remediator",
|
|
67
|
+
"modifies_code": true
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"name": "/torusguard recheck",
|
|
71
|
+
"description": "Re-scan modified files to verify fix integrity and detect potential regressions.",
|
|
72
|
+
"usage": "/torusguard recheck [run_id]",
|
|
73
|
+
"workflow": ".torusguard/workflows/recheck.md",
|
|
74
|
+
"agent": "reviewer",
|
|
75
|
+
"modifies_code": false
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"name": "/torusguard report",
|
|
79
|
+
"description": "Generate unified Markdown executive report, finding cards, and multi-analysis OASIS SARIF v2.1.0 output.",
|
|
80
|
+
"usage": "/torusguard report [run_id]",
|
|
81
|
+
"workflow": ".torusguard/workflows/report.md",
|
|
82
|
+
"agent": "reviewer",
|
|
83
|
+
"modifies_code": false
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"name": "/torusguard status",
|
|
87
|
+
"description": "Display current security posture, active run history, configuration, and activated rule count.",
|
|
88
|
+
"usage": "/torusguard status",
|
|
89
|
+
"workflow": ".torusguard/workflows/status.md",
|
|
90
|
+
"agent": null,
|
|
91
|
+
"modifies_code": false
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"name": "/torusguard full",
|
|
95
|
+
"description": "Execute the complete 7-stage end-to-end security pipeline: init, authorize, audit, validate, harden, apply, recheck, and report.",
|
|
96
|
+
"usage": "/torusguard full",
|
|
97
|
+
"workflow": "skills/torusguard-full/SKILL.md",
|
|
98
|
+
"agent": null,
|
|
99
|
+
"modifies_code": true
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "../schemas/torusguard-config.schema.json",
|
|
3
|
+
"version": "0.9.2",
|
|
4
|
+
"product": "TorusGuard Security Skill Kit",
|
|
5
|
+
"severity_threshold": "medium",
|
|
6
|
+
"auto_detect_stack": true,
|
|
7
|
+
"runs_dir": ".torusguard/runs",
|
|
8
|
+
"authorization_required_for_runtime": true,
|
|
9
|
+
"sarif_export": true,
|
|
10
|
+
"governance": {
|
|
11
|
+
"max_patch_additions": 35,
|
|
12
|
+
"max_patch_deletions": 25,
|
|
13
|
+
"require_user_approval_for_apply": true,
|
|
14
|
+
"dry_run_sensitive_paths": true
|
|
15
|
+
},
|
|
16
|
+
"runtime_validation": {
|
|
17
|
+
"default_timeout_seconds": 10,
|
|
18
|
+
"max_concurrent_probes": 3,
|
|
19
|
+
"auto_redact_tokens": true,
|
|
20
|
+
"safe_methods_only": true
|
|
21
|
+
},
|
|
22
|
+
"ignored_rules": [],
|
|
23
|
+
"custom_rules_dir": null,
|
|
24
|
+
"report_format": "markdown",
|
|
25
|
+
"detected_stack": {
|
|
26
|
+
"language": "TypeScript",
|
|
27
|
+
"framework": "None",
|
|
28
|
+
"data_layer": "None"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# TorusGuard Skill Reference: Django Security
|
|
2
|
+
|
|
3
|
+
> **Loaded When:** A project is identified as a Django application (`manage.py`, `settings.py`, or `django` dependency detected).
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 🛡️ Key Inspection Areas & Rules
|
|
8
|
+
|
|
9
|
+
### 1. Secrets & Production Configuration
|
|
10
|
+
* `TG-SEC-001`: Verify `SECRET_KEY` is loaded via `os.environ` or a secrets manager, not hardcoded.
|
|
11
|
+
* `TG-PLATFORM-003`: Verify `DEBUG = False` in production configs.
|
|
12
|
+
* `TG-PLATFORM-001`: Ensure `ALLOWED_HOSTS` is restricted to legitimate hostnames.
|
|
13
|
+
|
|
14
|
+
### 2. Authentication & Authorization
|
|
15
|
+
* `TG-AUTH-001`: Ensure protected views use `@login_required` or `LoginRequiredMixin`.
|
|
16
|
+
* `TG-AUTH-007`: Enforce object-level ownership checks (e.g. `get_object_or_404(Model, id=id, user=request.user)`). Avoid unrestricted numeric ID lookups.
|
|
17
|
+
|
|
18
|
+
### 3. Mass Assignment
|
|
19
|
+
* `TG-AUTH-006`: Ensure `ModelForm` definitions specify explicit `fields = [...]` lists instead of `fields = '__all__'`.
|
|
20
|
+
|
|
21
|
+
### 4. Injection & Database Security
|
|
22
|
+
* `TG-INPUT-003`: Ensure `Model.objects.raw()` or `cursor.execute()` uses parameterized inputs (`%s`), never f-strings or `.format()`.
|
|
23
|
+
|
|
24
|
+
### 5. CSRF & Request Security
|
|
25
|
+
* `TG-CSRF-001`: Verify `django.middleware.csrf.CsrfViewMiddleware` is active in `MIDDLEWARE`. Avoid indiscriminate `@csrf_exempt`.
|
|
26
|
+
* `TG-CACHE-001`: Verify sensitive authenticated endpoints use `@never_cache`.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## 🛠️ Safe Patterns Summary
|
|
31
|
+
```python
|
|
32
|
+
# Safe Object Lookup
|
|
33
|
+
item = get_object_or_404(Invoice, id=invoice_id, account=request.user.account)
|
|
34
|
+
|
|
35
|
+
# Safe Form
|
|
36
|
+
class ProfileForm(forms.ModelForm):
|
|
37
|
+
class Meta:
|
|
38
|
+
model = Profile
|
|
39
|
+
fields = ['bio', 'website_url', 'avatar']
|
|
40
|
+
|
|
41
|
+
# Safe Raw SQL (if mandatory)
|
|
42
|
+
cursor.execute("SELECT * FROM reports WHERE account_id = %s", [request.user.account_id])
|
|
43
|
+
```
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# TorusGuard Skill Reference: Django REST Framework (DRF)
|
|
2
|
+
|
|
3
|
+
> **Loaded When:** Project uses `rest_framework` dependencies or imports.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 🛡️ Key Inspection Areas & Rules
|
|
8
|
+
|
|
9
|
+
### 1. Permissions & Endpoint Exposure
|
|
10
|
+
* `TG-AUTH-001`: Inspect `settings.py` for `REST_FRAMEWORK['DEFAULT_PERMISSION_CLASSES']`. If missing or set to `AllowAny`, verify that individual views specify explicit `permission_classes`.
|
|
11
|
+
* `TG-AUTH-007`: In `ModelViewSet` and API views, check if `get_queryset()` returns `Model.objects.all()` without filtering by `request.user` or tenant context.
|
|
12
|
+
|
|
13
|
+
### 2. Serializer Field Whitelists & Mass Assignment
|
|
14
|
+
* `TG-AUTH-006`: Inspect Serializer classes. Flag serializers where `fields = '__all__'` or where administrative/financial fields are not in `read_only_fields`.
|
|
15
|
+
|
|
16
|
+
### 3. Throttling & Rate Limits
|
|
17
|
+
* `TG-RATE-001`: Check authentication endpoints (login, password reset, register, OTP) for throttle classes (`UserRateThrottle`, `ScopedRateThrottle`).
|
|
18
|
+
|
|
19
|
+
### 4. Pagination Caps
|
|
20
|
+
* `TG-RATE-002`: Check custom pagination classes for `max_page_size`. If client-controlled `page_size_query_param` is enabled without a ceiling, flag as unbound resource risk.
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# Express Security Guide
|
|
2
|
+
|
|
3
|
+
## When to use
|
|
4
|
+
|
|
5
|
+
Load during audits of Node.js Express APIs serving web or mobile clients.
|
|
6
|
+
|
|
7
|
+
**Related rules:** TG-INPUT-001, TG-INPUT-002, TG-AUTH-003, TG-AUTH-004, TG-RATE-001, TG-PLATFORM-001 … TG-PLATFORM-004
|
|
8
|
+
|
|
9
|
+
## Checklist
|
|
10
|
+
|
|
11
|
+
- [ ] Helmet or equivalent security headers (TG-PLATFORM-002)
|
|
12
|
+
- [ ] CORS explicit allowlist — never `*` with credentials (TG-PLATFORM-001)
|
|
13
|
+
- [ ] `express.json({ limit: '100kb' })` or appropriate cap (TG-PLATFORM-004)
|
|
14
|
+
- [ ] Zod/Joi validation on every mutating route (TG-INPUT-001)
|
|
15
|
+
- [ ] Parameterized SQL or ORM — no concatenation (TG-INPUT-002)
|
|
16
|
+
- [ ] Rate limits on login, reset, OTP (TG-RATE-001)
|
|
17
|
+
- [ ] Central error handler — generic client messages (TG-PLATFORM-003)
|
|
18
|
+
- [ ] Secure cookie flags for sessions (TG-AUTH-004)
|
|
19
|
+
- [ ] Ownership middleware on resource routes (TG-AUTH-003)
|
|
20
|
+
|
|
21
|
+
## Baseline server setup
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
import express from 'express';
|
|
25
|
+
import helmet from 'helmet';
|
|
26
|
+
import cors from 'cors';
|
|
27
|
+
import rateLimit from 'express-rate-limit';
|
|
28
|
+
|
|
29
|
+
const app = express();
|
|
30
|
+
const allowedOrigins = ['https://app.example.com'];
|
|
31
|
+
|
|
32
|
+
app.use(helmet());
|
|
33
|
+
app.use(cors({
|
|
34
|
+
origin(origin, cb) {
|
|
35
|
+
if (!origin || allowedOrigins.includes(origin)) cb(null, true);
|
|
36
|
+
else cb(new Error('Not allowed by CORS'));
|
|
37
|
+
},
|
|
38
|
+
credentials: true,
|
|
39
|
+
}));
|
|
40
|
+
app.use(express.json({ limit: '100kb' }));
|
|
41
|
+
|
|
42
|
+
const loginLimiter = rateLimit({
|
|
43
|
+
windowMs: 15 * 60 * 1000,
|
|
44
|
+
max: 5,
|
|
45
|
+
standardHeaders: true,
|
|
46
|
+
message: { error: 'Too many attempts' },
|
|
47
|
+
});
|
|
48
|
+
app.post('/api/login', loginLimiter, loginHandler);
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Validation middleware
|
|
52
|
+
|
|
53
|
+
```javascript
|
|
54
|
+
import { z } from 'zod';
|
|
55
|
+
|
|
56
|
+
function validate(schema) {
|
|
57
|
+
return (req, res, next) => {
|
|
58
|
+
const parsed = schema.safeParse({ body: req.body, query: req.query, params: req.params });
|
|
59
|
+
if (!parsed.success) return res.status(400).json({ error: 'Invalid input' });
|
|
60
|
+
req.validated = parsed.data;
|
|
61
|
+
next();
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Ownership middleware
|
|
67
|
+
|
|
68
|
+
```javascript
|
|
69
|
+
async function requireOrderOwner(req, res, next) {
|
|
70
|
+
const order = await db.order.findUnique({ where: { id: req.params.id } });
|
|
71
|
+
if (!order || order.userId !== req.user.id) {
|
|
72
|
+
return res.status(403).json({ error: 'Forbidden' });
|
|
73
|
+
}
|
|
74
|
+
req.order = order;
|
|
75
|
+
next();
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Error handler
|
|
80
|
+
|
|
81
|
+
```javascript
|
|
82
|
+
app.use((err, req, res, next) => {
|
|
83
|
+
console.error({ err, requestId: req.id });
|
|
84
|
+
res.status(err.status || 500).json({
|
|
85
|
+
error: process.env.NODE_ENV === 'production' ? 'Internal server error' : err.message,
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Distributed rate limiting
|
|
91
|
+
|
|
92
|
+
Use Redis or similar shared store in multi-instance production — in-memory limiters alone are insufficient (TG-RATE-001).
|
|
93
|
+
|
|
94
|
+
## Manual review
|
|
95
|
+
|
|
96
|
+
- Enumerate all `app.use` order (auth before routes)
|
|
97
|
+
- Verify upload routes have size/type/auth checks
|
|
98
|
+
- Run dependency audit before deploy
|
|
99
|
+
|
|
100
|
+
## Related documentation
|
|
101
|
+
|
|
102
|
+
- [rules/TG-PLATFORM-001-wildcard-cors-with-credentials.md](../rules/TG-PLATFORM-001-wildcard-cors-with-credentials.md)
|
|
103
|
+
- [skills/TorusGuard/references/platform-hardening.md](../skills/TorusGuard/references/platform-hardening.md)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# TorusGuard Skill Reference: FastAPI Security
|
|
2
|
+
|
|
3
|
+
> **Loaded When:** Project uses `fastapi` dependencies or imports.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 🛡️ Key Inspection Areas & Rules
|
|
8
|
+
|
|
9
|
+
### 1. Route Authorization & Dependencies
|
|
10
|
+
* `TG-AUTH-001` / `TG-AUTH-003`: Verify protected routes include security dependencies (`Depends(get_current_user)`).
|
|
11
|
+
* `TG-AUTH-007`: In route handlers taking numeric/UUID path parameters (e.g. `profile_id`, `invoice_id`), verify that database queries filter by the authenticated user's ID.
|
|
12
|
+
|
|
13
|
+
### 2. Request Models & Mass Assignment
|
|
14
|
+
* `TG-AUTH-006`: Check that endpoints accept structured Pydantic `BaseModel` classes rather than raw `dict`, `Body(...)`, or unpacking `**payload` directly into ORM entities.
|
|
15
|
+
|
|
16
|
+
### 3. Outbound Requests & SSRF
|
|
17
|
+
* `TG-SSRF-001`: Inspect endpoints that fetch external URLs via `httpx` or `requests`. Verify scheme validation and private IP address filtering.
|
|
18
|
+
|
|
19
|
+
### 4. Webhook Integrity
|
|
20
|
+
* `TG-WEBHOOK-001`: In webhook endpoints, verify HMAC signature validation using `await request.body()` (raw bytes) before JSON parsing.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Firebase Security Guide
|
|
2
|
+
|
|
3
|
+
## When to use
|
|
4
|
+
|
|
5
|
+
Load during audits of Firebase Auth, Firestore, Realtime Database, or Storage.
|
|
6
|
+
|
|
7
|
+
**Related rules:** TG-DB-003, TG-AUTH-002, TG-AUTH-003, TG-SEC-002
|
|
8
|
+
|
|
9
|
+
## Key distinction
|
|
10
|
+
|
|
11
|
+
| SDK | Where | Purpose |
|
|
12
|
+
|-----|-------|---------|
|
|
13
|
+
| **Firebase client SDK** | Browser/mobile | User-facing ops constrained by Security Rules |
|
|
14
|
+
| **Firebase Admin SDK** | Server only | Privileged operations — never in frontend |
|
|
15
|
+
|
|
16
|
+
## Checklist
|
|
17
|
+
|
|
18
|
+
- [ ] Admin SDK credentials server-only (TG-DB-003)
|
|
19
|
+
- [ ] Firestore/RTDB Security Rules deployed and tested
|
|
20
|
+
- [ ] Storage rules restrict paths by `request.auth.uid`
|
|
21
|
+
- [ ] Client rules do not trust client-supplied ownership fields alone
|
|
22
|
+
- [ ] Custom claims used for roles verified server-side for sensitive ops
|
|
23
|
+
- [ ] Emulator tests for rule changes
|
|
24
|
+
|
|
25
|
+
## Client SDK (safe with rules)
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
import { initializeApp } from 'firebase/app';
|
|
29
|
+
import { getFirestore, doc, getDoc } from 'firebase/firestore';
|
|
30
|
+
|
|
31
|
+
const app = initializeApp(firebaseConfig); // public config is OK
|
|
32
|
+
const db = getFirestore(app);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Firestore rules example
|
|
36
|
+
|
|
37
|
+
```javascript
|
|
38
|
+
rules_version = '2';
|
|
39
|
+
service cloud.firestore {
|
|
40
|
+
match /databases/{database}/documents {
|
|
41
|
+
match /users/{userId} {
|
|
42
|
+
allow read, write: if request.auth != null && request.auth.uid == userId;
|
|
43
|
+
}
|
|
44
|
+
match /orders/{orderId} {
|
|
45
|
+
allow read: if request.auth != null
|
|
46
|
+
&& resource.data.ownerId == request.auth.uid;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Admin SDK (server only)
|
|
53
|
+
|
|
54
|
+
```javascript
|
|
55
|
+
// functions or server/index.js — never in React src/
|
|
56
|
+
import admin from 'firebase-admin';
|
|
57
|
+
admin.initializeApp({ credential: admin.credential.cert(serviceAccount) });
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Never commit service account JSON; use environment or secret manager (TG-SEC-001, TG-SEC-003).
|
|
61
|
+
|
|
62
|
+
## Manual rules review checklist
|
|
63
|
+
|
|
64
|
+
1. Default-deny: are unmatched paths blocked?
|
|
65
|
+
2. Can users read/write other users' documents by guessing IDs?
|
|
66
|
+
3. Are admin collections inaccessible to normal users?
|
|
67
|
+
4. Do Storage paths include user ID validation?
|
|
68
|
+
5. Run emulator tests for allow/deny cases
|
|
69
|
+
|
|
70
|
+
## Auth token validation
|
|
71
|
+
|
|
72
|
+
For custom backends verifying Firebase ID tokens, use Admin SDK `verifyIdToken` — do not decode JWT without signature verification.
|
|
73
|
+
|
|
74
|
+
## Related documentation
|
|
75
|
+
|
|
76
|
+
- [rules/TG-DB-003-frontend-admin-sdk.md](../rules/TG-DB-003-frontend-admin-sdk.md)
|
|
77
|
+
- [rules/TG-AUTH-003-missing-object-authorization.md](../rules/TG-AUTH-003-missing-object-authorization.md)
|
|
78
|
+
- [skills/TorusGuard/references/frontend-no-db.md](../skills/TorusGuard/references/frontend-no-db.md)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# TorusGuard Skill Reference: Flask Security
|
|
2
|
+
|
|
3
|
+
> **Loaded When:** Project uses `flask` dependencies or imports.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 🛡️ Key Inspection Areas & Rules
|
|
8
|
+
|
|
9
|
+
### 1. Secret Key & Cookie Configuration
|
|
10
|
+
* `TG-SEC-001`: Inspect `app.config['SECRET_KEY']`. Flag hardcoded string literals.
|
|
11
|
+
* `TG-PLATFORM-003`: Verify `app.debug = False` in production configs.
|
|
12
|
+
|
|
13
|
+
### 2. Authorization & Ownership (IDOR)
|
|
14
|
+
* `TG-AUTH-007`: In route handlers querying database models by route variables (e.g. `<int:id>`), verify that the query filters by `current_user.id`.
|
|
15
|
+
|
|
16
|
+
### 3. CSRF Protection
|
|
17
|
+
* `TG-CSRF-001`: Verify that cookie-authenticated web forms initialize `flask_wtf.CSRFProtect`.
|
|
18
|
+
|
|
19
|
+
### 4. File Uploads
|
|
20
|
+
* `TG-INPUT-004`: Ensure uploaded filenames are filtered using `secure_filename()` and validate against an extension whitelist.
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Next.js Security Guide
|
|
2
|
+
|
|
3
|
+
## When to use
|
|
4
|
+
|
|
5
|
+
Load during audits of Next.js App Router or Pages Router applications.
|
|
6
|
+
|
|
7
|
+
**Related rules:** TG-SEC-002, TG-DB-003, TG-AUTH-002, TG-AUTH-003, TG-CLIENT-001, TG-PLATFORM-002
|
|
8
|
+
|
|
9
|
+
## Server vs client boundary
|
|
10
|
+
|
|
11
|
+
| Location | Can use secrets? | Can access DB? |
|
|
12
|
+
|----------|------------------|----------------|
|
|
13
|
+
| Server Components, Route Handlers, Server Actions | Yes (env without `NEXT_PUBLIC_`) | Yes (server SDK) |
|
|
14
|
+
| Client Components (`'use client'`) | No | No |
|
|
15
|
+
|
|
16
|
+
Never import server-only modules (Prisma, `pg`, Firebase Admin, service-role Supabase) into Client Components.
|
|
17
|
+
|
|
18
|
+
## Checklist
|
|
19
|
+
|
|
20
|
+
- [ ] No `NEXT_PUBLIC_*` variables hold secrets (TG-SEC-002)
|
|
21
|
+
- [ ] Route handlers and Server Actions validate input and authorize users
|
|
22
|
+
- [ ] `productionBrowserSourceMaps: false` in production
|
|
23
|
+
- [ ] Cookie sessions use httpOnly, Secure, SameSite (TG-AUTH-004)
|
|
24
|
+
- [ ] CSRF considered for cookie-authenticated mutations
|
|
25
|
+
- [ ] Sensitive data not over-cached in public CDN routes
|
|
26
|
+
- [ ] Security headers via `next.config` or middleware/Helmet on custom server
|
|
27
|
+
|
|
28
|
+
## Environment variables
|
|
29
|
+
|
|
30
|
+
```env
|
|
31
|
+
# Server-only
|
|
32
|
+
DATABASE_URL=postgresql://...
|
|
33
|
+
JWT_SECRET=...
|
|
34
|
+
|
|
35
|
+
# Client-safe
|
|
36
|
+
NEXT_PUBLIC_API_URL=https://api.example.com
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Route handler pattern
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
// app/api/orders/[id]/route.ts
|
|
43
|
+
import { z } from 'zod';
|
|
44
|
+
import { getSession } from '@/lib/session';
|
|
45
|
+
import { db } from '@/lib/db';
|
|
46
|
+
|
|
47
|
+
const paramsSchema = z.object({ id: z.string().uuid() });
|
|
48
|
+
|
|
49
|
+
export async function GET(req: Request, { params }: { params: { id: string } }) {
|
|
50
|
+
const session = await getSession();
|
|
51
|
+
if (!session) return Response.json({ error: 'Unauthorized' }, { status: 401 });
|
|
52
|
+
|
|
53
|
+
const parsed = paramsSchema.safeParse(params);
|
|
54
|
+
if (!parsed.success) return Response.json({ error: 'Invalid input' }, { status: 400 });
|
|
55
|
+
|
|
56
|
+
const order = await db.order.findFirst({
|
|
57
|
+
where: { id: parsed.data.id, userId: session.userId },
|
|
58
|
+
});
|
|
59
|
+
if (!order) return Response.json({ error: 'Not found' }, { status: 404 });
|
|
60
|
+
|
|
61
|
+
return Response.json(order);
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Server Actions
|
|
66
|
+
|
|
67
|
+
Validate and authorize at the start of every Server Action. Do not trust hidden form fields for `role` or `userId`.
|
|
68
|
+
|
|
69
|
+
## Source maps
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
// next.config.js
|
|
73
|
+
const nextConfig = {
|
|
74
|
+
productionBrowserSourceMaps: false,
|
|
75
|
+
};
|
|
76
|
+
export default nextConfig;
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## CSRF and sessions
|
|
80
|
+
|
|
81
|
+
When using cookie-based auth with Server Actions or form POSTs, verify Origin/Referer or use CSRF tokens for state-changing requests.
|
|
82
|
+
|
|
83
|
+
## Cache and privacy
|
|
84
|
+
|
|
85
|
+
Avoid caching personalized responses at CDN edge unless intentionally public. Review `fetch` cache options and `revalidate` settings for user-specific data.
|
|
86
|
+
|
|
87
|
+
## Manual review
|
|
88
|
+
|
|
89
|
+
- Trace every `'use client'` file for accidental secret imports
|
|
90
|
+
- Test IDOR on dynamic `[id]` routes (TG-AUTH-003)
|
|
91
|
+
- Review middleware auth coverage
|
|
92
|
+
|
|
93
|
+
## Related documentation
|
|
94
|
+
|
|
95
|
+
- [rules/TG-AUTH-003-missing-object-authorization.md](../rules/TG-AUTH-003-missing-object-authorization.md)
|
|
96
|
+
- [guides/express-security.md](express-security.md) (custom server)
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# React + Vite Security Guide
|
|
2
|
+
|
|
3
|
+
## When to use
|
|
4
|
+
|
|
5
|
+
Load during audits of React + Vite frontends with a separate or proxied API backend.
|
|
6
|
+
|
|
7
|
+
**Related rules:** TG-SEC-002, TG-DB-001, TG-DB-002, TG-AUTH-002, TG-CLIENT-001, TG-CLIENT-002, TG-INPUT-003
|
|
8
|
+
|
|
9
|
+
## Core truth: the browser bundle is public
|
|
10
|
+
|
|
11
|
+
If the browser receives JavaScript, users can read it in DevTools, Sources, and network tabs. TorusGuard cannot block Inspect Element. Never put secrets, database credentials, or authorization decisions only in client code.
|
|
12
|
+
|
|
13
|
+
## Checklist
|
|
14
|
+
|
|
15
|
+
- [ ] No secrets in `VITE_*` environment variables
|
|
16
|
+
- [ ] No SQL, ORM, or DB driver imports in `src/`
|
|
17
|
+
- [ ] Private data fetched only through authenticated API calls
|
|
18
|
+
- [ ] `build.sourcemap: false` for production (TG-CLIENT-001)
|
|
19
|
+
- [ ] No `console.log` of tokens, users, or config in production paths
|
|
20
|
+
- [ ] Route guards are UX only — server enforces authorization (TG-AUTH-002)
|
|
21
|
+
- [ ] User HTML rendered as text unless sanitized (TG-INPUT-003)
|
|
22
|
+
- [ ] CSP configured at hosting/API layer where applicable
|
|
23
|
+
|
|
24
|
+
## Environment variables
|
|
25
|
+
|
|
26
|
+
Only intentionally public values belong in Vite client env:
|
|
27
|
+
|
|
28
|
+
```env
|
|
29
|
+
# .env.example — safe for client
|
|
30
|
+
VITE_API_URL=http://localhost:3001
|
|
31
|
+
VITE_APP_NAME=MyApp
|
|
32
|
+
|
|
33
|
+
# NEVER prefix secrets with VITE_
|
|
34
|
+
# JWT_SECRET, DATABASE_URL, STRIPE_SECRET_KEY → server only
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```javascript
|
|
38
|
+
// vite.config.js — disable public production source maps
|
|
39
|
+
export default defineConfig({
|
|
40
|
+
build: { sourcemap: false },
|
|
41
|
+
server: {
|
|
42
|
+
proxy: { '/api': 'http://localhost:3001' },
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Data access pattern
|
|
48
|
+
|
|
49
|
+
```javascript
|
|
50
|
+
// client/src/api/users.js — safe
|
|
51
|
+
export async function fetchMyProfile() {
|
|
52
|
+
const res = await fetch('/api/users/me', { credentials: 'include' });
|
|
53
|
+
if (!res.ok) throw new Error('Unauthorized');
|
|
54
|
+
return res.json();
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Never construct SQL or import `pg`, `@prisma/client`, or Supabase service-role client in `src/`.
|
|
59
|
+
|
|
60
|
+
## Client route guards
|
|
61
|
+
|
|
62
|
+
```jsx
|
|
63
|
+
// UX redirect only — NOT security
|
|
64
|
+
function AdminRoute({ children }) {
|
|
65
|
+
const { user } = useAuth();
|
|
66
|
+
if (!user?.role) return <Navigate to="/login" />;
|
|
67
|
+
return children;
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Every admin action must still fail on the server without proper role checks.
|
|
72
|
+
|
|
73
|
+
## Safe rendering
|
|
74
|
+
|
|
75
|
+
```jsx
|
|
76
|
+
// Safe — React escapes text by default
|
|
77
|
+
<p>{user.bio}</p>
|
|
78
|
+
|
|
79
|
+
// High risk — only with trusted/sanitized HTML
|
|
80
|
+
<div dangerouslySetInnerHTML={{ __html: sanitizedHtml }} />
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## CSP considerations
|
|
84
|
+
|
|
85
|
+
Define CSP at the reverse proxy or Express/Next layer. Account for Vite dev server in development; tighten for production with explicit `script-src`, `connect-src`, and `img-src` origins.
|
|
86
|
+
|
|
87
|
+
## Manual review
|
|
88
|
+
|
|
89
|
+
- Verify API endpoints enforce auth for every sensitive client call
|
|
90
|
+
- Confirm no secret accidentally added to `import.meta.env` usage
|
|
91
|
+
- Review third-party scripts loaded in `index.html`
|
|
92
|
+
|
|
93
|
+
## Related documentation
|
|
94
|
+
|
|
95
|
+
- [rules/TG-SEC-002-public-environment-secrets.md](../rules/TG-SEC-002-public-environment-secrets.md)
|
|
96
|
+
- [rules/TG-CLIENT-001-public-production-source-maps.md](../rules/TG-CLIENT-001-public-production-source-maps.md)
|
|
97
|
+
- [skills/TorusGuard/references/client-code-exposure.md](../skills/TorusGuard/references/client-code-exposure.md)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# TorusGuard Skill Reference: SQLAlchemy Security
|
|
2
|
+
|
|
3
|
+
> **Loaded When:** Project uses `sqlalchemy` dependencies or imports.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 🛡️ Key Inspection Areas & Rules
|
|
8
|
+
|
|
9
|
+
### 1. SQL Injection in Raw Query Clauses
|
|
10
|
+
* `TG-INPUT-003`: Search for `text(f"...")`, `text("..." + ...)`, or `.format()` inside `text()` constructs. Ensure parameter mapping `text("... WHERE col = :val")` is used.
|
|
11
|
+
|
|
12
|
+
### 2. Tenant Scoping & Object Ownership
|
|
13
|
+
* `TG-AUTH-007`: Verify queries on tenant-isolated tables include tenant/user ID predicates in `.filter()` or `.filter_by()`.
|
|
14
|
+
|
|
15
|
+
### 3. Mass Assignment via Bulk Updates
|
|
16
|
+
* `TG-AUTH-006`: Inspect `.update(dict)` calls to ensure input dictionaries are filtered against permitted field allowlists.
|