# Understand common backend security errors

> Short answer: Security errors often mean a request does not match the policy you intended. The safe fix is to correct the identity, role, or resource rule—not to turn off access controls until the error disappears.

## Start with the request identity

Check whether the request is anonymous or authenticated, which role reaches the database, and which row or operation is being attempted. A missing session, wrong owner field, or policy for a different command can all produce a denial.

Do not paste an elevated service key into browser code to bypass a denial. Privileged operations belong on a trusted server with their own authentication and authorization checks.

## Use a safe test case

Reproduce the behavior with a non-sensitive test record. Test the anonymous role, the intended owner, and a different user; then verify that only the intended cases succeed after the policy change.

## Related pages

- [Fix Anthropic 401 authentication_error 'invalid x-api-key'](https://proofforge.live/errors/anthropic-authentication-error) — The Claude API couldn't authenticate the x-api-key header.
- [Fix 'AuthSessionMissingError: Auth session missing!'](https://proofforge.live/errors/auth-session-missing) — Supabase-js was asked for the current user (getUser(), updateUser(), signOut()) but has no session.
- [Fix AWS 'SignatureDoesNotMatch' (signature we calculated…)](https://proofforge.live/errors/aws-signature-does-not-match) — AWS recomputed the Signature Version 4 signature for your request and got a different value.
- [Fix CORS error: wildcard '*' with credentials 'include'](https://proofforge.live/errors/cors-wildcard-with-credentials) — Your request sends cookies or auth (credentials: 'include'), and the server answered Access-Control-Allow-Origin: *, which browsers forbid for credentialed requests.
- [Fix CSP warning: 'unsafe-inline' allows unsafe scripts](https://proofforge.live/errors/csp-unsafe-inline-warning) — Your CSP's script-src includes 'unsafe-inline', so any script an attacker injects into the page will run, and the policy no longer stops XSS.
- [Fix ERR_SSL_PROTOCOL_ERROR on your custom domain](https://proofforge.live/errors/err-ssl-protocol-error) — The TLS handshake failed, usually a certificate not issued yet or DNS pointing elsewhere.
- [Fix Firestore 'Missing or insufficient permissions'](https://proofforge.live/errors/firebase-missing-or-insufficient-permissions) — Cloud Firestore Security Rules denied the read or write (error code permission-denied).
- [Fix Firebase Realtime Database 'PERMISSION_DENIED'](https://proofforge.live/errors/firebase-permission-denied) — Your Realtime Database Security Rules didn't grant .read or .write at that path for this user.
- [Fix GitHub GH013 'Push cannot contain secrets'](https://proofforge.live/errors/github-push-protection-secret) — GitHub push protection found a supported secret (an API key or token) in the commits you're pushing and blocked the push.
- [Fix Google Maps RefererNotAllowedMapError / ApiTargetBlocked](https://proofforge.live/errors/google-maps-key-restriction) — Your Google Maps API key has restrictions, and this request doesn't match them.
- [Fix hstspreload.org errors (max-age, preload, subdomains)](https://proofforge.live/errors/hsts-preload-error) — To join the browser HSTS preload list, your HTTPS response must send Strict-Transport-Security with max-age of at least 31536000, plus includeSubDomains and preload.
- [Fix 'Invalid API key' from Supabase](https://proofforge.live/errors/invalid-api-key-supabase) — The apikey the request sent doesn't match a live key for that project.
- [Fix 'Mixed Content: … was loaded over HTTPS, but requested…'](https://proofforge.live/errors/mixed-content-blocked) — Your HTTPS page tried to load something over plain http://, such as an API URL, script, iframe or image, and the browser blocked or auto-upgraded it.
- [Fix NET::ERR_CERT_COMMON_NAME_INVALID](https://proofforge.live/errors/net-err-cert-common-name-invalid) — The certificate doesn't cover this hostname, often www vs apex.
- [Fix 'new row violates row-level security policy' (Supabase)](https://proofforge.live/errors/new-row-violates-row-level-security-policy) — RLS is on for the table, but no INSERT or UPDATE policy's WITH CHECK clause allows the row you sent.
- [Fix process.env.NEXT_PUBLIC_… undefined in Next.js](https://proofforge.live/errors/next-public-env-undefined) — Next.js only sends variables prefixed NEXT_PUBLIC_ to the browser, and it inlines them at build time.
- [Fix 'No Access-Control-Allow-Origin header is present'](https://proofforge.live/errors/no-access-control-allow-origin-header) — The browser blocked your frontend from reading an API response because the server didn't send Access-Control-Allow-Origin for your site's origin.
- [Fix OpenAI 401 'Incorrect API key provided'](https://proofforge.live/errors/openai-incorrect-api-key) — OpenAI didn't accept the key in the Authorization header (401, code invalid_api_key).
- [Fix OpenAI 429 'You exceeded your current quota'](https://proofforge.live/errors/openai-insufficient-quota) — A billing error (no credits or a spend limit), not a rate limit. Retrying won't help.
- [OpenAI 'your API key was leaked and disabled': what to do](https://proofforge.live/errors/openai-key-disabled-leaked) — OpenAI found your key somewhere public, usually a GitHub repo or a website's JavaScript, and disabled it immediately.
- [Fix 'permission denied for table' in Supabase / Postgres](https://proofforge.live/errors/permission-denied-for-table) — The role making the request (anon, authenticated or service_role) has no privilege on that table.
- [Fix PGRST116 'Cannot coerce result to single JSON object'](https://proofforge.live/errors/pgrst116) — You asked for exactly one row (.single()), but the query returned zero or more than one, so PostgREST answers 406 with PGRST116.
- [Fix 'PGRST301 JWT expired' / PGRST303 in Supabase](https://proofforge.live/errors/pgrst301-jwt-expired) — The access token sent with the request is past its exp time, so PostgREST rejects it with 401.
- [Fix 'Refused to display … in a frame' (X-Frame-Options)](https://proofforge.live/errors/refused-to-display-in-frame) — The framed page tells browsers not to be embedded by other sites, via X-Frame-Options or CSP frame-ancestors.
- [Fix 'Refused to load the script' (CSP violation)](https://proofforge.live/errors/refused-to-load-script-csp) — Your Content-Security-Policy doesn't list the script's origin in script-src (or default-src), so the browser refused to run it.
- ['DevTools failed to load source map': fix or ignore?](https://proofforge.live/errors/source-map-warning-devtools) — A JS or CSS file references a .map file (//# sourceMappingURL=) that DevTools couldn't fetch.
- [Fix Stripe 'Invalid API Key provided' / api_key_expired](https://proofforge.live/errors/stripe-invalid-api-key) — The request sent a key Stripe doesn't recognize for that account or mode, often test vs live mixed up, a typo, or an empty env var.
- [Supabase says your secret key leaked: what to do now](https://proofforge.live/errors/supabase-leaked-service-key-email) — A Supabase secret key (sb_secret_…) was detected in a public GitHub repository through GitHub secret scanning, and Supabase revoked it automatically.
- [Fix Supabase Storage upload 'violates row-level security'](https://proofforge.live/errors/supabase-storage-new-row-rls) — Uploads write a row to storage.objects, and RLS there has no INSERT policy allowing this user to write to this bucket and path.
- [Fix import.meta.env.VITE_… is undefined (Vite)](https://proofforge.live/errors/vite-env-undefined) — Vite only exposes variables that start with VITE_, and it bakes them into the bundle at build time.

## Frequently asked questions

**Should I disable RLS to fix a denied insert?**

No. Add an operation-specific policy that matches the intended user and row owner.

**Does an authorization error mean the table is secure?**

It confirms one request was denied. Review every operation and role, including reads and updates.

**Why does an upsert fail when insert works?**

The request may also take an update path, which needs its own policy and row checks.

---
Last updated 2026-11-25 · Reviewed by ProofForge. Methodology: https://proofforge.live/methodology
