fixes / launch-ready

How I Would Fix exposed API keys and missing auth in a Vercel AI SDK and OpenAI waitlist funnel Using Launch Ready.

The symptom is usually blunt: someone finds your OpenAI key in the browser bundle, your waitlist form can be hit without limits, and your funnel starts...

How I Would Fix exposed API keys and missing auth in a Vercel AI SDK and OpenAI waitlist funnel Using Launch Ready

The symptom is usually blunt: someone finds your OpenAI key in the browser bundle, your waitlist form can be hit without limits, and your funnel starts burning credits or collecting junk signups. In most cases, the root cause is the same pattern: the app was built fast, but API calls, auth checks, and secrets handling were treated like frontend details instead of production risks.

The first thing I would inspect is the deployed build, not just the source code. I want to see where the OpenAI call is happening, whether any secret is being exposed in client-side code or environment variables with the wrong prefix, and whether the waitlist endpoint has any real server-side protection at all.

Triage in the First Hour

1. Check the live site in an incognito browser.

  • Open DevTools and inspect network requests.
  • Confirm whether any request from the browser contains an OpenAI key, internal token, or admin endpoint.

2. Inspect Vercel deployment logs.

  • Look for repeated form submissions, 401s that should be 403s, rate spikes, and errors from AI SDK routes.
  • Check if a recent deploy introduced a new public env var or route change.

3. Review Vercel environment variables.

  • Confirm secrets are stored only in server-side env vars.
  • Verify nothing sensitive uses `NEXT_PUBLIC_`, `VITE_`, or any other client-exposed prefix.

4. Check API routes and server actions.

  • Find every place where waitlist submission happens.
  • Verify there is a backend boundary before anything touches OpenAI.

5. Review authentication and access rules.

  • If there is no auth yet, confirm whether the product actually needs it.
  • For a waitlist funnel, at minimum I expect server-side anti-abuse controls, even if users do not log in.

6. Inspect Cloudflare and Vercel protections.

  • Look for bot protection, WAF rules, rate limiting, geo rules, and caching headers.
  • Confirm SSL is active on all domains and subdomains.

7. Check email delivery setup.

  • Validate SPF, DKIM, and DMARC if confirmation emails or lead routing are live.
  • Broken email auth can hide spam abuse until it becomes a support problem.

8. Audit recent commits and builds.

  • Find the exact commit where secrets or auth were broken.
  • If needed, roll back first and fix forward after containment.
## Quick local check for accidental secret exposure
grep -R "OPENAI\|sk-" . --exclude-dir=node_modules --exclude-dir=.next

Root Causes

| Likely cause | What it looks like | How I confirm it | |---|---|---| | OpenAI key used in client code | Key visible in browser source or network calls | Search bundle output and DevTools network tab | | Missing server-side auth check | Anyone can hit submit endpoints directly | Send a request without a session or token | | Env vars misconfigured in Vercel | Secret appears as public config | Review env var names and build settings | | No rate limiting or bot protection | Spam signups or credit drain | Check logs for repeated IPs and user agents | | Overly permissive CORS or exposed route handlers | Cross-origin calls succeed from anywhere | Inspect response headers and route config | | Weak validation on form input | Garbage payloads reach backend or email tools | Test malformed JSON and oversized payloads |

The most common failure here is not just "missing auth". It is missing trust boundaries everywhere. The funnel was probably built to look finished on top of an API route that was never hardened for real traffic.

The Fix Plan

1. Contain first.

  • Rotate every exposed OpenAI key immediately.
  • Revoke any leaked tokens tied to email tools, analytics, admin panels, or webhook services.
  • If abuse is active, temporarily disable the vulnerable endpoint while keeping the landing page live.

2. Move all AI calls behind a server-only boundary.

  • The browser should never talk directly to OpenAI with a secret key.
  • Use a Vercel Route Handler or Server Action to receive input from the form, validate it, then call OpenAI from server code only.

3. Lock down environment variables.

  • Store secrets only in Vercel project settings as server env vars.
  • Remove any secret from client-exposed prefixes.
  • Make sure preview environments do not inherit production secrets unless you explicitly want that behavior.

4. Add authentication or signed access where needed.

  • For a pure waitlist funnel, full user login may be unnecessary.
  • But admin pages, lead export routes, webhook receivers, and internal dashboards must require auth or signed verification.

5. Add validation on every input boundary.

  • Validate name, email, company size, message length, and referral fields on the server.
  • Reject oversized payloads early to reduce abuse and cost.

6. Add rate limiting and bot defense.

  • Rate limit by IP plus fingerprint where appropriate.
  • Add Cloudflare Turnstile or another friction step if spam is already happening.
  • Block obvious automated patterns at the edge before they hit your app logic.

7. Tighten CORS and headers.

  • Only allow known origins if you truly need cross-origin requests.
  • Set strict security headers where possible: CSP, frame-ancestors, X-Content-Type-Options.

