Your first check is free. No card needed.Run a free security check

How to fix a security finding with your AI coding tool without breaking the app

Fix one finding at a time: give the tool the finding's proof and the behaviour you expect, ask for a plan before any edit, and reject plans that only hide the symptom in the browser. Then prove the fix yourself by repeating the request from the report on the running app, keep a regression test such as a two-account test, and commit each fix separately so you can undo it.

Imagine the report lands on a Monday: 11 findings, one marked Critical. "Any signed-in user can read every row in the invoices table." You paste the whole report into your AI coding tool and type "fix all of these". Twenty minutes later it replies that all 11 issues are resolved, and the invoices page now shows only your own invoices.

Then you open the Network tab. The request behind that page still returns every customer's invoices. The tool added a filter in the page component, so the browser hides the other rows after downloading them. The finding is exactly as open as it was this morning, and now it looks closed.

What is a finding actually telling you?

A good finding has four parts. Read all four before you prompt anything.

  • What: the behaviour, in one sentence. "User B can read user A's invoices."
  • Where: the page, the API address or the table. "GET /rest/v1/invoices, table public.invoices."
  • Proof: the request that was sent and the response that came back. This is the part your AI tool needs most, because it shows the real behaviour instead of a description of it.
  • Severity: how bad it is if someone uses it. Some reports use the CVSS scale, where Low is 0.1 to 3.9, Medium 4.0 to 6.9, High 7.0 to 8.9 and Critical 9.0 to 10.0 (FIRST, CVSS v4.0). CVSS describes the severity of a flaw relative to others; your own context can move it up or down.

A finding with no proof is a lead, not a fact. Ask whoever wrote the report for the request and response before you spend a prompt on it.

Which findings should you fix first?

Our order, regardless of the labels in the report:

  1. Data anyone can read or change. Tables without row level security, one user reaching another's records, public storage buckets, a secret key in the browser's scripts. For a leaked key, rotate it in the provider's dashboard first, then fix the code (what to do about an exposed key).
  2. Sign-in and accounts. Password reset flaws, admin pages an ordinary user can open, a role field a user can set (can a user make themselves admin?).
  3. Things that cost you money. AI or paid endpoints anyone can call without signing in (stopping AI bill abuse).
  4. Injection and cross-site scripting.
  5. Settings. Security headers, cookie flags, CORS, verbose error pages.

Header findings can fill a page of a report, which makes them feel urgent. They are the least urgent item on this list. Fix them, but not before a table anyone can read.

How should you write the prompt?

One finding per prompt. A prompt with 11 findings gets 11 shallow changes and one vague "done", and when something breaks you cannot tell which change did it.

Each prompt should carry five things:

  • The finding's what and where, copied from the report.
  • The proof: paste the request and response.
  • The expected behaviour: "User B gets an empty list or a 403 for user A's invoices. User A still sees their own."
  • The constraint: "Fix it in the database policy or the server route. Do not filter in the browser, do not disable checks, do not change tests to pass."
  • The check: "Add a test that signs in as two accounts and fails if B can read A's invoice."

Ask for a plan before any edit. Each tool has a mode for it:

  • Claude Code: plan mode, where it "reads files and proposes a plan but makes no edits until you approve". Press Shift+Tab until the status bar shows plan mode, or start with claude --permission-mode plan (Claude Code docs).
  • Cursor: Plan Mode, which "creates detailed implementation plans before writing any code". Press Shift+Tab in the chat input or pick it from the mode menu (Cursor docs).
  • Lovable: Chat mode "never changes your project's code or data" (Lovable docs), and Plan mode writes a plan you approve before it builds (Lovable docs).

Read the plan for one thing above all: where the fix lives. If the plan touches only a React component for a data-access finding, say no and point it at the policy or the route. Our fix prompt library has ready prompts in this shape, for example owner-only rows and checking the owner on every record.

What does a fake fix look like?

Here is the fix from the opening scene:

// The page loaded every invoice
const { data } = await supabase.from("invoices").select("*")

// The "fix": hide other people's rows after they arrive
const mine = data?.filter((row) => row.user_id === session.user.id)

Every row still reaches the browser, and anyone with your publishable key can call the same API without your page at all. The fix belongs in the database:

alter table public.invoices enable row level security;

-- Remove the policy that let every signed-in user read everything
drop policy if exists "Authenticated users can read invoices" on public.invoices;

create policy "Owners read their own invoices"
on public.invoices for select
to authenticated
using ( (select auth.uid()) = user_id );

