Secure AI Vibe Coding with Rules Files
Large Language Models (LLMs) are good at coding, powering AI-assisted programming tools like GitHub Copilot, AI IDEs, and IDE extensions. This democratizes some elements of development, giving birth to Vibe Coding, where you "forget that the code even exists." However, not all AI-assisted coding is vibe coding, and security risk emerges as developers are removed from the details of generated code.
LLMs Generate Insecure Code, Vibe Coders Moreso
It's clear that AI-generated code is not secure by default. Based on research, somewhere between 25% and 70% of working coding outputs from leading models contain vulnerabilities. Vibe coding increases this risk even more, with users given an AI assistant often producing more vulnerable code due to excessive confidence in the generated code.
Traditional software security tooling still has merit in securing code, with tools like SAST, SCA, and secrets scanning all having a role to play. The emergence of AI-assisted programming increases the importance of shifting such scans left, into the IDE. PR time scanning and remediation continue to be crucial, and the creation and adoption of secure by default frameworks and libraries can also reduce risk.
Where AI coding assistants have brought with them one new capability to exert leverage on application security is through:
Rules Files
Rules files are an emerging pattern to allow you to provide standard guidance to AI coding assistants. You can use these rules to establish project, company, or developer-specific context, preferences, or workflows. Most popular AI coding tools offer rules, including:
- GitHub Copilot: Repository Custom Instructions
- Codex: AGENTS.md
- Aider: Conventions
- Cline: Custom Instructions
- Claude: CLAUDE.md
- Cursor: Rules
- Windsurf: Rules
Rules Files for Security
Research consistently finds that crafted prompts can significantly reduce the number of vulnerabilities in AI-generated code. Rules files offer an ideal method to centralize and standardize these security-focused prompting improvements. To methodically craft a rules file for security:
- Craft instructions that are clear, concise, and actionable
- Tailor rules to their relevant scope, such as a particular programming language
- Break down complex guidelines into smaller, atomic, and composable rules
- Keep the overall rules concise; under 500 lines
The following are common vulnerabilities in AI-generated code:
- CWE-94 (Code Injection)
- CWE-78 (OS Command Injection)
- CWE-190 (Integer Overflow or Wraparound)
- CWE-306 (Missing Authentication for Critical Function)
- CWE-434 (Unrestricted File Upload)
Open-Sourcing Secure Rules Files
Rules files have yet to see broad adoption for security use cases. However, to help unstick the blank page problem, we're open-sourcing a set of baseline secure rules files. These rules were created with the help of Gemini, using a prompt that encodes the guidance outlined above. Check out the open-source rules files over on GitHub!
References
- Vibe Coding: Shipping Features or Shipping Vulnerabilities?
- Vibe Coding is a Dangerous Fantasy
- Can AI “Vibe Coding” Be Trusted? It Depends…
- Not all AI-assisted programming is vibe coding (but vibe coding rocks)
- Andrej Karpathy tweet coining “Vibe Coding”
- Code of Silence – The Hidden Risks of AI-Generated Code
- Secure Vibe Coding Made Simple
- Finding more vulnerabilities in vibe coded apps
- The Rise of Slopsquatting
- Secure Vibe Coding Guide
- Securing React: Prompt Engineering for Robust and Secure Code Generation - Jim Manico
- Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributions
- SecRepoBench: Benchmarking LLMs for Secure Code Generation in Real-World Repositories
- The Hidden Risks of LLM-Generated Web Application Code: A Security-Centric Evaluation of Code Generation Capabilities in Large Language Models
- A Comprehensive Study of LLM Secure Code Generation
- Benchmarking Prompt Engineering Techniques for Secure Code Generation with GPT Models
- CWEVAL: Outcome-driven Evaluation on Functionality and Security of LLM Code Generation
- Security and Quality in LLM-Generated Code: A Multi-Language, Multi-Model Analysis
- Secure Coding with AI – From Creation to Inspection
- Do Users Write More Insecure Code with AI Assistants?
- Artificial-Intelligence Generated Code Considered Harmful: A Road Map for Secure and High-Quality Code Generation
- Prompting Techniques for Secure Code Generation: A Systematic Investigation
- How Secure is Code Generated by ChatGPT?
- Is Your AI-Generated Code Really Safe? Evaluating Large Language Models on Secure Code Generation with CodeSecEval
- Is GitHub’s Copilot as Bad as Humans at Introducing Vulnerabilities in Code?
- Assessing the Security of GitHub Copilot’s Generated Code - A Targeted Replication Study
- A systematic literature review on the impact of AI models on the security of code generation
- Just another copy and paste? Comparing the security vulnerabilities of ChatGPT generated code and StackOverflow answers
- Can You Really Trust Code Copilots? Evaluating Large Language Models from a Code Security Perspective
- SOK: Exploring Hallucinations and Security Risks in AI-Assisted Software Development with Insights for LLM Deployment
- From Vulnerabilities to Remediation: A Systematic Literature Review of LLMs in Code Security
- We Have a Package for You! A Comprehensive Analysis of Package Hallucinations by Code Generating LLMs
- HexaCoder: Secure Code Generation via Oracle-Guided Synthetic Training Data
- SALLM: Security Assessment of Generated Code
Tags
- #Research
- #Security
- #AI