What AI-Generated Code Gets Wrong
AI code generators are optimized to produce code that works, not code that's secure. They're trained to satisfy the prompt, not to think about edge cases, attack vectors, or production-scale failure modes. Here are the most common vulnerabilities we see:
Missing Row-Level Security (RLS) policies — This is the single most common vulnerability in Lovable and Supabase-based applications. Without RLS, any authenticated user can read, modify, or delete any other user's data. AI tools rarely configure these correctly.
Hardcoded API keys and secrets in client-side code — AI generators frequently embed API keys directly in frontend components. If you are building with Claude API or other LLM services, this is especially dangerous. These keys are visible to anyone who opens browser DevTools. We have found Stripe secret keys, Supabase service role keys, and third-party API credentials exposed this way.
No input validation or sanitization — AI-generated forms typically send user input directly to the database without validation. This opens the door to SQL injection, XSS attacks, and data corruption.
Authentication bypass patterns — Weak password policies, missing email verification, and improperly configured auth flows that allow account takeover.
Missing error handling that exposes stack traces — When AI-generated code fails, it often dumps full error messages to the user — including database schemas, file paths, and internal system details that attackers use for reconnaissance.
Over-permissive CORS configurations — Many AI-generated backends allow requests from any origin (Access-Control-Allow-Origin: *), enabling cross-site request forgery and data theft.
What Should Your 14-Point AI Code Audit Cover?
Use this checklist to audit any AI-generated application before going to production. Our
software testing team uses this exact framework. Each item addresses a specific vulnerability pattern we've identified across 50+ audits:
1. Check Supabase RLS policies on every table — Verify that every table has Row-Level Security enabled and that policies correctly restrict access. Test by logging in as different users and attempting to access each other's data.
2. Verify no API keys in client-side code — Search your entire codebase for hardcoded keys. Check environment variable usage. Only the Supabase anon key should ever appear in frontend code.
3. Test authentication flows (signup, login, password reset) — Attempt to bypass each step. Try weak passwords. Test email verification. Check that password reset tokens expire correctly.
4. Check for SQL injection in custom queries — If your app uses any raw SQL or custom database functions, test with injection payloads. Ensure all queries use parameterized statements.
5. Validate all user inputs server-side — Client-side validation is easily bypassed. Every input that reaches your server must be validated for type, length, format, and allowed values.
6. Review CORS configuration — Your API should only accept requests from your own domain(s). Remove wildcard origins. Add appropriate preflight handling.
7. Check for exposed environment variables — Ensure .env files are in .gitignore. Verify that build processes don't bundle secret variables into client-side code.
8. Test error handling (do errors leak internals?) — Trigger errors intentionally and check what information is returned to the client. Production errors should show generic messages, not stack traces.
9. Review third-party dependencies for known CVEs — Run npm audit or use Snyk to check for known vulnerabilities in your dependency tree. Update or replace vulnerable packages.
10. Check file upload validation (type, size, malware) — If your app accepts file uploads, verify that you validate file types (not just extensions), enforce size limits, and scan for malicious content.
11. Test rate limiting on auth and API endpoints — Without rate limiting, attackers can brute-force passwords, abuse your API, and rack up costs on paid services. Verify limits exist on login, signup, and resource-intensive endpoints.
12. Verify HTTPS enforcement and security headers — Check that HTTP redirects to HTTPS. Verify headers: Strict-Transport-Security, X-Content-Type-Options, X-Frame-Options, and Content-Security-Policy.
13. Check for insecure direct object references (IDOR) — Try accessing other users' resources by changing IDs in URLs or API requests. Each request should verify that the authenticated user owns the requested resource.
14. Review logging (no PII in logs, audit trail exists) — Ensure that logs don't contain passwords, tokens, or personally identifiable information. Verify that security-relevant events (login, data access, permission changes) are logged for audit purposes.