How to Prevent Serverless Function Timeout Exploits in Vibe-Coded Apps
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:
What to check first
Before you fix exploits, verify your current setup:
maxDuration in vercel.json; Netlify: functions.timeout in netlify.toml; AWS Lambda: Timeout in function configuration)..timeout() or equivalent.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 = 10For 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
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:
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 1kOr 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:
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.