@defai.digital/automatosx 5.6.35 → 5.7.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/CHANGELOG.md +142 -0
- package/README.md +44 -2
- package/dist/index.js +1129 -345
- package/examples/agents/.automatosx/abilities/accessibility.md +115 -0
- package/examples/agents/.automatosx/abilities/api-design.md +159 -0
- package/examples/agents/.automatosx/abilities/best-practices.md +102 -0
- package/examples/agents/.automatosx/abilities/caching-strategy.md +165 -0
- package/examples/agents/.automatosx/abilities/ci-cd.md +61 -0
- package/examples/agents/.automatosx/abilities/clean-code.md +398 -0
- package/examples/agents/.automatosx/abilities/code-generation.md +95 -0
- package/examples/agents/.automatosx/abilities/code-review.md +42 -0
- package/examples/agents/.automatosx/abilities/component-architecture.md +112 -0
- package/examples/agents/.automatosx/abilities/content-creation.md +97 -0
- package/examples/agents/.automatosx/abilities/data-modeling.md +171 -0
- package/examples/agents/.automatosx/abilities/data-validation.md +50 -0
- package/examples/agents/.automatosx/abilities/db-modeling.md +158 -0
- package/examples/agents/.automatosx/abilities/debugging.md +43 -0
- package/examples/agents/.automatosx/abilities/dependency-audit.md +60 -0
- package/examples/agents/.automatosx/abilities/design-patterns.md +437 -0
- package/examples/agents/.automatosx/abilities/design-system-implementation.md +126 -0
- package/examples/agents/.automatosx/abilities/documentation.md +54 -0
- package/examples/agents/.automatosx/abilities/error-analysis.md +107 -0
- package/examples/agents/.automatosx/abilities/etl-pipelines.md +44 -0
- package/examples/agents/.automatosx/abilities/feasibility-study.md +20 -0
- package/examples/agents/.automatosx/abilities/general-assistance.md +26 -0
- package/examples/agents/.automatosx/abilities/idea-evaluation.md +21 -0
- package/examples/agents/.automatosx/abilities/infra-as-code.md +57 -0
- package/examples/agents/.automatosx/abilities/job-orchestration.md +44 -0
- package/examples/agents/.automatosx/abilities/literature-review.md +19 -0
- package/examples/agents/.automatosx/abilities/logical-analysis.md +21 -0
- package/examples/agents/.automatosx/abilities/longform-report.md +25 -0
- package/examples/agents/.automatosx/abilities/mathematical-reasoning.md +170 -0
- package/examples/agents/.automatosx/abilities/mission-analysis.md +49 -0
- package/examples/agents/.automatosx/abilities/observability.md +61 -0
- package/examples/agents/.automatosx/abilities/orbital-mechanics.md +50 -0
- package/examples/agents/.automatosx/abilities/our-architecture-decisions.md +180 -0
- package/examples/agents/.automatosx/abilities/our-code-review-checklist.md +149 -0
- package/examples/agents/.automatosx/abilities/our-coding-standards.md +270 -0
- package/examples/agents/.automatosx/abilities/our-project-structure.md +183 -0
- package/examples/agents/.automatosx/abilities/performance-analysis.md +56 -0
- package/examples/agents/.automatosx/abilities/performance.md +80 -0
- package/examples/agents/.automatosx/abilities/problem-solving.md +50 -0
- package/examples/agents/.automatosx/abilities/propulsion-systems.md +50 -0
- package/examples/agents/.automatosx/abilities/quantum-algorithm-design.md +54 -0
- package/examples/agents/.automatosx/abilities/quantum-error-correction.md +56 -0
- package/examples/agents/.automatosx/abilities/quantum-frameworks-transpilation.md +53 -0
- package/examples/agents/.automatosx/abilities/quantum-noise-modeling.md +58 -0
- package/examples/agents/.automatosx/abilities/refactoring.md +223 -0
- package/examples/agents/.automatosx/abilities/release-strategy.md +58 -0
- package/examples/agents/.automatosx/abilities/risk-assessment.md +19 -0
- package/examples/agents/.automatosx/abilities/secrets-policy.md +61 -0
- package/examples/agents/.automatosx/abilities/secure-coding-review.md +51 -0
- package/examples/agents/.automatosx/abilities/security-audit.md +65 -0
- package/examples/agents/.automatosx/abilities/software-architecture.md +394 -0
- package/examples/agents/.automatosx/abilities/solid-principles.md +341 -0
- package/examples/agents/.automatosx/abilities/sql-optimization.md +84 -0
- package/examples/agents/.automatosx/abilities/state-management.md +96 -0
- package/examples/agents/.automatosx/abilities/task-planning.md +65 -0
- package/examples/agents/.automatosx/abilities/technical-writing.md +77 -0
- package/examples/agents/.automatosx/abilities/telemetry-diagnostics.md +51 -0
- package/examples/agents/.automatosx/abilities/testing.md +47 -0
- package/examples/agents/.automatosx/abilities/threat-modeling.md +49 -0
- package/examples/agents/.automatosx/abilities/troubleshooting.md +80 -0
- package/examples/agents/.automatosx/agents/aerospace-scientist.yaml +75 -0
- package/examples/agents/.automatosx/agents/backend.yaml +152 -0
- package/examples/agents/.automatosx/agents/ceo.yaml +63 -0
- package/examples/agents/.automatosx/agents/creative-marketer.yaml +121 -0
- package/examples/agents/.automatosx/agents/cto.yaml +72 -0
- package/examples/agents/.automatosx/agents/data-scientist.yaml +124 -0
- package/examples/agents/.automatosx/agents/data.yaml +77 -0
- package/examples/agents/.automatosx/agents/design.yaml +74 -0
- package/examples/agents/.automatosx/agents/devops.yaml +89 -0
- package/examples/agents/.automatosx/agents/frontend.yaml +139 -0
- package/examples/agents/.automatosx/agents/fullstack.yaml +151 -0
- package/examples/agents/.automatosx/agents/mobile.yaml +161 -0
- package/examples/agents/.automatosx/agents/product.yaml +72 -0
- package/examples/agents/.automatosx/agents/quality.yaml +79 -0
- package/examples/agents/.automatosx/agents/quantum-engineer.yaml +75 -0
- package/examples/agents/.automatosx/agents/researcher.yaml +71 -0
- package/examples/agents/.automatosx/agents/security.yaml +86 -0
- package/examples/agents/.automatosx/agents/stan.yaml +189 -0
- package/examples/agents/.automatosx/agents/writer.yaml +78 -0
- package/examples/agents/.automatosx/teams/business.yaml +56 -0
- package/examples/agents/.automatosx/teams/core.yaml +60 -0
- package/examples/agents/.automatosx/teams/design.yaml +58 -0
- package/examples/agents/.automatosx/teams/engineering.yaml +69 -0
- package/examples/agents/.automatosx/teams/research.yaml +56 -0
- package/examples/agents/.automatosx/templates/analyst.yaml +60 -0
- package/examples/agents/.automatosx/templates/assistant.yaml +48 -0
- package/examples/agents/.automatosx/templates/basic-agent.yaml +28 -0
- package/examples/agents/.automatosx/templates/code-reviewer.yaml +52 -0
- package/examples/agents/.automatosx/templates/debugger.yaml +63 -0
- package/examples/agents/.automatosx/templates/designer.yaml +69 -0
- package/examples/agents/.automatosx/templates/developer.yaml +60 -0
- package/examples/agents/.automatosx/templates/fullstack-developer.yaml +395 -0
- package/examples/agents/.automatosx/templates/qa-specialist.yaml +71 -0
- package/examples/agents/.claude/commands/ax-agent.md +37 -0
- package/examples/agents/.claude/commands/ax-clear.md +22 -0
- package/examples/agents/.claude/commands/ax-init.md +25 -0
- package/examples/agents/.claude/commands/ax-list.md +19 -0
- package/examples/agents/.claude/commands/ax-memory.md +25 -0
- package/examples/agents/.claude/commands/ax-status.md +24 -0
- package/examples/agents/.claude/commands/ax-update.md +28 -0
- package/examples/agents/.claude/mcp/automatosx.json +244 -0
- package/examples/agents/CLAUDE.md +262 -0
- package/package.json +1 -1
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
# Refactoring Ability
|
|
2
|
+
|
|
3
|
+
Expert knowledge of code smells, refactoring techniques, and strategies for improving code quality without changing behavior.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Refactoring is the process of restructuring existing code without changing its external behavior. The goal is to improve code quality, readability, and maintainability.
|
|
8
|
+
|
|
9
|
+
## Code Smells
|
|
10
|
+
|
|
11
|
+
Code smells are indicators that something might be wrong with your code structure.
|
|
12
|
+
|
|
13
|
+
### Bloaters
|
|
14
|
+
|
|
15
|
+
**Long Method**
|
|
16
|
+
- **Smell**: Method with too many lines
|
|
17
|
+
- **Impact**: Hard to understand, test, and maintain
|
|
18
|
+
- **Refactoring**: Extract Method, Replace Temp with Query, Decompose Conditional
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
// ❌ BAD: Long method
|
|
22
|
+
function processOrder(order: Order) {
|
|
23
|
+
// Validate order
|
|
24
|
+
if (!order.id) throw new Error('Invalid order');
|
|
25
|
+
if (order.items.length === 0) throw new Error('Empty order');
|
|
26
|
+
for (const item of order.items) {
|
|
27
|
+
if (item.quantity <= 0) throw new Error('Invalid quantity');
|
|
28
|
+
if (!item.price) throw new Error('Missing price');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Calculate total
|
|
32
|
+
let subtotal = 0;
|
|
33
|
+
for (const item of order.items) {
|
|
34
|
+
subtotal += item.price * item.quantity;
|
|
35
|
+
}
|
|
36
|
+
const tax = subtotal * 0.1;
|
|
37
|
+
const shipping = subtotal > 100 ? 0 : 10;
|
|
38
|
+
const total = subtotal + tax + shipping;
|
|
39
|
+
|
|
40
|
+
// Apply discounts
|
|
41
|
+
let discount = 0;
|
|
42
|
+
if (order.customer.isPremium) {
|
|
43
|
+
discount = total * 0.15;
|
|
44
|
+
} else if (total > 200) {
|
|
45
|
+
discount = total * 0.1;
|
|
46
|
+
} else if (total > 100) {
|
|
47
|
+
discount = total * 0.05;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Save order
|
|
51
|
+
// ... 50 more lines
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// ✅ GOOD: Extracted methods
|
|
55
|
+
function processOrder(order: Order) {
|
|
56
|
+
validateOrder(order);
|
|
57
|
+
const total = calculateTotal(order);
|
|
58
|
+
const discounted = applyDiscounts(total, order.customer);
|
|
59
|
+
return saveOrder(order, discounted);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function validateOrder(order: Order) {
|
|
63
|
+
if (!order.id) throw new Error('Invalid order');
|
|
64
|
+
if (order.items.length === 0) throw new Error('Empty order');
|
|
65
|
+
order.items.forEach(validateOrderItem);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function calculateTotal(order: Order): number {
|
|
69
|
+
const subtotal = calculateSubtotal(order.items);
|
|
70
|
+
const tax = calculateTax(subtotal);
|
|
71
|
+
const shipping = calculateShipping(subtotal);
|
|
72
|
+
return subtotal + tax + shipping;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function applyDiscounts(total: number, customer: Customer): number {
|
|
76
|
+
const discountRate = getDiscountRate(total, customer);
|
|
77
|
+
return total * (1 - discountRate);
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
**Large Class**
|
|
82
|
+
- **Smell**: Class with too many fields, methods, or responsibilities
|
|
83
|
+
- **Impact**: Violates Single Responsibility Principle
|
|
84
|
+
- **Refactoring**: Extract Class, Extract Subclass
|
|
85
|
+
|
|
86
|
+
**Long Parameter List**
|
|
87
|
+
- **Smell**: Function with many parameters
|
|
88
|
+
- **Impact**: Hard to use, understand, and change
|
|
89
|
+
- **Refactoring**: Introduce Parameter Object, Preserve Whole Object
|
|
90
|
+
|
|
91
|
+
**Primitive Obsession**
|
|
92
|
+
- **Smell**: Using primitives instead of small objects
|
|
93
|
+
- **Impact**: Loss of type safety and domain meaning
|
|
94
|
+
- **Refactoring**: Replace Data Value with Object, Introduce Value Object
|
|
95
|
+
|
|
96
|
+
### Object-Orientation Abusers
|
|
97
|
+
|
|
98
|
+
**Switch Statements**
|
|
99
|
+
- **Smell**: Type-based conditionals instead of polymorphism
|
|
100
|
+
- **Impact**: Violates Open/Closed Principle, hard to extend
|
|
101
|
+
- **Refactoring**: Replace Conditional with Polymorphism
|
|
102
|
+
|
|
103
|
+
**Refused Bequest**
|
|
104
|
+
- **Smell**: Subclass doesn't use inherited methods
|
|
105
|
+
- **Impact**: Violates Liskov Substitution Principle
|
|
106
|
+
- **Refactoring**: Replace Inheritance with Delegation, Push Down Method
|
|
107
|
+
|
|
108
|
+
### Change Preventers
|
|
109
|
+
|
|
110
|
+
**Divergent Change**
|
|
111
|
+
- **Smell**: One class changed for many different reasons
|
|
112
|
+
- **Impact**: Violates Single Responsibility Principle
|
|
113
|
+
- **Refactoring**: Extract Class
|
|
114
|
+
|
|
115
|
+
**Shotgun Surgery**
|
|
116
|
+
- **Smell**: Every change requires many small changes in many classes
|
|
117
|
+
- **Impact**: Hard to make changes, easy to miss updates
|
|
118
|
+
- **Refactoring**: Move Method, Move Field, Inline Class
|
|
119
|
+
|
|
120
|
+
### Dispensables
|
|
121
|
+
|
|
122
|
+
**Duplicate Code**
|
|
123
|
+
- **Smell**: Same code structure in multiple places
|
|
124
|
+
- **Impact**: Maintenance nightmare, bugs replicate
|
|
125
|
+
- **Refactoring**: Extract Method, Extract Class, Pull Up Method
|
|
126
|
+
|
|
127
|
+
**Dead Code**
|
|
128
|
+
- **Smell**: Unused variables, parameters, methods, classes
|
|
129
|
+
- **Impact**: Confusion, maintenance burden
|
|
130
|
+
- **Refactoring**: Delete it
|
|
131
|
+
|
|
132
|
+
**Speculative Generality**
|
|
133
|
+
- **Smell**: "We might need this someday" code
|
|
134
|
+
- **Impact**: Unnecessary complexity
|
|
135
|
+
- **Refactoring**: Collapse Hierarchy, Inline Class, Remove Parameter
|
|
136
|
+
|
|
137
|
+
## Refactoring Techniques
|
|
138
|
+
|
|
139
|
+
### Extract Method
|
|
140
|
+
|
|
141
|
+
**When**: Code fragment can be grouped together
|
|
142
|
+
**Benefit**: Improves clarity, reusability
|
|
143
|
+
|
|
144
|
+
### Inline Method
|
|
145
|
+
|
|
146
|
+
**When**: Method body is as clear as the name
|
|
147
|
+
**Benefit**: Reduces unnecessary indirection
|
|
148
|
+
|
|
149
|
+
### Extract Variable
|
|
150
|
+
|
|
151
|
+
**When**: Complex expression that's hard to understand
|
|
152
|
+
**Benefit**: Makes expression clearer
|
|
153
|
+
|
|
154
|
+
### Rename Variable/Method/Class
|
|
155
|
+
|
|
156
|
+
**When**: Name doesn't reveal intent
|
|
157
|
+
**Benefit**: Improves readability
|
|
158
|
+
|
|
159
|
+
### Move Method/Field
|
|
160
|
+
|
|
161
|
+
**When**: Method/field used more by another class
|
|
162
|
+
**Benefit**: Reduces coupling, improves cohesion
|
|
163
|
+
|
|
164
|
+
### Extract Class
|
|
165
|
+
|
|
166
|
+
**When**: Class has responsibilities for multiple concerns
|
|
167
|
+
**Benefit**: Follows Single Responsibility Principle
|
|
168
|
+
|
|
169
|
+
### Replace Conditional with Polymorphism
|
|
170
|
+
|
|
171
|
+
**When**: Type-based conditionals
|
|
172
|
+
**Benefit**: Follows Open/Closed Principle
|
|
173
|
+
|
|
174
|
+
## Refactoring Strategies
|
|
175
|
+
|
|
176
|
+
### 1. The Refactoring Workflow
|
|
177
|
+
|
|
178
|
+
**Red-Green-Refactor (TDD)**:
|
|
179
|
+
1. **Red**: Write failing test
|
|
180
|
+
2. **Green**: Make test pass (quick and dirty)
|
|
181
|
+
3. **Refactor**: Improve code while keeping tests green
|
|
182
|
+
|
|
183
|
+
**Safe Refactoring**:
|
|
184
|
+
1. Ensure tests exist and pass
|
|
185
|
+
2. Make small, incremental changes
|
|
186
|
+
3. Run tests after each change
|
|
187
|
+
4. Commit frequently
|
|
188
|
+
5. Use automated refactoring tools when possible
|
|
189
|
+
|
|
190
|
+
### 2. When to Refactor
|
|
191
|
+
|
|
192
|
+
**Rule of Three**:
|
|
193
|
+
- First time: Just do it
|
|
194
|
+
- Second time: Wince but do it anyway
|
|
195
|
+
- Third time: Refactor
|
|
196
|
+
|
|
197
|
+
**Opportunistic Refactoring**:
|
|
198
|
+
- While adding features
|
|
199
|
+
- While fixing bugs
|
|
200
|
+
- During code review
|
|
201
|
+
- When understanding code
|
|
202
|
+
|
|
203
|
+
### 3. When NOT to Refactor
|
|
204
|
+
|
|
205
|
+
- Code is about to be deleted
|
|
206
|
+
- Rewriting is easier than refactoring
|
|
207
|
+
- Close to a deadline (defer to later)
|
|
208
|
+
- Code works and doesn't need changes
|
|
209
|
+
|
|
210
|
+
## Best Practices
|
|
211
|
+
|
|
212
|
+
1. **Test Coverage First**: Ensure tests exist before refactoring
|
|
213
|
+
2. **Small Steps**: Make one change at a time
|
|
214
|
+
3. **Commit Often**: Save working states frequently
|
|
215
|
+
4. **Use Tools**: Leverage IDE and automated refactoring
|
|
216
|
+
5. **Review Changes**: Have someone review your refactoring
|
|
217
|
+
6. **Document Why**: Explain major refactorings in commit messages
|
|
218
|
+
|
|
219
|
+
## Further Reading
|
|
220
|
+
|
|
221
|
+
- "Refactoring" by Martin Fowler
|
|
222
|
+
- "Working Effectively with Legacy Code" by Michael Feathers
|
|
223
|
+
- "Your Code as a Crime Scene" by Adam Tornhill
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Release Strategy
|
|
2
|
+
|
|
3
|
+
Plan and execute safe, controlled software releases. Use deployment patterns that minimize risk and enable quick rollback.
|
|
4
|
+
|
|
5
|
+
## Deployment Patterns
|
|
6
|
+
|
|
7
|
+
### 1. Blue-Green Deployment
|
|
8
|
+
```bash
|
|
9
|
+
# ✅ Switch traffic instantly
|
|
10
|
+
kubectl apply -f deployment-green.yaml
|
|
11
|
+
curl http://green.example.com/health
|
|
12
|
+
kubectl patch service app -p '{"spec":{"selector":{"version":"green"}}}'
|
|
13
|
+
# Rollback if needed: switch back to blue
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### 2. Canary Deployment
|
|
17
|
+
```yaml
|
|
18
|
+
# ✅ Good: Gradual rollout (10% canary, 90% stable)
|
|
19
|
+
apiVersion: apps/v1
|
|
20
|
+
kind: Deployment
|
|
21
|
+
metadata:
|
|
22
|
+
name: app-stable
|
|
23
|
+
spec:
|
|
24
|
+
replicas: 9
|
|
25
|
+
---
|
|
26
|
+
apiVersion: apps/v1
|
|
27
|
+
kind: Deployment
|
|
28
|
+
metadata:
|
|
29
|
+
name: app-canary
|
|
30
|
+
spec:
|
|
31
|
+
replicas: 1
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### 3. Feature Flags
|
|
35
|
+
```javascript
|
|
36
|
+
// ✅ Good: Gradual feature rollout
|
|
37
|
+
if (featureFlags.isEnabled('new-checkout', user.id)) {
|
|
38
|
+
return <NewCheckout />;
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Don'ts ❌
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# ❌ Bad: Big bang release on Friday
|
|
46
|
+
./deploy-all-changes.sh
|
|
47
|
+
# Go home, hope for best
|
|
48
|
+
|
|
49
|
+
# ❌ Bad: No rollback plan
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Best Practices
|
|
53
|
+
- Release during low-traffic periods
|
|
54
|
+
- Have documented rollback procedure
|
|
55
|
+
- Use feature flags for risky changes
|
|
56
|
+
- Monitor key metrics during/after release
|
|
57
|
+
- Automate deployment process
|
|
58
|
+
- Document release notes
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Goal
|
|
2
|
+
- Identify and prioritize risks; propose mitigations and owners.
|
|
3
|
+
|
|
4
|
+
How to do it
|
|
5
|
+
- List risks by category (technical, operational, legal, market).
|
|
6
|
+
- Rate likelihood and impact (Low/Med/High or 1–5).
|
|
7
|
+
- Propose mitigations, triggers, and owners.
|
|
8
|
+
|
|
9
|
+
Do
|
|
10
|
+
- Use a table: Risk | Likelihood | Impact | Mitigation | Owner | Trigger.
|
|
11
|
+
- Include residual risk after mitigation.
|
|
12
|
+
|
|
13
|
+
Don’t
|
|
14
|
+
- Don’t list generic risks without project context.
|
|
15
|
+
- Don’t skip ownership/trigger criteria.
|
|
16
|
+
|
|
17
|
+
Output
|
|
18
|
+
- A prioritized risk register plus a short mitigation plan.
|
|
19
|
+
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Secrets Management Policy
|
|
2
|
+
|
|
3
|
+
Securely store, rotate, and access secrets (API keys, passwords, certificates). Never commit secrets to version control.
|
|
4
|
+
|
|
5
|
+
## Do's ✅
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# ✅ Good: Environment variables
|
|
9
|
+
export DATABASE_URL="postgresql://user:password@localhost/db"
|
|
10
|
+
export API_KEY="sk_live_abc123"
|
|
11
|
+
|
|
12
|
+
# Access in code
|
|
13
|
+
const dbUrl = process.env.DATABASE_URL;
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```javascript
|
|
17
|
+
// ✅ Good: AWS Secrets Manager
|
|
18
|
+
const AWS = require('aws-sdk');
|
|
19
|
+
const client = new AWS.SecretsManager({ region: 'us-east-1' });
|
|
20
|
+
|
|
21
|
+
async function getSecret(name) {
|
|
22
|
+
const data = await client.getSecretValue({ SecretId: name }).promise();
|
|
23
|
+
return JSON.parse(data.SecretString);
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
# ✅ Good: .gitignore secrets
|
|
29
|
+
.env
|
|
30
|
+
.env.local
|
|
31
|
+
secrets/
|
|
32
|
+
*.pem
|
|
33
|
+
*.key
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Don'ts ❌
|
|
37
|
+
|
|
38
|
+
```javascript
|
|
39
|
+
// ❌ Bad: Hardcoded secrets
|
|
40
|
+
const API_KEY = "sk_live_abc123xyz";
|
|
41
|
+
const DB_PASSWORD = "SuperSecret123!";
|
|
42
|
+
|
|
43
|
+
// ❌ Bad: Logging secrets
|
|
44
|
+
logger.info('DB connection', { password: dbPassword });
|
|
45
|
+
|
|
46
|
+
// ❌ Bad: Secrets in URLs
|
|
47
|
+
fetch(`https://api.com/data?api_key=${apiKey}`);
|
|
48
|
+
// ✅ Good: In headers
|
|
49
|
+
fetch('https://api.com/data', {
|
|
50
|
+
headers: { 'Authorization': `Bearer ${apiKey}` }
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Best Practices
|
|
55
|
+
- Never commit secrets to git
|
|
56
|
+
- Use secret management tools (Vault, AWS Secrets Manager)
|
|
57
|
+
- Rotate secrets regularly (90 days)
|
|
58
|
+
- Different secrets for dev/staging/prod
|
|
59
|
+
- Audit secret access
|
|
60
|
+
- Encrypt at rest and in transit
|
|
61
|
+
- Use pre-commit hooks (detect-secrets)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Secure Coding Review
|
|
2
|
+
|
|
3
|
+
Review code for security vulnerabilities using OWASP Top 10 and secure coding standards. Identify and fix flaws before production.
|
|
4
|
+
|
|
5
|
+
## OWASP Top 10 Examples
|
|
6
|
+
|
|
7
|
+
### A01: Broken Access Control
|
|
8
|
+
```javascript
|
|
9
|
+
// ❌ Bad: No authorization
|
|
10
|
+
app.get('/api/users/:id/orders', async (req, res) => {
|
|
11
|
+
const orders = await db.getOrders(req.params.id);
|
|
12
|
+
res.json(orders); // Any user can view any orders!
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
// ✅ Good: Verify ownership
|
|
16
|
+
app.get('/api/users/:id/orders', auth, async (req, res) => {
|
|
17
|
+
if (req.user.id !== parseInt(req.params.id)) {
|
|
18
|
+
return res.status(403).json({ error: 'Forbidden' });
|
|
19
|
+
}
|
|
20
|
+
const orders = await db.getOrders(req.params.id);
|
|
21
|
+
res.json(orders);
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### A02: Cryptographic Failures
|
|
26
|
+
```javascript
|
|
27
|
+
// ❌ Bad: Weak hashing
|
|
28
|
+
const hash = crypto.createHash('md5').update(password).digest('hex');
|
|
29
|
+
|
|
30
|
+
// ✅ Good: Strong hashing
|
|
31
|
+
const hash = await bcrypt.hash(password, 12);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### A03: Injection
|
|
35
|
+
```javascript
|
|
36
|
+
// ❌ Bad: SQL Injection
|
|
37
|
+
const query = `SELECT * FROM users WHERE email = '${email}'`;
|
|
38
|
+
|
|
39
|
+
// ✅ Good: Parameterized query
|
|
40
|
+
const query = 'SELECT * FROM users WHERE email = ?';
|
|
41
|
+
const results = await db.query(query, [email]);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Review Checklist
|
|
45
|
+
- ✅ MFA for sensitive actions
|
|
46
|
+
- ✅ Authorization checks on all endpoints
|
|
47
|
+
- ✅ Input validation and sanitization
|
|
48
|
+
- ✅ Parameterized queries
|
|
49
|
+
- ✅ Secrets not hardcoded
|
|
50
|
+
- ✅ TLS 1.2+ required
|
|
51
|
+
- ✅ No sensitive data in logs
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Security Audit Ability
|
|
2
|
+
|
|
3
|
+
Identify and mitigate security vulnerabilities in code.
|
|
4
|
+
|
|
5
|
+
## OWASP Top 10 Focus
|
|
6
|
+
|
|
7
|
+
1. **Injection Attacks**
|
|
8
|
+
- SQL injection
|
|
9
|
+
- Command injection
|
|
10
|
+
- XSS (Cross-Site Scripting)
|
|
11
|
+
- Prevention: Input validation, parameterized queries
|
|
12
|
+
|
|
13
|
+
2. **Broken Authentication**
|
|
14
|
+
- Weak passwords
|
|
15
|
+
- Session management issues
|
|
16
|
+
- Missing MFA
|
|
17
|
+
- Prevention: Strong auth mechanisms, secure sessions
|
|
18
|
+
|
|
19
|
+
3. **Sensitive Data Exposure**
|
|
20
|
+
- Unencrypted data
|
|
21
|
+
- Hardcoded secrets
|
|
22
|
+
- Logging sensitive info
|
|
23
|
+
- Prevention: Encryption, secret management
|
|
24
|
+
|
|
25
|
+
4. **Access Control**
|
|
26
|
+
- Missing authorization checks
|
|
27
|
+
- Privilege escalation
|
|
28
|
+
- IDOR (Insecure Direct Object References)
|
|
29
|
+
- Prevention: Proper authorization, RBAC
|
|
30
|
+
|
|
31
|
+
5. **Security Misconfiguration**
|
|
32
|
+
- Default credentials
|
|
33
|
+
- Unnecessary services enabled
|
|
34
|
+
- Debug mode in production
|
|
35
|
+
- Prevention: Secure defaults, hardening
|
|
36
|
+
|
|
37
|
+
## Security Checklist
|
|
38
|
+
|
|
39
|
+
Input Validation:
|
|
40
|
+
|
|
41
|
+
- [ ] Validate all user inputs
|
|
42
|
+
- [ ] Whitelist > blacklist
|
|
43
|
+
- [ ] Sanitize outputs
|
|
44
|
+
- [ ] Check file upload types and sizes
|
|
45
|
+
|
|
46
|
+
Authentication & Authorization:
|
|
47
|
+
|
|
48
|
+
- [ ] Strong password requirements
|
|
49
|
+
- [ ] Secure session management
|
|
50
|
+
- [ ] Proper authorization checks
|
|
51
|
+
- [ ] Rate limiting on auth endpoints
|
|
52
|
+
|
|
53
|
+
Data Protection:
|
|
54
|
+
|
|
55
|
+
- [ ] Encrypt sensitive data at rest
|
|
56
|
+
- [ ] Use HTTPS for data in transit
|
|
57
|
+
- [ ] No secrets in code/logs
|
|
58
|
+
- [ ] Secure key management
|
|
59
|
+
|
|
60
|
+
Code Security:
|
|
61
|
+
|
|
62
|
+
- [ ] No eval() or dangerous functions
|
|
63
|
+
- [ ] Parameterized queries (no string concat)
|
|
64
|
+
- [ ] Secure random number generation
|
|
65
|
+
- [ ] Dependency vulnerability scanning
|