@martinffx/atelier 1.1.0 → 1.2.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/CHANGELOG.md +16 -0
- package/README.md +7 -2
- package/package.json +1 -1
- package/skills/code-debug/SKILL.md +119 -187
- package/skills/code-debug/references/bug-patterns.md +71 -0
- package/skills/code-debug/references/techniques.md +44 -4
- package/skills/code-handoff/SKILL.md +16 -0
- package/skills/oracle-architect/SKILL.md +82 -1
- package/skills/oracle-architect/references/ddd-patterns.md +101 -0
- package/skills/oracle-architect/references/interface-design.md +203 -0
- package/skills/oracle-doubt/SKILL.md +252 -0
- package/skills/oracle-doubt/references/adversarial-prompt.md +47 -0
- package/skills/oracle-security/SKILL.md +225 -0
- package/skills/oracle-security/references/security-patterns.md +236 -0
- package/skills/oracle-security/references/threat-modeling-guide.md +137 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Adversarial Reviewer Prompt Template
|
|
2
|
+
|
|
3
|
+
Use this prompt when spawning a fresh-context reviewer via the `task` tool.
|
|
4
|
+
The reviewer must receive **ARTIFACT + CONTRACT only** — never the CLAIM or orchestrator's reasoning.
|
|
5
|
+
|
|
6
|
+
## Template
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
Adversarial review. Find what is wrong with this artifact.
|
|
10
|
+
Assume the author is overconfident. Look for:
|
|
11
|
+
- Unstated assumptions
|
|
12
|
+
- Edge cases not handled
|
|
13
|
+
- Hidden coupling or shared state
|
|
14
|
+
- Ways the contract could be violated
|
|
15
|
+
- Existing conventions this might break
|
|
16
|
+
- Failure modes under unexpected input
|
|
17
|
+
|
|
18
|
+
Do NOT validate. Do NOT summarize. Find issues, or state explicitly
|
|
19
|
+
that you cannot find any after thorough examination.
|
|
20
|
+
|
|
21
|
+
ARTIFACT:
|
|
22
|
+
{ARTIFACT}
|
|
23
|
+
|
|
24
|
+
CONTRACT:
|
|
25
|
+
{CONTRACT}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Dispatch via task tool
|
|
29
|
+
|
|
30
|
+
Spawn **parallel** subagents for cross-perspective review:
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
# Reviewer 1: oracle perspective
|
|
34
|
+
<task tool call with subagent_type="oracle">
|
|
35
|
+
|
|
36
|
+
# Reviewer 2: architect perspective
|
|
37
|
+
<task tool call with subagent_type="architect">
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Each receives the **same** adversarial prompt above with ARTIFACT and CONTRACT.
|
|
41
|
+
|
|
42
|
+
## Rules
|
|
43
|
+
|
|
44
|
+
- **Never pass the CLAIM** — handing the reviewer your conclusion biases them toward agreement
|
|
45
|
+
- **Never pass your reasoning** — the reviewer must independently determine whether the artifact satisfies the contract
|
|
46
|
+
- **Paste this prompt verbatim** — it overrides any persona's default response shape (which may be balanced/validating)
|
|
47
|
+
- **No session context** — the subagent starts fresh with only this prompt
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: oracle-security
|
|
3
|
+
description: Security architecture and threat modeling knowledge. Auto-invokes when designing features that handle untrusted data, authentication, authorization, external integrations, file uploads, or sensitive data. Provides risk assessment frameworks, trust boundary analysis, and security design principles — not implementation code.
|
|
4
|
+
user-invocable: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# oracle-security: Security Architecture & Threat Modeling
|
|
8
|
+
|
|
9
|
+
## When to Use
|
|
10
|
+
|
|
11
|
+
Auto-invokes when context contains:
|
|
12
|
+
- Authentication, authorization, session management
|
|
13
|
+
- User input, validation, untrusted data
|
|
14
|
+
- External integrations, webhooks, third-party APIs
|
|
15
|
+
- File uploads, data processing
|
|
16
|
+
- Encryption, hashing, secrets, sensitive data
|
|
17
|
+
- Security concerns, vulnerabilities, threats
|
|
18
|
+
|
|
19
|
+
## The Security Mindset
|
|
20
|
+
|
|
21
|
+
### Core Principles
|
|
22
|
+
|
|
23
|
+
1. **Validate at Boundaries** — Every entry point is a trust boundary. Assume everything that crosses it is hostile until proven otherwise.
|
|
24
|
+
|
|
25
|
+
2. **Never Trust the Client** — Client-side validation, hidden fields, and browser headers are UX conveniences, not security controls. The server is the only security boundary that matters.
|
|
26
|
+
|
|
27
|
+
3. **Fail Closed** — Deny by default. When in doubt, reject. When validation fails, stop. When auth is uncertain, deny. "Fail open" is an accidental backdoor.
|
|
28
|
+
|
|
29
|
+
4. **Defense in Depth** — No single control should be the only thing preventing compromise. Layer them so that bypassing one still leaves others.
|
|
30
|
+
|
|
31
|
+
5. **Least Privilege** — Every component should have the minimum access necessary to do its job, and only for the minimum time required.
|
|
32
|
+
|
|
33
|
+
6. **Compartmentalize** — A breach in one area should not automatically grant access to everything else. Isolate by function, data sensitivity, and trust level.
|
|
34
|
+
|
|
35
|
+
### The Trust Boundary Model
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
External World → [Trust Boundary] → Internal System
|
|
39
|
+
↑ ↑
|
|
40
|
+
Validate here Enforce here
|
|
41
|
+
Sanitize here Audit here
|
|
42
|
+
Authenticate here Authorize here
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Trust boundaries exist at every system edge where data or control crosses from a less-trusted to a more-trusted zone:
|
|
46
|
+
|
|
47
|
+
- **API routes / controllers** — Where external requests enter
|
|
48
|
+
- **Event consumers** — Where external events are processed
|
|
49
|
+
- **File processors** — Where external files are handled
|
|
50
|
+
- **External service callbacks** — Where third-party responses enter
|
|
51
|
+
- **Database writes** — When data from external sources persists
|
|
52
|
+
|
|
53
|
+
**Key insight**: Security enforcement should happen as close to the trust boundary as possible. Don't let untrusted data travel deep into your system before validation.
|
|
54
|
+
|
|
55
|
+
## Threat Modeling Quick-Start
|
|
56
|
+
|
|
57
|
+
### Simplified STRIDE
|
|
58
|
+
|
|
59
|
+
For every feature, ask these six questions:
|
|
60
|
+
|
|
61
|
+
| Threat | Question | Example Concern |
|
|
62
|
+
|--------|----------|----------------|
|
|
63
|
+
| **S**poofing | Who could pretend to be someone else? | Fake user IDs, stolen tokens, forged requests |
|
|
64
|
+
| **T**ampering | What could be modified in transit or at rest? | Request payload alteration, data corruption |
|
|
65
|
+
| **R**epudiation | Can actions be denied after the fact? | Missing audit logs, unaccountable changes |
|
|
66
|
+
| **I**nformation Disclosure | What sensitive data could leak? | Error messages, logs, API responses |
|
|
67
|
+
| **D**enial of Service | How could this be overwhelmed or broken? | No rate limits, expensive queries, resource exhaustion |
|
|
68
|
+
| **E**levation of Privilege | Who could gain more access than intended? | Missing authorization checks, parameter tampering |
|
|
69
|
+
|
|
70
|
+
### Attack Tree Thinking
|
|
71
|
+
|
|
72
|
+
For critical features, build a simple attack tree:
|
|
73
|
+
|
|
74
|
+
1. **Goal**: What does the attacker want? (data, access, disruption)
|
|
75
|
+
2. **Paths**: How could they achieve it? (multiple entry points, chained vulnerabilities)
|
|
76
|
+
3. **Barriers**: What stops each path? (validation, auth, rate limits, encryption)
|
|
77
|
+
4. **Gaps**: Where are there no barriers? (missing checks, implicit trust)
|
|
78
|
+
|
|
79
|
+
**Usage**: You don't need a formal diagram. A bullet list of "to steal X, attacker could Y which is blocked by Z, unless they find W" is sufficient for most design reviews.
|
|
80
|
+
|
|
81
|
+
## Risk Proportionality
|
|
82
|
+
|
|
83
|
+
### Assessment Dimensions
|
|
84
|
+
|
|
85
|
+
Consider two factors:
|
|
86
|
+
|
|
87
|
+
- **Impact**: What happens if this is exploited? (reputational damage, financial loss, legal consequences, user harm)
|
|
88
|
+
- **Likelihood**: How easy is exploitation? (public internet access, authenticated only, internal network, physical access required)
|
|
89
|
+
|
|
90
|
+
### Flexible Guidance
|
|
91
|
+
|
|
92
|
+
| Context | Typical Posture |
|
|
93
|
+
|---------|-----------------|
|
|
94
|
+
| Public-facing, unauthenticated | Maximum validation, rate limiting, minimal data exposure, aggressive fail-closed |
|
|
95
|
+
| Authenticated user operations | Standard validation, authorization checks, audit logging, session management |
|
|
96
|
+
| Internal admin tools | Authentication essential, authorization by role, audit everything, additional monitoring |
|
|
97
|
+
| Background processing | Input validation still required, fail-safe defaults, logging for debugging |
|
|
98
|
+
|
|
99
|
+
**Adjust based on your threat model.** A public search box and an internal admin panel have different risks. Don't apply maximum security everywhere — apply *proportional* security everywhere.
|
|
100
|
+
|
|
101
|
+
## Security Architecture Patterns
|
|
102
|
+
|
|
103
|
+
### Defense in Depth
|
|
104
|
+
|
|
105
|
+
Don't rely on a single control. Layer them:
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
Input → [Validation] → [Authentication] → [Authorization] → [Audit]
|
|
109
|
+
↑ ↑ ↑ ↑
|
|
110
|
+
Reject bad Verify who Check can-do Log did-do
|
|
111
|
+
data they are they have they did
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
If any layer fails, the others still provide protection. A validation bypass shouldn't automatically mean unauthorized access.
|
|
115
|
+
|
|
116
|
+
### Least Privilege
|
|
117
|
+
|
|
118
|
+
- Services should have minimum database permissions (read-only where possible, never admin by default)
|
|
119
|
+
- API tokens should have scoped access (not blanket permissions)
|
|
120
|
+
- User sessions should timeout (not indefinite, not excessively long)
|
|
121
|
+
- Background jobs should run with restricted credentials (not application-level access)
|
|
122
|
+
|
|
123
|
+
**Corollary**: When a component needs elevated access temporarily, that access should be explicitly granted and automatically revoked.
|
|
124
|
+
|
|
125
|
+
### Fail-Safe Defaults
|
|
126
|
+
|
|
127
|
+
- Permission denied unless explicitly granted (not granted unless explicitly denied)
|
|
128
|
+
- Reject input that doesn't match expected format (don't try to fix or coerce)
|
|
129
|
+
- Lock account after repeated failures (don't allow infinite attempts)
|
|
130
|
+
- Default to most restrictive CORS, CSP, and network policies (open up explicitly)
|
|
131
|
+
|
|
132
|
+
**Key question**: "If this component fails or is misconfigured, what's the safest default state?"
|
|
133
|
+
|
|
134
|
+
### Compartmentalization
|
|
135
|
+
|
|
136
|
+
- Separate sensitive data from operational data (different stores, different access levels)
|
|
137
|
+
- Use different credentials for different services (one breach doesn't cascade)
|
|
138
|
+
- Isolate file processing from application logic (sandbox, validate before processing)
|
|
139
|
+
- Don't mix admin and user operations in the same endpoints or components
|
|
140
|
+
|
|
141
|
+
## Design Review Questions
|
|
142
|
+
|
|
143
|
+
Ask before implementing:
|
|
144
|
+
|
|
145
|
+
### Data Handling
|
|
146
|
+
- [ ] What data enters the system? Where does it come from? How is it validated?
|
|
147
|
+
- [ ] What data exits the system? Who can see it? Is it filtered appropriately?
|
|
148
|
+
- [ ] What happens to data at rest? Is sensitive data protected?
|
|
149
|
+
- [ ] Are there retention/deletion requirements? How are they enforced?
|
|
150
|
+
|
|
151
|
+
### Access Control
|
|
152
|
+
- [ ] Who can access this feature? How is that authenticated and enforced?
|
|
153
|
+
- [ ] Can users access other users' data? How is that prevented?
|
|
154
|
+
- [ ] Are there different permission levels? How are they checked?
|
|
155
|
+
- [ ] What happens when permissions change (revocation, role change)?
|
|
156
|
+
|
|
157
|
+
### Threat Surface
|
|
158
|
+
- [ ] What new entry points does this feature create?
|
|
159
|
+
- [ ] What existing trust boundaries does this cross?
|
|
160
|
+
- [ ] What external systems does this depend on? What's their security posture?
|
|
161
|
+
- [ ] What happens if those systems are compromised or unavailable?
|
|
162
|
+
|
|
163
|
+
### Failure Modes
|
|
164
|
+
- [ ] What happens when validation fails? (Should fail closed)
|
|
165
|
+
- [ ] What happens when authentication fails? (Should not reveal user existence)
|
|
166
|
+
- [ ] What happens when dependencies fail? (Should degrade safely)
|
|
167
|
+
- [ ] Are errors informative for debugging without being revealing for attackers?
|
|
168
|
+
|
|
169
|
+
## Red Flags & Anti-Patterns
|
|
170
|
+
|
|
171
|
+
### Architectural Smells
|
|
172
|
+
|
|
173
|
+
- **Trusting external input without validation** — Browser headers, webhook payloads, file contents, third-party API responses. All are untrusted until validated.
|
|
174
|
+
|
|
175
|
+
- **Single authorization check at entry** — Checking auth at the route level but not verifying resource ownership on each operation. Every action on a resource needs its own authorization check.
|
|
176
|
+
|
|
177
|
+
- **Errors revealing system internals** — Stack traces, database schemas, file paths, internal IDs in error messages. Debug information belongs in logs, not responses.
|
|
178
|
+
|
|
179
|
+
- **No audit trail for sensitive operations** — If you can't reconstruct who did what after an incident, you can't investigate or recover.
|
|
180
|
+
|
|
181
|
+
- **Broad permissions by default** — Service accounts with admin access, tokens with blanket permissions, users with more roles than they need.
|
|
182
|
+
|
|
183
|
+
- **Security logic in client code** — "The frontend will validate" or "the mobile app won't send that." The client is not a security boundary.
|
|
184
|
+
|
|
185
|
+
### Process Smells
|
|
186
|
+
|
|
187
|
+
- "We'll add security later" — Security retrofitting is 10x harder and 10x more expensive than designing it in.
|
|
188
|
+
- "This is just internal" — Internal tools are prime targets. Attackers specifically look for weak internal systems.
|
|
189
|
+
- "No one would try to exploit this" — Automated attacks are indiscriminate. You don't need to be a target to be compromised.
|
|
190
|
+
- "The framework handles security" — Frameworks provide primitives and tools. You must compose them correctly.
|
|
191
|
+
- "Security slows development" — Insecure code slows you more when you have to stop everything to respond to a breach.
|
|
192
|
+
|
|
193
|
+
## Common Rationalizations
|
|
194
|
+
|
|
195
|
+
| Rationalization | Reality |
|
|
196
|
+
|-----------------|---------|
|
|
197
|
+
| "It's just a prototype" | Prototypes become production. Security habits from day one prevent day-one-hundred emergencies. |
|
|
198
|
+
| "This is an internal tool" | Internal tools are targets. Attackers look for the weakest link, and internal systems are often it. |
|
|
199
|
+
| "We'll add security later" | Later rarely comes. Retrofitting is expensive, error-prone, and usually incomplete. |
|
|
200
|
+
| "The framework handles security" | Frameworks provide primitives. You compose them correctly. They don't secure your application by default. |
|
|
201
|
+
| "No one would target us" | Automated attacks are indiscriminate. Scanners don't care who you are. |
|
|
202
|
+
| "Security slows development" | Insecure code costs more: incident response, legal exposure, user trust loss. |
|
|
203
|
+
|
|
204
|
+
## Verification
|
|
205
|
+
|
|
206
|
+
After designing security-relevant features:
|
|
207
|
+
|
|
208
|
+
- [ ] Threat model documented (even if brief — STRIDE questions answered)
|
|
209
|
+
- [ ] Trust boundaries identified and validation points specified
|
|
210
|
+
- [ ] Input validation strategy defined (where, what, how strict)
|
|
211
|
+
- [ ] Authentication requirements specified (who, how, session management)
|
|
212
|
+
- [ ] Authorization rules documented (who can do what to what)
|
|
213
|
+
- [ ] Failure modes specified (fail closed, not open)
|
|
214
|
+
- [ ] Audit requirements identified (what to log, where)
|
|
215
|
+
- [ ] External dependencies' security posture considered
|
|
216
|
+
- [ ] No secrets or sensitive data in design documents (future attack surface)
|
|
217
|
+
|
|
218
|
+
## See Also
|
|
219
|
+
|
|
220
|
+
- `references/threat-modeling-guide.md` — Extended threat modeling approaches
|
|
221
|
+
- `references/security-patterns.md` — Catalog of security design patterns
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
*Security is not a feature you add. It's a property of the system you design.*
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
# Security Design Patterns
|
|
2
|
+
|
|
3
|
+
Catalog of architectural patterns for building secure systems.
|
|
4
|
+
|
|
5
|
+
## Input Validation Patterns
|
|
6
|
+
|
|
7
|
+
### Whitelist Validation
|
|
8
|
+
Define what's allowed, reject everything else. More secure than blacklist (define what's blocked, allow everything else).
|
|
9
|
+
|
|
10
|
+
- Specify allowed types, formats, lengths, ranges
|
|
11
|
+
- Reject input that doesn't match exactly
|
|
12
|
+
- Don't try to "fix" invalid input — reject it
|
|
13
|
+
|
|
14
|
+
### Schema Validation
|
|
15
|
+
Define expected structure and enforce it at the boundary.
|
|
16
|
+
|
|
17
|
+
- Types, required fields, field constraints
|
|
18
|
+
- Nested object validation
|
|
19
|
+
- Array item validation
|
|
20
|
+
|
|
21
|
+
### Sanitization vs. Validation
|
|
22
|
+
|
|
23
|
+
| Approach | When to Use | Risk |
|
|
24
|
+
|----------|-------------|------|
|
|
25
|
+
| **Validation** | Reject invalid input entirely | Low — no invalid data enters system |
|
|
26
|
+
| **Sanitization** | Clean input for safe use | Medium — subtle bugs in sanitization logic |
|
|
27
|
+
| **Encoding** | Escape for specific context | Context-dependent — wrong encoding for wrong context |
|
|
28
|
+
|
|
29
|
+
**Rule**: Validate first. Only sanitize if you understand exactly what the destination context requires.
|
|
30
|
+
|
|
31
|
+
## Authentication Patterns
|
|
32
|
+
|
|
33
|
+
### Session-Based Authentication
|
|
34
|
+
- Server-side session storage
|
|
35
|
+
- Session ID in httpOnly, secure, sameSite cookie
|
|
36
|
+
- Server validates session on every request
|
|
37
|
+
|
|
38
|
+
### Token-Based Authentication
|
|
39
|
+
- Signed token (JWT, Paseto) containing claims
|
|
40
|
+
- Token sent in Authorization header
|
|
41
|
+
- Server validates signature and expiry
|
|
42
|
+
|
|
43
|
+
### Multi-Factor Authentication
|
|
44
|
+
- Something you know (password)
|
|
45
|
+
- Something you have (device, token)
|
|
46
|
+
- Something you are (biometric)
|
|
47
|
+
|
|
48
|
+
**Key Decision**: Session vs. Token depends on state requirements, scale, and revocation needs.
|
|
49
|
+
|
|
50
|
+
## Authorization Patterns
|
|
51
|
+
|
|
52
|
+
### Role-Based Access Control (RBAC)
|
|
53
|
+
- Users assigned to roles
|
|
54
|
+
- Roles granted permissions
|
|
55
|
+
- Simple to understand and audit
|
|
56
|
+
|
|
57
|
+
### Attribute-Based Access Control (ABAC)
|
|
58
|
+
- Policies based on user attributes, resource attributes, environment
|
|
59
|
+
- More flexible but more complex
|
|
60
|
+
- Better for fine-grained, dynamic access control
|
|
61
|
+
|
|
62
|
+
### Resource-Level Authorization
|
|
63
|
+
Every operation checks: "Does this user have permission to perform this action on this specific resource?"
|
|
64
|
+
|
|
65
|
+
- Don't check once at login and assume it's valid for all subsequent actions
|
|
66
|
+
- Re-verify on every request that touches a resource
|
|
67
|
+
- Consider resource ownership, sharing, delegation
|
|
68
|
+
|
|
69
|
+
## Output Protection Patterns
|
|
70
|
+
|
|
71
|
+
### Response Filtering
|
|
72
|
+
Remove sensitive fields from API responses based on caller's authorization level.
|
|
73
|
+
|
|
74
|
+
- Never return internal IDs, passwords, tokens, or secrets
|
|
75
|
+
- Filter differently for different user types
|
|
76
|
+
- Consider field-level access control
|
|
77
|
+
|
|
78
|
+
### Error Message Safety
|
|
79
|
+
- Return generic errors to users
|
|
80
|
+
- Log detailed errors internally
|
|
81
|
+
- Never expose: stack traces, database schemas, file paths, internal IPs, system versions
|
|
82
|
+
|
|
83
|
+
## Audit and Logging Patterns
|
|
84
|
+
|
|
85
|
+
### Security Event Logging
|
|
86
|
+
Log events that matter for security investigations:
|
|
87
|
+
|
|
88
|
+
- Authentication attempts (success and failure)
|
|
89
|
+
- Authorization failures
|
|
90
|
+
- Sensitive data access
|
|
91
|
+
- Configuration changes
|
|
92
|
+
- Privilege escalations
|
|
93
|
+
|
|
94
|
+
### Audit Trail Requirements
|
|
95
|
+
- **Who**: Which user or service performed the action
|
|
96
|
+
- **What**: What action was performed
|
|
97
|
+
- **When**: Timestamp (UTC)
|
|
98
|
+
- **Where**: Source IP, endpoint, service
|
|
99
|
+
- **Result**: Success or failure
|
|
100
|
+
- **Context**: Relevant IDs, parameters (sanitized)
|
|
101
|
+
|
|
102
|
+
### Log Protection
|
|
103
|
+
- Logs should be tamper-evident (append-only, signed)
|
|
104
|
+
- Separate log access from application access
|
|
105
|
+
- Retain according to compliance requirements
|
|
106
|
+
- Don't log secrets, tokens, or sensitive personal data
|
|
107
|
+
|
|
108
|
+
## Secrets Management Patterns
|
|
109
|
+
|
|
110
|
+
### Environment-Based Configuration
|
|
111
|
+
- Secrets in environment variables, never in code
|
|
112
|
+
- Separate config per environment (dev, staging, prod)
|
|
113
|
+
- Use secret management services in production (Vault, AWS Secrets Manager, etc.)
|
|
114
|
+
|
|
115
|
+
### Secret Rotation
|
|
116
|
+
- Rotate credentials regularly
|
|
117
|
+
- Support emergency rotation
|
|
118
|
+
- Don't hardcode secret references
|
|
119
|
+
|
|
120
|
+
### Least-Exposure Principle
|
|
121
|
+
- Services should only know the secrets they absolutely need
|
|
122
|
+
- Don't use one API key for everything
|
|
123
|
+
- Separate credentials by function and scope
|
|
124
|
+
|
|
125
|
+
## Resilience Patterns
|
|
126
|
+
|
|
127
|
+
### Circuit Breaker
|
|
128
|
+
When a dependency fails repeatedly, stop calling it temporarily to prevent cascading failures.
|
|
129
|
+
|
|
130
|
+
- Detect failure threshold
|
|
131
|
+
- Open circuit (fail fast) for a period
|
|
132
|
+
- Half-open (test with limited traffic) before fully closing
|
|
133
|
+
|
|
134
|
+
### Rate Limiting
|
|
135
|
+
Prevent abuse by limiting requests per time window per client.
|
|
136
|
+
|
|
137
|
+
- Different limits for different endpoints (auth vs. data)
|
|
138
|
+
- Different limits for different user types (anonymous vs. authenticated)
|
|
139
|
+
- Consider burst allowances and graceful degradation
|
|
140
|
+
|
|
141
|
+
### Timeout and Backoff
|
|
142
|
+
- All external calls should have timeouts
|
|
143
|
+
- Retry with exponential backoff for transient failures
|
|
144
|
+
- Don't retry authentication failures (could be brute force)
|
|
145
|
+
|
|
146
|
+
## Data Protection Patterns
|
|
147
|
+
|
|
148
|
+
### Encryption at Rest
|
|
149
|
+
- Sensitive data encrypted in database
|
|
150
|
+
- Key management separate from data access
|
|
151
|
+
- Consider performance impact on queries
|
|
152
|
+
|
|
153
|
+
### Encryption in Transit
|
|
154
|
+
- TLS for all external communication
|
|
155
|
+
- Consider mTLS for service-to-service
|
|
156
|
+
- Don't disable certificate verification
|
|
157
|
+
|
|
158
|
+
### Tokenization
|
|
159
|
+
Replace sensitive data with non-sensitive equivalents.
|
|
160
|
+
|
|
161
|
+
- Actual data stored in secure vault
|
|
162
|
+
- Token used in application logic
|
|
163
|
+
- Reduces exposure surface
|
|
164
|
+
|
|
165
|
+
## Secure Defaults Patterns
|
|
166
|
+
|
|
167
|
+
### Deny by Default
|
|
168
|
+
- All access denied unless explicitly granted
|
|
169
|
+
- All features disabled unless explicitly enabled
|
|
170
|
+
- All connections rejected unless explicitly allowed
|
|
171
|
+
|
|
172
|
+
### Minimal Surface Area
|
|
173
|
+
- Don't expose features you don't need
|
|
174
|
+
- Disable unused endpoints, services, protocols
|
|
175
|
+
- Remove default accounts and sample data
|
|
176
|
+
|
|
177
|
+
### Secure Configuration
|
|
178
|
+
- Framework defaults should be hardened
|
|
179
|
+
- Don't rely on "out of the box" security
|
|
180
|
+
- Explicitly configure security settings
|
|
181
|
+
|
|
182
|
+
## Defense in Depth Patterns
|
|
183
|
+
|
|
184
|
+
### Layered Controls
|
|
185
|
+
Multiple independent controls for the same threat:
|
|
186
|
+
|
|
187
|
+
```
|
|
188
|
+
Threat: SQL Injection
|
|
189
|
+
├── Layer 1: Input validation (reject non-matching input)
|
|
190
|
+
├── Layer 2: Parameterized queries (prevent interpretation as SQL)
|
|
191
|
+
├── Layer 3: Least privilege database user (limit damage if bypassed)
|
|
192
|
+
└── Layer 4: Monitoring (detect and alert on suspicious patterns)
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Compartmentalization
|
|
196
|
+
- Separate sensitive operations from general operations
|
|
197
|
+
- Isolate user data by tenant or scope
|
|
198
|
+
- Use different credentials for different functions
|
|
199
|
+
|
|
200
|
+
### Fail-Safe States
|
|
201
|
+
- When validation fails: reject
|
|
202
|
+
- When auth fails: deny
|
|
203
|
+
- When encryption fails: don't send
|
|
204
|
+
- When logging fails: fail closed (don't proceed silently)
|
|
205
|
+
|
|
206
|
+
## Anti-Patterns to Avoid
|
|
207
|
+
|
|
208
|
+
### God Object Security
|
|
209
|
+
Putting all security logic in one place (e.g., a single middleware) instead of at each layer.
|
|
210
|
+
|
|
211
|
+
**Problem**: Bypass the middleware, bypass all security.
|
|
212
|
+
**Fix**: Security at every relevant layer.
|
|
213
|
+
|
|
214
|
+
### Client-Side Security
|
|
215
|
+
Relying on browser validation, hidden fields, or client logic for security.
|
|
216
|
+
|
|
217
|
+
**Problem**: Clients are completely under attacker control.
|
|
218
|
+
**Fix**: Server-side validation is the only validation that matters.
|
|
219
|
+
|
|
220
|
+
### Security Through Obscurity
|
|
221
|
+
Relying on secrecy of design or implementation for security.
|
|
222
|
+
|
|
223
|
+
**Problem**: Once discovered (and it will be), there's no protection.
|
|
224
|
+
**Fix**: Assume attackers know your design. Security should work even when public.
|
|
225
|
+
|
|
226
|
+
### Trusting the Network
|
|
227
|
+
Assuming internal network traffic is safe.
|
|
228
|
+
|
|
229
|
+
**Problem**: Lateral movement after initial compromise is common.
|
|
230
|
+
**Fix**: Authenticate and validate internal traffic too.
|
|
231
|
+
|
|
232
|
+
### Hardcoded Secrets
|
|
233
|
+
Embedding credentials, keys, or tokens in source code.
|
|
234
|
+
|
|
235
|
+
**Problem**: Committed to version control, visible to anyone with code access.
|
|
236
|
+
**Fix**: Environment variables, secret managers, runtime injection.
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# Threat Modeling Guide
|
|
2
|
+
|
|
3
|
+
Extended approaches for analyzing security threats during system design.
|
|
4
|
+
|
|
5
|
+
## Data Flow Analysis
|
|
6
|
+
|
|
7
|
+
Map how data moves through your system to identify trust boundaries:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
External Request → [Trust Boundary] → API Gateway → [Trust Boundary] → Service → [Trust Boundary] → Database
|
|
11
|
+
↑ ↑
|
|
12
|
+
Authenticate Authorize
|
|
13
|
+
Validate input Validate output
|
|
14
|
+
Rate limit Audit log
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
**Process**:
|
|
18
|
+
1. Draw the data flow for a specific use case
|
|
19
|
+
2. Identify every trust boundary crossing
|
|
20
|
+
3. Ask: "What's the worst thing that could enter here?"
|
|
21
|
+
4. Ask: "What validation or enforcement should happen at this boundary?"
|
|
22
|
+
5. Look for paths that bypass expected controls
|
|
23
|
+
|
|
24
|
+
## STRIDE in Depth
|
|
25
|
+
|
|
26
|
+
### Spoofing
|
|
27
|
+
- **Threat**: Attacker pretends to be a legitimate user or system
|
|
28
|
+
- **Questions**: How are identities verified? Can tokens be stolen or forged? Can sessions be hijacked?
|
|
29
|
+
- **Controls**: Strong authentication, token binding, session validation, mutual TLS
|
|
30
|
+
|
|
31
|
+
### Tampering
|
|
32
|
+
- **Threat**: Data is modified in transit or at rest
|
|
33
|
+
- **Questions**: Is integrity checked? Can parameters be altered? Can files be modified?
|
|
34
|
+
- **Controls**: Input validation, checksums, signatures, immutable audit logs
|
|
35
|
+
|
|
36
|
+
### Repudiation
|
|
37
|
+
- **Threat**: Actions can't be traced back to an actor
|
|
38
|
+
- **Questions**: Are all sensitive operations logged? Are logs tamper-evident? Can users deny their actions?
|
|
39
|
+
- **Controls**: Comprehensive audit logging, signed logs, non-repudiation mechanisms
|
|
40
|
+
|
|
41
|
+
### Information Disclosure
|
|
42
|
+
- **Threat**: Sensitive data leaks to unauthorized parties
|
|
43
|
+
- **Questions**: What data is exposed in errors? In logs? In API responses? Can users access other users' data?
|
|
44
|
+
- **Controls**: Output filtering, log redaction, access controls, encryption at rest/transit
|
|
45
|
+
|
|
46
|
+
### Denial of Service
|
|
47
|
+
- **Threat**: System becomes unavailable or unusable
|
|
48
|
+
- **Questions**: Can endpoints be overwhelmed? Are there expensive operations? Can resources be exhausted?
|
|
49
|
+
- **Controls**: Rate limiting, resource quotas, circuit breakers, caching, input size limits
|
|
50
|
+
|
|
51
|
+
### Elevation of Privilege
|
|
52
|
+
- **Threat**: User gains more access than authorized
|
|
53
|
+
- **Questions**: Is authorization checked on every operation? Can parameters be manipulated to access other resources? Are roles properly enforced?
|
|
54
|
+
- **Controls**: Resource-level authorization, parameter validation, role enforcement, privilege separation
|
|
55
|
+
|
|
56
|
+
## Attack Trees
|
|
57
|
+
|
|
58
|
+
### Building an Attack Tree
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
Goal: Access User Data
|
|
62
|
+
├── Path A: Steal Session Token
|
|
63
|
+
│ ├── Phishing (requires social engineering)
|
|
64
|
+
│ ├── XSS (requires input injection) ← Mitigated by output encoding
|
|
65
|
+
│ └── Network interception (requires unencrypted traffic) ← Mitigated by HTTPS
|
|
66
|
+
├── Path B: Direct Database Access
|
|
67
|
+
│ ├── SQL Injection (requires unparameterized query) ← Mitigated by parameterized queries
|
|
68
|
+
│ └── Direct connection (requires network access) ← Mitigated by network segmentation
|
|
69
|
+
└── Path C: Abuse API
|
|
70
|
+
├── IDOR (requires missing authorization) ← Mitigated by resource checks
|
|
71
|
+
└── Parameter tampering (requires missing validation) ← Mitigated by input validation
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
**Usage**: Focus on the unmitigated paths. If you find a path with no controls, that's your priority.
|
|
75
|
+
|
|
76
|
+
### Risk Scoring
|
|
77
|
+
|
|
78
|
+
For each identified threat, assess:
|
|
79
|
+
|
|
80
|
+
- **Impact** (1-5): How bad would exploitation be?
|
|
81
|
+
- **Likelihood** (1-5): How easy is it to exploit?
|
|
82
|
+
- **Risk** = Impact × Likelihood
|
|
83
|
+
|
|
84
|
+
| Score | Action |
|
|
85
|
+
|-------|--------|
|
|
86
|
+
| 20-25 | Must mitigate before release |
|
|
87
|
+
| 12-16 | Should mitigate in next release cycle |
|
|
88
|
+
| 6-10 | Track and mitigate when convenient |
|
|
89
|
+
| 1-5 | Accept risk, document reasoning |
|
|
90
|
+
|
|
91
|
+
## Trust Boundary Patterns
|
|
92
|
+
|
|
93
|
+
### External → Internal
|
|
94
|
+
- Every external request is hostile until authenticated and validated
|
|
95
|
+
- Validation must happen before any processing
|
|
96
|
+
- Never use external data to make internal decisions without verification
|
|
97
|
+
|
|
98
|
+
### Internal → External
|
|
99
|
+
- Assume external systems are compromised or malicious
|
|
100
|
+
- Validate all responses from third parties
|
|
101
|
+
- Don't expose internal state or identifiers
|
|
102
|
+
|
|
103
|
+
### User → User
|
|
104
|
+
- Users should never directly access each other's data
|
|
105
|
+
- All cross-user access must go through authorization checks
|
|
106
|
+
- Consider temporal access (can user A access user B's data at time T?)
|
|
107
|
+
|
|
108
|
+
### Process → Process
|
|
109
|
+
- Inter-service communication should be authenticated
|
|
110
|
+
- Don't trust internal network traffic by default
|
|
111
|
+
- Validate messages between components as if they came from outside
|
|
112
|
+
|
|
113
|
+
## Threat Modeling Checklist
|
|
114
|
+
|
|
115
|
+
For each feature or component:
|
|
116
|
+
|
|
117
|
+
- [ ] All entry points identified
|
|
118
|
+
- [ ] All trust boundaries mapped
|
|
119
|
+
- [ ] STRIDE threats considered
|
|
120
|
+
- [ ] Attack paths identified for high-value targets
|
|
121
|
+
- [ ] Existing controls mapped
|
|
122
|
+
- [ ] Gaps identified and prioritized
|
|
123
|
+
- [ ] Risk scores assigned
|
|
124
|
+
- [ ] Mitigations planned and scheduled
|
|
125
|
+
- [ ] Assumptions documented (what are we trusting?)
|
|
126
|
+
|
|
127
|
+
## Lightweight Threat Modeling
|
|
128
|
+
|
|
129
|
+
When you don't have time for full analysis:
|
|
130
|
+
|
|
131
|
+
1. **Write the user story**: "As an attacker, I want to..."
|
|
132
|
+
2. **Identify one critical asset**: What would hurt most to lose?
|
|
133
|
+
3. **Find the shortest path**: What's the easiest way to access it?
|
|
134
|
+
4. **Add one control**: What's the simplest mitigation?
|
|
135
|
+
5. **Repeat**: Do this for 3-5 attack stories
|
|
136
|
+
|
|
137
|
+
This takes 15 minutes and catches the most obvious issues.
|