← All posts
serverlesstimeout exploitvibe codingsecurityAI apps

How to Prevent Serverless Function Timeout Exploits in Vibe-Coded Apps

O

OverMCP Team

Quick answer

Serverless function timeout exploits occur when attackers send slow or incomplete requests to keep your serverless functions running, causing unexpected costs or denial of service. To prevent this, set appropriate timeout limits in your serverless configuration, implement request validation, and use connection pooling with database clients. For vibe-coded apps built with Cursor, Bolt.new, or v0, this is a common blind spot because AI tools often generate default configurations without timeout safeguards.

What is a serverless function timeout exploit?

When you deploy a serverless function (e.g., on Vercel, Netlify, AWS Lambda), it typically has a maximum execution time—often 10 seconds on free plans, up to 15 minutes on paid tiers. An attacker can exploit this by sending a request that never completes, causing your function to run until it times out. If you pay per invocation or per execution time, this can lead to unexpected bills. In vibe-coded apps, where AI tools generate backend logic quickly, developers often forget to set explicit timeouts or handle slow external calls properly.

How vibe-coded apps get this wrong

AI coding tools like Cursor and v0 generate code that works for demos but often lacks production hardening. Here are common mistakes:

  • No explicit timeout on HTTP calls: AI-generated fetch or axios calls don't include a timeout option.
  • Long-running database queries without limits: The AI assumes queries always return quickly.
  • Missing request validation: Without checking request parameters early, the function may wait for large payloads.
  • Default serverless configuration: Many platforms have generous timeout defaults; AI-generated deploy configs rarely override them.
  • What to check first

    Before you fix exploits, verify your current setup:

  • [ ] Check your serverless platform's timeout setting (Vercel: maxDuration in vercel.json; Netlify: functions.timeout in netlify.toml; AWS Lambda: Timeout in function configuration).
  • [ ] Review all HTTP client calls in your code for .timeout() or equivalent.
  • [ ] Look for database queries that could be slow—especially those without indexes or with large result sets.
  • [ ] Ensure request body size limits are enforced.
  • [ ] Test with a slow endpoint using curl --no-buffer or a tool like slowserver.
  • Step-by-step fix

    Here's how to secure your vibe-coded serverless functions:

    1. Set serverless function timeout

    If you're on Vercel, add maxDuration to your vercel.json:

    {
      "functions": {
        "api/*.ts": {
          "maxDuration": 10
        }
      }
    }

    For Netlify, in netlify.toml:

    [functions]
    timeout = 10

    For AWS Lambda, set Timeout: 10 in your SAM template or via console.

    2. Add timeouts to HTTP clients

    If your function calls external APIs, add a timeout. Here's an example using fetch:

    const controller = new AbortController();
    const timeoutId = setTimeout(() => controller.abort(), 5000); // 5 seconds
    
    try {
      const response = await fetch('https://api.example.com/data', {
        signal: controller.signal
      });
      clearTimeout(timeoutId);
      // process response
    } catch (error) {
      if (error.name === 'AbortError') {
        console.error('Request timed out');
        return new Response('Request timed out', { status: 504 });
      }
      throw error;
    }

    Using axios:

    const response = await axios.get('https://api.example.com/data', {
      timeout: 5000
    });

    3. Implement request validation early

    Validate inputs at the start of your function to reject invalid requests quickly:

    export default async (req) => {
      if (!req.body || req.body.length > 10000) {
        return new Response('Invalid request', { status: 400 });
      }
      // ... rest of logic
    };

    4. Use connection pooling for databases

    For vibe-coded apps using MongoDB or PostgreSQL, ensure your database client pools connections and doesn't open new connections per request. Example with Prisma:

    import { PrismaClient } from '@prisma/client';
    
    const globalForPrisma = globalThis as unknown as { prisma: PrismaClient };
    
    export const prisma = globalForPrisma.prisma || new PrismaClient({
      log: ['query'],
    });
    
    if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma;

    5. Monitor and alert

    Set up monitoring to detect abnormal execution times. Use OverMCP's continuous security monitoring to get alerts when your functions behave unexpectedly.

    Common mistakes

  • Not setting a timeout at all: Many vibe-coded apps use default platform timeouts (e.g., Vercel's 10 seconds on Hobby plan), but attackers can still cause repeated invocations.
  • Using synchronous database drivers: In serverless environments, synchronous calls block the event loop and can cause timeouts.
  • Ignoring external API failures: If your function calls an external service that hangs, your function hangs too. Always wrap external calls with timeouts.
  • Assuming AI-generated code is safe: AI tools often omit error handling for timeouts because they're trained on toy examples. Always review and add timeouts manually.
  • Why vibe-coded apps are particularly vulnerable

    When you build an app quickly with AI, you focus on features, not edge cases. The AI models generate code that works under ideal conditions. They rarely include:

  • Timeout configurations for serverless functions
  • Abort controllers for fetch requests
  • Request size limits
  • Database query timeouts
  • This makes your app an easy target for attackers who can exploit these gaps to run up your bill or cause slowdowns. Using a free AI app security scanner can help you catch these issues before they're exploited.

    How to test for timeout exploits

    You can simulate a slow request using curl:

    curl -X POST https://your-app.vercel.app/api/slow \
      -H "Content-Type: application/json" \
      -d '{"data":"test"}' \
      --limit-rate 1k

    Or use a slow client tool:

    import requests
    
    def slow_request():
        # Send data byte by byte
        for _ in range(1000):
            requests.post('https://your-app.vercel.app/api/slow', data=b'a', timeout=30)

    Check your platform's logs to see if the function times out and how long it runs.

    Preventing cost explosions

    Serverless billing is based on execution time and memory. A timeout exploit can run your function for the maximum allowed time repeatedly. If your function has a 10-second timeout and the attacker sends 100 requests per minute, that's over 16 minutes of execution per hour. On AWS Lambda, that could cost you tens of dollars per day depending on memory allocation.

    To prevent this:

  • Set your timeout as low as your application can tolerate (e.g., 5 seconds for most APIs).
  • Use security headers checker to ensure your app has proper security headers that can help mitigate certain attacks.
  • Implement rate limiting using a service like Upstash or a simple in-memory counter for low-traffic apps.
  • FAQ

    What is a serverless function timeout exploit?

    An attacker sends slow or incomplete requests that keep your serverless function running until it hits its timeout limit, causing increased costs and potential denial of service.

    How do I set a timeout in Vercel serverless functions?

    Add maxDuration in your vercel.json under the functions key. For example: "maxDuration": 10 sets a 10-second timeout.

    Can vibe-coded apps be automatically scanned for this?

    Yes, tools like OverMCP's free AI app security scanner can detect missing timeouts and other common vulnerabilities in apps built with Cursor, Bolt.new, and v0.

    Is your app secure?

    Free scan in 30 seconds. No signup needed.

    Scan My App Free