@martinffx/atelier 1.0.1 → 1.1.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 +17 -0
- package/README.md +1 -5
- package/package.json +1 -2
- package/skills/{code-conventional-commit → code-commit}/SKILL.md +16 -1
- package/skills/code-commit/references/pr-workflow.md +145 -0
- package/skills/code-debug/SKILL.md +0 -4
- package/skills/code-review/references/reviewers.md +3 -11
- package/skills/code-review/references/rq.md +4 -5
- package/skills/oracle-grillme/SKILL.md +160 -0
- package/skills/oracle-grillme/references/ADR-FORMAT.md +47 -0
- package/skills/oracle-grillme/references/CONTEXT-FORMAT.md +63 -0
- package/skills/spec-finish/SKILL.md +2 -5
- package/skills/spec-implement/SKILL.md +1 -1
- package/skills/code-conventional-commit/evals/evals.json +0 -23
- package/skills/code-conventional-commit/workspace/iteration-1/eval-0/with_skill/outputs/commit-message.txt +0 -4
- package/skills/code-conventional-commit/workspace/iteration-1/eval-0/with_skill/outputs/eval_metadata.json +0 -6
- package/skills/code-conventional-commit/workspace/iteration-1/eval-1/with_skill/outputs/eval_metadata.json +0 -6
- package/skills/code-conventional-commit/workspace/iteration-1/eval-1/with_skill/outputs/validation-result.txt +0 -16
- package/skills/code-conventional-commit/workspace/iteration-1/eval-2/with_skill/outputs/commit-message.txt +0 -8
- package/skills/code-conventional-commit/workspace/iteration-1/eval-2/with_skill/outputs/eval_metadata.json +0 -6
- package/skills/code-conventional-commit/workspace/iteration-1/report.html +0 -1325
- package/skills/code-git-worktrees/SKILL.md +0 -218
- package/skills/code-perf/SKILL.md +0 -163
- package/skills/code-perf/references/common-bottlenecks.md +0 -124
- package/skills/code-perf/references/optimization-patterns.md +0 -167
- package/skills/code-perf/references/profiling-tools.md +0 -126
- package/skills/code-security/SKILL.md +0 -183
- package/skills/code-security/references/owasp-top-10.md +0 -129
- package/skills/code-security/references/security-tools.md +0 -102
- package/skills/code-security/references/vulnerability-patterns.md +0 -129
- package/skills/code-stacked-commit/SKILL.md +0 -155
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
# Profiling Tools
|
|
2
|
-
|
|
3
|
-
## Node.js
|
|
4
|
-
|
|
5
|
-
### Built-in
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
# CPU profile
|
|
9
|
-
node --prof app.js
|
|
10
|
-
# Creates isolate-*.log
|
|
11
|
-
|
|
12
|
-
# Analyze
|
|
13
|
-
node --prof-process isolate-*.log
|
|
14
|
-
|
|
15
|
-
# Memory
|
|
16
|
-
node --inspect app.js
|
|
17
|
-
# Open chrome://inspect
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
### clinic.js
|
|
21
|
-
|
|
22
|
-
```bash
|
|
23
|
-
npm install -g clinic
|
|
24
|
-
|
|
25
|
-
# CPU + event loop
|
|
26
|
-
clinic doctor -- node app.js
|
|
27
|
-
|
|
28
|
-
# CPU flame graph
|
|
29
|
-
clinic flame -- node app.js
|
|
30
|
-
|
|
31
|
-
# Memory flame graph
|
|
32
|
-
clinic泡沫 -- node app.js
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
---
|
|
36
|
-
|
|
37
|
-
## Python
|
|
38
|
-
|
|
39
|
-
### cProfile
|
|
40
|
-
|
|
41
|
-
```bash
|
|
42
|
-
# Profile
|
|
43
|
-
python -m cProfile -o profile.prof app.py
|
|
44
|
-
|
|
45
|
-
# Analyze (sorted by cumulative)
|
|
46
|
-
python -m cProfile -s cumulative app.py
|
|
47
|
-
|
|
48
|
-
# Analyze (sorted by time)
|
|
49
|
-
python -m cProfile -s tottime app.py
|
|
50
|
-
|
|
51
|
-
# Interactive
|
|
52
|
-
python -m cProfile -m app.py
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
### line-profiler
|
|
56
|
-
|
|
57
|
-
```bash
|
|
58
|
-
pip install line_profiler
|
|
59
|
-
|
|
60
|
-
# Add @profile decorator
|
|
61
|
-
@profile
|
|
62
|
-
def slow_function():
|
|
63
|
-
...
|
|
64
|
-
|
|
65
|
-
# Run
|
|
66
|
-
kernprof -l -v app.py
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
---
|
|
70
|
-
|
|
71
|
-
## Go
|
|
72
|
-
|
|
73
|
-
### pprof
|
|
74
|
-
|
|
75
|
-
```bash
|
|
76
|
-
# CPU profile
|
|
77
|
-
go test -cpuprofile=cpu.prof -bench=.
|
|
78
|
-
go tool pprof cpu.prof
|
|
79
|
-
|
|
80
|
-
# Memory profile
|
|
81
|
-
go test -memprofile=mem.prof -bench=.
|
|
82
|
-
go tool pprof mem.prof
|
|
83
|
-
|
|
84
|
-
# Web UI
|
|
85
|
-
go tool pprof -http=:8080 cpu.prof
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
### Built-in
|
|
89
|
-
|
|
90
|
-
```bash
|
|
91
|
-
# Runtime stats
|
|
92
|
-
import runtime
|
|
93
|
-
|
|
94
|
-
func printStats() {
|
|
95
|
-
var m runtime.MemStats
|
|
96
|
-
runtime.ReadMemStats(&m)
|
|
97
|
-
println(m.Alloc, m.TotalAlloc, m.Mallocs)
|
|
98
|
-
}
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
---
|
|
102
|
-
|
|
103
|
-
## Browser
|
|
104
|
-
|
|
105
|
-
### Chrome DevTools
|
|
106
|
-
|
|
107
|
-
1. Open DevTools (F12)
|
|
108
|
-
2. Performance tab
|
|
109
|
-
3. Click Record
|
|
110
|
-
4. Perform action
|
|
111
|
-
5. Click Stop
|
|
112
|
-
6. Analyze flame graph
|
|
113
|
-
|
|
114
|
-
### What to Look For
|
|
115
|
-
|
|
116
|
-
- Long tasks (50ms+)
|
|
117
|
-
- Large paint/layout
|
|
118
|
-
- Expensive JS functions
|
|
119
|
-
- Memory growth over time
|
|
120
|
-
|
|
121
|
-
### Memory Tab
|
|
122
|
-
|
|
123
|
-
- Take heap snapshot
|
|
124
|
-
- Compare snapshots
|
|
125
|
-
- Find detached DOM trees
|
|
126
|
-
- Track memory growth
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: code-security
|
|
3
|
-
description: >
|
|
4
|
-
Security audit and vulnerability detection. Use when reviewing code for security issues,
|
|
5
|
-
scanning dependencies, or addressing security concerns. Triggers on "security", "vulnerability",
|
|
6
|
-
"audit", "CVE", "injection", "XSS", "SQL injection", "auth", or when the user asks to check
|
|
7
|
-
for security issues.
|
|
8
|
-
user-invocable: true
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
# Code Security
|
|
12
|
-
|
|
13
|
-
Security audit workflow and checklist.
|
|
14
|
-
|
|
15
|
-
## The Workflow
|
|
16
|
-
|
|
17
|
-
### 1. Scan
|
|
18
|
-
|
|
19
|
-
Run automated security tools.
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
# Check dependencies
|
|
23
|
-
npm audit
|
|
24
|
-
pip audit
|
|
25
|
-
cargo audit
|
|
26
|
-
|
|
27
|
-
# Run security scanner
|
|
28
|
-
trivy fs .
|
|
29
|
-
snyk test
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
### 2. Review
|
|
33
|
-
|
|
34
|
-
Manual code review against checklist.
|
|
35
|
-
|
|
36
|
-
See references/owasp-top-10.md for common vulnerabilities.
|
|
37
|
-
|
|
38
|
-
### 3. Fix
|
|
39
|
-
|
|
40
|
-
Remediate vulnerabilities found.
|
|
41
|
-
|
|
42
|
-
### 4. Verify
|
|
43
|
-
|
|
44
|
-
Re-scan to confirm fixes.
|
|
45
|
-
|
|
46
|
-
---
|
|
47
|
-
|
|
48
|
-
## Security Checklist
|
|
49
|
-
|
|
50
|
-
### Injection
|
|
51
|
-
|
|
52
|
-
| Check | Pattern |
|
|
53
|
-
|-------|---------|
|
|
54
|
-
| SQL | Parameterized queries |
|
|
55
|
-
| Command | No shell execution with user input |
|
|
56
|
-
| XSS | Escape/validate output |
|
|
57
|
-
| LDAP | Escape DN components |
|
|
58
|
-
|
|
59
|
-
### Authentication
|
|
60
|
-
|
|
61
|
-
| Check | Pattern |
|
|
62
|
-
|-------|---------|
|
|
63
|
-
| Passwords | Hash with bcrypt/argon2 |
|
|
64
|
-
| Sessions | Secure, httpOnly cookies |
|
|
65
|
-
| Tokens | Short-lived, proper validation |
|
|
66
|
-
| MFA | Consider for sensitive ops |
|
|
67
|
-
|
|
68
|
-
### Data Protection
|
|
69
|
-
|
|
70
|
-
| Check | Pattern |
|
|
71
|
-
|-------|---------|
|
|
72
|
-
| Secrets | Never in code |
|
|
73
|
-
| PII | Encrypt at rest |
|
|
74
|
-
| Transport | HTTPS only |
|
|
75
|
-
| Logs | No sensitive data |
|
|
76
|
-
|
|
77
|
-
### Dependencies
|
|
78
|
-
|
|
79
|
-
| Check | Pattern |
|
|
80
|
-
|-------|---------|
|
|
81
|
-
| Vulnerabilities | Scan regularly |
|
|
82
|
-
| Outdated | Update promptly |
|
|
83
|
-
| Sources | Trusted packages only |
|
|
84
|
-
|
|
85
|
-
---
|
|
86
|
-
|
|
87
|
-
## Common Vulnerabilities
|
|
88
|
-
|
|
89
|
-
See references/vulnerability-patterns.md for detailed patterns:
|
|
90
|
-
|
|
91
|
-
### SQL Injection
|
|
92
|
-
|
|
93
|
-
```python
|
|
94
|
-
# BAD
|
|
95
|
-
query = f"SELECT * FROM users WHERE id = {user_id}"
|
|
96
|
-
|
|
97
|
-
# GOOD
|
|
98
|
-
query = "SELECT * FROM users WHERE id = %s"
|
|
99
|
-
cursor.execute(query, (user_id,))
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
### XSS
|
|
103
|
-
|
|
104
|
-
```javascript
|
|
105
|
-
// BAD
|
|
106
|
-
element.innerHTML = userInput;
|
|
107
|
-
|
|
108
|
-
// GOOD
|
|
109
|
-
element.textContent = userInput;
|
|
110
|
-
// or
|
|
111
|
-
element.setAttribute('title', sanitize(userInput))
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
### Command Injection
|
|
115
|
-
|
|
116
|
-
```python
|
|
117
|
-
# BAD
|
|
118
|
-
os.system(f"ping {host}")
|
|
119
|
-
|
|
120
|
-
# GOOD
|
|
121
|
-
subprocess.run(['ping', host])
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
### Hardcoded Secrets
|
|
125
|
-
|
|
126
|
-
```javascript
|
|
127
|
-
// BAD
|
|
128
|
-
const apiKey = "sk_live_12345";
|
|
129
|
-
|
|
130
|
-
// GOOD (environment variable)
|
|
131
|
-
const apiKey = process.env.API_KEY;
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
---
|
|
135
|
-
|
|
136
|
-
## Tools
|
|
137
|
-
|
|
138
|
-
See references/security-tools.md for setup and usage:
|
|
139
|
-
|
|
140
|
-
| Tool | Ecosystem | Purpose |
|
|
141
|
-
|------|-----------|---------|
|
|
142
|
-
| npm audit | Node.js | Dependency vulnerabilities |
|
|
143
|
-
| pip-audit | Python | Dependency vulnerabilities |
|
|
144
|
-
| cargo-audit | Rust | Dependency vulnerabilities |
|
|
145
|
-
| Snyk | Multi | Vulnerability scanning |
|
|
146
|
-
| Trivy | Multi | Container/infra scanning |
|
|
147
|
-
| OWASP ZAP | Multi | Web app scanning |
|
|
148
|
-
| bandit | Python | Static analysis |
|
|
149
|
-
| ESLint security | JS/TS | Static analysis |
|
|
150
|
-
|
|
151
|
-
---
|
|
152
|
-
|
|
153
|
-
## Output Format
|
|
154
|
-
|
|
155
|
-
After security audit:
|
|
156
|
-
|
|
157
|
-
```markdown
|
|
158
|
-
## Security Audit
|
|
159
|
-
|
|
160
|
-
### Scan Results
|
|
161
|
-
- Dependencies: 0 vulnerabilities
|
|
162
|
-
- Static analysis: 1 issue found
|
|
163
|
-
|
|
164
|
-
### Issues Found
|
|
165
|
-
|
|
166
|
-
| Severity | Issue | Location | Fix |
|
|
167
|
-
|----------|-------|----------|-----|
|
|
168
|
-
| High | SQL injection | users.py:42 | Use parameterized query |
|
|
169
|
-
| Medium | Hardcoded secret | config.js:5 | Use env var |
|
|
170
|
-
|
|
171
|
-
### Recommendations
|
|
172
|
-
1. Enable 2FA for admin accounts
|
|
173
|
-
2. Rotate API keys quarterly
|
|
174
|
-
3. Set up automated dependency scanning
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
---
|
|
178
|
-
|
|
179
|
-
## Skill Loading
|
|
180
|
-
|
|
181
|
-
- For database issues → load python-sqlalchemy or typescript-drizzle-orm
|
|
182
|
-
- For auth issues → load relevant auth patterns
|
|
183
|
-
- For deployment security → load infra skills if available
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
# OWASP Top 10 (2021)
|
|
2
|
-
|
|
3
|
-
## A01: Broken Access Control
|
|
4
|
-
|
|
5
|
-
Users acting outside their intended permissions.
|
|
6
|
-
|
|
7
|
-
**Check:**
|
|
8
|
-
- Enforce authorization on every request
|
|
9
|
-
- Don't rely on hidden URLs
|
|
10
|
-
- Disable directory listing
|
|
11
|
-
- Log access control failures
|
|
12
|
-
|
|
13
|
-
**Patterns:**
|
|
14
|
-
```javascript
|
|
15
|
-
// Check permission
|
|
16
|
-
if (user.id !== resource.ownerId) {
|
|
17
|
-
throw new ForbiddenError();
|
|
18
|
-
}
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
---
|
|
22
|
-
|
|
23
|
-
## A02: Cryptographic Failures
|
|
24
|
-
|
|
25
|
-
Data exposure due to weak cryptography.
|
|
26
|
-
|
|
27
|
-
**Check:**
|
|
28
|
-
- Encrypt sensitive data at rest
|
|
29
|
-
- Use strong encryption (AES-256, RSA-2048+)
|
|
30
|
-
- Don't use deprecated algorithms (MD5, SHA1)
|
|
31
|
-
- Proper key management
|
|
32
|
-
|
|
33
|
-
---
|
|
34
|
-
|
|
35
|
-
## A03: Injection
|
|
36
|
-
|
|
37
|
-
User data interpreted as code.
|
|
38
|
-
|
|
39
|
-
**Types:**
|
|
40
|
-
- SQL
|
|
41
|
-
- NoSQL
|
|
42
|
-
- OS Command
|
|
43
|
-
- LDAP
|
|
44
|
-
- Expression Language
|
|
45
|
-
|
|
46
|
-
**Prevention:**
|
|
47
|
-
- Parameterized queries
|
|
48
|
-
- Input validation
|
|
49
|
-
- Escape output
|
|
50
|
-
|
|
51
|
-
---
|
|
52
|
-
|
|
53
|
-
## A04: Insecure Design
|
|
54
|
-
|
|
55
|
-
Missing security controls in design.
|
|
56
|
-
|
|
57
|
-
**Check:**
|
|
58
|
-
- Threat modeling
|
|
59
|
-
- Secure design patterns
|
|
60
|
-
- Segregation of duties
|
|
61
|
-
|
|
62
|
-
---
|
|
63
|
-
|
|
64
|
-
## A05: Security Misconfiguration
|
|
65
|
-
|
|
66
|
-
Incorrect security settings.
|
|
67
|
-
|
|
68
|
-
**Check:**
|
|
69
|
-
- Default credentials
|
|
70
|
-
- Unnecessary features
|
|
71
|
-
- Error handling (no stack traces)
|
|
72
|
-
- Security headers
|
|
73
|
-
|
|
74
|
-
---
|
|
75
|
-
|
|
76
|
-
## A06: Vulnerable Components
|
|
77
|
-
|
|
78
|
-
Using components with known vulnerabilities.
|
|
79
|
-
|
|
80
|
-
**Check:**
|
|
81
|
-
- Keep dependencies updated
|
|
82
|
-
- Monitor CVE feeds
|
|
83
|
-
- Remove unused components
|
|
84
|
-
|
|
85
|
-
---
|
|
86
|
-
|
|
87
|
-
## A07: Auth Failures
|
|
88
|
-
|
|
89
|
-
Weaknesses in authentication.
|
|
90
|
-
|
|
91
|
-
**Check:**
|
|
92
|
-
- Don't ship with default credentials
|
|
93
|
-
- Implement MFA
|
|
94
|
-
- Proper session handling
|
|
95
|
-
- Credential recovery flows
|
|
96
|
-
|
|
97
|
-
---
|
|
98
|
-
|
|
99
|
-
## A08: Software/Data Integrity Failures
|
|
100
|
-
|
|
101
|
-
Assuming software updates are safe.
|
|
102
|
-
|
|
103
|
-
**Check:**
|
|
104
|
-
- Verify integrity (signatures, checksums)
|
|
105
|
-
- Don't use untrusted CDNs
|
|
106
|
-
- CI/CD security
|
|
107
|
-
|
|
108
|
-
---
|
|
109
|
-
|
|
110
|
-
## A09: Logging Failures
|
|
111
|
-
|
|
112
|
-
Insufficient logging and monitoring.
|
|
113
|
-
|
|
114
|
-
**Check:**
|
|
115
|
-
- Log access control failures
|
|
116
|
-
- Log sensitive operations
|
|
117
|
-
- Don't log secrets
|
|
118
|
-
- Set up alerting
|
|
119
|
-
|
|
120
|
-
---
|
|
121
|
-
|
|
122
|
-
## A10: SSRF
|
|
123
|
-
|
|
124
|
-
Fetching remote resources without validating URLs.
|
|
125
|
-
|
|
126
|
-
**Check:**
|
|
127
|
-
- Validate URLs
|
|
128
|
-
- Disable HTTP redirects
|
|
129
|
-
- Use allowlists
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
# Security Tools
|
|
2
|
-
|
|
3
|
-
## Node.js
|
|
4
|
-
|
|
5
|
-
### npm audit
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm audit
|
|
9
|
-
npm audit fix
|
|
10
|
-
npm audit --audit-level=high
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
### Snyk
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
npm install -g snyk
|
|
17
|
-
snyk auth
|
|
18
|
-
snyk test
|
|
19
|
-
snyk monitor
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
### ESLint Security
|
|
23
|
-
|
|
24
|
-
```bash
|
|
25
|
-
npm install --save-dev eslint-plugin-security
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
.eslintrc.json:
|
|
29
|
-
```json
|
|
30
|
-
{
|
|
31
|
-
"plugins": ["security"],
|
|
32
|
-
"rules": {
|
|
33
|
-
"security/detect-object-injection": "error",
|
|
34
|
-
"security/detect-non-literal-fs-filename": "error"
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
---
|
|
40
|
-
|
|
41
|
-
## Python
|
|
42
|
-
|
|
43
|
-
### pip-audit
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
pip install pip-audit
|
|
47
|
-
pip-audit
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
### Bandit
|
|
51
|
-
|
|
52
|
-
```bash
|
|
53
|
-
pip install bandit
|
|
54
|
-
bandit -r src/
|
|
55
|
-
bandit -r src/ -f json -o report.json
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
### Safety
|
|
59
|
-
|
|
60
|
-
```bash
|
|
61
|
-
pip install safety
|
|
62
|
-
safety check
|
|
63
|
-
safety check --json
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
---
|
|
67
|
-
|
|
68
|
-
## Go
|
|
69
|
-
|
|
70
|
-
### govulncheck
|
|
71
|
-
|
|
72
|
-
```bash
|
|
73
|
-
go install golang.org/x/vuln/cmd/govulncheck@latest
|
|
74
|
-
govulncheck ./...
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
### gosec
|
|
78
|
-
|
|
79
|
-
```bash
|
|
80
|
-
go install github.com/securego/gosec/cmd/gosec@latest
|
|
81
|
-
gosec ./...
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
---
|
|
85
|
-
|
|
86
|
-
## Multi-Language
|
|
87
|
-
|
|
88
|
-
### Trivy
|
|
89
|
-
|
|
90
|
-
```bash
|
|
91
|
-
brew install trivy
|
|
92
|
-
trivy fs .
|
|
93
|
-
trivy fs --severity HIGH,CRITICAL .
|
|
94
|
-
trivy image myimage:latest
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
### OWASP ZAP
|
|
98
|
-
|
|
99
|
-
```bash
|
|
100
|
-
# Docker
|
|
101
|
-
docker run -p 8080:8080 owasp/zap2docker-stable zap-baseline.py -t https://example.com
|
|
102
|
-
```
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
# Vulnerability Patterns
|
|
2
|
-
|
|
3
|
-
## SQL Injection
|
|
4
|
-
|
|
5
|
-
### Bad
|
|
6
|
-
```python
|
|
7
|
-
query = f"SELECT * FROM users WHERE id = {user_id}"
|
|
8
|
-
```
|
|
9
|
-
|
|
10
|
-
### Good
|
|
11
|
-
```python
|
|
12
|
-
query = "SELECT * FROM users WHERE id = %s"
|
|
13
|
-
cursor.execute(query, (user_id,))
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
---
|
|
17
|
-
|
|
18
|
-
## Command Injection
|
|
19
|
-
|
|
20
|
-
### Bad
|
|
21
|
-
```python
|
|
22
|
-
os.system(f"ping {host}")
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
### Good
|
|
26
|
-
```python
|
|
27
|
-
subprocess.run(['ping', host], check=True)
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
---
|
|
31
|
-
|
|
32
|
-
## XSS (Cross-Site Scripting)
|
|
33
|
-
|
|
34
|
-
### Bad
|
|
35
|
-
```javascript
|
|
36
|
-
element.innerHTML = userInput;
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
### Good
|
|
40
|
-
```javascript
|
|
41
|
-
element.textContent = userInput;
|
|
42
|
-
// or
|
|
43
|
-
element.setAttribute('title', sanitize(userInput));
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
---
|
|
47
|
-
|
|
48
|
-
## Path Traversal
|
|
49
|
-
|
|
50
|
-
### Bad
|
|
51
|
-
```python
|
|
52
|
-
file = open(f"uploads/{filename}")
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
### Good
|
|
56
|
-
```python
|
|
57
|
-
import os
|
|
58
|
-
base = "/app/uploads"
|
|
59
|
-
filename = os.path.basename(filename)
|
|
60
|
-
filepath = os.path.join(base, filename)
|
|
61
|
-
if not filepath.startswith(base):
|
|
62
|
-
raise ValueError("Invalid path")
|
|
63
|
-
file = open(filepath)
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
---
|
|
67
|
-
|
|
68
|
-
## Hardcoded Secrets
|
|
69
|
-
|
|
70
|
-
### Bad
|
|
71
|
-
```javascript
|
|
72
|
-
const API_KEY = "sk_live_abc123";
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
### Good
|
|
76
|
-
```javascript
|
|
77
|
-
const API_KEY = process.env.API_KEY;
|
|
78
|
-
if (!API_KEY) throw new Error("API_KEY not set");
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
---
|
|
82
|
-
|
|
83
|
-
## Insecure Random
|
|
84
|
-
|
|
85
|
-
### Bad
|
|
86
|
-
```javascript
|
|
87
|
-
const token = Math.random().toString(36);
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
### Good
|
|
91
|
-
```javascript
|
|
92
|
-
const crypto = require('crypto');
|
|
93
|
-
const token = crypto.randomBytes(32).toString('hex');
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
---
|
|
97
|
-
|
|
98
|
-
## Unvalidated Redirect
|
|
99
|
-
|
|
100
|
-
### Bad
|
|
101
|
-
```javascript
|
|
102
|
-
res.redirect(req.query.url);
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
### Good
|
|
106
|
-
```javascript
|
|
107
|
-
const allowed = ['/dashboard', '/profile'];
|
|
108
|
-
if (allowed.includes(req.query.url)) {
|
|
109
|
-
res.redirect(req.query.url);
|
|
110
|
-
}
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
---
|
|
114
|
-
|
|
115
|
-
## Mass Assignment
|
|
116
|
-
|
|
117
|
-
### Bad
|
|
118
|
-
```javascript
|
|
119
|
-
const user = req.body; // All fields accepted
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
### Good
|
|
123
|
-
```javascript
|
|
124
|
-
const user = {
|
|
125
|
-
name: req.body.name,
|
|
126
|
-
email: req.body.email
|
|
127
|
-
// Explicitly select allowed fields
|
|
128
|
-
};
|
|
129
|
-
```
|