FleetOS Security & Credentials Management

πŸ”΄ CRITICAL SECURITY ISSUES FOUND

Issue 1: Service Role Key Exposed to Frontend

Current (INSECURE):

VITE_SUPABASE_SERVICE_ROLE_KEY=eyJhbGciOiJIUzI1NiIs...

Problem:

  • The VITE_ prefix means this key is bundled into the frontend JavaScript

  • Anyone can open browser DevTools and see the service role key

  • Service role key bypasses ALL Row Level Security policies

  • Attackers can read/modify/delete ANY data in your database

Impact: πŸ”΄ CRITICAL - Complete database compromise possible

Fix:

  1. Remove VITE_ prefix (rename to SUPABASE_SERVICE_ROLE_KEY)

  2. Only use in server-side scripts (not in browser code)

  3. Rotate the key immediately via Supabase dashboard

  4. Use VITE_SUPABASE_ANON_KEY in frontend (this is safe - it respects RLS)


Issue 2: Production Credentials in .env File

Current (INSECURE):

Problem:

  • .env file is tracked in git (even if in .gitignore now)

  • Credentials may be in git history

  • Anyone with repo access sees production keys

Impact: 🟑 HIGH - Unauthorized access possible

Fix:

  1. Create .env.production with real credentials (gitignored)

  2. Use .env.production.example as template (no real credentials)

  3. Rotate all exposed keys

  4. Check git history for leaked credentials


βœ… Secure Environment Variable Setup

Frontend vs Backend Variables

Frontend (Safe to expose):

  • βœ… VITE_SUPABASE_URL - Public URL, safe to expose

  • βœ… VITE_SUPABASE_ANON_KEY - Public key, respects RLS, safe to expose

  • βœ… VITE_APP_URL - Your domain, safe to expose

  • βœ… VITE_SENTRY_DSN - Sentry project ID, safe to expose

Backend ONLY (NEVER expose to frontend):

  • ❌ SUPABASE_SERVICE_ROLE_KEY - Bypasses RLS, server-side only

  • ❌ SUPABASE_DB_PASSWORD - Direct database access, server-side only

  • ❌ TWILIO_AUTH_TOKEN - Can send SMS/WhatsApp, server-side only

  • ❌ SENDGRID_API_KEY - Can send emails, server-side only

  • ❌ JWT_SECRET - Can forge tokens, server-side only

Rule: If it starts with VITE_, it's bundled into frontend JavaScript and visible to users.


πŸ” How to Rotate Supabase Service Role Key

Step 1: Generate New Key

  1. Go to https://supabase.com/dashboard

  2. Select your project

  3. Go to Settings β†’ API

  4. Under "Project API keys" section

  5. Click "Reset service_role secret"

  6. WARNING: This will immediately invalidate the old key

  7. Copy the new service_role key

Step 2: Update Environment Variables

Step 3: Update Server-Side Scripts

Update all scripts that use the service role key:

  • scripts/* - Test and setup scripts

  • Backend API endpoints (if you have a backend)

  • CI/CD pipelines

Step 4: Verify


πŸ“‹ Environment Variable Checklist

Before deploying to production:


πŸ› οΈ Environment Variable Validation

Add to App.tsx


πŸ” Check for Leaked Credentials in Git History

If you find leaked credentials in git history:

  1. Rotate ALL exposed keys immediately

  2. Consider using BFG Repo-Cleaner to remove from history:

  3. Force push to GitHub (if using private repo)

  4. Notify team members to re-clone repo


πŸš€ Deployment Environment Variables

Vercel

  1. Go to Project Settings β†’ Environment Variables

  2. Add each variable from .env.production

  3. Set scope: Production, Preview, Development

  4. DO NOT add service role key (not needed in frontend deploy)

Netlify

  1. Go to Site Settings β†’ Build & Deploy β†’ Environment

  2. Add variables from .env.production

  3. Keep sensitive keys out of frontend deploy

Custom Server (VPS, AWS, etc.)


⚑ Quick Fix Script


πŸ“ž Support

If you've accidentally exposed credentials:

  1. Immediately rotate all keys (Supabase, Twilio, SendGrid)

  2. Check database audit logs for unauthorized access

  3. Review recent service requests for suspicious activity

  4. Consider reaching out to Supabase support if breach suspected


Security Status: πŸ”΄ CRITICAL β†’ βœ… SECURE (after fixes applied)

Time to Fix: ~30 minutes

Priority: IMMEDIATE - Do not deploy to production until fixed

Last updated

Was this helpful?