Security fix prompts for your AI coding tool

A free library of prompts to paste into Lovable, Bolt, Cursor, Claude Code or another AI coding tool. Each one fixes one common weakness in apps built with AI tools, says how to tell whether you have it, and ends with how to verify the fix on the running app. No sign-up, and nothing here sends a request to your site.

Saqr (usesaqr.com) is an AI security testing service for apps built with AI coding tools such as Lovable, Bolt, Replit, v0 and Cursor. From $19 a month, cancel any time. Tests only apps you have shown are yours.

How do I use a fix prompt?

  1. Find the weakness below and do the check by hand, on your own app.
  2. Copy the prompt and fill in the parts in square brackets.
  3. Paste it into the AI coding tool that built your app, and read what it plans to change before it changes it.
  4. Verify on the running app, not by asking the tool whether it worked.
  • Lovable, Bolt, v0 or Replit: paste it into the chat of the project that holds your app.
  • Cursor: paste it into the agent chat with your project open.
  • Claude Code or another terminal tool: paste it as your message, in the project's folder.

The prompts are free to copy, adapt and share. A prompt is only as good as the description of the problem, so add what you know.

These prompts are general. Saqr's are written for your app: the exact address, the proof, and the tests that match what it found. Open the sample AI fix pack

Data

Turn on row-level security for every table

When to use it

Use this when your app uses Supabase or another Postgres database that the browser talks to directly, and you are not sure every table has row-level security turned on. In Supabase, open the Security Advisor and the table list: a table in the public schema without row-level security is readable through the API with the public key.

By hand: sign out of your app, then request a table through the API with only the public key. If rows come back that a signed-out visitor should not see, use this prompt.

Before you paste

List the tables that hold user data if you know them. If you do not, leave the instruction to list every table as it is.

Fix a security weakness: tables without row-level security

What is wrong:
One or more database tables that the browser can reach through the
database API do not have row-level security turned on, or have it turned
on with a policy that allows everyone. Anyone who has the public key
(it ships in the front end by design) can read or change rows in those
tables.

Where:
- [List the tables that hold user data, if you know them. If you are not
  sure, list every table and view in the schemas exposed through the
  API, with whether row-level security is on and which policies exist,
  before changing anything.]

Required secure behavior:
Every table reachable through the API has row-level security turned on.
Each table has explicit policies for select, insert, update and delete
that match how the app uses it. A signed-out request, using only the
public key, can read only data that is meant to be public.

How to fix it:
1. Write a migration that enables row-level security on every table in
   the exposed schemas.
2. For each table, add policies per operation. For user-owned data,
   allow a row only when its owner column equals the signed-in user's
   id. For data that is meant to be public, allow select only.
