cortexhawk 3.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/.cortexhawk-team.yml +65 -0
- package/CHANGELOG.md +268 -0
- package/CLAUDE.md +96 -0
- package/LICENSE +21 -0
- package/PACKS.md +14 -0
- package/README.md +418 -0
- package/REGISTRY.md +23 -0
- package/agents/architect.md +46 -0
- package/agents/brainstormer.md +57 -0
- package/agents/code-simplifier.md +56 -0
- package/agents/codebase-mapper.md +63 -0
- package/agents/copywriter.md +48 -0
- package/agents/debugger.md +44 -0
- package/agents/designer.md +53 -0
- package/agents/devops.md +49 -0
- package/agents/docs-manager.md +50 -0
- package/agents/fullstack-developer.md +55 -0
- package/agents/git-manager.md +63 -0
- package/agents/implementer.md +30 -0
- package/agents/journal-writer.md +53 -0
- package/agents/planner.md +52 -0
- package/agents/project-manager.md +50 -0
- package/agents/researcher.md +46 -0
- package/agents/reviewer.md +63 -0
- package/agents/security-auditor.md +92 -0
- package/agents/teacher.md +71 -0
- package/agents/tester.md +41 -0
- package/commands/api-gen.md +17 -0
- package/commands/backlog.md +26 -0
- package/commands/bootstrap.md +32 -0
- package/commands/brainstorm.md +18 -0
- package/commands/build.md +16 -0
- package/commands/chain.md +46 -0
- package/commands/changelog.md +16 -0
- package/commands/check.md +40 -0
- package/commands/ci.md +32 -0
- package/commands/context.md +35 -0
- package/commands/debug.md +16 -0
- package/commands/deploy.md +16 -0
- package/commands/doc.md +15 -0
- package/commands/export.md +17 -0
- package/commands/journal.md +18 -0
- package/commands/learn.md +16 -0
- package/commands/map.md +16 -0
- package/commands/migrate.md +17 -0
- package/commands/monitor.md +16 -0
- package/commands/optimize.md +17 -0
- package/commands/plan.md +17 -0
- package/commands/pulse.md +46 -0
- package/commands/refactor.md +16 -0
- package/commands/research.md +18 -0
- package/commands/review.md +16 -0
- package/commands/scan.md +19 -0
- package/commands/ship.md +17 -0
- package/commands/simplify.md +16 -0
- package/commands/task.md +32 -0
- package/commands/tdd.md +17 -0
- package/commands/test.md +16 -0
- package/commands/upgrade.md +27 -0
- package/cortexhawk +450 -0
- package/hooks/agent-analytics.sh +67 -0
- package/hooks/branch-guard.sh +56 -0
- package/hooks/codex-dispatcher.sh +84 -0
- package/hooks/commit-guard.sh +71 -0
- package/hooks/compose.yml +47 -0
- package/hooks/dependency-check.sh +56 -0
- package/hooks/file-guard.sh +69 -0
- package/hooks/hooks.json +46 -0
- package/hooks/self-review.sh +71 -0
- package/hooks/session-start.sh +132 -0
- package/hooks/session-telemetry.sh +60 -0
- package/hooks/test-reminder.sh +75 -0
- package/install.sh +3805 -0
- package/mcp/README.md +37 -0
- package/mcp/context7.json +8 -0
- package/mcp/puppeteer.json +8 -0
- package/mcp/sequential-thinking.json +8 -0
- package/modes/default.md +5 -0
- package/modes/fast.md +5 -0
- package/modes/learn.md +9 -0
- package/modes/orchestration.md +5 -0
- package/modes/pair.md +10 -0
- package/modes/research.md +5 -0
- package/modes/review.md +5 -0
- package/package.json +32 -0
- package/profiles/api.json +27 -0
- package/profiles/data.json +23 -0
- package/profiles/fullstack.json +27 -0
- package/scripts/autodetect-profile.sh +68 -0
- package/scripts/benchmark.sh +106 -0
- package/scripts/chain-post-save.sh +23 -0
- package/scripts/generate-plans-index.sh +50 -0
- package/scripts/git-workflow-init.sh +115 -0
- package/scripts/install-codex.sh +128 -0
- package/scripts/interactive-init.sh +264 -0
- package/scripts/post-install-audit.sh +130 -0
- package/scripts/validate.sh +214 -0
- package/settings.json +90 -0
- package/setup.sh +67 -0
- package/skills/databases/schema-designer/SKILL.md +54 -0
- package/skills/databases/sql-optimizer/SKILL.md +37 -0
- package/skills/devops/ci-cd/SKILL.md +59 -0
- package/skills/devops/deployment/SKILL.md +49 -0
- package/skills/devops/docker/SKILL.md +57 -0
- package/skills/frameworks/api-design/SKILL.md +103 -0
- package/skills/frameworks/fastapi/SKILL.md +68 -0
- package/skills/frameworks/nextjs/SKILL.md +74 -0
- package/skills/frameworks/python/SKILL.md +89 -0
- package/skills/frameworks/react/SKILL.md +83 -0
- package/skills/frameworks/sveltekit/SKILL.md +69 -0
- package/skills/frameworks/tailwindcss/SKILL.md +75 -0
- package/skills/frameworks/typescript/SKILL.md +94 -0
- package/skills/meta/mcp-builder/SKILL.md +54 -0
- package/skills/meta/skill-creator/SKILL.md +43 -0
- package/skills/optimization/performance/SKILL.md +70 -0
- package/skills/quality/complexity-analyzer/SKILL.md +52 -0
- package/skills/quality/error-handling/SKILL.md +123 -0
- package/skills/quality/log-analyzer/SKILL.md +31 -0
- package/skills/quality/pattern-detector/SKILL.md +50 -0
- package/skills/security/auth-analyzer/SKILL.md +96 -0
- package/skills/security/compliance-checker/SKILL.md +92 -0
- package/skills/security/container-security/SKILL.md +128 -0
- package/skills/security/dependency-auditor/SKILL.md +100 -0
- package/skills/security/encryption/SKILL.md +94 -0
- package/skills/security/incident-response/SKILL.md +127 -0
- package/skills/security/secrets/SKILL.md +93 -0
- package/skills/security/security-headers/SKILL.md +83 -0
- package/skills/security/security-logging/SKILL.md +107 -0
- package/skills/security/vulnerability-scanner/SKILL.md +114 -0
- package/skills/testing/e2e-testing/SKILL.md +119 -0
- package/skills/testing/tdd/SKILL.md +40 -0
- package/skills/testing/test-generator/SKILL.md +39 -0
- package/skills/workflow/commit/SKILL.md +61 -0
- package/skills/workflow/confidence-check/SKILL.md +90 -0
- package/skills/workflow/pr-review-comments/SKILL.md +81 -0
- package/skills/workflow/pr-review-comments/scripts/fetch_comments.py +237 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: container-security
|
|
3
|
+
description: Docker and Kubernetes security — image hardening, pod security, network policies, secrets in containers, and runtime monitoring.
|
|
4
|
+
detect: Dockerfile docker-compose.yml docker-compose.yaml
|
|
5
|
+
requires: devops/docker
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Container Security
|
|
9
|
+
|
|
10
|
+
## Docker Image Rules
|
|
11
|
+
```
|
|
12
|
+
1. Use minimal base images (distroless, Alpine, scratch)
|
|
13
|
+
2. Pin base image digests, not just tags
|
|
14
|
+
3. Multi-stage builds — tools in build stage, only runtime in final
|
|
15
|
+
4. Run as non-root: USER 1001:1001 (numeric IDs)
|
|
16
|
+
5. No secrets in Dockerfile or build args
|
|
17
|
+
6. Remove package managers/shells from production images
|
|
18
|
+
7. Read-only filesystem where possible
|
|
19
|
+
8. Use COPY, not ADD (ADD auto-extracts, security risk)
|
|
20
|
+
9. Set explicit HEALTHCHECK
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Dockerfile Template
|
|
24
|
+
```dockerfile
|
|
25
|
+
# Build stage
|
|
26
|
+
FROM node:20-alpine@sha256:<pinned> AS builder
|
|
27
|
+
WORKDIR /app
|
|
28
|
+
COPY package*.json ./
|
|
29
|
+
RUN npm ci --only=production
|
|
30
|
+
COPY . .
|
|
31
|
+
RUN npm run build
|
|
32
|
+
|
|
33
|
+
# Production stage
|
|
34
|
+
FROM gcr.io/distroless/nodejs20-debian12
|
|
35
|
+
WORKDIR /app
|
|
36
|
+
COPY --from=builder /app/dist ./dist
|
|
37
|
+
COPY --from=builder /app/node_modules ./node_modules
|
|
38
|
+
USER 1001:1001
|
|
39
|
+
EXPOSE 3000
|
|
40
|
+
CMD ["dist/server.js"]
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Image Scanning
|
|
44
|
+
```
|
|
45
|
+
Tools: Trivy, Grype, Snyk Container, Docker Scout
|
|
46
|
+
|
|
47
|
+
Scan: On build (CI), on push to registry, daily (new CVEs)
|
|
48
|
+
Block: CRITICAL/HIGH CVEs
|
|
49
|
+
Sign: cosign/Notary, verify before deploy
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Kubernetes Hardening
|
|
53
|
+
|
|
54
|
+
### Pod Security Context
|
|
55
|
+
```yaml
|
|
56
|
+
securityContext:
|
|
57
|
+
runAsNonRoot: true
|
|
58
|
+
runAsUser: 1001
|
|
59
|
+
runAsGroup: 1001
|
|
60
|
+
readOnlyRootFilesystem: true
|
|
61
|
+
allowPrivilegeEscalation: false
|
|
62
|
+
capabilities:
|
|
63
|
+
drop: ["ALL"]
|
|
64
|
+
seccompProfile:
|
|
65
|
+
type: RuntimeDefault
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Network Policies
|
|
69
|
+
```yaml
|
|
70
|
+
# Default: deny all, then allow explicitly
|
|
71
|
+
apiVersion: networking.k8s.io/v1
|
|
72
|
+
kind: NetworkPolicy
|
|
73
|
+
metadata:
|
|
74
|
+
name: default-deny-all
|
|
75
|
+
spec:
|
|
76
|
+
podSelector: {}
|
|
77
|
+
policyTypes: [Ingress, Egress]
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### RBAC Rules
|
|
81
|
+
- No cluster-admin for workloads
|
|
82
|
+
- Service accounts per workload (not default SA)
|
|
83
|
+
- Namespace-scoped Roles, not ClusterRoles
|
|
84
|
+
- `automountServiceAccountToken: false` when not needed
|
|
85
|
+
- Review RBAC quarterly
|
|
86
|
+
|
|
87
|
+
### Admission Control
|
|
88
|
+
```
|
|
89
|
+
Enforce via OPA Gatekeeper / Kyverno:
|
|
90
|
+
- No privileged/root containers
|
|
91
|
+
- Required resource limits (CPU/memory)
|
|
92
|
+
- Approved image registries only
|
|
93
|
+
- No hostPath/hostNetwork
|
|
94
|
+
- Required security context and labels
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Secrets in Containers
|
|
98
|
+
```
|
|
99
|
+
NEVER: env vars (docker inspect), build args (cached), baked in image
|
|
100
|
+
|
|
101
|
+
APPROVED:
|
|
102
|
+
- K8s Secrets (encrypted at rest) + volume mount
|
|
103
|
+
- External Secrets Operator + Vault/AWS SM
|
|
104
|
+
- CSI Secrets Store Driver
|
|
105
|
+
- Vault Agent Sidecar Injector
|
|
106
|
+
|
|
107
|
+
Pattern: Store in Vault -> ExternalSecret CR -> K8s Secret -> Pod volume mount (tmpfs)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Runtime Monitoring
|
|
111
|
+
```
|
|
112
|
+
Tools: Falco, Sysdig, Aqua
|
|
113
|
+
|
|
114
|
+
Detect: shell spawned in container, unexpected processes, writes to read-only FS,
|
|
115
|
+
unexpected network connections, privilege escalation, sensitive file access
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Checklist
|
|
119
|
+
- [ ] Base images pinned by digest
|
|
120
|
+
- [ ] Images scanned in CI (block CRITICAL/HIGH)
|
|
121
|
+
- [ ] Containers run as non-root with dropped capabilities
|
|
122
|
+
- [ ] Read-only root filesystem
|
|
123
|
+
- [ ] Network policies enforced (default deny)
|
|
124
|
+
- [ ] Secrets mounted as volumes (not env vars)
|
|
125
|
+
- [ ] Admission controllers enforce policies
|
|
126
|
+
- [ ] Runtime monitoring active
|
|
127
|
+
- [ ] Images signed and verified
|
|
128
|
+
- [ ] Resource limits on all containers
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: dependency-auditor
|
|
3
|
+
description: Audit dependencies for CVEs, supply chain threats, license issues — with CI/CD integration and automated updates.
|
|
4
|
+
detect: base
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Dependency Auditor
|
|
8
|
+
|
|
9
|
+
## Scanning Tools
|
|
10
|
+
| Ecosystem | Built-in | Third-party |
|
|
11
|
+
|---|---|---|
|
|
12
|
+
| npm/yarn/pnpm | `npm audit` | Snyk, Socket.dev, Renovate |
|
|
13
|
+
| Python (pip) | `pip-audit`, `safety` | Snyk, Dependabot |
|
|
14
|
+
| Go | `govulncheck` | Snyk, Dependabot |
|
|
15
|
+
| Rust | `cargo audit` | Snyk, Dependabot |
|
|
16
|
+
| Java/Maven | OWASP Dep-Check | Snyk, Dependabot |
|
|
17
|
+
| Ruby | `bundler-audit` | Snyk, Dependabot |
|
|
18
|
+
| Multi-language | — | Trivy, Grype, Snyk |
|
|
19
|
+
|
|
20
|
+
## Risk Assessment
|
|
21
|
+
| Severity | Action | Timeline |
|
|
22
|
+
|---|---|---|
|
|
23
|
+
| Critical (CVSS ≥9) | Patch immediately | Same day |
|
|
24
|
+
| High (CVSS 7-8.9) | Patch in next release | This week |
|
|
25
|
+
| Medium (CVSS 4-6.9) | Schedule patch | This sprint |
|
|
26
|
+
| Low (CVSS <4) | Track, patch when convenient | Next quarter |
|
|
27
|
+
|
|
28
|
+
## CI/CD Integration
|
|
29
|
+
```
|
|
30
|
+
Pipeline: dependency-scan
|
|
31
|
+
Trigger: Every PR + daily on main
|
|
32
|
+
|
|
33
|
+
1. Install from lockfile (npm ci, not npm install)
|
|
34
|
+
2. Run ecosystem scanner (npm audit, pip-audit, etc.)
|
|
35
|
+
3. Run cross-ecosystem scanner (Trivy or Snyk)
|
|
36
|
+
4. Parse results:
|
|
37
|
+
CRITICAL → Block merge/deploy
|
|
38
|
+
HIGH → Block merge, create ticket
|
|
39
|
+
MEDIUM → Warn, SLA 30 days
|
|
40
|
+
LOW → Log, review quarterly
|
|
41
|
+
5. Post results as PR comment
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Supply Chain Security
|
|
45
|
+
```
|
|
46
|
+
Threats:
|
|
47
|
+
- Typosquatting (similar package names)
|
|
48
|
+
- Dependency confusion (private vs public name collision)
|
|
49
|
+
- Compromised maintainer accounts
|
|
50
|
+
- Malicious post-install scripts
|
|
51
|
+
|
|
52
|
+
Mitigations:
|
|
53
|
+
1. Use scoped packages for internal (@company/pkg)
|
|
54
|
+
2. Configure private registry priority (.npmrc, pip.conf)
|
|
55
|
+
3. Disable post-install scripts for untrusted packages
|
|
56
|
+
4. Pin by hash when possible (pip: --require-hashes)
|
|
57
|
+
5. Review new deps before adding (maintainers, downloads, last update)
|
|
58
|
+
6. Minimize dependency count — fewer deps = smaller surface
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Lockfile Rules
|
|
62
|
+
- ALWAYS commit lockfiles (package-lock.json, poetry.lock, Cargo.lock, go.sum)
|
|
63
|
+
- Use lockfile-only in CI (`npm ci`, not `npm install`)
|
|
64
|
+
- Review lockfile changes in PRs for unexpected additions
|
|
65
|
+
- Pin exact versions in production
|
|
66
|
+
|
|
67
|
+
## Automated Updates
|
|
68
|
+
```
|
|
69
|
+
Dependabot/Renovate:
|
|
70
|
+
- Auto-create PRs for security patches
|
|
71
|
+
- Group minor updates weekly
|
|
72
|
+
- Require CI pass before auto-merge
|
|
73
|
+
- Never auto-merge major versions
|
|
74
|
+
- Label PRs by severity
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## License Compatibility
|
|
78
|
+
| License | Commercial | Copyleft risk |
|
|
79
|
+
|---|---|---|
|
|
80
|
+
| MIT, BSD, Apache 2.0 | Safe | None |
|
|
81
|
+
| LGPL | With conditions | Dynamic linking OK |
|
|
82
|
+
| GPL | Restricted | Viral — code becomes GPL |
|
|
83
|
+
| AGPL | Restricted | Viral even for SaaS |
|
|
84
|
+
| SSPL, BSL | Check terms | Often restrictive |
|
|
85
|
+
|
|
86
|
+
## Output
|
|
87
|
+
```markdown
|
|
88
|
+
## Dependency Audit — [date]
|
|
89
|
+
### Critical/High CVEs
|
|
90
|
+
| Package | Version | CVE | Severity | Fix |
|
|
91
|
+
|---|---|---|---|---|
|
|
92
|
+
|
|
93
|
+
### Outdated (major version behind)
|
|
94
|
+
| Package | Current | Latest | Risk |
|
|
95
|
+
|---|---|---|---|
|
|
96
|
+
|
|
97
|
+
### License Flags
|
|
98
|
+
| Package | License | Risk |
|
|
99
|
+
|---|---|---|
|
|
100
|
+
```
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: encryption
|
|
3
|
+
description: Encryption best practices — algorithms, data at rest/in transit, key management, key rotation, and TLS configuration.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Encryption
|
|
7
|
+
|
|
8
|
+
## Approved Algorithms
|
|
9
|
+
| Purpose | Algorithm | Key Size |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| Symmetric encryption | AES-256-GCM | 256-bit |
|
|
12
|
+
| Symmetric (mobile/embedded) | ChaCha20-Poly1305 | 256-bit |
|
|
13
|
+
| Asymmetric encryption | RSA-OAEP | 4096-bit |
|
|
14
|
+
| Key agreement | ECDH (P-256/P-384) | 256/384-bit |
|
|
15
|
+
| Digital signatures | Ed25519 | 256-bit |
|
|
16
|
+
| Hashing | SHA-256 / SHA-384 | — |
|
|
17
|
+
| Password hashing | Argon2id | — |
|
|
18
|
+
| Password hashing (fallback) | bcrypt (cost >= 12) | — |
|
|
19
|
+
| Key derivation | HKDF-SHA256 | — |
|
|
20
|
+
|
|
21
|
+
## Banned Algorithms
|
|
22
|
+
- MD5, SHA-1 (broken)
|
|
23
|
+
- DES, 3DES, RC4, Blowfish (weak)
|
|
24
|
+
- AES-ECB (pattern leakage)
|
|
25
|
+
- RSA with PKCS#1 v1.5 (padding oracle)
|
|
26
|
+
- Any custom/homegrown crypto
|
|
27
|
+
|
|
28
|
+
## Data at Rest — Envelope Encryption
|
|
29
|
+
```
|
|
30
|
+
1. Generate DEK (Data Encryption Key) per record/file — AES-256-GCM
|
|
31
|
+
2. Encrypt data with DEK
|
|
32
|
+
3. Encrypt DEK with KEK (Key Encryption Key) from KMS
|
|
33
|
+
4. Store encrypted DEK alongside encrypted data
|
|
34
|
+
5. Store KEK only in KMS (AWS KMS, GCP CMEK, Vault Transit)
|
|
35
|
+
6. Never store plaintext DEK on disk
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### What to Encrypt
|
|
39
|
+
```
|
|
40
|
+
Encrypt: PII, financial data, health records, auth credentials
|
|
41
|
+
Don't encrypt: Primary/foreign keys (breaks joins), WHERE clause fields
|
|
42
|
+
Use deterministic encryption or blind indexes for searchable encrypted fields
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Data in Transit — TLS
|
|
46
|
+
```
|
|
47
|
+
Minimum: TLS 1.2 (prefer TLS 1.3)
|
|
48
|
+
Cipher suites (TLS 1.3):
|
|
49
|
+
- TLS_AES_256_GCM_SHA384
|
|
50
|
+
- TLS_CHACHA20_POLY1305_SHA256
|
|
51
|
+
- TLS_AES_128_GCM_SHA256
|
|
52
|
+
|
|
53
|
+
Disable: TLS 1.0/1.1, SSL 2.0/3.0, weak ciphers (RC4, DES, NULL, EXPORT)
|
|
54
|
+
|
|
55
|
+
Certificate management:
|
|
56
|
+
- Automated renewal (Let's Encrypt + certbot, or cloud-native)
|
|
57
|
+
- Pin certs in mobile apps (with backup pins)
|
|
58
|
+
- Monitor expiry (alert 30 days before)
|
|
59
|
+
- Private keys: chmod 600, never in git
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Key Lifecycle
|
|
63
|
+
```
|
|
64
|
+
Generation -> Storage -> Distribution -> Usage -> Rotation -> Revocation -> Destruction
|
|
65
|
+
|
|
66
|
+
1. Generation: CSPRNG only. Never from predictable sources.
|
|
67
|
+
2. Storage: HSM or KMS only. Never on app servers.
|
|
68
|
+
3. Distribution: Encrypted channels only.
|
|
69
|
+
4. Usage: Access via API. Log all usage.
|
|
70
|
+
5. Rotation: Automated per schedule.
|
|
71
|
+
6. Revocation: Immediate on compromise.
|
|
72
|
+
7. Destruction: Cryptographic erasure. Verify.
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Rotation Schedule
|
|
76
|
+
| Key Type | Period | Method |
|
|
77
|
+
|---|---|---|
|
|
78
|
+
| KEK (master) | 365 days | Re-encrypt DEKs with new KEK |
|
|
79
|
+
| DEK (data) | 90 days | Re-encrypt data |
|
|
80
|
+
| TLS certificates | 90 days | Auto-renew (Let's Encrypt) |
|
|
81
|
+
| API signing keys | 90 days | Publish new, deprecate old |
|
|
82
|
+
| SSH keys | 180 days | Distribute new, revoke old |
|
|
83
|
+
|
|
84
|
+
## Checklist
|
|
85
|
+
- [ ] All sensitive data encrypted at rest (AES-256-GCM)
|
|
86
|
+
- [ ] All data in transit uses TLS 1.2+
|
|
87
|
+
- [ ] No banned algorithms in use
|
|
88
|
+
- [ ] Keys managed via KMS/HSM (not filesystem)
|
|
89
|
+
- [ ] Key rotation automated
|
|
90
|
+
- [ ] Envelope encryption for data at rest
|
|
91
|
+
- [ ] Password hashing uses Argon2id or bcrypt (cost >= 12)
|
|
92
|
+
- [ ] No hardcoded encryption keys
|
|
93
|
+
- [ ] IVs/nonces unique per operation (never reused)
|
|
94
|
+
- [ ] Authenticated encryption used (GCM/Poly1305)
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: incident-response
|
|
3
|
+
description: Incident response planning — 6-phase IR process, severity classification, containment, backup strategy, and runbooks.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Incident Response
|
|
7
|
+
|
|
8
|
+
## Response Phases
|
|
9
|
+
```
|
|
10
|
+
1. PREPARATION — Before any incident
|
|
11
|
+
2. DETECTION — Identify and classify
|
|
12
|
+
3. CONTAINMENT — Limit damage
|
|
13
|
+
4. ERADICATION — Remove the threat
|
|
14
|
+
5. RECOVERY — Restore operations
|
|
15
|
+
6. LESSONS LEARNED — Improve defenses
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Severity Classification
|
|
19
|
+
| Level | Examples | Response | SLA |
|
|
20
|
+
|---|---|---|---|
|
|
21
|
+
| SEV-1 (Critical) | Active breach, ransomware, prod creds compromised | Immediate, all-hands | Contain in 1h |
|
|
22
|
+
| SEV-2 (High) | Unauthorized access, critical vuln exploited | 30 min, core team | Contain in 4h |
|
|
23
|
+
| SEV-3 (Medium) | Suspicious activity, non-critical system compromised | 2h, assigned team | Contain in 24h |
|
|
24
|
+
| SEV-4 (Low) | Policy violation, blocked phishing | Next business day | Resolve in 1 week |
|
|
25
|
+
|
|
26
|
+
## Preparation
|
|
27
|
+
- [ ] IR team defined (roles, contacts, escalation path)
|
|
28
|
+
- [ ] Communication templates ready (internal, customer, regulatory)
|
|
29
|
+
- [ ] Runbooks for common scenarios
|
|
30
|
+
- [ ] Access to forensic tools
|
|
31
|
+
- [ ] Tabletop exercises quarterly
|
|
32
|
+
- [ ] Regulatory notification requirements documented (GDPR: 72h)
|
|
33
|
+
|
|
34
|
+
## Containment (First 30 Minutes)
|
|
35
|
+
```
|
|
36
|
+
1. Activate IR team, open incident channel
|
|
37
|
+
2. Begin timestamped incident log
|
|
38
|
+
3. Assess scope: systems, data, users affected
|
|
39
|
+
4. Contain the threat:
|
|
40
|
+
- Isolate affected systems
|
|
41
|
+
- Revoke compromised credentials (ALL)
|
|
42
|
+
- Block malicious IPs/domains
|
|
43
|
+
- Preserve evidence BEFORE changes (snapshots, log exports)
|
|
44
|
+
|
|
45
|
+
Decision tree:
|
|
46
|
+
Credential compromise -> Rotate ALL secrets, revoke sessions
|
|
47
|
+
Malware/ransomware -> Isolate, DO NOT pay, engage forensics
|
|
48
|
+
Data breach -> Identify scope, preserve logs, notify legal
|
|
49
|
+
DDoS -> Enable protection, scale, block patterns
|
|
50
|
+
Insider threat -> Revoke access, preserve audit trail, HR/legal
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Eradication & Recovery
|
|
54
|
+
```
|
|
55
|
+
Eradication:
|
|
56
|
+
1. Identify root cause
|
|
57
|
+
2. Remove attacker access (patch vuln, remove backdoors, rotate creds)
|
|
58
|
+
3. Verify clean state (scan for IOCs, review logs)
|
|
59
|
+
|
|
60
|
+
Recovery:
|
|
61
|
+
1. Restore from verified clean backups
|
|
62
|
+
2. Deploy patches BEFORE reconnecting
|
|
63
|
+
3. Monitor intensely 24-72 hours
|
|
64
|
+
4. Staged restore (not all at once)
|
|
65
|
+
5. Verify data integrity
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Backup Strategy (3-2-1 Rule)
|
|
69
|
+
```
|
|
70
|
+
3 copies, 2 different media, 1 offsite
|
|
71
|
+
+ 1 immutable copy (WORM storage)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
| Type | Frequency | Retention |
|
|
75
|
+
|---|---|---|
|
|
76
|
+
| Full backup | Weekly | 90 days |
|
|
77
|
+
| Incremental | Daily | 30 days |
|
|
78
|
+
| Transaction logs | Continuous | 7 days |
|
|
79
|
+
| Snapshots | Every 4h | 7 days |
|
|
80
|
+
| Config backups | On change | 1 year |
|
|
81
|
+
|
|
82
|
+
### RTO/RPO Targets
|
|
83
|
+
```
|
|
84
|
+
Tier 1 (critical): RTO 1h, RPO 0 (zero data loss)
|
|
85
|
+
Tier 2 (important): RTO 4h, RPO 1h
|
|
86
|
+
Tier 3 (standard): RTO 24h, RPO 24h
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Runbooks
|
|
90
|
+
|
|
91
|
+
### Credential Leak
|
|
92
|
+
```
|
|
93
|
+
1. Identify scope (which credentials, where exposed)
|
|
94
|
+
2. Revoke/rotate immediately
|
|
95
|
+
3. Search logs for unauthorized usage
|
|
96
|
+
4. If used: escalate to full incident
|
|
97
|
+
5. Scan git history for additional leaks
|
|
98
|
+
6. Add pre-commit hooks to prevent recurrence
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Ransomware
|
|
102
|
+
```
|
|
103
|
+
1. Isolate affected systems (disconnect network)
|
|
104
|
+
2. DO NOT pay ransom
|
|
105
|
+
3. Preserve evidence (disk images)
|
|
106
|
+
4. Identify variant (nomoreransom.org)
|
|
107
|
+
5. Restore from clean backups
|
|
108
|
+
6. Rebuild affected systems from scratch
|
|
109
|
+
7. Patch entry vector before reconnecting
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Lessons Learned (Within 5 Business Days)
|
|
113
|
+
1. Timeline reconstruction
|
|
114
|
+
2. Root cause analysis (5 Whys)
|
|
115
|
+
3. What worked / what to improve
|
|
116
|
+
4. Action items with owners and deadlines
|
|
117
|
+
5. Share sanitized findings with team
|
|
118
|
+
|
|
119
|
+
## Checklist
|
|
120
|
+
- [ ] IR plan documented and accessible
|
|
121
|
+
- [ ] Team roles and escalation defined
|
|
122
|
+
- [ ] Runbooks ready for common scenarios
|
|
123
|
+
- [ ] 3-2-1 backup strategy implemented
|
|
124
|
+
- [ ] Backups encrypted and immutable
|
|
125
|
+
- [ ] Restoration tested monthly
|
|
126
|
+
- [ ] RTO/RPO defined per service tier
|
|
127
|
+
- [ ] Post-incident review process established
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: secrets
|
|
3
|
+
description: Secret management — secure storage, rotation, detection, and emergency response for API keys, passwords, certificates, and tokens.
|
|
4
|
+
detect: base
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Secret Management
|
|
8
|
+
|
|
9
|
+
## Core Rules
|
|
10
|
+
1. **Never hardcode secrets** — not in code, configs, comments, or git history
|
|
11
|
+
2. **Never log secrets** — sanitize all log outputs
|
|
12
|
+
3. **Never transmit in URLs** — use headers or request body
|
|
13
|
+
4. **Encrypt at rest** — all secret storage must be encrypted
|
|
14
|
+
5. **Audit all access** — every secret read/write must be logged
|
|
15
|
+
6. **Rotate regularly** — automated rotation on schedule + on compromise
|
|
16
|
+
|
|
17
|
+
## Storage Hierarchy
|
|
18
|
+
| Priority | Solution | Use Case |
|
|
19
|
+
|---|---|---|
|
|
20
|
+
| 1 | Secret Manager (Vault, AWS SM, GCP SM, Azure KV) | Production |
|
|
21
|
+
| 2 | CI/CD platform secrets (GitHub Actions, GitLab CI) | Pipelines |
|
|
22
|
+
| 3 | Encrypted `.env` with key from secret manager | Local dev |
|
|
23
|
+
| 4 | OS keychain (macOS Keychain, Linux Secret Service) | Dev machines |
|
|
24
|
+
| Never | Plain `.env`, config files, code, git history | — |
|
|
25
|
+
|
|
26
|
+
## Vault Pattern
|
|
27
|
+
```
|
|
28
|
+
1. Enable AppRole or Kubernetes auth backend
|
|
29
|
+
2. Create policy with least-privilege paths
|
|
30
|
+
3. Issue short-lived tokens (max TTL 1h)
|
|
31
|
+
4. Enable audit logging
|
|
32
|
+
5. Authenticate on startup, fetch secrets into memory (never disk)
|
|
33
|
+
6. Set up lease renewal for dynamic secrets
|
|
34
|
+
7. Watch for rotation events, re-fetch on signal
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## AWS Secrets Manager Pattern
|
|
38
|
+
```
|
|
39
|
+
1. Create secret with automatic rotation enabled
|
|
40
|
+
2. Use IAM roles (not access keys) for access
|
|
41
|
+
3. Configure rotation lambda (30-90 day cycle)
|
|
42
|
+
4. Use resource policies for cross-account access
|
|
43
|
+
5. Enable CloudTrail for all GetSecretValue calls
|
|
44
|
+
6. Cache secrets client-side with TTL
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Environment Variables
|
|
48
|
+
- [ ] `.env` in `.gitignore` (verify with pre-commit hook)
|
|
49
|
+
- [ ] `.env.example` contains key names only, never values
|
|
50
|
+
- [ ] Production secrets never as plain env vars on disk
|
|
51
|
+
- [ ] Container secrets mounted as tmpfs, not env vars
|
|
52
|
+
- [ ] CI/CD secrets marked as masked/protected
|
|
53
|
+
- [ ] No secrets in `docker inspect`, `ps aux`, or `/proc/*/environ`
|
|
54
|
+
|
|
55
|
+
## Pre-commit Secret Detection
|
|
56
|
+
```
|
|
57
|
+
Tools: git-secrets, truffleHog, detect-secrets, gitleaks
|
|
58
|
+
|
|
59
|
+
Hook should:
|
|
60
|
+
1. Scan staged files for high-entropy strings
|
|
61
|
+
2. Check against known patterns (AWS keys, private keys, tokens)
|
|
62
|
+
3. Block commit if secret detected
|
|
63
|
+
4. Allow .allowlist for false positives (review quarterly)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Rotation Schedule
|
|
67
|
+
| Secret Type | Period | Method |
|
|
68
|
+
|---|---|---|
|
|
69
|
+
| Database passwords | 90 days | Automated via secret manager |
|
|
70
|
+
| API keys | 90 days | Generate new, deprecate old |
|
|
71
|
+
| TLS certificates | Auto-renew 30d before expiry | Let's Encrypt / cloud-native |
|
|
72
|
+
| SSH keys | 180 days | Distribute new, revoke old |
|
|
73
|
+
| Service account tokens | 30 days | Automated rotation |
|
|
74
|
+
|
|
75
|
+
## Emergency Response
|
|
76
|
+
```
|
|
77
|
+
If a secret is compromised:
|
|
78
|
+
1. Immediately revoke/rotate the compromised secret
|
|
79
|
+
2. Issue new secret via secret manager
|
|
80
|
+
3. Deploy updated secret to all consumers
|
|
81
|
+
4. Audit access logs for unauthorized usage
|
|
82
|
+
5. If in git history: rewrite history + rotate ALL secrets in the repo
|
|
83
|
+
6. Document incident
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Checklist
|
|
87
|
+
- [ ] No hardcoded secrets in codebase
|
|
88
|
+
- [ ] All secrets stored in dedicated secret manager
|
|
89
|
+
- [ ] Pre-commit hooks scan for secrets
|
|
90
|
+
- [ ] Rotation automated for all secret types
|
|
91
|
+
- [ ] Access to secrets audited and logged
|
|
92
|
+
- [ ] Emergency rotation procedure documented
|
|
93
|
+
- [ ] .env files excluded from version control
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: security-headers
|
|
3
|
+
description: HTTP security headers, CSP, CORS, CSRF protection — configuration and validation for web applications.
|
|
4
|
+
detect: package.json:express package.json:fastify requirements.txt:fastapi pyproject.toml:fastapi
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Security Headers
|
|
8
|
+
|
|
9
|
+
## Required Headers
|
|
10
|
+
| Header | Value | Purpose |
|
|
11
|
+
|---|---|---|
|
|
12
|
+
| `Strict-Transport-Security` | `max-age=31536000; includeSubDomains; preload` | Force HTTPS |
|
|
13
|
+
| `Content-Security-Policy` | App-specific (see below) | Prevent XSS, injection |
|
|
14
|
+
| `X-Content-Type-Options` | `nosniff` | Prevent MIME sniffing |
|
|
15
|
+
| `X-Frame-Options` | `DENY` or `SAMEORIGIN` | Prevent clickjacking |
|
|
16
|
+
| `Referrer-Policy` | `strict-origin-when-cross-origin` | Control referrer leakage |
|
|
17
|
+
| `Permissions-Policy` | `camera=(), microphone=(), geolocation=()` | Restrict browser APIs |
|
|
18
|
+
| `Cross-Origin-Opener-Policy` | `same-origin` | Isolate browsing context |
|
|
19
|
+
| `Cross-Origin-Resource-Policy` | `same-origin` | Prevent cross-origin reads |
|
|
20
|
+
|
|
21
|
+
Remove: `X-Powered-By`, `Server` (or set generic value)
|
|
22
|
+
|
|
23
|
+
## CSP Template
|
|
24
|
+
```
|
|
25
|
+
default-src 'self';
|
|
26
|
+
script-src 'self' 'nonce-{random}';
|
|
27
|
+
style-src 'self' 'unsafe-inline';
|
|
28
|
+
img-src 'self' data: https:;
|
|
29
|
+
font-src 'self';
|
|
30
|
+
connect-src 'self' https://api.yourdomain.com;
|
|
31
|
+
frame-ancestors 'none';
|
|
32
|
+
base-uri 'self';
|
|
33
|
+
form-action 'self';
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## CORS Checklist
|
|
37
|
+
- Never `Access-Control-Allow-Origin: *` with credentials
|
|
38
|
+
- Whitelist specific origins — never reflect Origin blindly
|
|
39
|
+
- Limit `Allow-Methods` to what's needed
|
|
40
|
+
- Set `Access-Control-Max-Age: 86400` to cache preflight
|
|
41
|
+
|
|
42
|
+
## CSRF Protection
|
|
43
|
+
| App Type | Method |
|
|
44
|
+
|---|---|
|
|
45
|
+
| Server-rendered (MPA) | Synchronizer token (hidden form field) |
|
|
46
|
+
| SPA + API | SameSite cookies + custom header |
|
|
47
|
+
| API-only | Require custom header (`X-Requested-With`) |
|
|
48
|
+
|
|
49
|
+
### CSRF Rules
|
|
50
|
+
1. `SameSite=Strict` on all auth cookies (Lax minimum)
|
|
51
|
+
2. Forms: CSRF token per session, validate server-side
|
|
52
|
+
3. SPAs: Double Submit Cookie or custom header
|
|
53
|
+
4. Reject requests without valid CSRF token
|
|
54
|
+
5. Never rely on Referer/Origin alone
|
|
55
|
+
6. Regenerate CSRF token on login
|
|
56
|
+
|
|
57
|
+
## Framework Examples
|
|
58
|
+
|
|
59
|
+
### Express.js
|
|
60
|
+
```javascript
|
|
61
|
+
const helmet = require('helmet');
|
|
62
|
+
app.use(helmet());
|
|
63
|
+
app.use(helmet.contentSecurityPolicy({
|
|
64
|
+
directives: { defaultSrc: ["'self'"], scriptSrc: ["'self'"] }
|
|
65
|
+
}));
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### FastAPI
|
|
69
|
+
```python
|
|
70
|
+
@app.middleware("http")
|
|
71
|
+
async def security_headers(request, call_next):
|
|
72
|
+
response = await call_next(request)
|
|
73
|
+
response.headers["X-Content-Type-Options"] = "nosniff"
|
|
74
|
+
response.headers["X-Frame-Options"] = "DENY"
|
|
75
|
+
response.headers["Strict-Transport-Security"] = "max-age=31536000; includeSubDomains"
|
|
76
|
+
response.headers["Referrer-Policy"] = "strict-origin-when-cross-origin"
|
|
77
|
+
response.headers["Permissions-Policy"] = "camera=(), microphone=(), geolocation=()"
|
|
78
|
+
return response
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Validation
|
|
82
|
+
Test: `curl -I https://yourdomain.com`
|
|
83
|
+
Online: securityheaders.com, observatory.mozilla.org
|