- Home
- Skills
- Frontend & Web Apps
- Next Env Secret Boundary
Next Env Secret Boundary
Stop API keys and service-role tokens from leaking into the Next.js browser bundle — audit NEXT_PUBLIC_ misuse and harden server-only boundaries.
$9
Works with the AI Agents you already use
Next Env Secret Boundary
Example session with this skill installed
Audit the Supabase client setup in this Next.js project. I suspect the service role key is leaking into the browser bundle.
- Read your context and instructions
- Compiled the next env secret
I have audited your Supabase configuration and identified a major boundary violation where the service role key is exposed via a public prefix.
Secret inventory
| Name | Source | Type | Importers |
|---|---|---|---|
NEXT_PUBLIC_SUPABASE_URL | .env.local | Public | lib/supabase.ts |
NEXT_PUBLIC_SUPABASE_SERVICE_ROLE_KEY | .env.local | SECRET | lib/supabase.ts, components/AdminPanel.tsx |
Boundary findings
Blocker: NEXT_PUBLIC_SUPABASE_SERVICE_ROLE_KEY uses a public prefix. Next.js will inline this value into the browser bundle at build time.
- Major:
components/AdminPanel.tsxis a"use client"module importing the admin client directly. - Minor:
lib/supabase.tslacks aserver-onlyguard, allowing it to be imported by any client component.
Hardening patch
// 1. Rename variable in .env.local to remove public prefix:
// SUPABASE_SERVICE_ROLE_KEY=your_secret_here
// 2. Create a server-only admin client
// lib/supabase/admin.ts
import "server-only";
import { createClient } from "@supabase/supabase-js";
export function createAdminClient() {
const url = process.env.NEXT_PUBLIC_SUPABASE_URL;
const key = process.env.SUPABASE_SERVICE_ROLE_KEY;
if (!url || !key) throw new Error("missing_supabase_admin_env");
return createClient(url, key, {
auth: { persistSession: false, autoRefreshToken: false },
});
}
Residual risks
Rotation: The SERVICE_ROLE_KEY has been exposed to the client. You must rotate this key in the Supabase dashboard immediately.
- Git History: Check if
.env.localwas ever committed to version control. - CI: Ensure secret scanning is enabled to catch future
NEXT_PUBLIC_secret additions.
Next steps
- Rename the environment variable in your local and production environments.
- Replace direct admin client imports in client components with Server Actions.
- Run a fresh build to verify the secret is no longer in the JS chunks.
Connects securely to your tools. The creator never sees your data.
About this skill
Keep privileged secrets on the server. This Cursor skill audits Next.js / React apps for env boundary bugs: admin keys under NEXT_PUBLIC_*, service-role clients imported by "use client" modules, missing server-only guards, hardcoded tokens, and secrets echoed in client-visible errors. Output every run: Secret inventory → Boundary findings (blocker/major/minor) → Hardening patch → Residual risks (rotation + git history). Fits App Router + TypeScript. Complements Server Action AuthZ and Webhook HMAC Gate without duplicating them. Does not replace cloud key rotation or IAM.
Requires access to .env files and source code. Does not rotate keys in external vaults or manage Cloud IAM. Cannot guarantee detection if bundle analysis is not possible from source code.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before any payment.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 20 days ago