← All posts

How to Secure an AI Coded App: A Checklist for Vibe Coders

O

OverMCP Team

Quick answer

Securing an AI-coded app doesn't require a security degree, but it does require a checklist. The most common vulnerabilities in vibe-coded apps are exposed secrets, missing authentication checks, insecure database rules, and weak dependency hygiene. Focus on these four areas first, and you'll eliminate the majority of real-world attack vectors.

What to check first

Before you do anything else, run through this checklist. It targets the issues that show up most often in AI-generated code.

  • Scan for leaked secrets: Search your repo for API keys, tokens, and passwords. Use a secret leak scanner to automate this.
  • Review your database rules: If you're using Firebase or Supabase, check that your security rules are locked down. A common mistake is leaving them wide open for development.
  • Test authentication and authorization: Ensure that protected routes actually check if the user is logged in and has the right permissions. Try accessing an admin page while logged out.
  • Check for security headers: Your app should send headers like Content-Security-Policy, X-Frame-Options, and Strict-Transport-Security. Use a security headers checker to verify.
  • Verify SSL/TLS: Make sure your domain has a valid SSL certificate. An expired or self-signed cert is a red flag. Use an SSL certificate checker.
  • Audit dependencies: Run npm audit or yarn audit to see if any of your packages have known vulnerabilities. Update or patch them.
  • Look for common web vulnerabilities: Test for SQL injection, XSS, and CSRF. Many AI-generated apps are missing basic input validation.
  • Step-by-step fix

    Once you've identified the issues, here's how to fix them. I'll walk through the most critical ones.

    1. Fix exposed secrets

    If you find a hardcoded API key or secret, remove it immediately and rotate the key. Move it to environment variables. In Next.js, you can use .env.local for local development and set them in your hosting platform (Vercel, Netlify, etc.) for production.

    Here's an example of how to properly use environment variables in a Next.js app:

    // .env.local
    OPENAI_API_KEY=sk-...
    
    // pages/api/openai.js
    export default async function handler(req, res) {
      const apiKey = process.env.OPENAI_API_KEY;
      // Use apiKey to call OpenAI
    }

    Never commit .env files to your repository. Add them to .gitignore.

    2. Lock down your database rules

    If you're using Firebase or Supabase, review your security rules. For Firebase, you might have something like this:

    {
      "rules": {
        ".read": true,
        ".write": true
      }
    }

    This is a disaster waiting to happen. Change it to something like:

    {
      "rules": {
        "users": {
          "$uid": {
            ".read": "auth != null && auth.uid == $uid",
            ".write": "auth != null && auth.uid == $uid"
          }
        }
      }
    }

    For Supabase, use Row Level Security (RLS). Write policies that restrict access to the owner of the data. For example:

    create policy "Users can only access their own data"
    on profiles for select
    using ( auth.uid() = user_id );

    3. Add authentication checks to API routes

    AI-generated code often forgets to check if the user is authenticated. In Next.js API routes, add a check at the top:

    import { getSession } from 'next-auth/react';
    
    export default async function handler(req, res) {
      const session = await getSession({ req });
      if (!session) {
        return res.status(401).json({ error: 'Unauthorized' });
      }
      // Proceed with the rest of the handler
    }

    Make sure to do this for every route that accesses sensitive data or performs mutations.

    4. Set security headers

    You can add security headers manually in your hosting config. For Vercel, you can use a vercel.json file:

    {
      "headers": [
        {
          "source": "/(.*)",
          "headers": [
            { "key": "Content-Security-Policy", "value": "default-src 'self'" },
            { "key": "X-Frame-Options", "value": "DENY" },
            { "key": "Strict-Transport-Security", "value": "max-age=31536000; includeSubDomains" }
          ]
        }
      ]
    }

    Alternatively, use a security headers checker to see what's missing and then implement them.

    5. Update dependencies

    Run npm audit and fix any critical vulnerabilities. If a package has no fix, consider replacing it. For example, if you're using a vulnerable version of lodash, update it or switch to a modern alternative.

    Common mistakes

    Here are the mistakes I see all the time in vibe-coded apps:

  • Hardcoding secrets: AI tools often write code with API keys directly in the source. This is the #1 mistake. Always use environment variables.
  • Overly permissive CORS: Setting Access-Control-Allow-Origin: * is common. This allows any website to make requests to your API. Restrict it to your own domain.
  • Missing input validation: AI-generated forms often lack server-side validation. Attackers can send malicious data that leads to SQL injection or XSS.
  • Ignoring rate limiting: If your API has no rate limiting, bots can hammer it. This can lead to abuse and high costs if you're paying for API calls.
  • Skipping security headers: Many apps don't set CSP or HSTS headers. This leaves users vulnerable to XSS and MITM attacks.
  • Forgetting to check authorization: Just because a user is logged in doesn't mean they can access any resource. Always check ownership (IDOR vulnerabilities).
  • How to keep your app secure over time

    Security isn't a one-time fix. As you continue to add features with AI, new vulnerabilities can creep in. Here's how to stay on top:

  • Set up continuous monitoring: Use a tool like OverMCP's continuous security monitoring to get alerts when new issues are detected.
  • Run scans before every deploy: Make it a habit to run a free AI app security scanner before pushing to production. It takes minutes.
  • Keep dependencies updated: Set up Dependabot or Renovate to automatically open PRs for outdated packages.
  • Educate yourself on OWASP Top 10: Understanding these common vulnerabilities will help you spot them in AI-generated code.
  • FAQ

    What is the most common security issue in AI-coded apps?

    The most common issue is exposed secrets. AI models often generate code with hardcoded API keys or database credentials. Always scan your repo for secrets before deploying.

    Do I need a pentest for my vibe-coded app?

    Not necessarily. For a small app, a vulnerability scan and manual review of the checklist above is usually enough. Pentests are more appropriate for larger apps with sensitive data.

    How can I scan my AI-coded app for free?

    You can use OverMCP's free AI app security scanner to check for common vulnerabilities. It's built for indie developers and takes less than a minute to run.

    ---

    By following this guide, you'll significantly reduce the risk of a security breach in your AI-coded app. Remember, security is a journey, not a destination. Keep scanning, keep fixing, and ship with confidence.

    Is your app secure?

    Free scan in 30 seconds. No signup needed.

    Scan My App Free