NEXT_PUBLIC_ Sensitive

NEXT_PUBLIC_ prefix on secret env vars

criticalSecuritynext-public-sensitive

Why this matters

The NEXT_PUBLIC_ prefix tells Next.js to inline the value into client-side JavaScript. If you prefix a secret key this way, it ships to every browser that loads your app.

Example

Flagged.env
# .env
NEXT_PUBLIC_STRIPE_SECRET_KEY=sk_live_abc123
NEXT_PUBLIC_DATABASE_URL=postgres://admin:pass@host/db
Fixed.env
# .env
STRIPE_SECRET_KEY=sk_live_abc123
DATABASE_URL=postgres://admin:pass@host/db
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_live_xyz789

How to fix

Only use the NEXT_PUBLIC_ prefix for values that are safe to be public (publishable keys, API URLs). Keep secret keys, database URLs, and tokens without the prefix.

Reference

In the output
Findings carry "ruleId": "next-public-sensitive" in --json and the same id in SARIF and in the terminal.
Silence one line
// prodlint-disable-next-line next-public-sensitive
Silence a whole file
// prodlint-disable next-public-sensitive at the top of the file
How it works
Matches text patterns. Source on GitHub