fixes / launch-ready

How I Would Fix database rules leaking customer data in a Bolt plus Vercel AI chatbot product Using Launch Ready.

If a Bolt-built AI chatbot is leaking customer data, I treat it as a production security incident first and a product bug second. The most likely root...

How I Would Fix database rules leaking customer data in a Bolt plus Vercel AI chatbot product Using Launch Ready

If a Bolt-built AI chatbot is leaking customer data, I treat it as a production security incident first and a product bug second. The most likely root cause is weak database authorization, usually rules that are too broad, missing row-level checks, or server-side code on Vercel reading data with a privileged secret and returning too much.

The first thing I would inspect is not the UI. I would inspect the data path: database rules, serverless functions, env vars, and any API route that fetches chat history, user profiles, or conversation context.

Triage in the First Hour

1. Check the live symptom with two test accounts.

  • Create one normal user and one separate user.
  • Confirm whether user A can see user B's chats, profile fields, uploaded files, or generated summaries.

2. Review recent deploys in Vercel.

  • Look at the last 3 deployments.
  • Note whether the leak started after a schema change, rule change, or chatbot prompt update.

3. Inspect database access rules first.

  • Check row-level security policies, Firestore rules, Supabase policies, or any custom ACL logic.
  • Look for `allow read: if true`, missing tenant filters, or owner checks that are not enforced everywhere.

4. Review serverless logs and function traces.

  • Search for endpoints returning full records instead of filtered fields.
  • Look for logs that accidentally print message bodies, tokens, emails, or metadata.

5. Audit environment variables in Vercel.

  • Confirm no public client variable contains admin credentials.
  • Confirm service-role keys are only used server-side and never shipped to the browser.

6. Check auth session handling.

  • Verify the app is using the correct authenticated user ID from the session.
  • Make sure requests are not trusting a user-provided `userId` from the frontend.

7. Inspect database queries used by the chatbot.

  • Review any query that loads memory, conversation history, tickets, or customer records into the model context.
  • Confirm those queries are scoped to one tenant and one user.

8. Freeze risky changes until containment is done.

  • Pause new deployments if possible.
  • Rotate exposed secrets if there is any chance they were logged or leaked.

A simple way I would map this during triage:

Root Causes

1. Over-permissive database rules

  • Symptom: any authenticated user can read rows belonging to other users or tenants.
  • How to confirm: test direct reads with two different accounts and review policy conditions for missing owner or tenant checks.

2. Server-side code bypassing intended rules

  • Symptom: the frontend looks safe, but a Vercel function uses an admin key and returns unfiltered results.
  • How to confirm: inspect API routes and server actions for service-role access or broad queries without `where` clauses.

3. Broken tenant scoping in chatbot memory retrieval

  • Symptom: one user's chat history appears in another user's assistant context or response suggestions.
  • How to confirm: trace how conversation IDs are loaded into prompts and verify they are tied to both `tenant_id` and `user_id`.

4. Client trust of user-supplied identifiers

  • Symptom: requests include `userId`, `orgId`, or `email`, and the backend trusts them without comparing them to the authenticated session.
  • How to confirm: search for request bodies or query params being used directly for authorization decisions.

5. Misconfigured preview or production environment separation

  • Symptom: preview app points at production database or shared storage buckets expose real customer data during testing.
  • How to confirm: compare Vercel env vars across Preview and Production and verify each environment uses isolated resources.

6. Logging or analytics leaking sensitive content

  • Symptom: customer messages appear in logs, error trackers, browser analytics, or AI tracing tools.
  • How to confirm: search log sinks and observability dashboards for email addresses, names, message text, tokens, or file contents.

The Fix Plan

I would fix this in layers so we stop the leak first and then remove the underlying weakness.

1. Contain exposure immediately.

  • Disable any endpoint that returns broad customer records if needed.
  • Rotate exposed secrets if there is even a small chance they were printed in logs or committed accidentally.
  • If you cannot verify access control quickly, temporarily restrict access by tenant until testing passes.

2. Enforce authorization at the data layer.

  • Add row-level security or equivalent ownership checks on every table containing customer data.
  • Require both authentication and tenant scope on reads, updates, deletes, and list queries.
  • Do not rely on frontend filtering as your main protection.

3. Remove admin-key reads from unsafe paths.

  • Keep privileged keys only inside server-only code paths that strictly filter by session identity.
  • Replace broad selects with explicit field selection and scoped filters.
  • Return only what the UI needs.

4. Fix chatbot retrieval logic.

  • Limit memory retrieval to records owned by the current authenticated user or org.
  • Separate system instructions from customer content so one user's data cannot bleed into another user's prompt context.
  • If you use vector search or embeddings, namespace by tenant before retrieval.

