← All posts
CORSsecurity scannervibe codingAI-built appsNext.js

CORS Security Scanner: Free Guide for Vibe-Coded Apps

O

OverMCP Team

Quick answer

A free CORS security scanner checks your web app's Cross-Origin Resource Sharing (CORS) headers for misconfigurations that let malicious sites steal data or perform actions on behalf of your users. For vibe-coded apps, where AI tools often generate permissive CORS policies, running a scanner is a quick, essential step before launch. Use free tools like the security headers checker from OverMCP to detect and fix these issues in minutes.

What to check first

Before diving into a full CORS security scanner, run this quick checklist on your AI-built app. Many vibe-coded apps share the same CORS blind spots, so these checks will catch the most common issues fast.

  • [ ] Inspect your CORS headers: Open your browser's developer tools (F12), go to the Network tab, and click on any API request. Look for Access-Control-Allow-Origin in the response headers. If it's * or echoes any origin, you have a problem.
  • [ ] Check for credentials: If your app uses cookies or authorization headers, the Access-Control-Allow-Credentials header must be true, but Access-Control-Allow-Origin cannot be *. This combination is a classic CORS misconfiguration.
  • [ ] Test with a CORS scanner: Use a free tool like OverMCP's security headers checker to scan your live URL. It will flag missing or misconfigured CORS headers.
  • [ ] Review serverless functions: If you're on Vercel, Netlify, or AWS Lambda, check your serverless function responses. AI-generated code often adds CORS headers in each function, and they're easy to get wrong.
  • [ ] Look for hardcoded origins: Search your codebase for Access-Control-Allow-Origin or cors() calls. In vibe-coded apps, you'll often find * or a hardcoded list that includes your localhost.
  • Step-by-step fix

    Once you've run a CORS security scanner and found issues, here's how to fix them. Let's use a Next.js API route as an example, since it's common in vibe-coded apps.

    1. Identify the misconfiguration

    Run your CORS security scanner and note the exact header values. For instance, you might see:

    Access-Control-Allow-Origin: *
    Access-Control-Allow-Credentials: true

    This is a severe issue: it allows any origin to make authenticated requests, enabling cross-site request forgery (CSRF) and data theft.

    2. Replace wildcard with specific origins

    Instead of *, allow only your trusted domains. Here's a proper CORS setup in a Next.js API route:

    // pages/api/user.ts
    import type { NextApiRequest, NextApiResponse } from 'next';
    
    const allowedOrigins = [
      'https://yourapp.com',
      'https://www.yourapp.com',
      process.env.NODE_ENV === 'development' ? 'http://localhost:3000' : ''
    ].filter(Boolean);
    
    export default function handler(req: NextApiRequest, res: NextApiResponse) {
      const origin = req.headers.origin;
      if (origin && allowedOrigins.includes(origin)) {
        res.setHeader('Access-Control-Allow-Origin', origin);
      }
      res.setHeader('Access-Control-Allow-Credentials', 'true');
      res.setHeader('Access-Control-Allow-Methods', 'GET,POST,PUT,DELETE,OPTIONS');
      res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
      
      // Handle preflight requests
      if (req.method === 'OPTIONS') {
        res.status(200).end();
        return;
      }
      // ... rest of your handler
    }

    3. Use environment variables

    Never hardcode origins. Put them in env variables so you can change them without redeploying. In your .env.local:

    CORS_ORIGINS=https://yourapp.com,https://www.yourapp.com

    Then in your code:

    const allowedOrigins = process.env.CORS_ORIGINS?.split(',') || [];

    4. Apply globally with middleware

    Instead of adding CORS headers to every route, use a global middleware. For Next.js, you can use middleware.ts:

    // middleware.ts
    import { NextResponse } from 'next/server';
    import type { NextRequest } from 'next/server';
    
    const allowedOrigins = process.env.CORS_ORIGINS?.split(',') || [];
    
    export function middleware(request: NextRequest) {
      const origin = request.headers.get('origin') || '';
      const response = NextResponse.next();
      
      if (allowedOrigins.includes(origin)) {
        response.headers.set('Access-Control-Allow-Origin', origin);
      }
      response.headers.set('Access-Control-Allow-Credentials', 'true');
      response.headers.set('Access-Control-Allow-Methods', 'GET,POST,PUT,DELETE,OPTIONS');
      response.headers.set('Access-Control-Allow-Headers', 'Content-Type, Authorization');
      
      return response;
    }
    
    export const config = {
      matcher: '/api/:path*',
    };

    5. Re-scan with your CORS security scanner

    After deploying, run the scanner again to confirm the headers are correct. OverMCP's continuous security monitoring can keep an eye on your headers over time, so you'll know if they regress.

    Common mistakes

    AI coding tools like Cursor, Bolt.new, and v0 often generate CORS configurations that are overly permissive or just wrong. Here are the most common mistakes I've seen in vibe-coded apps:

  • Using `` for everything**: It's the default suggestion from many AI tools. It works for simple public APIs, but breaks the moment you need cookies or authentication.
  • Forgetting to handle preflight requests: Browsers send an OPTIONS request before the actual request. If your API doesn't respond to OPTIONS with the right headers, the real request fails—or worse, if it does respond but with *, it's insecure.
  • Hardcoding localhost in production: AI might add http://localhost:3000 to the allowed origins to help you test, but you forget to remove it. That's a minor issue, but it's a sign of sloppy configuration.
  • Copy-pasting CORS middleware from a tutorial: Many tutorials show a simple cors() call with origin: '*' for convenience. If your AI assistant pulls from those, you get the same problem.
  • Not testing with a scanner: Many developers assume CORS is working because their frontend loads data. But a CORS misconfiguration can be silent if the request doesn't cross origins. Always run a CORS security scanner before launch.
  • Why CORS matters for vibe-coded apps

    Vibe-coded apps are built fast, and security often takes a backseat. But CORS is one of the most common vulnerabilities in AI-generated code. A single misconfigured header can expose your user's data to any malicious site. The good news is that with a free CORS security scanner, you can catch and fix these issues in minutes.

    At OverMCP, we built a free AI app security scanner that includes CORS checks, along with other common vulnerabilities like exposed secrets and missing security headers. It's designed specifically for apps built with AI tools, so you can ship fast and stay secure.

    FAQ

    What is a CORS security scanner?

    A CORS security scanner is a tool that analyzes your web application's CORS headers to detect misconfigurations that could allow unauthorized websites to make cross-origin requests to your API, potentially leading to data breaches or CSRF attacks.

    Can I use a free CORS security scanner for my Next.js app?

    Yes, there are several free options. OverMCP's security headers checker scans your live site and flags CORS issues. You can also use browser extensions or curl commands to inspect headers manually.

    How do I fix CORS errors in a vibe-coded app?

    First, identify the issue with a scanner. Then, replace wildcard origins with a whitelist of your trusted domains, ensure Access-Control-Allow-Credentials is set correctly, and handle preflight requests. Use middleware to apply these headers globally, as shown above.

    ---

    This article is part of a series on securing AI-built apps. Check out our [Vercel security scanner](https://www.overmcp.com/connect/vercel) for deployment-specific checks.

    Is your app secure?

    Free scan in 30 seconds. No signup needed.

    Scan My App Free