The drop policy line matters. In Postgres, "all permissive policies which are applicable to a given query will be combined together using the Boolean OR operator" (PostgreSQL docs). Add a strict policy next to an old permissive one and the old one still wins. Supabase recommends the (select auth.uid()) form for performance (Supabase docs); the RLS troubleshooting guide covers other ways a policy fails quietly.

Other symptom fixes to reject:

  • Catching the error and returning an empty list, so the finding's request "fails" politely while the data path stays open.
  • Turning off row level security or a check "temporarily" to make a feature work.
  • Removing the admin link from the menu while the admin API still answers.
  • Editing the test until it passes.

That last one is documented. In March 2025 OpenAI published examples of a reasoning model on coding tasks whose own notes said "We can circumvent verify to always return true", and another that skipped tests outright (OpenAI). The tool is doing what it was rewarded for: making the failure go away. Your prompt has to make the real fix the only acceptable one.

How do you prove the fix worked?

Do not ask the tool. Claude Code's own documentation says "Claude stops when the work looks done" and that "All tests pass" on its own "tells you very little"; ask for the command it ran and the output (Claude Code best practices).

First, keep a regression test. Run it against a staging project with two test accounts that each own data:

import { createClient } from "@supabase/supabase-js"
import { expect, test } from "vitest"

const env = process.env
async function signIn(email: string, password: string) {
  const client = createClient(env.SUPABASE_URL!, env.SUPABASE_PUBLISHABLE_KEY!)
  const { error } = await client.auth.signInWithPassword({ email, password })
  if (error) throw error
  return client
}

test("account B cannot read account A's invoice", async () => {
  const a = await signIn(env.A_EMAIL!, env.A_PASSWORD!)
  const b = await signIn(env.B_EMAIL!, env.B_PASSWORD!)
  const { data: own } = await a.from("invoices").select("id").limit(1)
  expect(own).toHaveLength(1) // A still sees their own
  const { data } = await b.from("invoices").select("id").eq("id", own![0].id)
  expect(data).toEqual([]) // hidden rows come back empty, not as an error
})

The empty result is expected: rows a policy hides "are silently suppressed; no error is reported" (PostgreSQL docs). If you prefer SQL, supabase test db runs pgTAP tests (Supabase docs).

Second, repeat the proof from the report on the running app. Sign in as the second test account, send the exact request from the finding, and read the response. The access control test walks through it with two accounts, including changes and deletes.

Third, ask whoever found it to recheck that finding. A scanner, a pentester or a platform scan can each confirm the request now fails from their side.

How do you avoid breaking the app, and undo a fix?

Commit before each finding and after it, one finding per commit, with the finding's title in the message. Tool undo features help, with limits:

  • Cursor's checkpoints are local snapshots of agent edits; its docs say to "use Git for permanent version control" (Cursor docs).
  • Lovable's revert restores "your project's code only" and "does not restore or roll back your database data"; migrations already run stay run (Lovable docs).

That second point bites with security fixes, because policies live in the database. Before a policy change, save the current policies (the SQL is in the RLS testing guide) so you can put them back by hand.

After each fix, click through the normal flows as both accounts. A tight policy often breaks something legitimate, such as a shared item or a team view. That is a design question for the plan, not a reason to loosen the policy.

Your next step: take the single most serious finding in your report, switch your tool to its plan mode, and paste in the proof with the five parts above.

Where does Saqr fit?

If your report came from Saqr, each finding already carries its proof, the request and response, and a fix prompt to paste into your AI coding tool; after fixing, ask "did my fixes work?" in Chat and it rechecks each finding on the live app. Your first check is free, no card needed.

Saqr (usesaqr.com) is AI security for web apps. Its AI agents attack your live app from the outside, the way a real attacker would, and show you exactly what to fix. From $19 a month, cancel any time. Tests only apps you have shown are yours.

Questions

Can I paste the whole security report into my AI tool at once?

You can ask it to read the report and suggest an order, but fix the findings one per prompt. Batched fixes are shallow, and when something breaks you cannot tell which change caused it.

The AI says the finding is a false positive. Should I believe it?

Only after you repeat the proof request yourself. If the response still shows the data or behaviour in the finding, it is real, whatever the tool says.

Is it fine to keep the filter in the frontend as well?

Yes, filtering in the query is good for speed and clarity. It just cannot be the only control, because anyone can call the API without your page.

What if the fix breaks a feature?

Roll back to the commit before the fix, then ask the tool in plan mode to design a policy that allows the legitimate case, such as team members sharing a record, without reopening access for everyone.

Do I need a staging copy to test fixes?

It is strongly recommended for anything that changes data or policies. If you test on production, use two test accounts that own only test data and never run write tests against real users' records.