5. Clean up environment boundaries in Vercel.

  • Confirm Production and Preview use separate databases where appropriate.
  • Lock down sensitive env vars so they are never exposed to client bundles.
  • Review build settings so no secret gets injected into public runtime config.

6. Tighten error handling and logging.

  • Stop logging full request bodies and model prompts in production unless absolutely necessary.
  • Redact emails, tokens, phone numbers, file names, and message text where possible.
  • Keep debug logging behind an explicit non-production flag.

7. Add monitoring for unauthorized reads after the fix goes live.

  • Alert on unusual spikes in list queries across tenants.

Monitor 401s and 403s separately so you can tell broken auth from active abuse.

If I were implementing this as Launch Ready work on Bolt plus Vercel, I would keep it narrow:

  • Day 1 morning: audit rules, functions, env vars, logs
  • Day 1 afternoon: patch authorization paths
  • Day 2 morning: retest with isolated accounts
  • Day 2 afternoon: redeploy with monitoring and handover

That is how you avoid turning a security fix into a rewrite that delays launch another week.

Regression Tests Before Redeploy

I would not redeploy until these pass:

1. Cross-account read test

  • Acceptance criteria: User A cannot read User B's conversations, uploads, profile fields, or generated outputs through UI or direct API calls.

2. Tenant isolation test

  • Acceptance criteria: every query returns only rows matching the authenticated user's tenant ID or org ID.

3. Privileged path test ```bash grep -R "service_role\|admin\|SUPABASE_SERVICE\|DATABASE_URL" .

Acceptance criteria: all privileged credentials are server-only and never reachable from client code.

4. Prompt context test
Acceptance criteria: chatbot responses do not include another user's messages when given two separate sessions with different accounts.

5. Error leakage test
Acceptance criteria: 500 errors do not expose SQL queries, secrets, stack traces with tokens, or raw payloads.

6. Preview versus production test
Acceptance criteria: preview deploys cannot reach production customer tables unless explicitly intended and approved.

7. Security smoke test
Acceptance criteria: unauthenticated requests get blocked; authenticated requests still respect ownership; rate limits hold under repeated requests.

8. Basic QA coverage target
Acceptance criteria: at least 80 percent coverage on authorization-critical helpers or policy tests before release.

I also want one human check before shipping:
- Open two browsers side by side
- Sign in as two different users
- Confirm no shared chat history appears anywhere in dashboard state

## Prevention

I would put guardrails around this so it does not come back after launch.

- Code review gate:
Review every data-access change for authz first. If a PR touches tables containing customer data but does not mention ownership checks explicitly, I block it.

- Security baseline:
Use least privilege everywhere. Client code gets only public keys; server code gets only what it needs; admin access stays isolated and audited.

- Observability:
Track failed authorization attempts separately from normal traffic. A sudden spike in cross-tenant requests is often an early warning sign before support tickets arrive.

- UX guardrails:
Show clear account boundaries in multi-user products so people understand which workspace they are inside of before they upload sensitive data.

- Performance guardrails:
Scoped queries should stay fast enough to avoid developers "fixing" slowness by removing filters later. I aim for p95 API latency under 300 ms for normal chat-history loads after indexing is corrected.

- QA process:
Add regression tests for every incident class like cross-user reads, broken login state, empty states after logout refreshes, and direct API misuse through stale sessions.

- Secret management:
Rotate keys quarterly at minimum for active products handling customer content. If there was an exposure event once already then rotate immediately after remediation is complete.

## When to Use Launch Ready

Launch Ready fits when you need me to stop the leak fast without dragging your team through a long security project you do not have time for right now.

This sprint is right when:
- The app works but you do not trust it with real users yet
- You need secure deployment before ads spend starts burning cash
- You have a Bolt prototype that needs production-safe wiring in Vercel
- You suspect secrets exposure , broken auth , bad redirects , or unstable hosting

What I need from you before starting:
- Vercel access
- Database admin access plus read-only access if available
- A short description of who should be able to see what data
- Any existing incident notes , screenshots , error logs , or support complaints
- Confirmation of which environments are live , preview , staging , and production

My goal in this sprint is simple: get you from "this might be leaking" to "we have verified controls , clean deployment , monitoring , and a clear handover."

## References

- https://roadmap.sh/api-security-best-practices
- https://roadmap.sh/cyber-security
- https://roadmap.sh/qa
- https://vercel.com/docs/deployments/environment-variables
- https://supabase.com/docs/guides/database/postgres/row-level-security

---

## 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.