@martinffx/atelier 1.2.1 → 1.3.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 +27 -0
- package/README.md +22 -24
- package/agents/architect.md +1 -1
- package/agents/oracle.md +1 -1
- package/dist/atelier.js +12 -14
- package/package.json +1 -1
- package/skills/code-commit/SKILL.md +5 -13
- package/skills/code-pull-request/SKILL.md +36 -0
- package/skills/code-pull-request/references/common.md +76 -0
- package/skills/code-pull-request/references/create-pr.md +122 -0
- package/skills/code-pull-request/references/default-template.md +25 -0
- package/skills/code-pull-request/references/leave-comment.md +53 -0
- package/skills/code-pull-request/references/merge-pr.md +94 -0
- package/skills/code-pull-request/references/read-comments.md +61 -0
- package/skills/code-pull-request/references/respond-to-comment.md +66 -0
- package/skills/code-review/SKILL.md +21 -12
- package/skills/code-review/references/reviewers.md +142 -41
- package/skills/code-review/references/rq.md +48 -32
- package/skills/oracle-debug/SKILL.md +218 -0
- package/skills/{code-debug → oracle-debug}/references/bug-patterns.md +3 -3
- package/skills/oracle-domain-modelling/SKILL.md +84 -0
- package/skills/oracle-grill-me/SKILL.md +20 -0
- package/skills/spec-brainstorm/SKILL.md +91 -71
- package/skills/spec-finish/SKILL.md +20 -14
- package/skills/spec-implement/SKILL.md +3 -2
- package/skills/spec-orchestrator/SKILL.md +4 -15
- package/skills/spec-plan/SKILL.md +1 -1
- package/agents/scout.md +0 -40
- package/skills/code-commit/references/pr-workflow.md +0 -145
- package/skills/code-debug/SKILL.md +0 -199
- package/skills/code-docs/SKILL.md +0 -171
- package/skills/code-docs/references/api-docs.md +0 -116
- package/skills/code-docs/references/changelog.md +0 -64
- package/skills/code-docs/references/readme-structure.md +0 -94
- package/skills/oracle-architect/SKILL.md +0 -327
- package/skills/oracle-architect/references/api-design.md +0 -345
- package/skills/oracle-architect/references/data-modeling.md +0 -318
- package/skills/oracle-architect/references/ddd-patterns.md +0 -348
- package/skills/oracle-architect/references/interface-design.md +0 -203
- package/skills/oracle-challenge/SKILL.md +0 -126
- package/skills/oracle-doubt/SKILL.md +0 -252
- package/skills/oracle-doubt/references/adversarial-prompt.md +0 -47
- package/skills/oracle-grillme/SKILL.md +0 -160
- package/skills/oracle-security/SKILL.md +0 -225
- package/skills/oracle-security/references/security-patterns.md +0 -236
- package/skills/oracle-security/references/threat-modeling-guide.md +0 -137
- package/skills/oracle-testing/SKILL.md +0 -237
- package/skills/oracle-testing/references/anti-patterns.md +0 -618
- package/skills/oracle-testing/references/boundaries.md +0 -579
- package/skills/oracle-testing/references/core-testing.md +0 -691
- package/skills/oracle-testing/references/edge-testing.md +0 -794
- package/skills/oracle-testing/references/stub-driven-tdd.md +0 -322
- package/skills/oracle-thinkdeep/SKILL.md +0 -164
- /package/skills/{code-debug → oracle-debug}/references/language-tools.md +0 -0
- /package/skills/{code-debug → oracle-debug}/references/techniques.md +0 -0
- /package/skills/{oracle-grillme → oracle-domain-modelling}/references/ADR-FORMAT.md +0 -0
- /package/skills/{oracle-grillme → oracle-domain-modelling}/references/CONTEXT-FORMAT.md +0 -0
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: oracle-grillme
|
|
3
|
-
description: >
|
|
4
|
-
Socratic interrogation of plans against the project's domain model and documented decisions.
|
|
5
|
-
Use when the user wants to stress-test a plan, clarify terminology, or validate assumptions
|
|
6
|
-
against existing domain language. Updates CONTEXT.md and ADRs inline as decisions crystallise.
|
|
7
|
-
user-invocable: true
|
|
8
|
-
---
|
|
9
|
-
|
|
10
|
-
# Grill Me
|
|
11
|
-
|
|
12
|
-
Relentless questioning of your plan against the project's domain model, sharpening terminology and updating documentation (CONTEXT.md, ADRs) inline as decisions crystallise.
|
|
13
|
-
|
|
14
|
-
## When to Use
|
|
15
|
-
|
|
16
|
-
- **Stress-testing a plan** — "I want to add a refund flow to the Order service"
|
|
17
|
-
- **Clarifying fuzzy language** — "We're calling it 'account' but is that a Customer or a User?"
|
|
18
|
-
- **Onboarding to a domain** — "Walk me through how the Billing context relates to Ordering"
|
|
19
|
-
- **Before writing specs** — Ensuring the domain language is solid before `spec-research` begins
|
|
20
|
-
- **After code review** — "The PR introduces 'cancellation' but our glossary says..."
|
|
21
|
-
|
|
22
|
-
## When NOT to Use
|
|
23
|
-
|
|
24
|
-
- **Simple implementation questions** — Use `oracle-challenge` or `oracle-architect` instead
|
|
25
|
-
- **Debugging** — Use `code-debug`
|
|
26
|
-
- **Testing strategy** — Use `oracle-testing`
|
|
27
|
-
- **Already in spec workflow** — Use `spec-research` + `oracle-architect` for domain discovery during the spec process
|
|
28
|
-
|
|
29
|
-
---
|
|
30
|
-
|
|
31
|
-
## How It Works
|
|
32
|
-
|
|
33
|
-
<interview-loop>
|
|
34
|
-
|
|
35
|
-
Interview me relentlessly about every aspect of this plan until we reach a shared understanding. Walk down each branch of the design tree, resolving dependencies between decisions one-by-one. For each question, provide your recommended answer.
|
|
36
|
-
|
|
37
|
-
Ask the questions one at a time, waiting for feedback on each question before continuing.
|
|
38
|
-
|
|
39
|
-
If a question can be answered by exploring the codebase, explore the codebase instead.
|
|
40
|
-
|
|
41
|
-
</interview-loop>
|
|
42
|
-
|
|
43
|
-
---
|
|
44
|
-
|
|
45
|
-
## Domain Awareness
|
|
46
|
-
|
|
47
|
-
### Discovering Context
|
|
48
|
-
|
|
49
|
-
Most repos have a single context:
|
|
50
|
-
|
|
51
|
-
```
|
|
52
|
-
/
|
|
53
|
-
├── CONTEXT.md
|
|
54
|
-
├── docs/
|
|
55
|
-
│ └── adr/
|
|
56
|
-
│ ├── 0001-event-sourced-orders.md
|
|
57
|
-
│ └── 0002-postgres-for-write-model.md
|
|
58
|
-
└── src/
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
If a `CONTEXT-MAP.md` exists at the root, the repo has multiple contexts. The map points to where each one lives:
|
|
62
|
-
|
|
63
|
-
```
|
|
64
|
-
/
|
|
65
|
-
├── CONTEXT-MAP.md
|
|
66
|
-
├── docs/
|
|
67
|
-
│ └── adr/ ← system-wide decisions
|
|
68
|
-
├── src/
|
|
69
|
-
│ ├── ordering/
|
|
70
|
-
│ │ ├── CONTEXT.md
|
|
71
|
-
│ │ └── docs/adr/ ← context-specific decisions
|
|
72
|
-
│ └── billing/
|
|
73
|
-
│ ├── CONTEXT.md
|
|
74
|
-
│ └── docs/adr/
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
Create files lazily — only when you have something to write. If no `CONTEXT.md` exists, create one when the first term is resolved. If no `docs/adr/` exists, create it when the first ADR is needed.
|
|
78
|
-
|
|
79
|
-
### During the Session
|
|
80
|
-
|
|
81
|
-
#### Challenge Against the Glossary
|
|
82
|
-
|
|
83
|
-
When the user uses a term that conflicts with the existing language in `CONTEXT.md`, call it out immediately.
|
|
84
|
-
|
|
85
|
-
> "Your glossary defines 'cancellation' as X, but you seem to mean Y — which is it?"
|
|
86
|
-
|
|
87
|
-
#### Sharpen Fuzzy Language
|
|
88
|
-
|
|
89
|
-
When the user uses vague or overloaded terms, propose a precise canonical term.
|
|
90
|
-
|
|
91
|
-
> "You're saying 'account' — do you mean the Customer or the User? Those are different things."
|
|
92
|
-
|
|
93
|
-
#### Discuss Concrete Scenarios
|
|
94
|
-
|
|
95
|
-
When domain relationships are being discussed, stress-test them with specific scenarios. Invent scenarios that probe edge cases and force the user to be precise about the boundaries between concepts.
|
|
96
|
-
|
|
97
|
-
#### Cross-Reference With Code
|
|
98
|
-
|
|
99
|
-
When the user states how something works, check whether the code agrees. If you find a contradiction, surface it:
|
|
100
|
-
|
|
101
|
-
> "Your code cancels entire Orders, but you just said partial cancellation is possible — which is right?"
|
|
102
|
-
|
|
103
|
-
#### Update CONTEXT.md Inline
|
|
104
|
-
|
|
105
|
-
When a term is resolved, update `CONTEXT.md` right there. Don't batch these up — capture them as they happen. Use the format in [references/CONTEXT-FORMAT.md](./references/CONTEXT-FORMAT.md).
|
|
106
|
-
|
|
107
|
-
`CONTEXT.md` should be totally devoid of implementation details. Do not treat `CONTEXT.md` as a spec, a scratch pad, or a repository for implementation decisions. It is a glossary and nothing else.
|
|
108
|
-
|
|
109
|
-
#### Offer ADRs Sparingly
|
|
110
|
-
|
|
111
|
-
Only offer to create an ADR when all three are true:
|
|
112
|
-
|
|
113
|
-
1. **Hard to reverse** — the cost of changing your mind later is meaningful
|
|
114
|
-
2. **Surprising without context** — a future reader will wonder "why did they do it this way?"
|
|
115
|
-
3. **The result of a real trade-off** — there were genuine alternatives and you picked one for specific reasons
|
|
116
|
-
|
|
117
|
-
If any of the three is missing, skip the ADR. Use the format in [references/ADR-FORMAT.md](./references/ADR-FORMAT.md).
|
|
118
|
-
|
|
119
|
-
---
|
|
120
|
-
|
|
121
|
-
## Usage Examples
|
|
122
|
-
|
|
123
|
-
### Stress-Test a New Feature
|
|
124
|
-
```
|
|
125
|
-
/grillme "I want to add a refund flow to the Order service"
|
|
126
|
-
```
|
|
127
|
-
> "Before we go further — your glossary defines 'Order' as a completed purchase. A refund implies the Order is no longer complete. Is 'refund' a state on Order, or a new concept entirely?"
|
|
128
|
-
|
|
129
|
-
### Clarify Ambiguous Terms
|
|
130
|
-
```
|
|
131
|
-
/grillme "We need to handle 'account' deletions"
|
|
132
|
-
```
|
|
133
|
-
> "You said 'account' — your CONTEXT.md has both Customer and User. Which one are we deleting, and what happens to their Orders?"
|
|
134
|
-
|
|
135
|
-
### Validate Against Existing Decisions
|
|
136
|
-
```
|
|
137
|
-
/grillme "I'm switching the write model from Postgres to DynamoDB"
|
|
138
|
-
```
|
|
139
|
-
> "ADR-0002 says we chose Postgres for the write model because of ACID requirements. Have those requirements changed, or is this a new trade-off?"
|
|
140
|
-
|
|
141
|
-
### Onboard to a Domain
|
|
142
|
-
```
|
|
143
|
-
/grillme "Explain how Billing relates to Ordering"
|
|
144
|
-
```
|
|
145
|
-
> "Ordering emits OrderPlaced events. Billing consumes them to create Invoices. But your CONTEXT.md says Invoice is a request for payment — who decides when payment is actually processed?"
|
|
146
|
-
|
|
147
|
-
---
|
|
148
|
-
|
|
149
|
-
## Relationship to Other Skills
|
|
150
|
-
|
|
151
|
-
| Skill | Use When |
|
|
152
|
-
|-------|----------|
|
|
153
|
-
| **oracle-grillme** | Questioning domain assumptions, sharpening terminology, updating docs inline |
|
|
154
|
-
| **oracle-challenge** | Critically evaluating a technical approach or decision |
|
|
155
|
-
| **oracle-architect** | Designing components, data models, API contracts during spec-research |
|
|
156
|
-
| **spec-research** | Structured discovery + architecture → spec.md (use grillme before this to solidify language) |
|
|
157
|
-
|
|
158
|
-
**Key distinction:**
|
|
159
|
-
- `oracle-challenge` = "Is this approach valid?" (critical evaluation)
|
|
160
|
-
- `oracle-grillme` = "What do we mean by these words?" (domain interrogation)
|
|
@@ -1,225 +0,0 @@
|
|
|
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.*
|
|
@@ -1,236 +0,0 @@
|
|
|
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.
|