8. Log safely without leaking secrets.

  • Remove any logging of request bodies that may contain tokens or sensitive data.
  • Log only what you need for incident review: timestamp, route name, status code, IP hash if allowed.

9. Test rollback before redeploying forward fixes.

  • If this started after a recent release, I would keep rollback ready until the patched build passes checks.

My preference here is simple: do not patch this in place with ad hoc frontend checks. Put the trust boundary on the server now. That reduces launch risk faster than trying to "hide" keys with UI changes that attackers ignore anyway.

Regression Tests Before Redeploy

Before shipping again, I would run these checks:

1. Secret exposure check

  • Acceptance criteria: no OpenAI key appears in browser source maps, JS bundles, network requests, logs, or rendered HTML.

2. Unauthorized request check

  • Acceptance criteria: direct POST requests to submit endpoints fail unless they meet your approved access rules.

3. Input validation check

  • Acceptance criteria: invalid emails, empty fields, long payloads over your limit such as 2 KB for free-text fields are rejected cleanly.

4. Rate limit check

  • Acceptance criteria: repeated submissions from one IP trigger throttling after a defined threshold such as 5 to 10 requests per minute.

5. Bot defense check

  • Acceptance criteria: automated submissions are blocked or challenged without breaking legitimate users on mobile Safari and Chrome.

6. Email delivery check

  • Acceptance criteria: confirmation emails pass SPF/DKIM/DMARC alignment and land reliably in inboxes during test sends.

7. Error handling check

  • Acceptance criteria: failed AI calls return a safe message to users without exposing stack traces or upstream provider details.

8. Performance check

  • Acceptance criteria: waitlist page still loads fast enough for paid traffic; target LCP under 2.5 seconds on mobile for primary landing page assets where feasible.

9. Monitoring check

  • Acceptance criteria: uptime alerts fire within 1 to 5 minutes of route failure or elevated error rates.

I would also run one manual exploratory pass:

  • Submit valid data twice quickly.
  • Submit malformed JSON once.
  • Disable an env var locally and confirm safe failure behavior.
  • Verify admin routes cannot be reached anonymously.

Prevention

The best prevention is boring discipline around boundaries.

  • Code review guardrails:
  • No direct third-party API calls from client components when secrets are involved.
  • Every new route gets an authorization review before merge.
  • Small changes only; avoid mixing security fixes with redesign work in one deploy.
  • Security guardrails:
  • Rotate keys on any suspected exposure event within 30 minutes of discovery when possible.
  • Keep least privilege across Vercel integrations and cloud services.
  • Review dependency risk monthly because SDK updates can change request behavior quietly.
  • Monitoring guardrails:
  • Alert on unusual token usage spikes from OpenAI billing dashboards.
  • Alert on repeated failed submissions per IP range or region if abuse appears geographic.

\- Track form conversion rate against error rate so you catch silent breakage early rather than after ad spend burns out.

  • UX guardrails:

\- Make it obvious what happens after signup so users do not resubmit multiple times out of uncertainty.\n \- Show clear loading states and success states; unclear feedback creates duplicate traffic that looks like abuse.\n

  • Performance guardrails:

\- Keep third-party scripts minimal on waitlist pages.\n \- Cache static assets aggressively at the edge.\n \- Remove unused SDK code so bundle size does not creep up with each feature addition.\n If there is one rule I would enforce permanently: secrets stay server-side by default unless there is a proven reason otherwise. Access to Vercel project settings.\n2. Access to Cloudflare DNS if it sits in front of the site.\n3. The current repo or deployment source.\n4. A list of all integrations:\nOpenAI,\nemail provider,\nautomation tools,\nand analytics.\n5. Any known bad deploy links,\nscreenshots,\nor error logs.\n\nIf I am brought in early enough,\nI can usually turn this into a clean handover instead of an emergency rebuild.\nIf you wait until keys are burned repeatedly,\nyou are paying for damage control instead of launch readiness.\n\n## References\n\n- https://roadmap.sh/cyber-security\n- https://roadmap.sh/api-security-best-practices\n- https://roadmap.sh/code-review-best-practices\n- https://platform.openai.com/docs/guides/production-best-practices\n- https://vercel.com/docs/environment-variables

Delivery Map

---

Take the next step

If this is a problem in your product right now, here is what to do next:

  • [Use the free Cyprian tools](/tools) - estimate cost, score app risk, check launch readiness, or pick the right service sprint.
  • [Book a discovery call](/contact) - I will tell you honestly whether you need a sprint or if you can DIY the next step.

*Written by Cyprian Tinashe Aarons - senior full-stack and AI engineer helping founders rescue, launch, automate, and scale AI-built products.*

Next steps
About the author

Cyprian Tinashe AaronsSenior Full Stack & AI Engineer

Cyprian helps founders rescue, secure, deploy, and automate AI-built apps with production-grade engineering, launch systems, and AI integration.