Secure vibe coding: what security prompts and rules files change, and what they cannot

Secure vibe coding means giving your AI builder standing security rules, then checking that the rules held. The first half helps: in a 2025 benchmark, a security line in the prompt cut vulnerabilities by up to 56%. It is not enough, because a rule in a prompt is advice the model can miss. Put the rules where your tool reads them on every request, back each one with a check that fails loudly, and test the live app.

The team behind Keybrum's attacksUpdated 13 min read

In short

  • With no security instructions, models wrote safe code in about 55% of Veracode's test tasks in Spring 2026. A security prefix in the prompt cut vulnerabilities by up to 56% for GPT-4o and GPT-4o-mini in a 2025 benchmark.
  • Every major builder has a place for standing rules: Instructions in Lovable, Knowledge in Bolt, replit.md in Replit, .cursor/rules in Cursor, CLAUDE.md in Claude Code. Most of them also read AGENTS.md.
  • Name the control. "Every new table enables row level security in the same migration" changes what the agent writes. "Write secure code" changes little.
  • A prompt is advice. Anthropic's docs say Claude treats CLAUDE.md as context, not enforced configuration. Pair each rule with a gate: a check in CI, a hook, a test with two users.
  • Rules files are worth protecting. Read any rules file you did not write, and review every change to yours like a change to code.
On this page

What secure vibe coding means

Secure vibe coding is the name given to building an app by prompting while keeping security in the loop. Most guides stop at the prompt: tell the AI to be careful. That is one layer of three, and the weakest on its own.

  • Guides steer the agent before it writes: standing rules in a file or a settings field, and a few prompts for risky moments.
  • Gates stop a bad change whatever the agent decided: a check that fails the build, a hook that blocks an edit, a test that expects a refusal.
  • Proof is what the deployed app answers to a stranger and to a second account. It is the only layer that covers settings changed in a dashboard after the last commit.

The distinction between a guide and a gate comes from a May 2026 article by a Thoughtworks team, published on Martin Fowler's site, about hardening an internal tool that a non-engineer had built with Gemini, Replit and Claude. Their conclusion is in the title: prompting your AI to be secure is not enough. This page covers all three layers, starting with what the research says about the first.

Does telling the AI to write secure code work?

It helps, measurably, and it leaves a lot behind. Start with the baseline. Veracode tests the latest models on 80 coding tasks with no security instructions. In its Spring 2026 update, about 55% of the answers were safe, a share that has stayed flat across model generations while the code itself got better at compiling.

FindingSource
A security-focused prefix in the prompt reduced vulnerabilities by up to 56% in code from GPT-4o and GPT-4o-mini.Bruni and colleagues, February 2025
With iterative prompting, the tested models detected and repaired between 41.9% and 68.7% of the vulnerabilities in code they had generated earlier.Bruni and colleagues, February 2025
Among the prompting techniques compared on GPT-3, GPT-3.5 and GPT-4, the one that reduced weaknesses most was Recursive Criticism and Improvement: the model criticises its answer, then improves it.Tony and colleagues, 2024, revised 2025
Telling the model it is an expert can backfire: some experiments found it often made results worse.OpenSSF guide for AI code assistant instructions, August 2025
Five coding agents building the same three apps wrote no exploitable SQL injection or XSS, and left out most security controls nobody had asked for.Tenzai, reported by SecurityWeek, January 2026
These are benchmarks on short tasks or test apps. They show a direction and promise nothing about your own app.

Read together, they say three things. A security instruction is worth writing. A review pass, where the agent attacks its own work, is worth more. And the flaws that remain are mostly omissions: in Tenzai's test, improper authorization on API calls was among the most common problems, and four of five agents accepted an order with a negative quantity because the prompt never said to refuse one. Often the agent did not write a bad control. It wrote none. So a useful rule names the control you expect.

The Thoughtworks team saw the other side of it. Their assistant recommended making a storage bucket public, and argued when challenged that every company does this. It also gave a service account a role far broader than the task needed. Both were caught because a person asked. A model takes the path that makes the feature work, and your rules have to say which paths are closed.

Where your security rules go, tool by tool

