@rafter-security/cli 0.7.0 → 0.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.
Files changed (56) hide show
  1. package/README.md +20 -1
  2. package/dist/commands/agent/audit-skill.js +2 -1
  3. package/dist/commands/agent/audit.js +27 -0
  4. package/dist/commands/agent/components.js +800 -0
  5. package/dist/commands/agent/disable.js +47 -0
  6. package/dist/commands/agent/enable.js +50 -0
  7. package/dist/commands/agent/index.js +6 -0
  8. package/dist/commands/agent/init.js +162 -164
  9. package/dist/commands/agent/list.js +72 -0
  10. package/dist/commands/brief.js +20 -0
  11. package/dist/commands/docs/index.js +18 -0
  12. package/dist/commands/docs/list.js +37 -0
  13. package/dist/commands/docs/show.js +64 -0
  14. package/dist/commands/mcp/server.js +84 -0
  15. package/dist/commands/skill/index.js +14 -0
  16. package/dist/commands/skill/install.js +89 -0
  17. package/dist/commands/skill/list.js +79 -0
  18. package/dist/commands/skill/registry.js +273 -0
  19. package/dist/commands/skill/remote.js +333 -0
  20. package/dist/commands/skill/review.js +975 -0
  21. package/dist/commands/skill/uninstall.js +65 -0
  22. package/dist/core/audit-logger.js +262 -21
  23. package/dist/core/config-manager.js +3 -0
  24. package/dist/core/docs-loader.js +148 -0
  25. package/dist/core/policy-loader.js +72 -1
  26. package/dist/index.js +6 -0
  27. package/package.json +1 -1
  28. package/resources/skills/rafter/SKILL.md +76 -96
  29. package/resources/skills/rafter/docs/backend.md +106 -0
  30. package/resources/skills/rafter/docs/cli-reference.md +199 -0
  31. package/resources/skills/rafter/docs/finding-triage.md +79 -0
  32. package/resources/skills/rafter/docs/guardrails.md +91 -0
  33. package/resources/skills/rafter/docs/shift-left.md +64 -0
  34. package/resources/skills/rafter-code-review/SKILL.md +91 -0
  35. package/resources/skills/rafter-code-review/docs/api.md +90 -0
  36. package/resources/skills/rafter-code-review/docs/asvs.md +120 -0
  37. package/resources/skills/rafter-code-review/docs/cwe-top25.md +78 -0
  38. package/resources/skills/rafter-code-review/docs/investigation-playbook.md +101 -0
  39. package/resources/skills/rafter-code-review/docs/llm.md +87 -0
  40. package/resources/skills/rafter-code-review/docs/web-app.md +84 -0
  41. package/resources/skills/rafter-secure-design/SKILL.md +103 -0
  42. package/resources/skills/rafter-secure-design/docs/api-design.md +97 -0
  43. package/resources/skills/rafter-secure-design/docs/auth.md +67 -0
  44. package/resources/skills/rafter-secure-design/docs/data-storage.md +90 -0
  45. package/resources/skills/rafter-secure-design/docs/dependencies.md +101 -0
  46. package/resources/skills/rafter-secure-design/docs/deployment.md +104 -0
  47. package/resources/skills/rafter-secure-design/docs/ingestion.md +98 -0
  48. package/resources/skills/rafter-secure-design/docs/standards-pointers.md +102 -0
  49. package/resources/skills/rafter-secure-design/docs/threat-modeling.md +128 -0
  50. package/resources/skills/rafter-skill-review/SKILL.md +106 -0
  51. package/resources/skills/rafter-skill-review/docs/authorship-provenance.md +82 -0
  52. package/resources/skills/rafter-skill-review/docs/changelog-review.md +99 -0
  53. package/resources/skills/rafter-skill-review/docs/data-practices.md +88 -0
  54. package/resources/skills/rafter-skill-review/docs/malware-indicators.md +79 -0
  55. package/resources/skills/rafter-skill-review/docs/prompt-injection.md +85 -0
  56. package/resources/skills/rafter-skill-review/docs/telemetry.md +78 -0
