Cybersecurity
When to Use
- Security review of code, configs, or infrastructure
- Hardening a service, container, or deployment
- Investigating or remediating a vulnerability
- Implementing auth, encryption, or access control
Workflow
1. Threat Model First
Before writing code, identify:
- What assets need protection (data, endpoints, keys)
- Who are the threat actors (external, internal, supply chain)
- What's the attack surface (network, API, file system, deps)
2. Audit
Systematic check in priority order:
Secrets & Credentials:
- No hardcoded secrets (grep for API keys, passwords, tokens)
- Secrets in env vars or vault, never in code/config files
- Rotate exposed credentials immediately
Authentication & Authorization:
- Verify auth on every endpoint, not just frontend
- Check for broken access control (IDOR, privilege escalation)
- Validate JWT/session tokens server-side
Input Validation:
# WRONG: trusting user input
query = f"SELECT * FROM users WHERE id = {request.args['id']}"
# RIGHT: parameterized queries
cursor.execute("SELECT * FROM users WHERE id = %s", (request.args['id'],))
Dependency Security:
# Check for known vulnerabilities
npm audit --production
pip-audit
cargo audit
trivy image myapp:latest
Transport & Encryption:
- TLS 1.2+ for all connections
- HSTS headers on web services
- Encrypt sensitive data at rest (AES-256-GCM)
3. Harden
Container hardening:
# Non-root user
RUN adduser -D appuser
USER appuser
# Minimal base image
FROM gcr.io/distroless/static:nonroot
# No secrets in layers
# Use multi-stage builds, copy only artifacts
Network hardening:
- Default-deny network policies
- Restrict egress to required endpoints only
- No unnecessary open ports
Application hardening:
# Security headers (nginx example)
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options DENY;
add_header Content-Security-Policy "default-src 'self'";
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
4. Verify
- Run SAST/DAST scans (semgrep, bandit, gosec)
- Test auth bypass paths manually
- Verify secrets aren't in git history:
git log -p | grep -i 'password\|secret\|api.key'
- Check container as non-root:
docker run --user 1000 myapp whoami
Common Pitfalls
| Pitfall |
Fix |
| SQL injection via string concat |
Always use parameterized queries |
| Secrets in Docker layers |
Multi-stage build, copy only artifacts |
| JWT validated client-side only |
Always verify server-side with secret |
| CORS wildcard (*) in production |
Explicit allowed origins list |
| Running containers as root |
USER directive + read-only filesystem |
| Logging sensitive data |
Sanitize logs, never log tokens/passwords |
| Outdated dependencies with CVEs |
Automated audit in CI pipeline |
Output Expectations
- Provide specific fixes with code, not just recommendations
- Flag severity (critical/high/medium/low)
- Prioritize: secrets > auth > injection > config > deps
1---
2name: cybersecurity-3
3description: Use for security audits, vulnerability remediation, hardening configs, and secure coding patterns. Not for compliance frameworks or policy writing.
4metadata:
5 source: https://skillmd.com/skills/aibot88/cybersecurity-3
6---
7
8# Cybersecurity
9
10## When to Use
11- Security review of code, configs, or infrastructure
12- Hardening a service, container, or deployment
13- Investigating or remediating a vulnerability
14- Implementing auth, encryption, or access control
15
16## Workflow
17
18### 1. Threat Model First
19Before writing code, identify:
20- What assets need protection (data, endpoints, keys)
21- Who are the threat actors (external, internal, supply chain)
22- What's the attack surface (network, API, file system, deps)
23
24### 2. Audit
25Systematic check in priority order:
26
27**Secrets & Credentials:**
28- No hardcoded secrets (grep for API keys, passwords, tokens)
29- Secrets in env vars or vault, never in code/config files
30- Rotate exposed credentials immediately
31
32**Authentication & Authorization:**
33- Verify auth on every endpoint, not just frontend
34- Check for broken access control (IDOR, privilege escalation)
35- Validate JWT/session tokens server-side
36
37**Input Validation:**
38```python
39# WRONG: trusting user input
40query = f"SELECT * FROM users WHERE id = {request.args['id']}"
41
42# RIGHT: parameterized queries
43cursor.execute("SELECT * FROM users WHERE id = %s", (request.args['id'],))
44```
45
46**Dependency Security:**
47```bash
48# Check for known vulnerabilities
49npm audit --production
50pip-audit
51cargo audit
52trivy image myapp:latest
53```
54
55**Transport & Encryption:**
56- TLS 1.2+ for all connections
57- HSTS headers on web services
58- Encrypt sensitive data at rest (AES-256-GCM)
59
60### 3. Harden
61
62**Container hardening:**
63```dockerfile
64# Non-root user
65RUN adduser -D appuser
66USER appuser
67
68# Minimal base image
69FROM gcr.io/distroless/static:nonroot
70
71# No secrets in layers
72# Use multi-stage builds, copy only artifacts
73```
74
75**Network hardening:**
76- Default-deny network policies
77- Restrict egress to required endpoints only
78- No unnecessary open ports
79
80**Application hardening:**
81```yaml
82# Security headers (nginx example)
83add_header X-Content-Type-Options nosniff;
84add_header X-Frame-Options DENY;
85add_header Content-Security-Policy "default-src 'self'";
86add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
87```
88
89### 4. Verify
90- Run SAST/DAST scans (semgrep, bandit, gosec)
91- Test auth bypass paths manually
92- Verify secrets aren't in git history: `git log -p | grep -i 'password\|secret\|api.key'`
93- Check container as non-root: `docker run --user 1000 myapp whoami`
94
95## Common Pitfalls
96| Pitfall | Fix |
97|---------|-----|
98| SQL injection via string concat | Always use parameterized queries |
99| Secrets in Docker layers | Multi-stage build, copy only artifacts |
100| JWT validated client-side only | Always verify server-side with secret |
101| CORS wildcard (*) in production | Explicit allowed origins list |
102| Running containers as root | USER directive + read-only filesystem |
103| Logging sensitive data | Sanitize logs, never log tokens/passwords |
104| Outdated dependencies with CVEs | Automated audit in CI pipeline |
105
106## Output Expectations
107- Provide specific fixes with code, not just recommendations
108- Flag severity (critical/high/medium/low)
109- Prioritize: secrets > auth > injection > config > deps