Security prompts

Security prompts and rules for Cursor, Claude Code and other AI coding agents

Rule files your agent reads on every task, and audit prompts you paste when you want a check. Copy them as they are or adjust to your stack.

Cursor security rules (.cursor/rules/security.mdc)

Save as .cursor/rules/security.mdc in your project. alwaysApply makes Cursor include it in every request.

.cursor/rules/security.mdc

---
description: Security rules for this project
alwaysApply: true
---

# Security rules

- Never hard-code secrets, API keys, tokens or passwords. Read them from environment variables on the server only.
- Never put secrets in variables with a NEXT_PUBLIC_, VITE_ or PUBLIC_ prefix: those are bundled into the browser.
- Check the session and the user's permissions on every API route, server action and Edge Function before returning or changing data.
- With Supabase, enable Row Level Security on every table and write owner-only policies. Never use a service_role or sb_secret_ key in client code.
- Set session cookies as HttpOnly, Secure and SameSite.
- Add rate limiting to login, signup, password reset and any endpoint that sends email or calls a paid API.
- Vet new dependencies before adding them: prefer well-maintained packages and avoid ones you cannot verify.
- Never log secrets, tokens or personal data.
- When you change anything security-related, explain it in plain English and say how to verify it.

CLAUDE.md security section

Add this to the CLAUDE.md at your repository root so Claude Code reads it at the start of every session.

CLAUDE.md

# Security rules

- Never hard-code secrets, API keys, tokens or passwords. Read them from environment variables on the server only.
- Never put secrets in variables with a NEXT_PUBLIC_, VITE_ or PUBLIC_ prefix: those are bundled into the browser.
- Check the session and the user's permissions on every API route, server action and Edge Function before returning or changing data.
- With Supabase, enable Row Level Security on every table and write owner-only policies. Never use a service_role or sb_secret_ key in client code.
- Set session cookies as HttpOnly, Secure and SameSite.
- Add rate limiting to login, signup, password reset and any endpoint that sends email or calls a paid API.
- Vet new dependencies before adding them: prefer well-maintained packages and avoid ones you cannot verify.
- Never log secrets, tokens or personal data.
- When you change anything security-related, explain it in plain English and say how to verify it.

AGENTS.md security section

Add this to AGENTS.md at the repository root. Many coding agents read this file, including Codex and Cursor.

AGENTS.md

# Security rules

- Never hard-code secrets, API keys, tokens or passwords. Read them from environment variables on the server only.
- Never put secrets in variables with a NEXT_PUBLIC_, VITE_ or PUBLIC_ prefix: those are bundled into the browser.
- Check the session and the user's permissions on every API route, server action and Edge Function before returning or changing data.
- With Supabase, enable Row Level Security on every table and write owner-only policies. Never use a service_role or sb_secret_ key in client code.
- Set session cookies as HttpOnly, Secure and SameSite.
- Add rate limiting to login, signup, password reset and any endpoint that sends email or calls a paid API.
- Vet new dependencies before adding them: prefer well-maintained packages and avoid ones you cannot verify.
- Never log secrets, tokens or personal data.
- When you change anything security-related, explain it in plain English and say how to verify it.

Find and remove exposed secrets

Paste into your coding agent with access to the repository.

Prompt

Audit this repository for exposed secrets:
1. Search all source files, config files and .env files for API keys, tokens, passwords and private keys, including Supabase service_role and sb_secret_ keys.
2. List every secret in a variable with a NEXT_PUBLIC_, VITE_ or PUBLIC_ prefix, because those reach the browser.
3. Move each one to a server-only place (API route, Edge Function or backend) that reads it from a secret.
4. Make sure .env files are in .gitignore and tell me which keys I must rotate.
Explain each change in plain English.

Audit Supabase Row Level Security

Paste into your coding agent in a project that uses Supabase.

Prompt

Audit Row Level Security in this Supabase project:
1. List every table in the public schema and whether RLS is enabled.
2. Enable RLS on every table that has it off.
3. Add owner-only policies for select, insert, update and delete using auth.uid(). Flag any table that is meant to be public and explain why.
4. Find views over protected tables and set security_invoker = true.
Show me the SQL before running it and explain each policy in plain English.

Pre-launch security review

Run once before real users sign up, and again after big changes.

Prompt

Do a security review of this app before launch and fix what you find, most severe first:
1. Secrets: nothing sensitive in client code, git history notes or public environment variables.
2. Auth: every API route and server action checks the session and the user's permissions.
3. Database: access rules (RLS or equivalent) on every table, scoped to the owner.
4. Headers: Content-Security-Policy, Strict-Transport-Security, frame-ancestors, X-Content-Type-Options and Referrer-Policy.
5. Cookies: HttpOnly, Secure and SameSite on session cookies.
6. Abuse: rate limits on login, signup, password reset and paid or email-sending endpoints.
7. Production: source maps off, no .env or .git files deployed, debug routes removed.
Explain each change in plain English and tell me how to verify it.

Rules guide the agent. A scan checks the result.

Rules and prompts shape what your AI writes, but they do not prove what shipped. Scan the live URL for exposed keys, missing headers and open endpoints. Your first scan is free.