@@ -0,0 +1,101 @@
1
+ # Dependencies & Supply Chain — Design Questions
2
+
3
+ Every dependency is a trust transfer: their bugs become yours, their maintainers become your dependency on goodwill. The question at design time is "is this worth the transfer?"
4
+
5
+ ## Pick vs. write — which one
6
+
7
+ - Cryptography, authN / authZ primitives, parsers for complex formats, protocol implementations: **pick, don't write.** The library has years of eyes and fuzz time.
8
+ - Glue code, config loaders, small utility functions: **write, don't pick.** A 5-line helper beats a transitively-huge dependency.
9
+ - The middle (rate limiters, retry logic, caches): depends on how mature your language's standard library is. Go stdlib + a small helper often beats pulling in a 300-line middleware framework.
10
+
11
+ ## Maintenance signal — before you adopt
12
+
13
+ Read the repo before adopting. Answers to these in one sitting:
14
+
15
+ - When was the last commit, release, CVE response? Dormant ≠ dead, but "last release 2019" for a security-adjacent lib is a risk.
16
+ - How many maintainers? Solo-maintainer packages are a bus-factor and takeover risk (npm `event-stream`, PyPI `ctx`).
17
+ - Does the project publish a security policy (SECURITY.md, GHSA history)? Projects that have handled CVEs well handle them well.
18
+ - Download count and reverse-dependency count: high-popularity packages get eyes on them; low-popularity is higher chance of silent badness.
19
+ - Typosquat / slopsquat check: is this the real package name? LLM-generated install instructions now routinely hallucinate package names that bad actors then register. Verify from the project's own README / GitHub.
20
+
21
+ ## Install-time execution
22
+
23
+ - `postinstall` / `preinstall` / `prepare` hooks in npm, arbitrary `setup.py` code in Python, Gradle init scripts, Cargo build scripts — all run with your developer's or CI's permissions.
24
+ - Does your package manager have a way to disable these? npm `--ignore-scripts`, `pnpm install --ignore-scripts` + allowlist via `packageExtensions`. Pip has `--no-binary` but less granular.
25
+ - CI should install with the strictest flags. Developers can run with scripts enabled *after* review.
26
+
27
+ ## Pinning & lockfiles
28
+
29
+ - Lockfile (`package-lock.json`, `pnpm-lock.yaml`, `yarn.lock`, `poetry.lock`, `Cargo.lock`, `go.sum`) committed. No exceptions for "libraries" — downstream lockfiles are the user's responsibility, but your CI needs reproducibility.
30
+ - Range pinning in the manifest (`^1.2.3`) is fine for libraries; applications benefit from exact pins + a lockfile for reproducibility.
31
+ - Lockfile verification in CI (`npm ci`, `pnpm install --frozen-lockfile`, `yarn install --immutable`, `poetry install --no-update`). Without verification, a drifted lockfile ships unknown code.
32
+
33
+ ## Vendoring vs. registry
34
+
35
+ - Registry (npm, PyPI, Go proxy, crates.io): convenient, but the registry is a trust root. Compromise of a maintainer account has shipped malware repeatedly.
36
+ - Registry mirror / proxy (Artifactory, Cloudsmith, Google Artifact Registry): lets you cache + scan + pin. Best-of-both for teams with infra.
37
+ - Vendoring: committing dependency code into your repo. Highest control, highest cost. Justified for (a) critical dependencies you need to patch locally, (b) airgapped builds, (c) compliance requirements.
38
+
39
+ ## SCA — hook it in, don't treat it as a quarterly task
40
+
41
+ - SCA on every PR and on main: Dependabot, Renovate, Snyk, Trivy, Grype, `rafter run` (which aggregates SCA).
42
+ - Auto-PRs for dependency updates: accept them with tests gating. Batching 3 months of updates is worse than a weekly drip.
43
+ - Critical CVEs (known-exploited, CVSS ≥ 9): page on detection, not "log and review later".
44
+ - Noise management: not every CVE applies to how you use the library. Triage policy is part of the design — who decides what's accepted, and how is the decision logged?
45
+
46
+ ## Supply chain attacks to design against
47
+
48
+ - **Typosquat / slopsquat**: package name misspellings, especially for names an LLM might generate. Pin from upstream README only.
49
+ - **Dependency confusion**: your private package name registered publicly. Publish a placeholder of your internal package names, or use scoped packages with registry routing.
50
+ - **Maintainer takeover**: compromised maintainer account publishes malware. Defenses: pin by digest (where supported), monitor for unexpected releases.
51
+ - **Protestware / hacktivism**: maintainer deliberately ships malware or destructive code (e.g., `node-ipc`). Pinning catches it; SCA post-mortem confirms.
52
+ - **Compromised CI**: build-time tamper that injects malware into your artifact. Defenses: reproducible builds, signed provenance (SLSA), isolated build environment.
53
+
54
+ ## Transitive depth
55
+
56
+ - How deep is the dep tree? `npm ls` / `cargo tree` / `pipdeptree`. Dozens of transitive deps per direct dep = huge attack surface.
57
+ - Does each direct dep pull in its own HTTP client, its own JSON parser, its own date library? Consolidate at the application level where possible.
58
+ - Transitive version conflicts: which wins? In npm / pnpm, hoisting rules. In Python, last-wins. Explicit `overrides` / `resolutions` let you force a patched version.
59
+
60
+ ## Container images as dependencies
61
+
62
+ - Base images are dependencies — same maintenance questions apply. Distroless (Google-maintained) and Chainguard (security-first) are first-party; random Docker Hub images are not.
63
+ - Pin by digest. `image:tag` is mutable.
64
+ - Multi-stage builds: builder image can be heavy; final image should be minimal. Don't ship your build toolchain to prod.
65
+ - Image scanning in CI: `trivy image`, `grype`, cloud-native scanners. Block deploys on critical findings for production.
66
+
67
+ ## SaaS dependencies
68
+
69
+ - Adopting a SaaS is also a dep: your data, their availability and security posture.
70
+ - Do they publish a SOC 2 / ISO 27001 / security whitepaper? Not gospel, but absence is a signal.
71
+ - Where does the data live (region, sub-processors)? For PII, this is a compliance question.
72
+ - Offboarding: if they vanish or you churn, how do you migrate? Vendor lock-in is a security issue too (can't rotate away from a breach).
73
+
74
+ ## LLM / AI libraries — the new supply chain
75
+
76
+ - Model weights are dependencies. Which model, which version, hosted where?
77
+ - Inference SDKs (openai, anthropic, litellm) are dependencies with the standard risks *plus* credential-surface (API keys per provider).
78
+ - Vector DB clients (pinecone, qdrant, chroma) are dependencies that also hold your embeddings — classify accordingly.
79
+ - `prompt-injection-guard` style libraries are pattern-based and will never catch novel attacks — adopt but don't trust absolutely.
80
+
81
+ ## Refuse-list
82
+
83
+ - Pulling a dependency from a raw git URL or GitHub tarball without pinning commit SHA.
84
+ - Adopting a package because an LLM suggested the name, without verifying it exists upstream (slopsquat bait).
85
+ - `:latest` tags on base images or dependency versions.
86
+ - CI that installs with `postinstall` enabled on every run without script review.
87
+ - Solo-maintained packages in your critical path (auth, crypto, payments) without a forking / vendoring plan.
88
+ - Adopting a SaaS for a compliance-scoped workload without reviewing their posture.
89
+ - Skipping the lockfile because "we're a library".
90
+ - SCA as a quarterly scan rather than a PR-level gate.
91
+
92
+ ---
93
+
94
+ ## Exit criteria
95
+
96
+ - Every new direct dependency has a one-line justification (pick vs. write, maintenance signal reviewed).
97
+ - Install-time execution policy is specified for CI.
98
+ - Lockfile + verification in CI is confirmed.
99
+ - SCA tool is wired to PRs, with a triage policy for findings.
100
+ - Base images are pinned by digest with a rebuild cadence.
101
+ - If the design uses a SaaS or LLM provider, the data-flow and credential-scope are drawn.
@@ -0,0 +1,104 @@
1
+ # Deployment — Design Questions
2
+
3
+ Deployment is where "the app is secure" meets reality. Network boundaries, runtime posture, secret distribution, build provenance — each decided here survives every refactor of the code.
4
+
5
+ ## Network topology — zones, not flat
6
+
7
+ - Sketch zones: public edge (LB / CDN / WAF), app tier, data tier, admin tier, third-party egress. Each is a distinct security zone.
8
+ - What traffic is allowed **between** zones, and what's denied by default? Default-deny is the only sane starting point. If the default is allow and you block selectively, you're one misconfiguration from exposure.
9
+ - Public edge: what terminates TLS? WAF in front or not? WAF is good for cheap-filter; not a substitute for app-side validation.
10
+ - Admin access (SSH, kube-exec, DB console): over the public internet? Over a VPN / zero-trust proxy (Tailscale, Cloudflare Access, Teleport)? The public-internet-with-a-bastion is a 2005 pattern.
11
+
12
+ ## Egress — the forgotten boundary
13
+
14
+ - Can your app reach arbitrary internet destinations? Default should be "allowlist of known egress targets" (external APIs you integrate with, OS package mirrors, telemetry).
15
+ - Egress control is the best SSRF defense *and* the best data-exfiltration defense. If a compromised app can only reach `api.stripe.com`, the blast radius is Stripe calls.
16
+ - Metadata services (169.254.169.254): block at the network layer, not just the app. IMDSv2 on AWS (required hop limit = 1 + session token) blocks the rebinding variant.
17
+
18
+ ## Identity & IAM
19
+
20
+ - Every compute workload has a workload identity (AWS IAM role, GCP service account, Kubernetes ServiceAccount + bound tokens, SPIFFE ID). **Not shared credentials, not long-lived keys.**
21
+ - Least privilege per workload. "The web service has DB read + DB write + admin on this one table" is better than "the web service has AdminAccess".
22
+ - Break-glass access: there's an auditable path for a human to gain emergency privileges. Not a shared `root` password.
23
+ - IAM changes go through code review (Terraform PR, Pulumi PR). Click-ops IAM is how wide-open permissions persist.
24
+
25
+ ## Secret distribution
26
+
27
+ - Where does each service get its secrets? Secret manager (Vault, AWS SM, GCP SM, Kubernetes Secrets with sealed / external-secrets), *not* Terraform-plan output, *not* env vars set by a deploy script that logs them.
28
+ - Secrets rotate. Short-lived DB credentials (Vault dynamic secrets, IAM database auth) > long-lived passwords. If your design says "quarterly rotation of a static password", name who does it and how.
29
+ - Secrets are scoped per service. The web tier doesn't have the admin DB credential.
30
+ - Encryption-at-rest for the secret manager itself: by default on all cloud-managed; verify for self-hosted.
31
+ - Secrets in CI: scoped per job, never printed to logs, masked in output. PR workflows triggered from forks don't see secrets.
32
+
33
+ ## Container / runtime posture
34
+
35
+ - Run as non-root. If `USER 0` or `runAsUser: 0`, flag it.
36
+ - Read-only root filesystem where possible. Writable mounts are explicit (`/tmp`, named volumes).
37
+ - Capabilities: drop all, add back only what's needed. `CAP_NET_BIND_SERVICE` is the usual one.
38
+ - Seccomp / AppArmor / SELinux profile: a real profile, not "Unconfined".
39
+ - Resource limits: CPU and memory limits per container. No limit = one compromised pod can starve the node.
40
+
41
+ ## Base images
42
+
43
+ - Distroless / Alpine / minimal / scratch > Ubuntu full. Fewer packages = fewer CVEs, smaller attack surface.
44
+ - Pin by digest (`image@sha256:...`), not tag. `:latest` and even `:v1.2.3` can be overwritten; digests are immutable.
45
+ - SCA on base images in CI. Re-pull / rebuild cadence (weekly) to pick up upstream patches.
46
+ - Who maintains the base image? First-party (your team) > team-adjacent > "some Docker Hub account". Unmaintained bases rot.
47
+
48
+ ## Build provenance & supply chain
49
+
50
+ - Is the build reproducible? Given the same inputs, does a rebuild produce the same artifact? Not always achievable, but worth asking.
51
+ - SLSA level: aim for SLSA 3 (hosted builder, signed provenance) for anything shipping to production. SLSA 1 (provenance exists) is the minimum.
52
+ - Artifact signing: Sigstore / Cosign / Notary. Signatures verified at deploy, not just at build.
53
+ - Dependency pinning: lockfile committed, lockfile verified in CI.
54
+ - `postinstall` / `prepare` scripts from dependencies: ban or audit. These execute arbitrary code on install — it's the npm supply-chain attack class.
55
+ - SBOM generation at build time. Store it with the artifact.
56
+
57
+ ## CI/CD posture
58
+
59
+ - Who can deploy to prod? Production deploys gated on approval, signed tags, or protected branch merges.
60
+ - CI runners: ephemeral (fresh VM / container per job), not long-running hosts with persistent state.
61
+ - Workflow permissions: least-privilege GITHUB_TOKEN / equivalent. Write-all is the click-to-compromise default.
62
+ - Self-hosted runners + public repo = RCE. Either make the repo private, use GitHub-hosted runners for public workflows, or lock runners to specific workflows.
63
+ - Branch protection: required reviews, required status checks, no force-push to main. Linear history if you need audit simplicity.
64
+
65
+ ## Production-vs-staging parity
66
+
67
+ - Same architecture in staging as prod, with masked / synthetic data. Staging that uses prod data = a second prod blast radius with half the controls.
68
+ - Config differences are explicit and minimal. "We disable auth in staging" is how auth gets disabled in prod one day by accident.
69
+ - Feature flags that default-off in prod and default-on in staging: tested in both states.
70
+
71
+ ## Multi-region / DR
72
+
73
+ - If the design spans regions: is the active/passive or active/active model clear? What's replicated, what's per-region?
74
+ - Encryption keys per region, or a global key? (Global is simpler but expands blast radius.)
75
+ - Failover runbook exists and was tested in the last 12 months. Not-yet-tested = doesn't work.
76
+
77
+ ## Logging & monitoring posture
78
+
79
+ - Structured logs, shipped to a separate system (not the same DB the app writes to). A compromise of app storage shouldn't delete the audit trail.
80
+ - Authentication to the log system: workload identity, not shared token.
81
+ - What paging signals exist? Login-anomaly rates, authZ denials, 5xx surges, unusual egress — without these, the breach is found by the customer.
82
+ - Retention: logs often outlive production data. Classify log contents and apply retention accordingly.
83
+
84
+ ## Refuse-list
85
+
86
+ - Long-lived static cloud credentials baked into container images or env vars.
87
+ - Privileged containers (`privileged: true`, `runAsUser: 0` without justification).
88
+ - `:latest` tags or unpinned base images in production manifests.
89
+ - CI workflows with write-all GITHUB_TOKEN scope by default.
90
+ - "We'll add network policy later" — network default-allow is not a plan.
91
+ - Secrets set via Terraform variable with plan output visible in logs.
92
+ - Shared SSH keys, shared `root` password, shared admin console.
93
+ - Metadata service reachable from a public-facing container (IMDSv1, or IMDSv2 with unlimited hop count).
94
+
95
+ ---
96
+
97
+ ## Exit criteria
98
+
99
+ - Zone diagram exists; cross-zone traffic is allowlisted, not denylisted.
100
+ - Each workload has a named identity and a scoped IAM role.
101
+ - Secret distribution names the secret manager and the rotation model.
102
+ - Container runtime posture is specified: user, filesystem, capabilities, resource limits.
103
+ - Build pipeline specifies provenance (SLSA), signing, and dependency pinning.
104
+ - Log shipping + retention is set, independent of application storage.
@@ -0,0 +1,98 @@
1
+ # Ingestion — Design Questions
2
+
3
+ Every byte crossing your trust boundary is a question: "who says this is safe, and how?" Most of the OWASP Top 10 lives at ingestion — parsers, decoders, fetchers, uploaders.
4
+
5
+ ## Trust boundaries — name them
6
+
7
+ - Draw the boundary: external (internet, partner API, user upload) → your edge → your internal services → your storage.
8
+ - Each boundary crossing is a *validation point*. Validation means: shape check (schema), size check (bytes / fields), semantic check (does this make sense here?).
9
+ - Validation at the edge is necessary but not sufficient — internal services that re-read the data need to re-validate if the trust delta matters (e.g., a cached input re-used later as a filename).
10
+ - Parsers *are* the boundary for complex formats. A "validated JSON blob" that contains an eval-able code path is still a hole.
11
+
12
+ ## Input schemas — declare, don't hand-parse
13
+
14
+ - Have a typed schema for every external input: JSON Schema, Zod, Pydantic, protobuf, OpenAPI-generated types. Reject unknown fields (`additionalProperties: false`).
15
+ - Accepting unknown fields is how mass-assignment bugs enter — the attacker ships `is_admin: true` and the schema silently accepts it.
16
+ - Length / size / range bounds on every field. Strings have max lengths, numbers have ranges, arrays have max sizes, nesting has max depth. Unbounded = DoS shape.
17
+ - Regex validation: anchor with `^` and `$`. Fear catastrophic backtracking — test with a regex-safety linter or prefer RE2-backed engines.
18
+
19
+ ## Size limits — everywhere, early
20
+
21
+ - Request body size cap at the edge (reverse proxy / API gateway). Don't rely on the framework to cap — it parses first, rejects second.
22
+ - Per-field limits inside the body.
23
+ - Upload size limits, file-count limits, total-request-size limits.
24
+ - Decoder limits: JSON depth, XML entity count, zip expansion ratio (zip bomb). The default parser often has no cap — configure it explicitly.
25
+
26
+ ## Parser selection — safe default, not fast default
27
+
28
+ - JSON: language-standard parser with strict mode. Reject duplicate keys (behavior varies across parsers — pick one that matches what your schema validator sees).
29
+ - YAML: `yaml.safe_load` in Python, `js-yaml` with `safeLoad` / schema, `serde_yaml` with explicit types. **Never `yaml.load` without `SafeLoader`.**
30
+ - XML: disable external entity resolution (XXE). `defusedxml` in Python, libraries with XXE off by default. If your design needs XML, flag this explicitly and pick the right library.
31
+ - CSV: beware formula injection (`=CMD(...)` in a field opened by Excel). Prefix fields starting with `= + - @ \t \r` when exporting.
32
+ - Protobuf / Thrift / MessagePack: safe-by-construction for schema violations, but size limits still needed.
33
+ - Regex-heavy parsers: ReDoS risk. Prefer PEG / EBNF grammars for untrusted input where possible.
34
+ - HTML / Markdown: never innerHTML raw; always sanitize (DOMPurify, bleach). Markdown renderers have inline-HTML modes — disable them for untrusted content.
35
+
36
+ ## Deserialization — the silent RCE
37
+
38
+ - Any of `pickle.loads`, `yaml.load` (default), Java `ObjectInputStream`, PHP `unserialize`, .NET `BinaryFormatter`, `Marshal.load` — on untrusted bytes — is RCE-shaped.
39
+ - If you *need* cross-language serialization: JSON, Protobuf, MessagePack, Avro. If you *need* native: sign the payload (HMAC) so only your own emitters are accepted, and still validate after deserialization.
40
+ - Node `JSON.parse` + object assignment: prototype pollution via `__proto__` / `constructor` / `prototype` keys. Use `Object.create(null)` for dictionaries or a library that filters.
41
+
42
+ ## File uploads
43
+
44
+ - What file types are accepted? Allowlist by **content sniff + declared MIME + extension**, not any one of them alone.
45
+ - Storage: write under a random name (UUID) — never preserve the client-supplied filename in the path. Preserving it enables path traversal and overwrite attacks.
46
+ - Scanner: for user-to-user content, run an AV / malware scan. For images, re-encode to strip EXIF + polyglot tricks.
47
+ - Serving: serve from a different origin / subdomain than your app (so a rendered SVG or HTML can't steal same-origin cookies). Set `Content-Disposition: attachment` for anything that isn't trusted media.
48
+ - Size: per-file and per-user/per-day quotas. Unbounded upload = cheap DoS + storage bomb.
49
+
50
+ ## Server-side fetchers — SSRF-shaped
51
+
52
+ If any part of the design does "take a URL from user, fetch it":
53
+
54
+ - Is there a concrete business reason? Image proxy, webhook configurer, PDF-from-URL, OAuth metadata fetch — each is a known SSRF vector.
55
+ - Allowlist the destination **after** DNS resolution. `https://attacker.com` that DNS-resolves to `127.0.0.1` is the rebinding attack — resolve first, then decide.
56
+ - Deny: RFC1918 (10/8, 172.16/12, 192.168/16), link-local (169.254/16), loopback (127/8, ::1), cloud metadata (169.254.169.254, metadata.google.internal, fd00:ec2::254), IPv6 equivalents, and any internal CIDR you own.
57
+ - Redirects are fresh SSRF checks per hop. Disable redirects or re-validate each one.
58
+ - Timeouts + max-response-size: unbounded fetches = DoS.
59
+ - Response parsing: the fetched content is *still untrusted*. Don't eval it, don't template it, don't copy it to storage unsanitized.
60
+
61
+ ## Content rendering — templates, markdown, rich text
62
+
63
+ - Which template engine? Autoescape on by default for HTML (`{{ user }}` escapes). The unsafe marker is `|safe` (Jinja), `{!! !!}` (Blade), `dangerouslySetInnerHTML` (React), `v-html` (Vue). Every use of the unsafe marker is a review point.
64
+ - Markdown: does the renderer allow inline HTML? For untrusted authors, disable it or sanitize post-render with a DOMPurify-equivalent.
65
+ - Rich text (TinyMCE, Quill, Slate): sanitize the HTML output *server-side* before storing. Client-side sanitization is advisory, not authoritative.
66
+ - SVG: SVGs can embed scripts. Re-render to PNG server-side, or sanitize with a tool that strips `<script>`, event handlers, and external references.
67
+
68
+ ## Search inputs
69
+
70
+ - Full-text search: user input goes into a query parser (Lucene syntax, etc.). Is there an injection risk (`field:*` to bypass scoping)? Sanitize or use parameterized search API.
71
+ - Sort / filter parameters: if user-controlled, allowlist the column names. `ORDER BY {user_input}` is SQL injection even if the rest of the query is parameterized.
72
+
73
+ ## Imports (batch data)
74
+
75
+ - CSV / XLS / JSON imports are trust-boundary crossings at scale. Same rules — schema, size, field limits — applied per row.
76
+ - Streaming vs. load-all: streaming is kinder to memory and enables early rejection. Load-all with a 1GB file = OOM.
77
+ - Partial-failure semantics: if row 500 is bad, does the import roll back rows 1-499? Either answer can be right, but it must be *decided*, not accidental.
78
+
79
+ ## Refuse-list
80
+
81
+ - `yaml.load` / `pickle.loads` / `Marshal.load` on any externally-sourced bytes.
82
+ - XML parsers with external entity resolution enabled.
83
+ - Uploads stored under client-supplied filenames.
84
+ - Server-side URL fetchers without an allowlist + post-DNS IP denylist.
85
+ - Schemas that accept unknown fields (`additionalProperties: true` by default).
86
+ - Unbounded sizes: no request body cap, no per-field length, no decoder depth limit.
87
+ - Markdown / HTML rendering of untrusted content without server-side sanitization.
88
+ - Regex patterns without anchors or on backtracking engines with untrusted input.
89
+
90
+ ---
91
+
92
+ ## Exit criteria
93
+
94
+ - Every external input has a named schema and a size/shape limit.
95
+ - Parser choices are listed with the safe variant selected.
96
+ - If any fetcher is in the design, its allowlist + IP denylist + redirect policy is specified.
97
+ - File upload flow names the content-sniff library, the storage-naming scheme, and the serving origin.
98
+ - The design identifies every "untrusted bytes → executable context" path and closes it.
@@ -0,0 +1,102 @@
1
+ # Standards & Frameworks — Pointers
2
+
3
+ This skill won't re-derive a compliance checklist. Pick the right baseline for your context, read the small number of sections that actually apply, and point your design doc at them. The goal is *known-adequate*, not *comprehensive*.
4
+
5
+ ## How to choose a baseline
6
+
7
+ Answer these three before picking a framework:
8
+
9
+ 1. **Regulatory scope**: GDPR / CCPA (personal data)? HIPAA (health)? PCI-DSS (payment cards)? SOX (financial reporting)? Each forces specific controls; skipping the wrong one is non-negotiable risk.
10
+ 2. **Maturity goal**: "We need something defensible in review" (ASVS L1), "We handle meaningful PII" (ASVS L2 + SAMM intermediate), "We're a high-value target or regulated" (ASVS L3 + NIST SSDF + SOC 2).
11
+ 3. **Audit horizon**: will anyone external look at this? If yes, align with their expected framework early; retrofitting evidence is expensive.
12
+
13
+ ## App security baseline — OWASP ASVS
14
+
15
+ [OWASP Application Security Verification Standard](https://owasp.org/www-project-application-security-verification-standard/).
16
+
17
+ - **L1 — opportunistic**: external-facing apps without sensitive data. Covers basic auth, input validation, encoding, config. This is the floor; below L1 is "indefensible."
18
+ - **L2 — standard**: apps handling PII, business-critical data, or B2B integrations. Adds cryptography requirements, session depth, access-control rigor.
19
+ - **L3 — advanced**: high-value targets, regulated industries, critical infrastructure. Adds deep crypto requirements, defense-in-depth, hostile-environment assumptions.
20
+
21
+ **Design-time use**: pick your level, scan the chapter for your domain (auth → V2, session → V3, access control → V4, validation → V5, crypto → V6, etc.), lift the requirements that match your design. Don't copy all 280+ requirements — that's audit prep, not design.
22
+
23
+ `rafter-code-review/docs/asvs.md` has a deeper walk for review time.
24
+
25
+ ## Secure development lifecycle — NIST SSDF / SP 800-218
26
+
27
+ [NIST Secure Software Development Framework](https://csrc.nist.gov/projects/ssdf).
28
+
29
+ Four practice areas — *PO* (prepare the org), *PS* (protect the software), *PW* (produce well-secured software), *RV* (respond to vulnerabilities). Most relevant at design time:
30
+
31
+ - **PW.1**: design software to meet security requirements and mitigate risks — the "why are we doing this skill" requirement.
32
+ - **PW.4**: reuse existing well-secured software — dependency selection (see `docs/dependencies.md`).
33
+ - **PW.6**: configure compilation/build/runtime for security — deployment posture.
34
+ - **RV.1**: identify vulnerabilities on ongoing basis — SCA + scanning.
35
+
36
+ Use SSDF as the program-level framework; ASVS fills in the per-app details.
37
+
38
+ ## Cloud & infra — CSA CCM / CIS Benchmarks / AWS Well-Architected
39
+
40
+ - **[CSA Cloud Controls Matrix](https://cloudsecurityalliance.org/research/cloud-controls-matrix/)**: cloud-native control framework, maps to ISO 27001 / SOC 2 / NIST / etc. Good for answering "are we doing the cloud thing right?"
41
+ - **[CIS Benchmarks](https://www.cisecurity.org/cis-benchmarks)** per cloud / OS / Kubernetes: concrete configuration checklists. Use for hardening specific components.
42
+ - **[AWS Well-Architected — Security Pillar](https://docs.aws.amazon.com/wellarchitected/latest/security-pillar/welcome.html)** (or GCP/Azure equivalents): opinionated cloud-architecture guidance. Start here before CCM for most AWS-native designs.
43
+
44
+ Pick one per component. Don't adopt all three to "maximize coverage" — they overlap and you'll drown.
45
+
46
+ ## Threat modeling reference
47
+
48
+ - **[Microsoft STRIDE](https://learn.microsoft.com/en-us/security/securing-devops/threat-modeling)** — the classic, used in `docs/threat-modeling.md`.
49
+ - **[MITRE ATT&CK](https://attack.mitre.org/)** — tactics/techniques for *real-world* attacker behavior. Use to sanity-check "what would an attacker actually do?"
50
+ - **[OWASP ASVS-companion ATM process](https://owasp.org/www-project-threat-modeling/)** — OWASP-flavored threat modeling methodology.
51
+ - **[LINDDUN](https://linddun.org/)** — privacy-focused threat modeling (complement to STRIDE for PII-heavy designs).
52
+
53
+ ## Privacy & compliance
54
+
55
+ - **GDPR**: data minimization, purpose limitation, user rights (access, deletion, portability), data transfer restrictions. Design-time decisions: what you collect, why, how long, where it lives.
56
+ - **CCPA / CPRA**: similar shape, California-specific. Know-your-rights, opt-out of sale.
57
+ - **HIPAA** (US health): PHI definition, covered entity / BA relationships. Requires BAAs with sub-processors.
58
+ - **PCI-DSS** (cards): scope reduction is the name of the game — tokenize early, keep cardholder data out of your systems.
59
+ - **SOC 2**: not a regulation, a report. Trust Services Criteria (Security, Availability, Confidentiality, Processing Integrity, Privacy). Design maps to controls; audit reads evidence.
60
+ - **ISO 27001**: information security management system. Certification is program-level, not design-level, but many controls live in design decisions.
61
+
62
+ At design time, the answer is usually "we're in scope for X, Y; Z doesn't apply; here's the mapping." Not a full compliance plan — just a pointer.
63
+
64
+ ## AI / LLM-specific
65
+
66
+ - **[OWASP LLM Top 10](https://owasp.org/www-project-top-10-for-large-language-model-applications/)** (2025): prompt injection, data disclosure, supply chain, poisoning, improper output handling, excessive agency, prompt leakage, vector/embedding weaknesses, misinformation, unbounded consumption.
67
+ - **[MITRE ATLAS](https://atlas.mitre.org/)**: ATT&CK for AI/ML systems.
68
+ - **[NIST AI RMF](https://www.nist.gov/itl/ai-risk-management-framework)**: risk management framework for AI (govern, map, measure, manage).
69
+ - **EU AI Act** (if you ship in EU): risk categories + obligations. High-risk systems have heavy requirements; general-purpose AI has lighter.
70
+
71
+ `rafter-code-review/docs/llm.md` walks LLM top 10 for review time.
72
+
73
+ ## Cheap-and-fast subset to start with
74
+
75
+ If you have 30 minutes and need a defensible baseline for a new feature:
76
+
77
+ 1. Pick ASVS L1 or L2 (L2 if any PII).
78
+ 2. Read the chapter that matches your design's top risk (auth / input / access control / crypto — whichever is most novel).
79
+ 3. Check CIS Benchmark for your cloud + one container-level CIS (if containerized).
80
+ 4. Write the applicable compliance scope (GDPR? HIPAA? none?).
81
+ 5. Document the threat-model pass result (from `docs/threat-modeling.md`).
82
+
83
+ This is less than a full compliance program and more than "we winged it." Most features don't need more at kickoff.
84
+
85
+ ## When to hire the specialist
86
+
87
+ The pointers above get you to "informed designer." They do not replace:
88
+
89
+ - A pentester on a high-risk launch.
90
+ - A compliance counsel for novel regulatory scope (PCI-DSS 4.0, GDPR cross-border, HIPAA BAs).
91
+ - A third-party audit for SOC 2 / ISO 27001 / FedRAMP.
92
+
93
+ Budget for these where the risk warrants. Skipping them is a risk transfer to the future, usually at a higher cost.
94
+
95
+ ---
96
+
97
+ ## Exit criteria
98
+
99
+ - The applicable regulatory scope is named (or "none, B2B internal only, accepted").
100
+ - The baseline framework is picked (ASVS L?, SSDF yes/no).
101
+ - The specific sections of the framework that match this design's novel risks are cited in the design doc.
102
+ - Compliance obligations (if any) are routed to a human owner, not left as "TBD".
@@ -0,0 +1,128 @@
1
+ # Threat Modeling — STRIDE on the Specific Design
2
+
3
+ This is the capstone. Walk after the individual decisions (auth, data, API, ingestion, deployment) are drafted. The goal: stress-test the design by asking "how would an attacker break *this specific thing*?"
4
+
5
+ ## Setup — the diagram you actually need
6
+
7
+ Before STRIDE, draw two things. Prose is fine; ASCII is fine. Drawings get handwaved.
8
+
9
+ 1. **Data-flow diagram**: boxes for processes, cylinders for stores, arrows for flows. Label each arrow with what crosses it (request type, data fields).
10
+ 2. **Trust boundaries**: dotted lines *across* the arrows — every arrow that crosses a boundary is a security control point.
11
+
12
+ Minimum sketch:
13
+ ```
14
+ [Browser] → [CDN/WAF] ┆→ [API Gateway] → [App Service] ┆→ [DB]
15
+
16
+ [Third-Party API]
17
+ ```
18
+ Boundaries: browser↔edge, edge↔app, app↔DB, app↔third-party.
19
+
20
+ Each boundary is where STRIDE is most productive.
21
+
22
+ ## STRIDE — one per category, per boundary
23
+
24
+ The trick is not to apply STRIDE globally; apply it to each trust-boundary crossing and each data-store.
25
+
26
+ ### S — Spoofing (identity)
27
+
28
+ Applied per boundary: can the entity on the other side be impersonated?
29
+
30
+ - Browser → edge: can an attacker present a valid-looking session cookie / token they didn't earn? (Authn strength, token theft, XSS → cookie steal.)
31
+ - App → DB: is the DB credential stealable? Replayable? Scoped to the app's workload identity, or shared?
32
+ - App → third-party: does the third-party authenticate the calling app? (Mutual TLS? Signed request?) If not, anyone on their egress path can spoof.
33
+ - Human → admin console: how is admin access authenticated, and is that *separate* from user authN?
34
+
35
+ ### T — Tampering (data integrity)
36
+
37
+ Per boundary + per store:
38
+
39
+ - Data in transit: TLS version, cert validation, downgrade defenses. "We assume the internal network is safe" is where tampering happens.
40
+ - Data at rest: can a DB compromise *modify* records undetectably? Append-only audit stores + signed rows are the high-assurance pattern.
41
+ - Data in cache / queue: is message integrity validated? (HMAC on queue payloads, especially if they cross services with different trust levels.)
42
+ - Build artifacts: tampering between build and deploy. Signed provenance catches it.
43
+
44
+ ### R — Repudiation
45
+
46
+ - Is there an audit log that names the actor, the action, the resource, the time, and a request id?
47
+ - Are the actor's identity and the action tamper-evident in the log? A log the app writes to a DB the app can also update is repudiable.
48
+ - For high-value actions (payments, data exports, admin changes), is the log shipped to an append-only store? Separately from app storage?
49
+ - Agents acting on behalf of users: does the log name both? "User X, via agent Y, did Z at T."
50
+
51
+ ### I — Information disclosure
52
+
53
+ Per boundary + per store:
54
+
55
+ - Errors: what do error responses reveal? (See `docs/api-design.md` error taxonomy.)
56
+ - Side-channels: timing of login responses (does valid vs invalid username take different time?), response size, cache-hit timing.
57
+ - Logs: what fields are logged? Do they contain credentials / PII / secrets?
58
+ - Backups: who can read them? Are they encrypted separately from live?
59
+ - Debug endpoints: `/debug`, `/metrics`, `/health` — what do they expose? `/metrics` with unauthenticated Prometheus is fine for latency, not for business counters that hint at usage.
60
+ - URL leakage: does the URL contain sensitive data (tokens, email in query string)? URLs end up in logs, browser history, referer headers.
61
+ - Third-party telemetry: does Datadog / Sentry / LogRocket see data it shouldn't? (Session replay tools are notorious for capturing PII.)
62
+
63
+ ### D — Denial of service
64
+
65
+ - Rate limits exist per endpoint, per user, per IP (see `docs/api-design.md`).
66
+ - Resource exhaustion: big uploads, deep JSON, big arrays, catastrophic regex, zip bombs (see `docs/ingestion.md`).
67
+ - Downstream dep failures: what happens if the third-party API is down? Timeout, circuit-break, fallback? Synchronous calls with no timeout = cascading outage.
68
+ - Queue / cache exhaustion: can a user enqueue infinite work? Background jobs that fan out per user need per-user caps.
69
+ - Expensive operations (LLM calls, ML inference, PDF rendering): per-user and per-tenant quotas. Cost DoS is real.
70
+
71
+ ### E — Elevation of privilege
72
+
73
+ - AuthZ gaps: user role → admin role escalation. Mass assignment of `role` / `is_admin`. Server-side role check on every sensitive endpoint.
74
+ - Tenant escalation: cross-tenant data access. Row-level isolation enforced by policy engine, not by convention.
75
+ - Horizontal privilege (same role, other user's data): the IDOR / BOLA surface. Resource-scoped authZ.
76
+ - Agent / service escalation: a compromised less-privileged service calling a more-privileged one. Per-caller authZ at the callee.
77
+ - Infra-level: a compromised container breaking out to the host, or to other containers. Non-root, read-only FS, seccomp, network policy.
78
+
79
+ ## Negative-space questions
80
+
81
+ STRIDE catches the known categories. These catch what STRIDE misses:
82
+
83
+ - **What did we assume is safe?** List the implicit trust assumptions. "We trust the CDN", "we trust that service X has done authN", "we trust the user to provide their own tenant_id". Each is a fragile assumption to revisit.
84
+ - **What's the worst-case single compromise?** Pick one component — the web server, the DB, the build runner, a maintainer's laptop. How far does compromise spread? Is that acceptable, or does the design need more segmentation?
85
+ - **What's the attacker's goal?** Data theft (who pays for it?), financial fraud (how does it monetize?), denial (who benefits from us being offline?), reputational (activist / extortion). The feasible attacks depend on who'd try.
86
+ - **What changes in an incident?** Under compromise, can you freeze sessions, rotate secrets, disable endpoints? If the runbook starts with "we'll figure it out", design in the controls now.
87
+
88
+ ## Abuse cases — the flipside of use cases
89
+
90
+ For each primary use case, write the abuse twin:
91
+
92
+ - "User invites a friend" → "Attacker invites 10,000 friends to spam; legitimate invitee sees their address used as spam source."
93
+ - "User uploads a profile picture" → "Attacker uploads a polyglot SVG to execute script in another user's browser."
94
+ - "User requests a password reset" → "Attacker bulk-enumerates emails or sends reset-spam."
95
+ - "User exports their data" → "Attacker exfiltrates via unthrottled export endpoint."
96
+
97
+ One abuse twin per use case is enough at kickoff. Each surfaces a control that *should* be in the design but often isn't.
98
+
99
+ ## Agentic / LLM-specific threats (if in scope)
100
+
101
+ If the design includes LLM or agent components, add these to the walk:
102
+
103
+ - Prompt injection: untrusted content reaches the model. Can it alter behavior of subsequent tool calls?
104
+ - Excessive agency: what tools does the agent have access to? Tools that write (email, file, DB, shell) are the blast-radius questions. Read-only tools are low-stakes.
105
+ - Data poisoning: RAG indexes over user content — can a user plant content that affects another user's retrieval?
106
+ - Model theft / extraction: API designs that let attackers reconstruct model behavior.
107
+ - Cross-tenant context bleed: if the model sees data from tenant A during a tenant B session, even as a system prompt leak, it's a disclosure bug.
108
+
109
+ ## Output
110
+
111
+ A threat-modeling pass should produce:
112
+
113
+ - The DFD / trust-boundary sketch (prose or image).
114
+ - For each boundary / store: the STRIDE findings and the proposed mitigations.
115
+ - The refuse-list items that surfaced (if any).
116
+ - A short list of residual risks the team is knowingly accepting, with a reason.
117
+ - Follow-up items to file as issues (new controls, instrumentation, tests).
118
+
119
+ ---
120
+
121
+ ## Exit criteria
122
+
123
+ - DFD + boundaries are drawn.
124
+ - STRIDE is applied per boundary (not globally).
125
+ - Negative-space questions are answered.
126
+ - At least one abuse twin is written per primary use case.
127
+ - Residual risks are explicit and accepted in writing, not implicit.
128
+ - Design is ready for implementation — `rafter-code-review` will walk the PR when it lands.