A rule typed in the chat lasts one conversation. Each builder has a place for rules it reads on every request. These are the locations their own documentation gives in November 2026.

ToolWhere standing rules liveWorth knowing
LovableProject settings, then Instructions. Also workspace and personal instructions. Lovable also reads a top-level AGENTS.md or CLAUDE.md with every messageUp to 10,000 characters per level. Instructions are always included in context
BoltKnowledge, at account, project and team level, in the matching settings pageProject knowledge applies to one project, account knowledge to all of yours
Replitreplit.md in the project's root directoryAgent creates the file, reads it automatically and can update it. It does not look in subdirectories
Cursor.cursor/rules, in files with the .mdc extension, or AGENTS.mdOnly alwaysApply: true loads a rule in every chat. A plain .md file in that folder is ignored. Keep rules under 500 lines
Claude CodeCLAUDE.md at the project root, or AGENTS.md when the repository has no CLAUDE.mdAnthropic suggests under 200 lines per file. Reading AGENTS.md directly needs version 2.1.277 or later
GitHub Copilot.github/copilot-instructions.md, and AGENTS.md anywhere in the repositoryThe nearest AGENTS.md in the directory tree takes precedence
CodexAGENTS.md, from the project root down to the current directory, plus one in ~/.codexFiles closer to the current directory come later and override earlier guidance. The combined size is capped at 32 KiB by default

One file name keeps coming back. Lovable, Cursor, Copilot and Codex read AGENTS.md, and Claude Code reads it when no CLAUDE.md exists. If several tools touch the same repository, write the rules once in AGENTS.md. On Bolt and Replit, paste the same text into Knowledge or replit.md.

A security rules file to paste

This file is written for the stack most builders generate: a JavaScript frontend, Supabase or another Postgres backend, Stripe and a model provider. Delete the lines that do not apply. The OpenSSF guide asks for instructions that are concise, specific and actionable, so every line here names a behaviour you can check afterwards. The sections follow the categories that leak most in AI-built apps, which the OWASP Top 10 for vibe coding goes through one by one.

markdown
# Security rules

These rules apply to every change. If a request conflicts with one,
stop and say so instead of working around it.

## Data access
- Every new table enables row level security in the same migration.
- Policies compare an owner column to auth.uid(). Never write a policy
  with using (true) on a table that holds user data.
- Never disable row level security to fix a bug. Fix the policy.
- Storage buckets are private unless I say a bucket is public.

## Keys
- Secret keys (service role, Stripe secret, model provider, any private
  key) are read on the server only. Never in client code, never in a
  variable prefixed NEXT_PUBLIC_ or VITE_.
- Never write a real key into source code, tests, comments or this file.

## Routes and server functions
- Take the user from the session on the server. Never from the request
  body, the URL or a header the client sets.
- Check that the record belongs to that user before reading or changing it.
- Never accept role, plan, credits, price or admin flags from the client.
- Admin pages check the role on the server, not only with a redirect.

## Payments and AI
- Webhooks verify the provider's signature on the raw body before acting.
- The server computes prices and quantities. Refuse negative or zero values.
- Routes that call a model require a session and a per-user limit.

## Errors and dependencies
- Return short error messages. No stack traces, SQL or file paths.
- If a check fails or throws, refuse the request.
- Before adding a package, confirm it exists on the registry and say
  why it is needed.

## When you finish a change
- List every table, policy, route and environment variable you touched.
- Say which of these rules the change relied on.
Save as AGENTS.md at the root of the repository, or paste into your builder's instructions field. About 1,700 characters.

On Firebase, replace the data access section with two lines: rules deny by default, and every rule ties a document or a file to request.auth.uid. The Firebase rules guide has the patterns. Whatever the stack, resist adding a persona such as "you are a senior security engineer": the OpenSSF guide reports that it often does not help, and it uses space the specific rules need.

Prompts for the moments that matter

Standing rules cover every change. Three moments deserve a prompt of their own: a new table, a new route, and the review before you publish.

text
NEW TABLE
Create the table for [what it stores]. In the same migration, enable row
level security and add policies so each user reads and writes only the
rows where user_id = auth.uid(). Then list every policy you created and
what each one allows, for a visitor and for a signed-in user.

