← All posts
OpenAPIsecurityvibe-codingAI-generated codeAPI security

How to Fix OpenAPI Spec Security Flaws in Vibe-Coded Apps

O

OverMCP Team

Quick answer

Vibe-coded apps often ship with OpenAPI specs that are missing security schemes, have overly permissive endpoints, or expose internal schemas. To fix this, run your generated spec through a linter, add proper securitySchemes objects, and scope each operation to the minimum required authentication. OverMCP's free AI app security scanner can detect these issues automatically before deployment.

What are OpenAPI security flaws in vibe-coded apps?

When you use Cursor, Bolt.new, v0, or Lovable to build a backend, the AI often generates an OpenAPI specification as part of the code. This spec documents your API endpoints, request/response schemas, and authentication methods. However, AI models are trained on public code—much of which contains security gaps. Common flaws include:

  • Missing securitySchemes: The spec defines endpoints but doesn't require any authentication.
  • Inconsistent security scopes: Some endpoints have auth, others don't.
  • Overly broad schemas: The spec exposes internal fields like passwordHash or apiKey.
  • Missing rate limiting or 429 responses: No indication of throttling, leaving you vulnerable to abuse.
  • Hardcoded example values: Example API keys or tokens that are real secrets.
  • These flaws are serious because your OpenAPI spec is often used to generate client SDKs, validate requests, and power API documentation. A weak spec means weak security everywhere.

    What to check first

    Before diving into fixes, use this checklist:

  • [ ] Does your spec have a components/securitySchemes section? If not, that's your top priority.
  • [ ] Are all paths operations annotated with a security block? Even public endpoints should explicitly declare "none".
  • [ ] Are example values in parameters or schemas real secrets? Search for sk-, AKIA, ghp_, etc.
  • [ ] Are write operations (POST, PUT, DELETE) protected differently from read operations?
  • [ ] Does the spec include a 429 Too Many Requests response for rate limiting?
  • [ ] Are internal-only fields (e.g., isAdmin, internalNotes) leaking in schemas?
  • You can use OverMCP's security headers checker as a supplementary tool, but OpenAPI linting requires a spec-specific approach.

    Step-by-step fix

    1. Add a security scheme

    Open your openapi.json or openapi.yaml and locate the components object. Add a securitySchemes block. For example:

    components:
      securitySchemes:
        bearerAuth:
          type: http
          scheme: bearer
          bearerFormat: JWT
        apiKey:
          type: apiKey
          in: header
          name: X-API-Key

    2. Apply security globally or per-operation

    Define a global security requirement:

    security:
      - bearerAuth: []

    Then override on public endpoints:

    paths:
      /health:
        get:
          security:
            - {}  # No auth required
          ...

    3. Scope scopes (if using OAuth2)

    If your AI-generated spec includes OAuth2, ensure each operation has the narrowest scope:

    paths:
      /users/{id}:
        get:
          security:
            - oauth2: [read:users]
        delete:
          security:
            - oauth2: [admin:users]

    4. Validate with a linter

    Use Spectral or Redocly CLI to lint:

    npx @redocly/cli lint openapi.yaml

    Look for rules like security-defined, oas3-valid-schema-example, and no-ambiguous-paths.

    5. Remove hardcoded secrets

    Replace example values with placeholders:

    headers:
      X-API-Key:
        schema:
          type: string
        example: "your-api-key-here"  # Not real key

    6. Add rate limiting to the spec

    Include a 429 response for all operations:

    responses:
      '429':
        description: Too Many Requests
        content:
          application/json:
            schema:
              type: object
              properties:
                retryAfter:
                  type: integer

    After fixing, run OverMCP's secret leak scanner to ensure no secrets remain in your spec or code.

    Common mistakes

  • Assuming AI specs are secure: AI models copy patterns from public repos—many of which are insecure. Never trust the generated spec blindly.
  • Using global security when not needed: Some endpoints (health, docs) should be public. Over-applying auth can break client integrations.
  • Forgetting to update examples: AI often leaves real-looking tokens in examples. These could be legitimate if the model memorized them.
  • Not linting the spec: Linters catch inconsistencies and missing security definitions. Skipping this step is like not running npm audit.
  • Ignoring 429 responses: Without rate limiting in the spec, API consumers won't know how to handle throttling, leading to client errors.
  • Why this matters for vibe-coded apps

    Vibe-coded apps are built fast and shipped faster. Security often takes a back seat. But your OpenAPI spec is the contract between your backend and every client—web, mobile, or third-party. A flawed spec leads to insecure client code, leaked endpoints, and potential abuse. By securing your OpenAPI spec early, you protect your entire API ecosystem.

    OverMCP's continuous security monitoring can watch your spec and codebase for regressions after each AI-assisted update.

    FAQ

    Why do AI coding tools generate insecure OpenAPI specs?

    AI models are trained on a mix of secure and insecure code from public repositories. They often replicate common patterns without understanding context, like missing authentication or exposing internal fields. The speed of generation means security checks are skipped.

    Can I use OverMCP to scan my OpenAPI spec?

    Yes. OverMCP's scanner automatically detects missing security schemes, hardcoded secrets, and overly permissive endpoints in your OpenAPI spec. It integrates with your CI/CD pipeline to catch issues before merge.

    Do I need to manually review every AI-generated spec?

    Yes, at least until automated scanning is in place. Human review catches logical flaws that linters miss, like whether the right scopes are applied. Pair manual review with automated tools for best results.

    Is your app secure?

    Free scan in 30 seconds. No signup needed.

    Scan My App Free