severity: errorpack: vercelv1.0 core
nextjs/client-secret-leak
Secret exposed through a `NEXT_PUBLIC_` variable
npx @pitcheye/check . --pack vercelwhyItBreaks
Next inlines every `NEXT_PUBLIC_*` value into the client bundle at build time. A prefix mistake publishes a full-privilege key to anyone who opens devtools, and because it "works", it survives review.
✖ Bad — triggers errorfixtures/nextjs-client-secret-leak/bad
export const cfg = { secret: process.env.NEXT_PUBLIC_STRIPE_SECRET_KEY! };✓ Good — passes checkfixtures/nextjs-client-secret-leak/good
export const cfg = { publishableKey: process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY! };suggestedFix
Drop the `NEXT_PUBLIC_` prefix, keep the secret server-only, and expose the capability through a route handler or server action. Only publishable/anon keys belong in the client.
explain_rule({"nextjs/client-secret-leak"})Agent & MCP JSON output contract
{
"ruleId": "nextjs/client-secret-leak",
"pack": "vercel",
"severity": "error",
"file": "vercel.json",
"line": 6,
"message": "a `NEXT_PUBLIC_*` env var whose name marks it as a secret",
"whyItBreaks": "Next inlines every `NEXT_PUBLIC_*` value into the client bundle at build time. A prefix mistake publishes a full-privilege key to anyone who opens devtools, and because it \"works\", it survives review.",
"suggestedFix": "Drop the `NEXT_PUBLIC_` prefix, keep the secret server-only, and expose the capability through a route handler or server action. Only publishable/anon keys belong in the client.",
"docsUrl": "https://pitcheye.dev/rules/nextjs-client-secret-leak"
}Markdown: curl -H "Accept: text/markdown" https://pitcheye.dev/rules/nextjs-client-secret-leak
raw markdown
# nextjs/client-secret-leak
- **severity:** error
- **pack:** vercel
- **docs:** https://pitcheye.dev/rules/nextjs-client-secret-leak
## whyItBreaks
Next inlines every `NEXT_PUBLIC_*` value into the client bundle at build time. A prefix mistake publishes a full-privilege key to anyone who opens devtools, and because it "works", it survives review.
## bad
```ts
export const cfg = { secret: process.env.NEXT_PUBLIC_STRIPE_SECRET_KEY! };
```
## good
```ts
export const cfg = { publishableKey: process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY! };
```
## suggestedFix
Drop the `NEXT_PUBLIC_` prefix, keep the secret server-only, and expose the capability through a route handler or server action. Only publishable/anon keys belong in the client.
## commands
```bash
npx @pitcheye/check . --pack vercel
```
```json
{"tool":"explain_rule","arguments":{"ruleId":"nextjs/client-secret-leak"}}
```