3. Do not write a policy that is always true (for example "using
   (true)") for insert, update or delete.
4. Tables the browser never needs get row-level security turned on and
   no policy, so only server code with a server-side key can reach them.
5. Check views and functions as well: make sure they do not bypass the
   policies of the tables underneath.

Constraints:
- Keep existing behavior for legitimate users and keep response formats
  unchanged unless the fix requires it.
- Make the smallest change that fixes the weakness everywhere it occurs,
  and follow the code style of the repository.
- Do not add new dependencies unless there is no maintained way to do
  this already; if you add one, explain why.
- Do not disable security controls, tests or linters to make the change
  pass.
- Before you change anything, list the files you will touch and why.
- Do not solve this by using a service or secret key in browser code.

Tests to add:
- A signed-out request to each private table returns no rows.
- A signed-in user can read and change their own rows.
- A signed-in user cannot read or change another user's rows.
- Inserting a row with another user's id as the owner is refused.

How to verify:
- Run the full test suite and confirm the new tests fail before the fix
  and pass after it.
- On the running app, signed out, request each table with only the
  public key and confirm private rows are not returned.
- Use the app as a normal user and confirm nothing that should work is
  now refused.

After the fix

Signed out, request each table with only the public key and confirm private rows are not returned. Sign in as a normal test user and confirm the app still works. In Supabase, run the Security Advisor again.

Data

Make each user see only their own rows

When to use it

Use this when row-level security is on, but the policies only check that someone is signed in, not which rows are theirs. A policy that exists is not the same as a policy that works.

By hand: create two test accounts. Signed in as the first, ask for a row that belongs to the second (for example by loading its id). If it comes back, use this prompt.

Before you paste

Name the tables and the column that records the owner (often user_id). For team or workspace data, say how membership is stored.

Fix a security weakness: signed-in users can read rows that belong to
other users

What is wrong:
Row-level security is on, but some policies only check that the caller
is signed in. Any signed-in user can read, and in some cases change,
rows that belong to other users.

Where:
- [List the tables and the column that records the owner of each row,
  for example orders.user_id. For shared data, say how membership of a
  team or workspace is stored. If you are not sure, list every policy on
  every table with the condition it uses before changing anything.]

Required secure behavior:
For every table with user-owned data, a user can select, update and
delete only rows they own, and can insert only rows owned by
themselves. For shared data, access follows membership of the team or
workspace, checked in the database.

How to fix it:
1. Replace each policy that only checks for a signed-in user with one
   that compares the owner column to the signed-in user's id.
2. Add a "with check" condition to insert and update policies, so a
   user cannot create a row for someone else or hand a row to another
   owner.
3. For team data, check membership with a query or a function that the
   caller cannot influence from the browser.
4. Make sure the owner column is set on the server or by a default, not
   taken from whatever the browser sends.
5. Add an index on the owner column if the policy would otherwise slow
   down large tables.

Constraints:
- Keep existing behavior for legitimate users and keep response formats
  unchanged unless the fix requires it.
- Make the smallest change that fixes the weakness everywhere it occurs,
  and follow the code style of the repository.
- Do not add new dependencies unless there is no maintained way to do
  this already; if you add one, explain why.
- Do not disable security controls, tests or linters to make the change
  pass.
- Before you change anything, list the files you will touch and why.
- Do not move the check into front-end code. Filtering in the browser is
  not a fix.

Tests to add:
- User A can read, update and delete their own row.
- User A cannot read, update or delete user B's row.
- User A cannot insert a row with user B as the owner.
- A list query as user A returns only user A's rows.

How to verify:
- Run the full test suite and confirm the new tests fail before the fix
  and pass after it.
- With two test accounts on the running app, sign in as the first and
  request a row that belongs to the second. Confirm it is refused or
  empty.

After the fix

With two test accounts on the running app, confirm each one sees and changes only its own rows, and that lists show only the caller's rows.

Data

Lock down open storage buckets

When to use it

Use this when your app stores uploads (photos, documents, exports) and you are not sure who can open them. A bucket marked public serves every file in it to anyone who has or can guess the address.

By hand: copy the address of an uploaded file from your app, sign out, and open it in a private browser window. If a private file opens, use this prompt.

Before you paste

List the buckets or folders and say which ones are meant to be public (for example a logo or product images) and which hold private files.

Fix a security weakness: files in storage can be opened or listed by
anyone

What is wrong:
One or more storage buckets are public, or their access rules allow
any visitor (or any signed-in user) to read, list or write files.
Private uploads can be opened by people who should not see them.

Where:
- [List the buckets or folders and say which are meant to be public and
  which hold private files. If you are not sure, list every bucket, its
  public or private setting and its access rules before changing
  anything. Include old buckets that the app no longer uses.]

Required secure behavior:
Buckets are private unless every file in them is meant for the whole
internet. A private file can be read only by its owner (or by users the
app explicitly allows). Nobody can list a bucket's contents unless the
app needs that. Only signed-in users can upload, only into their own
folder, with limits on file type and size.

How to fix it:
1. Set every bucket that holds user files to private.
2. Add access rules so a user can read, write and delete only files
   under a path that contains their own user id, or files recorded as
   theirs in the database.
3. Serve private files through short-lived signed addresses created on
   the server, after the server has checked the caller may see the
   file.
4. Update the app so it no longer depends on permanent public
   addresses for private files.
5. Restrict uploads to the file types and sizes the app needs.
6. Report any bucket that looks unused, so it can be made private or
   deleted by hand.

Constraints:
- Keep existing behavior for legitimate users and keep response formats
  unchanged unless the fix requires it.
- Make the smallest change that fixes the weakness everywhere it occurs,
  and follow the code style of the repository.
- Do not add new dependencies unless there is no maintained way to do
  this already; if you add one, explain why.
- Do not disable security controls, tests or linters to make the change
  pass.
- Before you change anything, list the files you will touch and why.
- Do not delete any stored file as part of this change.

Tests to add:
- A signed-out request for a private file is refused.
- A signed-in user can open their own file.
- A signed-in user cannot open or list another user's files.
- An upload outside the caller's own folder is refused.

How to verify:
- Run the full test suite and confirm the new tests fail before the fix
  and pass after it.
- On the running app, copy the address of a private file, sign out and
  open it in a private window. Confirm it is refused.
- Confirm that files meant to be public still load.

After the fix

Signed out, open the address of a private file and confirm it is refused. Signed in as a second test user, confirm you cannot open or list the first user's files. Confirm that old buckets you no longer use are private or removed.

Data

Tighten Firebase rules left open or in test mode

When to use it

Use this when your app uses Firestore, the Realtime Database or Cloud Storage for Firebase and the rules were set up quickly. Open the Rules tab in the Firebase console and look for allow read, write: if true, a rule that depends only on a date, or a rule that checks only request.auth != null.

By hand: read the rules for each product. If any path can be read or written by everyone, or by every signed-in user regardless of who owns the data, use this prompt.

Before you paste

Say which Firebase products the app uses and list the collections or paths with who should be able to read and write each one.

Fix a security weakness: Firebase Security Rules allow more than the
app needs

What is wrong:
The Security Rules for Firestore, the Realtime Database or Cloud
Storage are open ("allow read, write: if true"), were left in test
mode, or only check that the caller is signed in. Visitors, or any
signed-in user, can read or change data that belongs to other users.

Where:
- [Say which Firebase products the app uses and list the collections or
  paths with who should be able to read and write each one. If you are
  not sure, list every collection and storage path the app uses and the
  current rule that applies to it before changing anything.]

Required secure behavior:
Rules deny by default. Each collection and storage path has explicit
rules: a user can read and write only their own documents and files,
shared data follows membership recorded in the database, public data is
read-only, and writes are validated (required fields, types, sizes,
and no changing the owner).

How to fix it:
1. Replace open, test-mode and date-based rules with rules per
   collection and per storage path.
2. For user-owned data, compare request.auth.uid with the owner stored
   in the document or the path.
3. Validate writes: required fields, types, size limits, and that the
   owner field cannot be changed by the client.
4. Keep admin-only data unreadable from client code. Reach it from
   server code with the Admin SDK only.
5. Add rules unit tests that run in the Firebase Emulator Suite.
6. Keep the rules files in the repository and deploy them from there,
   so the deployed rules and the tested rules are the same file.

Constraints:
- Keep existing behavior for legitimate users and keep response formats
  unchanged unless the fix requires it.
- Make the smallest change that fixes the weakness everywhere it occurs,
  and follow the code style of the repository.
- Do not add new dependencies unless there is no maintained way to do
  this already; if you add one, explain why.
- Do not disable security controls, tests or linters to make the change
  pass.
- Before you change anything, list the files you will touch and why.
- Do not leave a catch-all rule that allows read or write.

Tests to add:
- A signed-out read or write of private data is denied.
- A signed-in user can read and write their own documents and files.
- A signed-in user cannot read or write another user's documents or
  files.
- A write that changes the owner field or breaks validation is denied.

How to verify:
- Run the rules tests in the emulator and confirm they fail against the
  old rules and pass against the new ones.
- Deploy the rules, then on the running app repeat the checks signed
  out and as a second test user.
- In the Firebase console, confirm the deployed rules match the file in
  the repository.

After the fix

Deploy the rules, then test from outside: signed out, and signed in as a second test user. Tests in the emulator cover the rules file you loaded, so also confirm that the deployed rules in the console match the file.

Access

Stop one user reading another user's records by changing an id

When to use it

Use this when your app has addresses or API calls with an id in them: orders, invoices, profiles, files. This weakness is often called an insecure direct object reference, a kind of broken access control.

By hand, on your own app only: create two test accounts. Signed in as the first, open a record, then change the id to one that belongs to the second account. A safe answer is 401, 403 or "not found". If you see the other account's record, use this prompt.

Before you paste

List the routes that take an id if you know them. If you do not, leave the instruction to find them as it is.

Fix a security weakness: one user can read another user's records by
changing an id

What is wrong:
Some endpoints return a record to any signed-in user who asks for it by
id. They check that the caller is signed in, but not that the record
belongs to the caller. Changing the id in the address (for example
/api/orders/1042 to /api/orders/1043) returns another user's record.

Where:
- [List the routes that take an id, for example /api/orders/:id,
  /api/invoices/:id, /api/profile/:id. If you are not sure, find every
  route, server action and database query that reads, updates or
  deletes a record by id and list them before changing anything.]

Required secure behavior:
Every read, update and delete of a record checks on the server that the
record belongs to the signed-in user (or that the user has a role that
allows it). A request for a record the caller does not own is refused
with 403 or 404, and returns no data from that record.

How to fix it:
1. For each route listed, load the record together with its owner and
   compare the owner to the signed-in user before returning or changing
   anything.
2. Put this ownership check in one shared function or policy and use it
   everywhere, so new routes cannot forget it.
3. If the database supports row-level security, also add a policy so
   the database itself refuses rows the user does not own.
4. Apply the same check to list endpoints: they must return only the
   caller's records, whatever filters are sent.

Constraints:
- Keep existing behavior for legitimate users and keep response formats
  unchanged unless the fix requires it.
- Make the smallest change that fixes the weakness everywhere it occurs,
  and follow the code style of the repository.
- Do not add new dependencies unless there is no maintained way to do
  this already; if you add one, explain why.
- Do not disable security controls, tests or linters to make the change
  pass.
- Before you change anything, list the files you will touch and why.
- Do the check on the server. Hiding a button or a link in the user
  interface is not a fix.

Tests to add:
- A signed-in user requesting their own record receives it.
- A signed-in user requesting another user's record receives 403 or
  404 and no data from that record.
- A signed-out request receives 401.
- The same three cases for update and delete.

How to verify:
- Run the full test suite and confirm the new tests fail before the fix
  and pass after it.
- With two test accounts on the running app, sign in as the first and
  request a record that belongs to the second. Confirm it is refused.
- Review the change for other places with the same pattern and fix
  them too.

After the fix

With two test accounts on the running app, repeat the id swap for reading, and then for changing and deleting on test data only. Each one should be refused.

Access

Require sign-in on every API route by default

When to use it

Use this when your app has API routes, server actions or serverless functions and sign-in is checked route by route. A route added later can simply forget the check, and a page that hides a button does not protect the route behind it.

By hand: open your browser's developer tools, use the app signed in and note the API addresses it calls. Then call the same addresses signed out (a private window is enough for GET requests). If data comes back, use this prompt.

Before you paste

List the routes that are meant to work without sign-in (sign-in itself, sign-up, password reset, webhooks, public pages).

Fix a security weakness: API routes that work without sign-in

What is wrong:
Sign-in is checked route by route, and some API routes, server actions
or server functions do not check it at all. They can be called
directly by anyone who knows the address, even though the page that
normally calls them is behind sign-in.

Where:
- [List the routes that are meant to be public: sign-in, sign-up,
  password reset, webhooks, public content. Then list every other API
  route, server action and server function, and whether it checks
  sign-in today, before changing anything.]

Required secure behavior:
Every API route, server action and server function requires a valid
session unless it is on an explicit list of public routes. A signed-out
request to any other route receives 401 and no data. Routes for
administrators also check the caller's role on the server and answer
403 otherwise.

How to fix it:
1. Add one shared check (middleware, a wrapper or a helper) that
   verifies the session on the server, and apply it to every route by
   default.
2. Keep the list of public routes in one place, short and explicit.
3. Treat server actions and server functions as public endpoints: each
   one verifies the session and the caller's permission itself.
4. Verify the session on the server (cookie or token), not from a value
   the browser sends such as a user id in the request body.
5. Webhooks stay public but must verify the sender's signature.

Constraints:
- Keep existing behavior for legitimate users and keep response formats
  unchanged unless the fix requires it.
- Make the smallest change that fixes the weakness everywhere it occurs,
  and follow the code style of the repository.
- Do not add new dependencies unless there is no maintained way to do
  this already; if you add one, explain why.
- Do not disable security controls, tests or linters to make the change
  pass.
- Before you change anything, list the files you will touch and why.
- Hiding a page or a button in the user interface is not a fix. The
  check must run on the server.

Tests to add:
- A signed-out request to each non-public route receives 401.
- A signed-in request receives the normal response.
- A normal user calling an admin route receives 403.
- Each public route still works signed out.

How to verify:
- Run the full test suite and confirm the new tests fail before the fix
  and pass after it.
- On the running app, signed out, call each non-public route directly
  and confirm it answers 401 with no data.

After the fix

Signed out, call each non-public route on the running app and confirm it answers 401. Confirm admin routes answer 403 for a normal test user.

Sign-in

Add a rate limit to sign-in and password reset

When to use it

Use this when your app has its own sign-in, sign-up, password reset or one-time code check, and nothing slows down repeated attempts. Without a limit, passwords and codes can be guessed by trying many times, and reset emails can be sent in bulk.

By hand, on your own app with a test account: enter a wrong password ten times in a row. If the tenth attempt is answered as quickly and in the same way as the first, use this prompt. If a hosted sign-in service handles this for you, check its rate-limit settings instead.

Before you paste

List the sign-in related endpoints your app has, and say whether a shared store (for example Redis or the database) is already available.

Fix a security weakness: no rate limit on sign-in and password reset

What is wrong:
Sign-in, sign-up, password reset and one-time code checks accept an
unlimited number of attempts. Passwords and codes can be guessed by
trying many times, and reset or confirmation emails can be triggered in
bulk.

Where:
- [List the endpoints: sign-in, sign-up, password reset request,
  password reset confirm, one-time code check, resend email. If you are
  not sure, find every endpoint that accepts a password, a code or an
  email address and list them before changing anything. If a hosted
  sign-in service handles some of these, say which, and configure its
  own limits instead of writing new code for them.]

Required secure behavior:
Repeated attempts are limited on the server, per account and per IP
address. After the limit, the endpoint answers 429 with a Retry-After
header and does nothing else. Messages do not reveal whether an account
exists. A successful sign-in is not blocked for a legitimate user
longer than the stated wait.

How to fix it:
1. Add a server-side limit to each endpoint listed: a small number of
   attempts per account and per IP address in a short window, with a
   growing wait after repeated failures.
2. Store the counters somewhere all server instances share (the
   existing database or cache), not in the memory of one process.
3. Limit how many reset and confirmation emails one address can
   receive per hour.
4. Use the same response for "wrong password" and "no such account",
   and for a reset request whether or not the email exists.
5. Read the client's IP address only from a header set by the hosting
   platform's trusted proxy.

Constraints:
- Keep existing behavior for legitimate users and keep response formats
  unchanged unless the fix requires it.
- Make the smallest change that fixes the weakness everywhere it occurs,
  and follow the code style of the repository.
- Do not add new dependencies unless there is no maintained way to do
  this already; if you add one, explain why.
- Do not disable security controls, tests or linters to make the change
  pass.
- Before you change anything, list the files you will touch and why.
- Do not lock an account permanently after failed attempts; that lets
  anyone lock other people out.

Tests to add:
- Attempts under the limit behave as before.
- The attempt over the limit receives 429 with a Retry-After header.
- After the wait, a correct sign-in succeeds.
- The limit applies per account even when the IP address changes.

How to verify:
- Run the full test suite and confirm the new tests fail before the fix
  and pass after it.
- On the running app, with a test account, enter a wrong password
  repeatedly until 429 appears, wait, and confirm the right password
  works.

After the fix

On the running app with a test account, repeat wrong passwords until the limit answers 429, then confirm the right password works again after the wait.

Sign-in

When to use it

Use this when your app keeps people signed in with a cookie. The cookie should carry three attributes: Secure (sent over HTTPS only), HttpOnly (not readable by scripts on the page) and SameSite (not sent along with requests from other sites, within limits).

By hand: sign in, open your browser's developer tools, find the cookies for your site (the Application or Storage tab) and look at the session cookie's columns. If Secure, HttpOnly or SameSite is missing, use this prompt.

Before you paste

Name the session cookie if you know it, and say whether the front end and the API are on the same domain.

After the fix

Sign in on the running app and look at the cookie again in the developer tools. Confirm sign-in, sign-out and any sign-in with another provider still work.

Secrets

Rotate an exposed service key and move it to the server

When to use it

Use this when a key that bypasses your database's access rules has reached the browser: a Supabase service_role or secret key, a Firebase Admin service account, or a database connection string. These are different from the public keys that are designed to ship in the front end.

By hand: open your deployed site, open the developer tools and search the loaded scripts (Sources or Network tab) for service_role, sb_secret_, private_key and postgres://. If one is there, rotate the key in the provider's dashboard first, then use this prompt. Treat the old key as known to others.

Before you paste

Rotate the key first. Then say which key it was and which features used it from the browser. Never paste the key itself into the prompt.

Fix a security weakness: a service key that bypasses access rules is
in browser code

What is wrong:
A database service key or admin credential is used in code that runs
in the browser, so it ships to every visitor inside the JavaScript
bundle. This kind of key bypasses row-level security and other access
rules. I have already rotated the key in the provider's dashboard; the
old value must be treated as public.

Where:
- [Say which key it was (for example the Supabase service_role or
  secret key, or a Firebase Admin service account) and which features
  used it from the browser. Do not paste the key. If you are not sure,
  find every place the key or its environment variable is referenced,
  including variables with a public prefix such as NEXT_PUBLIC_ or
  VITE_, and list them before changing anything.]

Required secure behavior:
No service key, admin credential or database connection string is
present in browser code, in the built bundle, in source maps or in the
repository history going forward. Browser code uses only the public
key, and the database's access rules protect the data. Work that needs
elevated access runs on the server, after the server has checked who
the caller is and what they may do.

How to fix it:
1. Remove the key from all client code and from any environment
   variable with a public prefix. Read the new key only in server code,
   from a server-side environment variable or the platform's secret
   store.
2. Move each feature that used the key into a server route or server
   function that verifies the caller's session and permission, then
   performs only that specific action.
3. Do not build a general "run this query for me" endpoint. Each
   server route does one thing.
4. Make sure row-level security or equivalent rules cover what the
   browser still does with the public key.
5. Add a check to the build or the tests that fails if the key's name
   or prefix appears in the client bundle.
6. Add the secret files to .gitignore and tell me if the old key is in
   the repository history, so I can decide what to do about it.

Constraints:
- Keep existing behavior for legitimate users and keep response formats
  unchanged unless the fix requires it.
- Make the smallest change that fixes the weakness everywhere it occurs,
  and follow the code style of the repository.
- Do not add new dependencies unless there is no maintained way to do
  this already; if you add one, explain why.
- Do not disable security controls, tests or linters to make the change
  pass.
- Before you change anything, list the files you will touch and why.
- Never print the key's value in code, logs, comments or your reply.

Tests to add:
- The built client bundle does not contain the key's name or prefix.
- Each moved feature works for a permitted user through the server
  route.
- The same server route refuses a signed-out caller with 401 and a
  caller without permission with 403.

How to verify:
- Run the full test suite and confirm the new tests fail before the fix
  and pass after it.
- Deploy, then search the deployed scripts in the browser's developer
  tools for the key's name and prefix. Confirm nothing is found.
- Confirm in the provider's dashboard that the old key is revoked.

After the fix

Build and deploy, then search the deployed scripts again for the key names. Confirm the old key no longer works and that the features that used it work through the server.

Secrets

Move secret keys out of the browser bundle

When to use it

Use this when the browser calls a paid or private API directly (an AI model, email, payments, maps with a secret key), or when a secret sits in an environment variable whose prefix makes it public, such as NEXT_PUBLIC_ or VITE_. Some keys are public by design (a Supabase publishable key, a Firebase web API key, a Stripe publishable key); secret keys are not.

By hand: open your deployed site, open the developer tools and search the loaded scripts for sk_, secret, api_key and the names of the services you use. Watch the Network tab while using the app: a request straight from the browser to a paid API with a key in it is the sign. Rotate any secret you find, then use this prompt.

Before you paste

Rotate the exposed keys first. List the services involved. Never paste a key into the prompt.

Fix a security weakness: secret API keys are in the front-end bundle

What is wrong:
One or more secret API keys are used in code that runs in the browser,
or are stored in environment variables with a public prefix (such as
NEXT_PUBLIC_ or VITE_), so they are included in the JavaScript sent to
every visitor. Anyone can copy them and use the service at my cost or
read data through it. I have already rotated the keys I found.

Where:
- [List the services involved, for example an AI model API, an email
  service, a payment provider's secret key. Do not paste any key. If
  you are not sure, list every environment variable with a public
  prefix and every call from client code to a third-party API, and say
  for each whether its key is meant to be public, before changing
  anything.]

Required secure behavior:
Only keys that their provider documents as safe for the browser
(publishable or public keys) appear in client code. Every secret key
is read only on the server. The browser calls my own server route,
which checks the caller's session, validates the input, applies a
usage limit and then calls the third-party service.

How to fix it:
1. Rename each secret's environment variable so it has no public
   prefix, and read it only in server code.
2. For each client-side call that used a secret, add a server route or
   server function that performs that one call, and point the client
   at it.
3. In each new route, require sign-in where the feature is for
   signed-in users, validate the input, and add a per-user rate limit
   so the route cannot be used to run up costs.
4. Return only the fields the page needs, not the provider's whole
   response.
5. Add a check to the build or the tests that fails if a known secret
   prefix or variable name appears in the client bundle.
6. Make sure .env files are in .gitignore, and tell me if a secret is
   in the repository history.

Constraints:
- Keep existing behavior for legitimate users and keep response formats
  unchanged unless the fix requires it.
- Make the smallest change that fixes the weakness everywhere it occurs,
  and follow the code style of the repository.
- Do not add new dependencies unless there is no maintained way to do
  this already; if you add one, explain why.
- Do not disable security controls, tests or linters to make the change
  pass.
- Before you change anything, list the files you will touch and why.
- Never print a key's value in code, logs, comments or your reply.

Tests to add:
- The built client bundle contains none of the secret variable names
  or key prefixes.
- Each new server route works for a permitted caller.
- Each new server route refuses a signed-out caller where sign-in is
  required, and answers 429 over the usage limit.

How to verify:
- Run the full test suite and confirm the new tests fail before the fix
  and pass after it.
- Deploy, then search the deployed scripts for the key names and watch
  the Network tab: the browser should call my own server, not the
  third-party API.
- Confirm in each provider's dashboard that the old keys are revoked.

After the fix

Deploy, then search the deployed scripts and watch the Network tab again. No secret should appear, and calls to the paid API should now go to your own server route.

Settings

Restrict CORS to the origins your app uses

When to use it

Use this when your API is called from a browser on another origin and its CORS settings were opened up to "make the error go away". CORS decides which other websites may read your API's responses from a visitor's browser. It is not sign-in: it does not stop direct requests.

By hand: in the developer tools' Network tab, look at an API response's Access-Control-Allow-Origin header. If it is * on an API that uses cookies or returns private data, or if it repeats back whatever Origin a request sends together with Access-Control-Allow-Credentials: true, use this prompt.

Before you paste

List the exact origins that should be allowed to call the API from a browser (scheme, host and port), for production, preview and local development.

Fix a security weakness: the CORS policy allows any website to read
API responses

What is wrong:
The API answers cross-origin requests with
Access-Control-Allow-Origin set to "*", or it copies the request's
Origin header into the response, in some cases together with
Access-Control-Allow-Credentials: true. Other websites can read
responses from this API in a visitor's browser.

Where:
- [List the exact origins that should be allowed: production, preview
  and local development, each with scheme, host and port. If you are
  not sure, find every place CORS headers are set (framework
  configuration, middleware, individual routes, the hosting platform's
  settings) and list them before changing anything.]

Required secure behavior:
The API allows cross-origin reads only from an explicit list of
origins. A request from any other origin receives no
Access-Control-Allow-Origin header for that origin. Credentials are
allowed only for listed origins, never together with a wildcard.
Allowed methods and headers are limited to the ones the app uses.

How to fix it:
1. Keep the allowed origins in one configuration value, read from the
   environment, and compare the request's Origin against it with an
   exact match.
2. When the origin is on the list, answer with that origin and add
   "Vary: Origin". Otherwise send no CORS headers.
3. Do not match with "ends with" or a loose pattern, and do not allow
   the "null" origin.
4. Set Access-Control-Allow-Credentials only if the app really sends
   cookies across origins.
5. Handle the OPTIONS preflight in the same place, with the same list.
6. If the front end and the API can share one origin, prefer that and
   remove CORS headers altogether.

Constraints:
- Keep existing behavior for legitimate users and keep response formats
  unchanged unless the fix requires it.
- Make the smallest change that fixes the weakness everywhere it occurs,
  and follow the code style of the repository.
- Do not add new dependencies unless there is no maintained way to do
  this already; if you add one, explain why.
- Do not disable security controls, tests or linters to make the change
  pass.
- Before you change anything, list the files you will touch and why.
- CORS is not access control. Keep sign-in and ownership checks on
  every route.

Tests to add:
- A request with a listed origin receives that origin in
  Access-Control-Allow-Origin and "Vary: Origin".
- A request with an unlisted origin receives no
  Access-Control-Allow-Origin header.
- A preflight request from a listed origin succeeds; from an unlisted
  origin it does not grant access.

How to verify:
- Run the full test suite and confirm the new tests fail before the fix
  and pass after it.
- On the running app, confirm the site still works, and check the
  response headers in the browser's developer tools.

After the fix

From the developer tools, confirm that a request from your own site still works, and that a response to a request with an unlisted origin carries no Access-Control-Allow-Origin header for it.

Settings

Add the standard security headers

When to use it

Use this when your site's responses carry no security headers. They are instructions to the browser that limit what a page can load and how it can be embedded, and they reduce the damage of other mistakes. They do not fix those mistakes.

By hand: open your site, open the developer tools' Network tab, select the first request (the page itself) and read its response headers. If Content-Security-Policy, Strict-Transport-Security and X-Content-Type-Options are missing, use this prompt.

Before you paste

Say where the site is hosted, and list the outside services its pages load (fonts, analytics, payment or sign-in widgets, image hosts).

Fix a security weakness: responses are missing standard security
headers

What is wrong:
The site's responses do not set the browser security headers that
limit what pages can load and how they can be embedded: a content
security policy, HTTP Strict Transport Security, and related headers.

Where:
- [Say where the site is hosted and how response headers are set there
  (framework configuration, middleware, or the hosting platform's
  header file). List the outside services the pages load: fonts,
  analytics, payment or sign-in widgets, image hosts. If you are not
  sure, list every external origin the pages load from before changing
  anything.]

Required secure behavior:
Every HTML response sets:
- Content-Security-Policy: a policy that starts from "default-src
  'self'" and allows only the specific sources the site uses, with
  "frame-ancestors 'none'" (or the specific sites allowed to embed it),
  "base-uri 'self'" and "object-src 'none'".
- Strict-Transport-Security with a max-age of at least one year.
- X-Content-Type-Options: nosniff.
- Referrer-Policy: strict-origin-when-cross-origin.
- Permissions-Policy that turns off features the site does not use.
The site works as before with these headers in place.

How to fix it:
1. Set the headers in one place that covers every response.
2. Build the content security policy from the sources the site really
   uses. For inline scripts the framework needs, use nonces or hashes
   instead of 'unsafe-inline'.
3. First ship the policy as Content-Security-Policy-Report-Only, load
   every main page, fix what it reports, then switch it to enforcing.
4. Add includeSubDomains to Strict-Transport-Security only if every
   subdomain is served over HTTPS.
5. Do not add deprecated headers such as X-XSS-Protection.

Constraints:
- Keep existing behavior for legitimate users and keep response formats
  unchanged unless the fix requires it.
- Make the smallest change that fixes the weakness everywhere it occurs,
  and follow the code style of the repository.
- Do not add new dependencies unless there is no maintained way to do
  this already; if you add one, explain why.
- Do not disable security controls, tests or linters to make the change
  pass.
- Before you change anything, list the files you will touch and why.
- Do not use "*" or 'unsafe-eval' in the policy to make errors go away.
  If something needs them, tell me what and why.

Tests to add:
- A request for the home page and for one signed-in page receives each
  header listed above.
- The content security policy does not contain "*" as a script source.

How to verify:
- Run the full test suite and confirm the new tests fail before the fix
  and pass after it.
- On the running app, load each main page with the browser console open
  and confirm there are no content security policy errors and nothing
  is missing from the page.

After the fix

Load every main page of the running app with the developer tools' Console open and confirm no content security policy errors appear. Read the response headers again.

Settings

Hide stack traces and file paths on error pages

When to use it

Use this when an error in your app shows visitors a stack trace, a file path, a database error or the framework's debug page. Those details help someone map how the app is built.

By hand, on your own app: open an address that does not exist, and send a form with a clearly wrong value (letters where a number belongs). If the answer shows code, file paths, SQL or a framework debug screen, use this prompt.

Before you paste

Say which framework the app uses and where it is hosted, so the tool can turn off the right debug setting.

Fix a security weakness: error pages show stack traces and internal
details

What is wrong:
When something fails, the app's response includes a stack trace, file
paths, a database error message or the framework's debug page. Visitors
can see how the app is built inside.

Where:
- [Say which framework the app uses and where it is hosted. If you are
  not sure where the details leak, find every error handler, every
  place an exception message is sent in a response, and every debug or
  development setting that could be on in production, and list them
  before changing anything.]

Required secure behavior:
In production, an error response contains a plain message, the right
status code and, at most, a reference code. It contains no stack
trace, file path, query, library version or internal host name. The
full detail is written to the server logs with the same reference
code. Debug mode is off in production.

How to fix it:
1. Add one central error handler for pages and one for API routes that
   returns a plain message and a reference code, and logs the detail on
   the server.
2. Replace every place that sends an exception's message or stack to
   the client.
3. Add plain 404 and 500 pages.
4. Make sure debug and development modes are off in the production
   build and in the hosting settings.
5. Do not ship source maps publicly unless that is a deliberate
   choice; say what the current setting is.
6. Keep secrets, tokens and personal data out of the logs.

Constraints:
- Keep existing behavior for legitimate users and keep response formats
  unchanged unless the fix requires it.
- Make the smallest change that fixes the weakness everywhere it occurs,
  and follow the code style of the repository.
- Do not add new dependencies unless there is no maintained way to do
  this already; if you add one, explain why.
- Do not disable security controls, tests or linters to make the change
  pass.
- Before you change anything, list the files you will touch and why.
- Keep detailed errors available in local development.

Tests to add:
- A request that triggers a server error receives status 500 with the
  plain message and no stack trace or file path in the body.
- An unknown address receives the 404 page.
- Invalid input receives a 400 with a message about the input only.

How to verify:
- Run the full test suite and confirm the new tests fail before the fix
  and pass after it.
- On the running app, open an address that does not exist and send a
  form with a wrong value. Confirm only the plain message appears.

After the fix

Repeat the two checks on the running app. You should see a plain message and, at most, a reference code.

Where does Saqr come in?

Saqr writes a prompt like these for every finding, with proof from your own app. No test can promise an app is secure. A task tells you what Saqr found that day, with proof.