Urgent.News

What's breaking now, across thousands of outlets.

Tech

Your NEXT_PUBLIC secret is already in the browser bundle

Problem In a Next.js app it’s easy to slip a secret (e.g., STRIPE_SECRET_KEY , OpenAI API key, Supabase JWT) into a client‑side bundle. When a server component reads process.env.STRIPE_SECRET_KEY it stays on the server, but copying that line into a client component causes the build to fail to resolve the variable. The common “quick fix”—renaming the variable with the NEXT_PUBLIC_ prefix—makes the…

Secrets like Stripe API keys and OpenAI tokens can unintentionally end up in the client-side bundle of a Next.js application. When developers try to access these secrets in server components, the build process automatically strips them from the client bundle. However, a developer might mistakenly copy the secret from a server component to a client component, or import a shared utility that includes the secret.

This results in the secret being included in the JavaScript that every visitor downloads, turning a server-only secret into a publicly exposed piece of information. Tools like KeyDrift can detect these unintentional leaks by scanning the client bundle for hard-coded secrets and environment variables. The scan cross-references each detected credential with the tool that introduced it, providing a clear report of the issue.

To fix the problem, developers have several options: they can keep the secret on the server, call a server-side function from the client, or remove the NEXT_PUBLIC_ prefix for real secrets. After making these changes, it's crucial to run a KeyDrift scan to ensure the secret is no longer present in the client bundle. Preventing these leaks involves storing public keys and tokens separately from the server-side secrets, avoiding dynamic imports of server-side modules, and properly configuring build settings to avoid stale bundles that contain the leaked values.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Your Supabase Storage bucket is public - signed URLs will not save you

Problem You are generating private B2B images with Sharp in a Next.js API route and storing the derivatives in Supabase Storage.

  • Supabase Storage buckets can be public, exposing sensitive images.
  • Turn off public flag to require authentication for access.
  • Use signed URLs with expiration to safeguard against unauthorized access.

Stripe Connect refunds: the two flags that silently cost platforms

Problem When a Stripe Connect platform refunds a charge, the platform often assumes that the original transfer and the application fee are automatically undone.

  • Refunds don't automatically reverse original transfer and application fee
  • Flags determine whether application fee and transfer are undone
  • Default flags false can cause silent financial losses for platforms

Hello World!

Hello everyone! 👋 Happy to be joining the DEV community. I’m a Computer Engineering student based in Italy. My main focus is Cybersecurity, but I strongly believe you have to know how to build a…

More from Friday 28 August →