Set Security Rules Once: Standing Instructions for Lovable, Bolt, Cursor, Replit and Claude Code
Instead of reminding your AI about security in every prompt, write the rules down once in the place your tool reads before every task. A short block of rules (protect data in the database, check access on the server, keep secret keys off the browser, never weaken security to fix an error) changes what gets generated from the first line. Below is a block you can paste, and where it goes in each tool.
On this page
AI builders follow standing instructions much more reliably than they guess what you meant. Without them, every new feature starts from "make it work", and security depends on whether you remembered to ask that day.
The rules block
Copy this, then adjust the parts in brackets to your app:
## Security rules (always follow)
Data access
- Every table that holds user data must have access rules enforced in the
database (for example Supabase Row Level Security), not only in the UI.
- Default to "users can only read and change their own rows". Anything
broader must be explained to me before you build it.
- When loading a record by ID, always check it belongs to the current user.
Server checks
- Every API route, server action and database function checks who is
logged in and whether they are allowed, on the server.
- Never trust prices, roles, plans, user IDs or credits sent from the browser.
Look them up on the server.
Secrets
- Secret keys (service role, sk_..., API keys for paid services) are only
used in server code and stored as environment variables.
- Never put a secret in browser code, in a file in the repository, or in a
variable whose name starts with NEXT_PUBLIC_, VITE_ or similar.
Changes
- Never disable a security rule, make data public, or switch to an admin key
to make an error go away. Stop and tell me what the error is.
- Never delete or weaken a test to make it pass.
- Tell me before adding any new package, and why.
- After any change that touches login, payments, data access or keys,
list what you changed and how I can test it.
App specifics
- [Admins are users with role = 'admin' in the user_roles table.]
- [Payments go through Stripe. Access is granted only from the verified webhook.]
Keep it short. Twenty clear rules work better than two hundred vague ones, and long instruction files get partly ignored.
Where to put it
Lovable. Add it to the project's Knowledge (project-level instructions in the project settings), so it applies to every message in that project. Lovable also runs a quick security scan automatically each time you publish, and has a deeper scan in the project's Security view. The rules reduce what the scan finds; the scan checks what the rules missed.
Bolt. Use the project prompt or system prompt so the instructions apply by default. Bolt's own guidance suggests exactly this for rules you always want followed.
Cursor. Create a rule file in .cursor/rules/ (for example security.mdc) and set it to always apply. Older projects use a .cursorrules file in the project root.
Replit. Put the rules in replit.md in the project root. Replit Agent reads that file when it works on your requests and uses it to follow your conventions. Replit also reads AGENTS.md and CLAUDE.md where present.
Claude Code. Put the rules in CLAUDE.md in the project root. It is loaded at the start of every session.
v0, Windsurf, Codex and others. Most have project instructions or read AGENTS.md. If unsure, add an AGENTS.md file with the rules, which many tools now pick up.
Check that the rules are being read
Open a new chat in the project and ask:
What security rules are you following in this project? List them.
If the answer does not match your block, the rules are in the wrong place or not loading.
Keep the rules honest
- Rules are not a guarantee. They lower the error rate. Keep testing: the two-account test, and our 30-minute no-code check.
- Update them when your app changes. New payment provider, new admin role, new kind of sensitive data: add a line.
- Do not put secrets in the rules file. It is part of your project and may be shared, committed to GitHub or read by other tools.
- Watch for rules files you did not write. If you clone a template or someone else's project, read its rules and instructions files first. They can tell the AI to do things you would not want.
When the AI ignores a rule
It will happen, usually under pressure to fix an error. When you notice:
You just [made the table public / used the service key in the browser].
That breaks the security rules in this project. Undo it and fix the
original problem another way. Explain what the original error was.
Then add a more specific line to the rules so it does not repeat.
The prompts to run a full review are in security prompts for vibe coding. If you want someone to set up rules, review what was built before they existed, and fix it, that is our app rescue and security audit.
