severity: errorpack: supabase-authv1.0 core
supabase-auth/service-role-in-client
Service-role key referenced in a client module
npx @pitcheye/check . --pack supabase-authwhyItBreaks
A client module is bundled and shipped to the browser. Next only inlines `NEXT_PUBLIC_*`, so this reference either compiles to `undefined` (every RLS policy silently bypassed at runtime) or — if someone "fixes" it by renaming — publishes a full-privilege key. Both outcomes are account-wide compromise.
✖ Bad — triggers errorfixtures/supabase-auth-service-role-in-client/bad
'use client'; const admin = createClient(url, process.env.SUPABASE_SERVICE_ROLE_KEY!);
✓ Good — passes checkfixtures/supabase-auth-service-role-in-client/good
import 'server-only'; const admin = createClient(url, process.env.SUPABASE_SERVICE_ROLE_KEY!);
suggestedFix
Move the admin client into a server-only module (`import "server-only"`), expose a route handler or server action, and keep the service-role key out of every client bundle.
explain_rule({"supabase-auth/service-role-in-client"})Agent & MCP JSON output contract
{
"ruleId": "supabase-auth/service-role-in-client",
"pack": "supabase-auth",
"severity": "error",
"file": "apps/web/src/app/dashboard/page.tsx",
"line": 6,
"message": "a `'use client'` module referencing SUPABASE_SERVICE_ROLE_KEY (or a bare non-NEXT_PUBLIC Supabase secret)",
"whyItBreaks": "A client module is bundled and shipped to the browser. Next only inlines `NEXT_PUBLIC_*`, so this reference either compiles to `undefined` (every RLS policy silently bypassed at runtime) or — if someone \"fixes\" it by renaming — publishes a full-privilege key. Both outcomes are account-wide compromise.",
"suggestedFix": "Move the admin client into a server-only module (`import \"server-only\"`), expose a route handler or server action, and keep the service-role key out of every client bundle.",
"docsUrl": "https://pitcheye.dev/rules/supabase-auth-service-role-in-client"
}Markdown: curl -H "Accept: text/markdown" https://pitcheye.dev/rules/supabase-auth-service-role-in-client
raw markdown
# supabase-auth/service-role-in-client
- **severity:** error
- **pack:** supabase-auth
- **docs:** https://pitcheye.dev/rules/supabase-auth-service-role-in-client
## whyItBreaks
A client module is bundled and shipped to the browser. Next only inlines `NEXT_PUBLIC_*`, so this reference either compiles to `undefined` (every RLS policy silently bypassed at runtime) or — if someone "fixes" it by renaming — publishes a full-privilege key. Both outcomes are account-wide compromise.
## bad
```ts
'use client';
const admin = createClient(url, process.env.SUPABASE_SERVICE_ROLE_KEY!);
```
## good
```ts
import 'server-only';
const admin = createClient(url, process.env.SUPABASE_SERVICE_ROLE_KEY!);
```
## suggestedFix
Move the admin client into a server-only module (`import "server-only"`), expose a route handler or server action, and keep the service-role key out of every client bundle.
## commands
```bash
npx @pitcheye/check . --pack supabase-auth
```
```json
{"tool":"explain_rule","arguments":{"ruleId":"supabase-auth/service-role-in-client"}}
```