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,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.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Supabase Security Guide
|
|
2
|
+
|
|
3
|
+
## When to use
|
|
4
|
+
|
|
5
|
+
Load during audits of applications using Supabase Auth, Database, or Storage.
|
|
6
|
+
|
|
7
|
+
**Related rules:** TG-DB-002, TG-DB-003, TG-AUTH-003, TG-SEC-002
|
|
8
|
+
|
|
9
|
+
## Key distinction
|
|
10
|
+
|
|
11
|
+
| Key | Where | Purpose |
|
|
12
|
+
|-----|-------|---------|
|
|
13
|
+
| **anon (public) key** | Browser OK | Client SDK with RLS enforced |
|
|
14
|
+
| **service-role key** | Server only | Bypasses RLS — never in frontend |
|
|
15
|
+
|
|
16
|
+
Violating this mapping triggers TG-DB-002 (Critical) and TG-DB-003 (Critical).
|
|
17
|
+
|
|
18
|
+
## Checklist
|
|
19
|
+
|
|
20
|
+
- [ ] Service-role key only in server/edge functions
|
|
21
|
+
- [ ] RLS enabled on every table exposed to client
|
|
22
|
+
- [ ] Policies verify `auth.uid()` ownership or role
|
|
23
|
+
- [ ] Storage bucket policies restrict read/write by user
|
|
24
|
+
- [ ] No sensitive logic relying only on client-side filters
|
|
25
|
+
- [ ] Server-only admin actions use service-role in trusted environment
|
|
26
|
+
|
|
27
|
+
## Browser client (safe)
|
|
28
|
+
|
|
29
|
+
```javascript
|
|
30
|
+
import { createClient } from '@supabase/supabase-js';
|
|
31
|
+
|
|
32
|
+
const supabase = createClient(
|
|
33
|
+
import.meta.env.VITE_SUPABASE_URL,
|
|
34
|
+
import.meta.env.VITE_SUPABASE_ANON_KEY
|
|
35
|
+
);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Server admin (safe)
|
|
39
|
+
|
|
40
|
+
```javascript
|
|
41
|
+
// server/admin.js — never import in client bundle
|
|
42
|
+
import { createClient } from '@supabase/supabase-js';
|
|
43
|
+
|
|
44
|
+
const admin = createClient(
|
|
45
|
+
process.env.SUPABASE_URL,
|
|
46
|
+
process.env.SUPABASE_SERVICE_ROLE_KEY
|
|
47
|
+
);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## RLS policy example
|
|
51
|
+
|
|
52
|
+
```sql
|
|
53
|
+
ALTER TABLE profiles ENABLE ROW LEVEL SECURITY;
|
|
54
|
+
|
|
55
|
+
CREATE POLICY "Users read own profile"
|
|
56
|
+
ON profiles FOR SELECT
|
|
57
|
+
USING (auth.uid() = user_id);
|
|
58
|
+
|
|
59
|
+
CREATE POLICY "Users update own profile"
|
|
60
|
+
ON profiles FOR UPDATE
|
|
61
|
+
USING (auth.uid() = user_id);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Manual RLS review checklist
|
|
65
|
+
|
|
66
|
+
For each table reachable from the browser:
|
|
67
|
+
|
|
68
|
+
1. Is RLS enabled?
|
|
69
|
+
2. Does SELECT policy prevent cross-user reads?
|
|
70
|
+
3. Do INSERT/UPDATE/DELETE policies verify ownership?
|
|
71
|
+
4. Are admin-only tables blocked for anon/authenticated roles?
|
|
72
|
+
5. Test with two user sessions — User A must not read User B rows
|
|
73
|
+
|
|
74
|
+
Document review date in project `SECURITY.md`.
|
|
75
|
+
|
|
76
|
+
## Storage
|
|
77
|
+
|
|
78
|
+
Apply bucket policies mirroring database ownership. Do not use public buckets for private user files without signed URL strategy.
|
|
79
|
+
|
|
80
|
+
## Related documentation
|
|
81
|
+
|
|
82
|
+
- [rules/TG-DB-002-privileged-database-credential.md](../rules/TG-DB-002-privileged-database-credential.md)
|
|
83
|
+
- [rules/TG-DB-003-frontend-admin-sdk.md](../rules/TG-DB-003-frontend-admin-sdk.md)
|
|
84
|
+
- [skills/TorusGuard/references/frontend-no-db.md](../skills/TorusGuard/references/frontend-no-db.md)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# TorusGuard Security Rule Catalog & Activation System
|
|
2
|
+
|
|
3
|
+
This directory manages the active and custom security rules enforced by TorusGuard.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1. Rule Architecture & Taxonomy
|
|
8
|
+
|
|
9
|
+
TorusGuard security rules follow a canonical identifier pattern: `TG-<CATEGORY>-<NUMBER>`.
|
|
10
|
+
|
|
11
|
+
| Category Prefix | Domain Area | Focus & Vulnerability Classes |
|
|
12
|
+
| :--- | :--- | :--- |
|
|
13
|
+
| `TG-AUTH` | Authentication & Authorization | Missing tenant scoping, client-only route guards, session cookie flags, insecure password resets |
|
|
14
|
+
| `TG-INPUT` | Input Validation & Injection | SQL injection, unsafe HTML/template rendering, unvalidated file uploads, path traversal |
|
|
15
|
+
| `TG-SEC` | Secrets & Configuration | Hardcoded API keys, tracked `.env` files, sensitive logging, exposed cloud credentials |
|
|
16
|
+
| `TG-DB` | Database & ORM Security | Frontend direct DB access, admin SDK exposure, missing multi-tenant query isolation |
|
|
17
|
+
| `TG-CLIENT` | Frontend & Client Bundles | Public production source maps, sensitive secrets embedded in client build assets |
|
|
18
|
+
| `TG-RATE` | Rate Limiting & Resource Abuse | Unlimited auth endpoints, unbounded pagination, excessive resource consumption |
|
|
19
|
+
| `TG-PLATFORM` | Platform & Gateway Hardening | Wildcard CORS with credentials, missing security headers, exposed stack traces |
|
|
20
|
+
| `TG-SSRF` | Outbound Requests & SSRF | Unvalidated HTTP client destinations, metadata IP access, internal network probing |
|
|
21
|
+
| `TG-SUPPLY` | Dependency & Supply Chain | Unpinned dependencies, known CVEs, malicious dependency confusion risks |
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 2. Active Rules System (`rules/active/`)
|
|
26
|
+
|
|
27
|
+
When you run `/torusguard init`, TorusGuard automatically inspects your project stack and activates relevant rules in `rules/active/`.
|
|
28
|
+
|
|
29
|
+
- **Universal Rules:** Always activated (`TG-SEC-*`, `TG-INPUT-*`, `TG-AUTH-*`).
|
|
30
|
+
- **Framework-Specific Rules:**
|
|
31
|
+
- Python / Django: `TG-DB-004`, `TG-RATE-001`, `TG-PLATFORM-*`.
|
|
32
|
+
- Next.js / React: `TG-CLIENT-*`, `TG-PLATFORM-001`, `TG-AUTH-002`.
|
|
33
|
+
- API / Node.js: `TG-INPUT-001`, `TG-SSRF-001`, `TG-RATE-002`.
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## 3. Creating Custom Rules
|
|
38
|
+
|
|
39
|
+
You can add custom rules directly into this directory or configure a custom path in `.torusguard/config/torusguard.json`:
|
|
40
|
+
|
|
41
|
+
```markdown
|
|
42
|
+
# TG-CUSTOM-001: Require Organization UUID on All Tenant Queries
|
|
43
|
+
|
|
44
|
+
**Severity:** High
|
|
45
|
+
**Category:** authentication-authorization
|
|
46
|
+
**Confidence Base:** 80
|
|
47
|
+
|
|
48
|
+
### Vulnerability Pattern
|
|
49
|
+
Ensure every database query on multi-tenant models filters explicitly by `org_id` or `tenant_id`.
|
|
50
|
+
|
|
51
|
+
### Unsafe Pattern
|
|
52
|
+
```python
|
|
53
|
+
# Unsafe: Queries tenant data globally without org predicate
|
|
54
|
+
TenantRecord.objects.filter(status="active")
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Safe Pattern
|
|
58
|
+
```python
|
|
59
|
+
# Safe: Scoped to requesting organization
|
|
60
|
+
TenantRecord.objects.filter(org_id=request.user.org_id, status="active")
|
|
61
|
+
```
|
|
62
|
+
```
|