fixes / launch-ready

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

The symptom is usually blunt: someone opens the app, finds OpenAI keys in the client bundle, and realizes the internal admin screens are reachable without...

How I Would Fix exposed API keys and missing auth in a Vercel AI SDK and OpenAI internal admin app Using Launch Ready

The symptom is usually blunt: someone opens the app, finds OpenAI keys in the client bundle, and realizes the internal admin screens are reachable without login. In business terms, that means anyone with the URL can burn your API budget, read sensitive admin data, and possibly trigger actions they should never see.

The most likely root cause is a rushed prototype that moved too fast from demo to deployment. The first thing I would inspect is the rendered frontend and deployed environment setup: where the OpenAI client is instantiated, which variables are exposed to the browser, and whether any route protection exists at the edge or in the app itself.

Triage in the First Hour

1. Check the live site in an incognito window.

  • Confirm whether admin routes load without login.
  • Test direct navigation to protected pages, not just clicks through the UI.

2. Inspect the deployed bundle for leaked secrets.

  • Search the built JS for `OPENAI_API_KEY`, `sk-`, or any hardcoded endpoints.
  • Verify whether environment variables were prefixed for client use by mistake.

3. Review Vercel project settings.

  • Check Environment Variables for production, preview, and development.
  • Confirm that secrets are only stored server-side and not copied into public vars.

4. Review auth implementation.

  • Look for middleware, route guards, session checks, or missing server-side authorization.
  • Confirm whether auth is only cosmetic in the frontend.

5. Check logs and usage dashboards.

  • Look at OpenAI usage spikes, 401/403 rates, and unusual traffic patterns.
  • Review Vercel deployment logs for failed builds or accidental secret exposure.

6. Audit connected accounts.

  • Rotate any exposed API keys immediately.
  • Check who has access to Vercel, GitHub, Cloudflare, and OpenAI projects.

7. Inspect source files most likely to leak secrets.

  • `app/`, `pages/`, `components/`, `api/`, `lib/ai.ts`, `middleware.ts`.
  • Search for direct OpenAI calls from client components.

8. Freeze changes until containment is done.

  • Do not keep iterating on features while secrets are live in a public bundle.
## Quick local search for likely leaks
grep -R "OPENAI_API_KEY\|sk-" . --exclude-dir=node_modules --exclude-dir=.next

Root Causes

| Likely cause | How to confirm | Business risk | |---|---|---| | OpenAI key used in client code | Search React components or browser bundle for API calls or secret names | Key theft, spend abuse, data exposure | | Missing server-side auth | Protected pages render without session checks on direct URL access | Unauthorized access to internal tools | | Auth exists only in UI state | Login button hides features but routes still work if visited directly | False sense of security | | Environment variables misconfigured in Vercel | Secret appears under public env vars or gets bundled into frontend code | Public leak across previews and production | | API routes lack authorization checks | Requests succeed even when no session cookie is present | Anyone can call privileged endpoints | | No rate limiting or monitoring | OpenAI spend jumps with no alerts or throttle controls | Budget drain and noisy incident response |

To confirm these causes safely, I would use code review plus runtime checks. I am looking for behavior first: who can reach what, which requests are trusted too much, and where secrets cross from server to browser.

The Fix Plan

My recommendation is one path: move all OpenAI calls behind authenticated server routes, then lock every admin route behind real session validation before shipping anything else. Do not patch this with frontend-only hiding or temporary passwords in a component file.

1. Rotate exposed secrets immediately.

  • Revoke the current OpenAI key.
  • Create a new key with least privilege where possible.
  • Rotate any related tokens in Vercel, GitHub, Cloudflare, and email providers if they were exposed too.

2. Remove all secret usage from client code.

  • The browser should never hold an OpenAI secret key.
  • Keep model calls inside server actions, route handlers, or backend services only.

3. Add real authentication at the edge and on the server.

  • Use middleware for route gating if appropriate.
  • Enforce session checks again inside each sensitive server handler.
  • Do not trust hidden UI elements as protection.

4. Add authorization rules for admin functions.

  • Distinguish between logged-in users and actual admins.
  • Check role claims or allowlists on every sensitive action.

5. Centralize AI access through one backend layer.

  • Create a single internal API wrapper around Vercel AI SDK calls.
  • Validate inputs before sending prompts to OpenAI.
  • Log request IDs and user IDs without logging secrets or raw sensitive content unless necessary.

6. Add rate limits and abuse controls.

  • Limit requests per user and per IP on admin endpoints.
  • Add backoff on repeated failures and alerting on unusual volume.

7. Harden deployment settings in Vercel and Cloudflare.

  • Confirm HTTPS only, correct redirects, secure cookies, CSP where relevant, and no public debug endpoints.
  • If subdomains exist, verify auth boundaries between them.

