Secret key in a NEXT_PUBLIC_ or VITE_ env var
Next.js copies every variable that starts with NEXT_PUBLIC_ into the JavaScript it sends to the browser at build time, and Vite does the same for VITE_. Anyone can open the bundle and read those values. A secret, a service role key, a private key, a password or a database URL with that prefix is public the moment you deploy. The fix is to rename the variable without the prefix, read it only in server code such as API routes, server actions or edge functions, and rotate the value, since earlier builds already shipped it.
The fix
NEXT_PUBLIC_SUPABASE_URL=https://abcd1234.supabase.co
NEXT_PUBLIC_STRIPE_SECRET_KEY=sk_live_...NEXT_PUBLIC_SUPABASE_URL=https://abcd1234.supabase.co
STRIPE_SECRET_KEY=sk_live_...How ShipReady finds it
ShipReady scans source and env files for variable names that start with NEXT_PUBLIC_, VITE_ or PUBLIC_ and contain SECRET, SERVICE_ROLE, PRIVATE_KEY, PASSWORD, DATABASE_URL or API_SECRET. Findings carry rule ID SR-SEC-001.
Run the check
npx @shipmate-agency/shipready check .# .github/workflows/shipready.yml
name: ShipReady
on: [push, pull_request]
permissions:
contents: read
security-events: write
jobs:
shipready:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: deeflect/shipready@v0.2.0Want a person to check every area and send the fixes as pull requests? Launch Lockdown, $950 once.