NEW ROUTE
Add the route for [what it does]. Take the user from the session on the
server. Answer 401 without a session and 404 when the record belongs to
someone else. Show me the two checks in the code.

REVIEW BEFORE PUBLISHING
Act as a second user of this app who wants to read or change the first
user's data, and as a visitor with no account. Go through every table,
route, storage bucket and server function. List each place where you
would succeed, with the file and the line. Do not fix anything yet.
Replace the bracketed parts. The review prompt asks for a list first: fix in a second step, then run the review again.

The third prompt is the critique-then-improve loop the research favours, pointed at the flaw agents skip most: access between users. Ask for findings before fixes, so you can read the list. It has a limit you should know: a model reviewing its own work shares its blind spots. The guide to auditing AI-generated code shows a stricter setup, where a second agent tries to disprove each finding.

Why a prompt is not a gate

The vendors say it themselves. Anthropic's documentation states that Claude treats CLAUDE.md as context, not enforced configuration, and points to a hook when an action must be blocked whatever Claude decides. OWASP's Secure Coding with AI cheat sheet warns against trusting AI-generated test suites as evidence of security. And the Thoughtworks article puts the contrast in one line: asking for tests in a prompt is a suggestion, while a coverage threshold in the build is a gate.

Rules can also move. Lovable's docs say that on paid plans it rewrites or removes a rule in AGENTS.md that no longer matches your code, unless you asked for that rule. Replit Agent can update replit.md as it learns. So keep your security rules in the settings field as well where one exists, and look at the file when you review a change.

For each rule, pick a check that does not depend on the agent remembering it:

RuleGate
Every table has row level securityThe SQL check below, run in CI against your database. On Supabase, also read the Security Advisor
No secret in the frontendSecret scanning on every push, and a search of the built files. See secrets management
Routes check the ownerA test that signs in as a second user and expects a refusal
The agent never edits .env or the lockfileA hook that blocks the edit. Claude Code and Cursor both support hooks
Webhooks verify signaturesA request with no signature must answer 400
Nothing regressed after the deployAn attack on the live app, on every deploy
sql
-- check-rls.sql: fails when a table in public has row level security off
do $$
declare
  open_tables text;
begin
  select string_agg(c.relname, ', ') into open_tables
  from pg_class c
  join pg_namespace n on n.oid = c.relnamespace
  where n.nspname = 'public'
    and c.relkind in ('r', 'p')
    and not c.relrowsecurity;

  if open_tables is not null then
    raise exception 'Tables without row level security: %', open_tables;
  end if;
end $$;
Run with psql "$DATABASE_URL" -v ON_ERROR_STOP=1 -f check-rls.sql. The command exits with an error when a table is open, which fails the CI job. It reads the catalog and changes nothing.

Rules files are also something to protect

A file the agent obeys in every session is a good place to hide an instruction. In March 2025 Pillar Security showed that invisible Unicode characters in a rules file could make Cursor and GitHub Copilot insert malicious code without mentioning it. GitHub added a warning for hidden Unicode text on github.com in May 2025. OWASP's cheat sheet now says to treat rules files as security-critical configuration, to require explicit approval for any modification, and not to let the agent change its own rules without it.

In practice: read every rules file you did not write before you use it, including the ones in templates and starter kits. Review changes to your own in the diff. The Cursor guide has a command that finds invisible characters in rules files.

What Keybrum checks here, and what it does not

Keybrum does not read your prompts, your rules files or your chat history, and it does not grade them. It tests what they were meant to produce: the deployed app. Each rule in the file above has an attack that says whether it held.

Rule in the fileThe attack on the live app
Row level security on every tableReads every table the public key can reach, as a stranger and as a new account, then tries inserts and updates that are rolled back
Buckets are privateLists the storage buckets named in your code and downloads one byte of one file as proof
Secret keys stay on the serverSearches the shipped JavaScript and API answers for keys, and checks the ones it finds with read-only calls
Routes check the ownerOne account creates a marked object, a second account tries to read and change it
No role, plan or price from the clientSends role, plan, credits and price fields on write routes and reads back what was stored
Webhooks verify signaturesSends one event with no signature to your Stripe, Polar, Lemon Squeezy, Paddle, GitHub or Clerk webhook
AI routes need a sessionCalls routes and Supabase Edge Functions that look like AI endpoints with no account
Short errorsSends malformed requests and reports stack traces, table names and file paths in the answers