8. Clean up configuration hygiene.

  • Move all production env vars into server-only scope.
  • Remove unused keys from preview deployments if they are not needed there.

9. Deploy as a controlled hotfix first.

  • Ship auth containment before any UI polish or feature work.
  • Keep the change set small so rollback stays simple if something breaks.

10. Document handover clearly.

  • Write down where secrets live now, how auth works, who owns rotation, and how incidents are detected.

That means domain setup if needed, SSL verification, DNS sanity checks, redirects for old paths if applicable, Cloudflare protection settings review, monitoring setup, secret cleanup, production deploy validation, and a handover checklist so you are not guessing later.

Regression Tests Before Redeploy

Before I redeploy anything touching auth or secrets, I want proof that the fix works under normal use and obvious abuse attempts.

  • Anonymous user cannot open any admin page directly.
  • Anonymous user cannot call protected API routes successfully.
  • Logged-in non-admin user cannot access admin-only actions.
  • Admin user can still complete all intended workflows end to end.
  • OpenAI requests succeed from server routes only; no secret appears in browser network traffic or page source.
  • Build output does not contain API keys or private env values.
  • Session cookies are marked secure and HttpOnly where applicable.
  • Failed auth attempts return clear but non-revealing errors like 401 or 403.
  • Rate limiting triggers after repeated rapid requests from one user or IP.

Acceptance criteria I would use:

  • 0 exposed secrets in client bundles after build inspection
  • 100 percent of protected routes require authenticated access
  • 100 percent of privileged actions require authorization checks
  • p95 response time stays under 500 ms for normal admin pages excluding model latency
  • No critical findings in a smoke test across desktop and mobile breakpoints
  • At least 1 successful rollback test plan documented before release

For QA coverage, I would run:

  • Direct URL tests
  • Logged-out session tests
  • Expired session tests
  • Role mismatch tests
  • Preview deployment checks
  • Build artifact inspection
  • Basic accessibility pass on login flow
  • Error-state checks for failed auth and failed model calls

Prevention

This issue should never be allowed back into production by accident. I would put guardrails at four levels: code review, deployment controls, monitoring, and product design.

Code review guardrails:

  • Block any diff that sends OpenAI keys to browser code.
  • Require explicit auth checks on every new route handler or server action touching admin data.
  • Review dependency changes that affect auth libraries or AI wrappers more carefully than UI-only changes.

Deployment guardrails:

  • Separate public env vars from private env vars in Vercel by policy.
  • Use preview deployments with dummy credentials whenever possible.
  • Keep Cloudflare protections active on admin subdomains if they exist.

Monitoring guardrails:

  • Alert on unusual OpenAI spend spikes within 15 minutes.
  • Alert on repeated 401s or 403s against admin endpoints after deploys.
  • Track login failures by IP range so brute force does not stay invisible.

Security guardrails:

  • Use least privilege everywhere possible now that secrets have already been exposed once before you trust them again fully after rotation because mistakes repeat when process is weak rather than because one developer made one bad commit alone
  • Add secret scanning to CI so keys fail builds before merge
  • Set a short review checklist for auth-sensitive changes

UX guardrails:

  • Make login state obvious with clear loading states instead of silent failure modes
  • Show permission denied messages when users hit restricted areas so they do not keep retrying broken paths
  • Keep internal admin routes separated from public marketing pages so there is less confusion during testing

Performance guardrails:

  • Cache static assets correctly so auth hardening does not slow everything down unnecessarily
  • Keep third-party scripts off protected pages unless truly needed
  • Watch bundle size after moving AI logic server-side because careless imports can still bloat the app

When to Use Launch Ready

Use Launch Ready when you need containment fast instead of a drawn-out rebuild. It fits best when you already have a working prototype but need it made safe enough to ship without leaking keys or exposing internal tools publicly.

I would recommend it if:

  • You found exposed secrets in production or preview builds
  • Admin pages have no real authentication yet
  • You need domain setup plus SSL plus monitoring cleaned up at the same time
  • Your team cannot spare several days to untangle deployment issues safely

What you should prepare before booking: 1. Access to Vercel project settings and deployments 2. Access to GitHub repo or source control provider 3. Access to Cloudflare DNS if your domain is managed there 4. Access to OpenAI account settings so keys can be rotated immediately 5. A list of all intended admin roles and who should have them 6. Any current login flow details if auth already exists partially

Delivery Map

References

1. Roadmap.sh API Security Best Practices: https://roadmap.sh/api-security-best-practices 2. Roadmap.sh Code Review Best Practices: https://roadmap.sh/code-review-best-practices 3. Roadmap.sh Cyber Security: https://roadmap.sh/cyber-security 4. Vercel Environment Variables: https://vercel.com/docs/projects/environment-variables 5. OpenAI API Security Best Practices: https://platform.openai.com/docs/guides/safety-best-practices

---

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.