Hardening Your Vercel Production Deployment
Vercel makes deploying effortless, which also means a leaked preview URL, mis-scoped production environment variable, or unthrottled serverless route can expose staging data or trigger unexpected usage spikes.
Founders often toggle 'All Environments' when pasting production Stripe/Supabase keys into Vercel, exposing live production data on unauthenticated PR preview deployments.
- Public PR preview URLs pointing at production databases or live Stripe accounts
- Missing Vercel Firewall / rate limiting rules on expensive AI routes
- Unconfigured security headers in vercel.json or next.config.ts
Vulnerable Pattern vs. Production Fix
{
"note": "Avoid sharing live STRIPE_SECRET_KEY & prod DATABASE_URL with Preview deployments",
"headers": []
}{
"headers": [
{
"source": "/(.*)",
"headers": [
{ "key": "Strict-Transport-Security", "value": "max-age=31536000; includeSubDomains" },
{ "key": "X-Frame-Options", "value": "DENY" },
{ "key": "X-Content-Type-Options", "value": "nosniff" },
{ "key": "Referrer-Policy", "value": "strict-origin-when-cross-origin" },
{ "key": "Permissions-Policy", "value": "camera=(), microphone=(), geolocation=()" }
]
}
]
}Copy-Paste AI Fix Prompt (Cursor · Lovable · Bolt · Claude Code)
Review this repository for Vercel production security readiness: 1. Add security headers in next.config.ts (or vercel.json) and disable poweredByHeader and productionBrowserSourceMaps. 2. Ensure all server-side API routes have input size limits, maxDuration bounds, and auth checks so serverless invocations cannot be abused. 3. Audit .env.example to clearly distinguish server-only secrets vs NEXT_PUBLIC_ browser variables and separate staging/production values.
How to Verify Your Fix Worked
- 1In Vercel Project Settings -> Environment Variables, ensure live production keys are checked ONLY for Production (not Preview).
- 2Enable Vercel Deployment Protection on Preview deployments so staging URLs require login.
- 3Scan your production domain with VibeSecCheck after every major deploy.
Frequently Asked Questions
Are Vercel preview URLs indexed by Google?
Vercel sends X-Robots-Tag: noindex on *.vercel.app preview URLs, but anyone with the link (or scraping certificate/git references) can still open them unless Deployment Protection is turned on.
Should I configure headers in next.config.ts or vercel.json?
For Next.js apps, next.config.ts is more portable across Vercel, Cloudflare, and self-hosted Node. For static Vite/SPA builds on Vercel, use vercel.json.
Does Vercel protect against DDoS automatically?
Vercel includes baseline L3/L4/L7 DDoS mitigation, but application-level abuse (like bots calling your OpenAI route) still requires per-user auth and rate limiting.