Threat Model Remediate (Question 3: What Are We Going to Do About It?)
Use this skill after threat-model-analyze (or whenever working through an existing docs/THREAT-MODEL.md) to safely fix confirmed vulnerabilities and harden design gaps without introducing regressions.
Core Principles
- Fix the bug class, not just one line: Whenever you fix a vulnerability (e.g., BOLA/IDOR, raw SQL, SSRF, mass assignment, missing authz), search sibling routes, handlers, and services for the same pattern and introduce a shared safe helper or guard.
- Fail closed, default deny (OWASP A01 / A10:2025): Auth checks, signature verifiers, SSRF validators, and error handlers must deny on error or ambiguity.
- Idiomatic & minimal changes: Use the repository's existing libraries, middleware patterns, validation schemas, and test framework. Avoid adding unnecessary dependencies.
- Prove every fix with a test: Write an automated security regression test that reproduces the attack vector and asserts it is blocked, while confirming legitimate calls continue to work.
- Never weaken security to make tests pass: Do not disable TLS verification, loosen CORS/CSP, bypass auth in production code, or swallow exceptions silently.
Workflow
Step 1: Triage & Order the Work
Read docs/THREAT-MODEL.md (and docs/threat-model.json if present) and load the matching stack-specific tm-* skills for idiomatic remediation patterns.
Work strictly in priority order:
- Critical (
confirmedfirst) - High (
confirmedfirst, thendesign-gap) - Medium (when in scope or straightforward)
- Low (hygiene pass if requested)
For findings that cannot be fixed in code alone (e.g., external WAF/IdP/cloud console setting), document the exact infrastructure/operational control needed and mark status appropriately (accepted or transferred only with user sign-off).
Step 2: Implement Each Fix Systematically
For each finding TM-XXX (see references/remediation-patterns.md for OWASP Cheat Sheet patterns):
- Re-read the exact cited code (
file:line) and all callers/siblings. - Design the structural fix:
- Access Control (BOLA/BFLA/Tenant Isolation): Enforce server-side policy + bind object queries to authenticated
userId/tenantId; return404or403consistently without leaking existence across tenants. - Injection (SQL/NoSQL/Command/Template/XSS): Replace concatenation with parameterized queries, argv-array process execution (
shell: false), strict allowlists, and context-aware output encoding. - SSRF: Parse URLs strictly, enforce
https:(or allowlisted schemes), resolve DNS and reject private/loopback/link-local/metadata IP ranges (IPv4 + IPv6 + IPv4-mapped IPv6), disable/re-validate redirects, and prefer explicit host allowlists. - Auth/Session/Tokens: Pin JWT algorithms, validate
iss/aud/exp/nbf, enforce PKCE +state/nonce, useHttpOnly; Secure; SameSite=Lax|Strictcookies, rotate sessions on login/privilege change, use constant-time secret comparison. - Mass Assignment / BOPLA: Bind inputs to explicit allowlisted schemas/DTOs and explicitly pick response fields.
- Error Handling (A10:2025): Catch cleanly, return generic client messages with correlation IDs, log details internally without secrets/PII, ensure auth/policy checks fail closed.
- AI / MCP: Separate system instructions from untrusted data, apply strict schema validation + least-privilege tool allowlists + human-in-the-loop approval for destructive/external side effects, scope RAG retrieval by caller tenant.
- Access Control (BOLA/BFLA/Tenant Isolation): Enforce server-side policy + bind object queries to authenticated
- Apply the fix cleanly and check formatting/types/linting.
Step 3: Write Security Regression Tests
For each mitigated finding, add or update an automated test in the project's test suite:
- Negative test (attacker path): Send the cross-tenant ID, forged header, invalid signature, injection payload, SSRF loopback URL, or unauthorized role and assert
401/403/404/400or safe sanitized output. - Positive test (legitimate path): Verify authorized users still succeed without regression.
- Run the full relevant test suite, typechecker, and linter.
Step 4: Update the Threat Model
Update docs/THREAT-MODEL.md (and docs/threat-model.json if present):
- Change finding status from
opentomitigated(orin-progress/acceptedwith documented rationale). - Update the Executive Summary severity count table.
- Record the changed files, regression test path, and remaining residual risk under Resolution Notes.
- Recommend running
threat-model-verifyas the final verification gate.