# Vibe coding security risks: where fast-built apps leak data

The main security risks in a vibe coded app sit in the database and server layer, not the interface. Five patterns cause most of the damage: missing or permissive Row Level Security, SECURITY DEFINER functions that anonymous users can call, unverified webhooks, secrets shipped to the browser, and views that bypass RLS. All five can be tested from outside the app in an afternoon and fixed in days.

By Shai Goldenberg. Updated: 2026-11-13.

## Why vibe coded apps fail in the same places

Vibe coding means describing what you want and letting an AI tool write the code. Lovable, Bolt, Cursor and Claude Code can take a founder from idea to a working product in days. Many of those products run on Supabase, which gives each project a Postgres database, authentication and an auto-generated API.

That architecture has one property that matters for security. The browser talks to the database API directly, using a key that is public by design. There is no server in the middle to say no. The only thing that decides who can read or change a row is the set of rules inside the database.

AI tools optimize for the thing you can see. A page that loads and saves data looks finished. A missing access rule produces no error, no failed test and no visual difference. So the same gaps appear across apps built by different people with different tools.

These are the five we look for first in a [security audit](https://goldenroz.com/security-audit/).

## The five failure patterns

### 1. Missing or permissive Row Level Security

Row Level Security (RLS) is the Postgres feature that filters rows per user. In Supabase, a table in an exposed schema with RLS turned off is readable and writable by anyone who has the publishable key, and that key is in your site's JavaScript.

Three versions of this failure are common:

- RLS was never enabled on a table created by a SQL migration.
- RLS is enabled, but a policy says `using (true)`, which allows every row to every caller. This often appears after the builder asks the AI to "fix the permissions error".
- A policy exists for reading but writes are open, or the insert policy does not check that the row belongs to the caller.

The fix is a policy per operation that compares the row's owner to the logged-in user. Our guide to [Supabase Row Level Security](https://goldenroz.com/blog/supabase-row-level-security/) has the SQL.

### 2. SECURITY DEFINER functions callable by anonymous users

A Postgres function marked `security definer` runs with the privileges of its owner, not its caller. In a Supabase project the owner is usually the `postgres` role, which bypasses RLS. Postgres also grants execute permission on new functions to every role by default, and Supabase exposes functions in the public schema as API endpoints.

Put those three facts together. A function written to "get all orders for the admin dashboard" can be called by a visitor with no account, and it returns every order.

The fix has three parts: revoke execute from `public` and `anon`, grant it only to the roles that need it, and check the caller's identity inside the function body. Set `search_path = ''` on every definer function so a caller cannot redirect table names.

### 3. Unverified webhooks

Payment providers notify your app through a webhook, which is a public URL that accepts a POST request. If the handler trusts whatever arrives, anyone who finds the URL can send a fake "payment succeeded" event and receive a paid plan, credits or a shipped order.

Stripe signs every event. The handler must verify that signature against the raw request body with the endpoint's signing secret before it does anything else. On Supabase edge functions, webhook endpoints are usually deployed with JWT verification turned off because Stripe cannot send a Supabase token. That makes the signature check the only protection the endpoint has.

Two related gaps: handlers that process the same event twice, and handlers that read the price or user ID from the request instead of looking it up from the verified event.

### 4. Secrets in the client

Anything in a browser bundle or a mobile app binary is public. We look for:

- The Supabase secret key (service role key) used in frontend code. It bypasses RLS completely.
- Keys for OpenAI, Anthropic, Stripe or an email provider in variables with a public prefix such as `VITE_` or `NEXT_PUBLIC_`.
- Keys committed to the git history, which remain readable after the file is deleted.

A leaked model key costs money. A leaked service role key exposes the whole database. Calls that need a secret belong in a server function, and any key that has ever shipped to a client must be rotated as well as moved.

### 5. Views that bypass RLS

A Postgres view runs with the privileges of the role that created it unless told otherwise. A view over a protected table can therefore return every row to every caller, even though the table's policies are correct.

On Postgres 15 and later, the fix is one line: create the view with `security_invoker = true` so that the caller's policies apply. This one is easy to miss because the builder checks the table, sees good policies and moves on.

## A self-check list

Run this before launch and after any large AI-generated change. None of it needs special tools.

1. **List tables without RLS.** In the SQL editor: `select tablename from pg_tables where schemaname = 'public' and rowsecurity = false;` The result should be empty.
2. **Read every policy.** Search for `using (true)` and `with check (true)`. Each one needs a written reason.
3. **Probe as a stranger.** Take the publishable key from your site, send requests with no login token, and try to select from each table and call each function.
4. **Probe as the wrong user.** Log in as user A and request user B's rows by ID.
5. **List definer functions.** `select proname from pg_proc where prosecdef and pronamespace = 'public'::regnamespace;` Check who can execute each one.
6. **Check views.** Confirm each view over a protected table sets `security_invoker`.
7. **Search the built bundle.** Open the deployed JavaScript and search for `service_role`, `sk_live` and `sk-`.
8. **Send a fake webhook.** POST an unsigned event to your payment endpoint. It should return an error and change nothing.
9. **Check storage buckets.** Confirm private files are not in a public bucket.
10. **Run the built-in linter.** The Supabase dashboard includes a security advisor that flags several of these patterns.

| Pattern | What an attacker gets | How hard to test | Typical fix |
|---|---|---|---|
| RLS off or `using (true)` | Read or change any row | Minutes | Enable RLS, one policy per operation |
| Open SECURITY DEFINER function | Data or actions as the database owner | Minutes | Revoke execute, check caller inside |
| Unverified webhook | Free paid access, forged orders | Minutes | Verify signature on raw body |
| Secret in client | Full database or billed API usage | Minutes | Move to server, rotate the key |
| View without `security_invoker` | Rows the table policy would hide | Minutes | Recreate view as security invoker |

## Practices that keep it fixed

A one-time review goes stale with the next migration. Shai runs a production marketplace with about 145 tables under RLS and 155 policies, built largely with Claude Code. Two practices from that system carry over to any AI-built app.

**A daily anonymous-user probe.** An automated job calls sensitive database functions as an anonymous user every day. If a call that should fail succeeds, the job closes the permission. A new function added by an AI agent on Tuesday is tested by Wednesday without anyone remembering to do it.

**Guard hooks.** Claude Code supports hooks that run before a tool call and can block it. Shai's setup blocks two SQL patterns that caused real incidents, so the agent cannot write them again. The rule lives in the repository and applies to every session. Our post on [Claude Code hooks](https://goldenroz.com/blog/claude-code-hooks/) explains the mechanism, and [Claude Code training](https://goldenroz.com/claude-code-training/) covers setting this up for a team.

Both ideas replace "remember to check" with a machine that checks.

## How an audit works

Our audit is a code and database security audit for apps built on Supabase or Postgres. It is not a certified penetration test and it does not produce a compliance attestation.

- **Scoping call.** Thirty minutes to see the stack, the size of the schema and what handles money or personal data. The price is fixed and quoted after this call.
- **Review.** Shai reads every table, policy, function, view, trigger, edge function and webhook handler, and probes the live API as an anonymous user and as a low-privilege user.
- **Findings report.** Each finding has a severity, a proof of how it can be reached and the exact change that closes it.
- **Fixes as pull requests.** You review and merge migrations, not a PDF of advice.
- **Daily probe left running.** The automated anonymous-user check stays in your CI after we leave.

## What to do next

Run the ten checks above this week. If any of them returns data it should not, treat it as a production incident, not a backlog item. If the app handles payments or personal data and nobody on the team reads SQL policies comfortably, book a scoping call for a [security audit](https://goldenroz.com/security-audit/). If you are still planning the build, our [MVP development](https://goldenroz.com/mvp-development/) work ships with these controls from the first migration.

## Questions buyers ask

### Is vibe coding safe for a production app?

It can be, if someone reviews what the AI did not think about. AI coding tools produce working features quickly, but access control is invisible when it is missing, so nothing prompts the builder to add it. A vibe coded app is safe for production once its database policies, server functions, webhooks and secrets have been checked by a person or an automated probe.

### Is the Supabase anon key a secret?

No. The publishable key, called the anon key in older projects, is designed to ship in the browser. It is safe only when Row Level Security is enabled with correct policies on every table in an exposed schema. The secret key, called the service role key in older projects, bypasses RLS and must never reach a client.

### How do I check if my Lovable or Bolt app is secure?

Call your own API as a stranger. Use the publishable key from your site's JavaScript, send no login token, and try to read each table and call each database function. Anything that returns data or succeeds without a login is open to the internet. The self-check list in this post covers the rest.

### What does a security audit of a vibe coded app include?

At Goldenroz it is a code and database security audit: a review of every table, policy, function, view, webhook and key, a findings report ranked by severity, fixes delivered as pull requests, and an automated daily probe left running. It is not a certified penetration test or a compliance attestation. The price is fixed and quoted after a 30-minute scoping call.

### Can an AI tool fix its own security problems?

Partly. An AI agent will fix a policy when you point it at the specific problem, and it is good at writing the migration. It is weak at noticing what is absent, so the list of problems has to come from a review, a database linter or a probe that tests the live system.

---
Page: https://goldenroz.com/blog/vibe-coding-security-risks/
Book a free one-hour call: https://calendly.com/daniarozin/daniel-rozin-consultation-1-hour-clone
