November 18, 2026
Make Claude Code Follow Security Best Practices by Default
A 6-step workflow to secure vibe-coded apps with STRIDE, OWASP and NIST, without slowing down.

By Muhammad Waleed
6 min read
Make Claude Write Secure Code by Default
Vibe coding is fast. You describe a feature to Claude, it writes the code, and you ship it the same day.
The catch? If you don't ask Claude for auth checks, input validation or rate limits, it may not add them. So the app can work perfectly, right up until someone changes a user ID in the URL and reads another customer's data.
The fix isn't to stop vibe coding. It's to hand Claude established security frameworks, STRIDE, OWASP and NIST, so it follows security best practices without you asking every single time.
The problem is that "it works" and "it's secure" are not the same thing. Veracode's 2025 GenAI Code Security Report tested more than 100 AI models on 80 coding tasks, and the generated code introduced a security vulnerability in 45% of cases. And Georgia Tech's Vibe Security Radar has confirmed 74 CVEs caused by AI coding tools in real-world software.
In this guide, I'll walk you through a simple workflow that uses STRIDE, OWASP and NIST to make Claude follow security best practices by default, without killing the speed.
Meet the Frameworks
These aren't three checklists to run one after another. Each one does a different job: STRIDE finds design-level threats before you build, OWASP covers the most common application security risks, and NIST SSDF builds secure practices into your whole development process. They work together, not instead of each other.
STRIDE
A threat modeling method from Microsoft. It checks every part of your app for six threats: Spoofing, Tampering, Repudiation, Information disclosure, Denial of service and Elevation of privilege. You use it before coding to find what could go wrong.
- Spoofing: Pretending to be someone else. Example: an API that trusts a userId sent from the client.
- Tampering: Changing data you shouldn't. Example: editing the price or role field in a request.
- Repudiation: Doing something with no record of it. Example: no audit log of who deleted what.
- Information disclosure: Seeing data you shouldn't. Example: API keys in frontend code, or reading another user's orders.
- Denial of service: Making the app unavailable. Example: no rate limits, unlimited file uploads.
- Elevation of privilege: Getting more access than you should. Example: an admin route protected only by a hidden button.
OWASP Top 10
A list of the 10 most critical web app security risks, like broken access control and injection. You use it after coding as a checklist to review what Claude wrote.
- Broken Access Control: Users can reach data or actions they shouldn't. Example: changing /orders/12 to /orders/13 shows someone else's order.
- Security Misconfiguration: Unsafe default settings. Example: debug mode or open CORS left on in production.
- Software Supply Chain Failures: Risky or fake dependencies. Example: installing a package name Claude hallucinated.
- Cryptographic Failures: Weak or missing encryption. Example: passwords stored in plain text.
- Injection: User input runs as code. Example: SQL built by joining strings.
- Insecure Design: Flaws in the plan, not the code. Example: a password reset with no expiry.
- Authentication Failures: Weak login and sessions. Example: no rate limit on login attempts.
- Software or Data Integrity Failures: Trusting data that can be changed. Example: unsigned webhooks.
- Security Logging and Alerting Failures: No record when something goes wrong. Example: failed logins aren't logged.
- Mishandling of Exceptional Conditions: Errors that leak data or fail open. Example: a stack trace shown to the user.
OWASP Top 10 for LLMs
The same idea for apps that use AI, covering risks like prompt injection and excessive agency. It protects your AI features and how you use Claude Code itself.
- Prompt Injection: Hidden instructions hijack the model. Example: a README that tells your AI agent to leak secrets.
- Sensitive Information Disclosure: The model reveals private data. Example: a chatbot that shares other users' details.
- Supply Chain: Risky models, plugins or packages. Example: an unverified model from a random repo.
- Data and Model Poisoning: Tampered training or reference data. Example: fake documents added to your knowledge base.
- Improper Output Handling: Using model output without checking it. Example: rendering AI output as raw HTML.
- Excessive Agency: The AI can do more than it should. Example: an agent allowed to run any shell command.
- System Prompt Leakage: Your hidden instructions get exposed. Example: API keys placed in the system prompt.
- Vector and Embedding Weaknesses: Flaws in RAG and vector search. Example: one user's documents showing up in another's results.
- Misinformation: Confident but wrong answers. Example: the model invents a package or API that doesn't exist.
- Unbounded Consumption: No limits on usage. Example: one user running up a huge token bill.
NIST SSDF
The US government's Secure Software Development Framework (SP 800โ218). It groups security into four practices: Prepare, Protect, Produce and Respond. It turns security from a one-time check into a habit.
- Prepare the Organization (PO): Set your security rules before you build. Example: security rules in CLAUDE.md.
- Protect the Software (PS): Keep your code and releases safe from tampering. Example: branch protection and secrets kept out of git.
- Produce Well-Secured Software (PW): Design, review and test for security. Example: STRIDE before coding, OWASP review after.
- Respond to Vulnerabilities (RV): Fix flaws and learn from them. Example: adding every bug's lesson back to CLAUDE.md.
What You'll Need
- Claude Code installed
- A project you're building
- That's it
Step#01: Give Claude Your Security Rules
Every new Claude session starts from zero. If you don't tell it your security rules, it won't follow any.
Claude Code reads CLAUDE.md at the start of every session, so write your rules there once:
Security rules
- Every API route checks auth AND that the user owns the resource.
- Never trust IDs, roles or prices sent from the client.
- Parameterized queries only. No string-built SQL or shell commands.
- Validate all input with a schema.
- Secrets come from env variables. Never hardcode or log them.
- Rate limit auth, public and LLM endpoints.
- Treat LLM output as untrusted input.
- Before adding a package, confirm it exists on the official registry.Security rules
- Every API route checks auth AND that the user owns the resource.
- Never trust IDs, roles or prices sent from the client.
- Parameterized queries only. No string-built SQL or shell commands.
- Validate all input with a schema.
- Secrets come from env variables. Never hardcode or log them.
- Rate limit auth, public and LLM endpoints.
- Treat LLM output as untrusted input.
- Before adding a package, confirm it exists on the official registry.This covers the Prepare practice from NIST SSDF.
One thing to be clear about: instructions are not security controls. Claude can miss, misread or override them. That's why every rule here also gets enforced through tests, code review and CI checks in the next steps.
Step#02: Threat Model Before You Build
Some security flaws come from the design, not the code. OWASP even has a category for it: Insecure Design. Catching them before you build saves you from rewriting later.
So before any feature that touches users, data or payments, ask Claude to run STRIDE first:
Before writing any code, threat-model this feature using STRIDE.
Feature: <describe it>
1. List the components and mark every trust boundary.
2. List concrete STRIDE threats for each boundary.
3. Rate each High / Medium / Low and propose a fix for every High.
4. Save it to docs/threat-model.md.Before writing any code, threat-model this feature using STRIDE.
Feature: <describe it>
1. List the components and mark every trust boundary.
2. List concrete STRIDE threats for each boundary.
3. Rate each High / Medium / Low and propose a fix for every High.
4. Save it to docs/threat-model.md.Take a few minutes to read the High-rated threats yourself. This is the one step you shouldn't skip.
Step#03: Build Against the Threat Model
Now Claude knows what can go wrong. Make it prove it handled each threat:
Implement the feature using docs/threat-model.md.
Every High threat needs a control in the code and a test for it.Implement the feature using docs/threat-model.md.
Every High threat needs a control in the code and a test for it.Step#04: Review Before You Commit
Even with rules and a threat model, things slip through. Catch them before they reach your repo.
Run the built-in security review inside Claude Code:
/security-review/security-reviewIt scans your pending changes for vulnerabilities, and you can ask Claude to fix whatever it finds. Treat it as a second pair of eyes, not proof that your app is secure. Then do a second pass with OWASP:
Review this branch against the OWASP Top 10:2025.
Mark each category PASS / FAIL / N/A with file and line.
Check especially: can user A read or change user B's data?
Fix every FAIL.Review this branch against the OWASP Top 10:2025.
Mark each category PASS / FAIL / N/A with file and line.
Check especially: can user A read or change user B's data?
Fix every FAIL.If your app uses an LLM, run the same review against the OWASP Top 10 for LLMs. And remember that Claude Code is an AI agent too. Don't blanket-approve shell commands, and verify every package before installing it.
Step#05: Automate the Review
You'll forget to run reviews manually. CI won't.
Add Anthropic's claude-code-security-review GitHub Action so every pull request gets reviewed automatically. Then add these checks to your pipeline:
- Secret scanning: catches API keys and passwords before they land in git.
- Dependency vulnerability scanning: flags packages with known CVEs.
- Static application security testing (SAST): finds risky code patterns like injection.
- Automated authorization tests: prove user A can't read or change user B's data.
- Lockfile verification: makes sure the dependencies you tested are the ones you ship.
Step#06: Teach Claude From Its Mistakes
When a bug slips through, don't just fix it. Add the lesson to CLAUDE.md so Claude has that context in every future session.
This is the Respond practice from NIST SSDF, and it means your rules grow with every bug you fix.
Conclusion
You don't need to read every framework cover to cover. STRIDE helps you design, OWASP helps you review, and NIST turns it into a habit.
Keep vibe coding. Just give Claude the structure it needs to do it safely.