Error and security guides
The exact error message or risk, why it happens, and a fix you can verify. Pick a topic:
- Supabase RLS and Storage
- Auth, JWT and secrets
- Edge Functions, webhooks and APIs
- Postgres errors and performance
- AI agent and LLM app security
Supabase RLS and Storage
- Supabase “new row violates row-level security policy” – causes and fixWhy Supabase returns 'new row violates row-level security policy' (42501) on insert, upsert or storage upload, and the exact policy that fixes each case.
- Supabase “must be owner of table objects” – what it means and what to run insteadWhy 'must be owner of table objects' appears when you enable RLS or add policies on Supabase storage.objects, and the SQL statements that work instead.
- Supabase “permission denied for table” – a missing GRANT, not a missing policyWhy Supabase returns 'permission denied for table' (42501) for anon or signed-in users, the GRANT that fixes it, and why new tables need explicit grants.
- Supabase “infinite recursion detected in policy for relation” – cause and fixWhy 'infinite recursion detected in policy for relation' happens when an RLS policy queries its own table, and the security definer function that fixes it.
- Supabase auth.uid() returns null – where it works, where it can't, and how to test policiesWhy auth.uid() is null in the Supabase SQL Editor, migrations, cron jobs and server code, how to test RLS as a real user, and how to pass the user's JWT.
- Supabase “duplicate key value violates unique constraint” on upsert – the five causesWhy Supabase upsert and insert fail with 'duplicate key value violates unique constraint' (23505, 409): onConflict, missing unique index, out-of-sync sequences.
- Supabase Realtime subscribed but no postgres_changes events – the checklistYour Supabase Realtime channel says SUBSCRIBED but no INSERT, UPDATE or DELETE events arrive. Check the publication, RLS, grants, filters and replica identity.
- Supabase PGRST116 “Cannot coerce the result to a single JSON object” – .single() explainedWhy supabase-js .single() fails with PGRST116 'Cannot coerce the result to a single JSON object' (406), when to use maybeSingle(), and how RLS hides rows.
- Supabase Storage “Object not found” (404) – when the file is really thereWhy Supabase Storage returns 'Object not found' (404) from createSignedUrl or download when the file exists: wrong path, missing SELECT policy, anon client.
- Slow Supabase queries with RLS – (select auth.uid()), indexes and the other fixesFix the Supabase 'Auth RLS Initialization Plan' warning and slow RLS queries: (select auth.uid()), indexes on policy columns, roles and fewer policies.
Auth, JWT and secrets
- Supabase “JWT expired” – why the token went stale and how to keep it freshWhy Supabase API calls fail with 'JWT expired' (401), where stale access tokens come from in browser, server and mobile code, and how supabase-js refreshes.
- Supabase service_role or secret key exposed in frontend code – detect, rotate, fixHow to find a Supabase service_role or sb_secret_ key in your frontend bundle, why it bypasses every RLS policy, and how to rotate it and move code server-side.
- Supabase “Database error deleting user” – the foreign key on auth.usersFix 'Database error deleting user' and 'violates foreign key constraint on table profiles' (23503) when deleting a Supabase auth user: ON DELETE rules.
- Supabase “Email link is invalid or has expired” and confirmation links that open localhostWhy Supabase confirmation and magic links fail with otp_expired or redirect to localhost: Site URL, redirect allow list, link scanners and PKCE. Exact fixes.
- redirect_uri_mismatch with Supabase Google or GitHub login – which URL goes whereFix 'Error 400: redirect_uri_mismatch' (Google) and 'The redirect_uri MUST match the registered callback URL' (GitHub) with Supabase Auth social login.
- Supabase “Database error saving new user” – find the failing trigger and fix itWhy Supabase sign-up fails with 'Database error saving new user' (500): a broken handle_new_user trigger, search_path or a constraint. Find it and fix it.
- A .env file or API key in Git history – rotate first, then rewrite historyYou pushed a .env file or API key to GitHub. Rotate the secrets first, then remove them from Git history with git-filter-repo, and block the next leak.
Edge Functions, webhooks and APIs
- Supabase Edge Function returns 404 NOT_FOUND on the CORS preflightThe OPTIONS request to your Supabase Edge Function returns 404 NOT_FOUND and the browser reports CORS. Your CORS code never ran: how to find the real cause.
- Supabase Edge Function 401 “Invalid JWT” or “Missing authorization header”Why a Supabase Edge Function returns 401 'Invalid JWT' or 'Missing authorization header' before your code runs, and the fix for browsers, webhooks and cron.
- Supabase Edge Function CORS errors from the browser – headers, preflight and error responsesFix 'Request header field x-client-info is not allowed by Access-Control-Allow-Headers' and other CORS errors when calling Supabase Edge Functions.
- Supabase cron (pg_cron) job not running – a checklist with the SQL for each stepYour Supabase cron job never runs or runs but does nothing. Check cron.job, job_run_details, the scheduler, UTC times and pg_net calls, with SQL.
- Supabase Database Webhooks and pg_net requests that never arrive – how to debug themSupabase Database Webhook or pg_net call not reaching your Edge Function? Read net._http_response, fix 401s and timeouts, and handle missed events.
- Stripe “No signatures found matching the expected signature for payload” – raw body and the right secretFix Stripe 'No signatures found matching the expected signature for payload' in Next.js, Express and Supabase Edge Functions: raw body, right secret, async.
- Rate limiting an API route – return 429 Too Many Requests before abuse costs youAdd rate limiting to a Next.js route, Express API or Supabase Edge Function: a Postgres fixed-window counter or Upstash Redis, 429 and Retry-After.
- CORS “must not be the wildcard '*' when the request's credentials mode is 'include'” – the safe fixFix the CORS error 'Access-Control-Allow-Origin must not be the wildcard * when the request's credentials mode is include' without opening your API.
Postgres errors and performance
- Postgres “new row for relation … violates check constraint” – find the rule and fix itWhat 'new row for relation violates check constraint' (23514) means, how to see the rule that failed, and how to change a CHECK constraint safely.
- “relation does not exist” in Postgres and Supabase – schema, quotes, search_path, cacheWhy Postgres says 'relation does not exist' (42P01) or Supabase says 'Could not find the table in the schema cache' (PGRST205) for a table you can see.
- Supabase rpc “Could not find the function … in the schema cache” and “function does not exist”Fix PGRST202 'Could not find the function in the schema cache' and 42883 'function does not exist' when calling supabase.rpc(): names, types, overloads.
- SECURITY DEFINER functions without a fixed search_path – the risk and the fixWhat Supabase's 'Function Search Path Mutable' and 'Public Can Execute SECURITY DEFINER Function' warnings mean, the real risk, and the SQL that fixes both.
- Supabase “too many connections” – Postgres slots, Supavisor limits and serverless poolsFix 'remaining connection slots are reserved', 'too many clients already' and Supavisor 'Max client connections reached' on Supabase: pooler modes, pool sizes.
- Postgres “deadlock detected” (40P01) – read it, then remove the lock-order problemWhat Postgres 'deadlock detected' (40P01) means, how to read the DETAIL lines, and the fixes that stop it: one lock order, shorter transactions, retries.
- Supabase “canceling statement due to statement timeout” (57014) – fix the query, then the limitWhy Supabase queries fail with 'canceling statement due to statement timeout' (57014), the default limits per role, and how to fix the query before raising one.
- Postgres “could not serialize access due to concurrent update” (40001) – retry or redesignWhy Postgres says 'could not serialize access due to concurrent update' (40001) under REPEATABLE READ or SERIALIZABLE, and how to retry or avoid it safely.
AI agent and LLM app security
- Prompt injection through retrieved documents (RAG) – what it is and how to contain itHow instructions hidden in retrieved documents hijack a RAG chatbot (indirect prompt injection), and the layered fixes that actually limit the damage it can do.
- LLM tool calls with over-broad permissions – a least-privilege pattern that holdsWhy giving an LLM agent run_sql or an admin key is excessive agency (OWASP LLM06), and a least-privilege design with per-user auth, schemas and confirmations.
- AI API keys and system prompts in frontend code – find them and move the call server-sideWhy OpenAI or Anthropic keys and system prompts in VITE_ or NEXT_PUBLIC_ variables are public, how to find them in your bundle, and move AI calls server-side.
- MCP server security basics – untrusted tool descriptions, local code and token scopeThe real risks of MCP servers: local code you run, tool descriptions and results the model trusts, and over-scoped tokens. Rules for users and server authors.
- LLM output rendered as HTML or run as SQL/shell – XSS and injection, and the safe patternsRendering LLM output with innerHTML or passing it to SQL or a shell is improper output handling (OWASP LLM05). How each attack works and the safe pattern.
- SSRF through an AI agent's “fetch this URL” tool – how it happens and how to block itAn AI agent's fetch_url tool can be steered to cloud metadata, localhost and internal services (SSRF). Validate the resolved IP, redirects and egress.
- Indirect prompt injection in email and calendar agents – one message, full accessHow a single email or calendar invite can hijack an AI assistant that reads your inbox, and the controls that stop data leaving: tool gating, scopes, rendering.
- Jailbreak vs prompt injection – the difference that decides your defencesJailbreaks and prompt injection are related but not the same. Who attacks, what breaks, and which defences in an LLM app actually address each one.
- Per-user token quotas for an LLM endpoint – stop unbounded consumption (OWASP LLM10)Stop one account from draining your OpenAI or Anthropic budget: a server-side key, daily per-user token quotas in Postgres, output caps and provider limits.
- Audit logs for AI agent tool calls – record enough to answer “why did it do that?”What to record for every AI agent tool call, how to keep the log append-only in Postgres, what to redact, and the queries that answer 'what did it do?'