The loop then closes on the agent's side. Through Keybrum's MCP server, Cursor or Claude Code reads each finding with the request that worked and the fix, applies it, and asks for a retest. A finding closes when the same attack fails. Plans attack again on every deploy, with a CI check, so a prompt that quietly removed a policy shows up on the next deploy.

What it does not cover: code that the live app never exposes, your build pipeline, and the security of the coding tool itself. Keybrum's code audit, which includes Cloudflare's security-audit skill, reads the repository for causes. Keybrum only attacks apps whose owner proved ownership. A one-time report costs €49, and plans start at €29 a month excluding VAT.

Questions

What is secure vibe coding?

It is building an app by prompting while keeping security in the loop: standing rules the AI reads on every request, checks that block a bad change, and a test of the deployed app. The prompt alone is the weakest of the three, because the model can miss it.

Do security prompts make AI-generated code safer?

Yes, to a point. In a 2025 benchmark by Bruni and colleagues, a security-focused prefix reduced vulnerabilities by up to 56% in code from GPT-4o and GPT-4o-mini. Flaws of omission remain: agents tend to skip access checks and limits that nobody asked for, so name those controls in your rules.

What should a security rules file contain?

Short, specific rules about data access, secret keys, ownership checks on routes, payment webhooks, AI routes, error messages and new packages. Each line should describe something you can verify afterwards. Vendors suggest keeping it short: under 200 lines for a CLAUDE.md, under 500 lines for a Cursor rule.

Which AI coding tools read AGENTS.md?

Lovable reads a top-level AGENTS.md with every message. Cursor, GitHub Copilot and Codex read it too, and Claude Code reads it when the repository has no CLAUDE.md, from version 2.1.277. Bolt uses its Knowledge settings and Replit uses replit.md.

Can I ask the AI to review its own code for security?

Yes, and research supports it: models repaired between 41.9% and 68.7% of their own vulnerabilities when prompted to review them. Ask for a list of findings before any fix, then run the review again. A model shares its own blind spots, so follow it with a test of the live app.

Should I tell the AI it is a security expert?

The OpenSSF guide for AI code assistant instructions advises against relying on it: some experiments found that telling the system it is an expert often makes it perform worse. Specific rules about what to do and what to refuse work better than a role.

Sources

  1. 1.Spring 2026 GenAI Code Security Update, Veracode
  2. 2.Benchmarking Prompt Engineering Techniques for Secure Code Generation with GPT Models, Bruni, Gabrielli, Ghafari and Kropp, arXiv
  3. 3.Prompting Techniques for Secure Code Generation: A Systematic Investigation, Tony, Díaz Ferreyra, Mutas, Dhiff and Scandariato, arXiv
  4. 4.Security-Focused Guide for AI Code Assistant Instructions, OpenSSF Best Practices Working Group
  5. 5.The VibeSec reckoning: Why prompting your AI to be secure isn't enough, Thoughtworks
  6. 6.Vibe Coding Tested: AI Agents Nail SQLi but Fail Miserably on Security Controls, SecurityWeek
  7. 7.Secure Coding with AI Cheat Sheet, OWASP Cheat Sheet Series
  8. 8.Secure AI Vibe Coding with Rules Files, Wiz
  9. 9.Instructions, Lovable Docs
  10. 10.Prompt effectively, Bolt Help Center
  11. 11.replit.md, Replit Docs
  12. 12.Rules, Cursor Docs
  13. 13.How Claude remembers your project, Claude Code Docs
  14. 14.Adding repository custom instructions for GitHub Copilot, GitHub Docs
  15. 15.Custom instructions with AGENTS.md, OpenAI
  16. 16.New Vulnerability in GitHub Copilot and Cursor: How Hackers Can Weaponize Code Agents, Pillar Security

Your app is public. So are its mistakes.

Check what any attacker can already see in it, free, in ten seconds. The full attack, with proof and fixes: €49 once, or €29 a month on a plan.

or continue with Google or GitHub