Next.js Production Security Scanner
Catch Next.js production misconfigurations before attackers do—from sensitive server props serialized into __NEXT_DATA__ to exposed browser source maps and missing CSP/HSTS headers.
01 · Exact Passive Checks
What LeakRay inspects on your live URL
| Rule ID & Check | What It Inspects | Why It's Passive & Safe |
|---|---|---|
nextjs-data-leak__NEXT_DATA__ Sensitive Prop Serialization | Parses the embedded `__NEXT_DATA__` JSON payload to detect accidentally serialized private fields such as `passwordHash`, `serviceRoleKey`, `apiSecret`, `refreshToken`, or `privateKey`. | Analyzes only the public HTML document already sent to every browser visitor. |
nextjs-debug-exposureDebug Stack Traces & Verbose Health Leaks | Checks rendered HTML and `__NEXT_DATA__.err` for webpack-internal paths, server file paths, development `buildId` signals, and verbose error stack frames. | Passive GET inspection only—never fuzzes routes or triggers deliberate server crashes. |
exposed-sourcemapsPublic Production Source Maps | Follows `sourceMappingURL` directives on `/_next/static/` chunks to verify that `.js.map` files containing original TypeScript source are not publicly downloadable. | Checks only declared map URLs within the 2 MB response limit and never crawls unlisted paths. |
security-headers-coreNext.js Security Headers & HSTS | Audits `Content-Security-Policy`, `Strict-Transport-Security`, `X-Content-Type-Options`, `X-Frame-Options`, `Referrer-Policy`, and `Permissions-Policy` on live responses. | Reads standard HTTP response headers from a single authorized GET/HEAD request. |
secret-private-keysNEXT_PUBLIC_ Leaked Private Keys | Scans `/_next/static/chunks/*.js` for server-only API keys accidentally prefixed with `NEXT_PUBLIC_` and inlined into the browser bundle. | Filters out placeholders and public publishable keys, and automatically redacts matched secrets. |
02 · Vulnerable vs. Fixed
Common production leak pattern and the exact fix
// Vulnerable next.config.ts & Pages Router prop serialization
const nextConfig = {
productionBrowserSourceMaps: true, // Exposes original TS source
// Missing security headers (CSP, HSTS, X-Frame-Options, nosniff)
};
export async function getServerSideProps() {
const user = await db.users.findFirst();
// Leaks passwordHash & refreshToken into __NEXT_DATA__ HTML
return { props: { user } };
}// Fixed next.config.ts & explicit DTO projection
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
poweredByHeader: false,
productionBrowserSourceMaps: false,
async headers() {
return [
{
source: "/(.*)",
headers: [
{ key: "Strict-Transport-Security", value: "max-age=31536000; includeSubDomains" },
{ key: "X-Content-Type-Options", value: "nosniff" },
{ key: "X-Frame-Options", value: "DENY" },
{ key: "Referrer-Policy", value: "strict-origin-when-cross-origin" },
],
},
];
},
};
export async function getServerSideProps() {
const user = await db.users.findFirst({
select: { id: true, displayName: true, avatarUrl: true },
});
return { props: { user } };
}03 · AI Fix Prompt
Paste into Cursor, Claude Code, Lovable, or Bolt
Harden my Next.js production configuration and data serialization:
1. Inspect `next.config.ts` (or `next.config.mjs`): set `poweredByHeader: false`, `productionBrowserSourceMaps: false`, and add a `headers()` rule setting `Strict-Transport-Security`, `X-Content-Type-Options: nosniff`, `X-Frame-Options: DENY`, `Referrer-Policy`, `Permissions-Policy`, and a tailored `Content-Security-Policy`.
2. Audit all `NEXT_PUBLIC_*` environment variables to confirm no private API keys, database URLs, or signing secrets are exposed to client bundles.
3. Audit `getServerSideProps`, Server Components passing props to Client Components, and API routes to ensure sensitive fields (`passwordHash`, `refreshToken`, `apiSecret`, `serviceRoleKey`) are stripped before serialization.
4. Confirm production error boundaries never leak raw stack traces or internal file paths.04 · Developer FAQ
Frequently asked questions
- Why do secrets end up inside __NEXT_DATA__ or Next.js client chunks?
- Two common causes: passing an entire database row (including password hashes or tokens) from getServerSideProps or a Server Component into a Client Component, or prefixing a server-only credential with NEXT_PUBLIC_ so Next.js inlines it into every browser bundle.
- Does LeakRay work on both Next.js App Router and Pages Router?
- Yes. LeakRay inspects live HTML, RSC/client JavaScript chunks under /_next/static/, __NEXT_DATA__ payloads when present, source map headers, cookies, and HTTP security headers across both App Router and Pages Router deployments.
- Should productionBrowserSourceMaps be disabled in Next.js?
- For most public web apps, yes. If you need stack trace symbolication in Sentry or Datadog, upload private source maps during CI/CD and delete or block public .map files so visitors cannot download your original TypeScript source.
- Will scanning my Vercel or Cloudflare Next.js app trigger rate limits or WAF blocks?
- LeakRay identifies itself transparently with LeakRayBot/1.0, caps each scan to a small set of passive GET/HEAD requests, respects a 15-second total budget, and never runs aggressive directory brute-forcing.
More Passive Scanners
Explore related LeakRay checks
Supabase RLS & Key Exposure Checker
Passively scan your live app for leaked Supabase service_role keys, exposed PostgREST schemas, and missing RLS signals. Zero signup, <15s.
Open scanner JS Bundles · Entropy + Context Validation · Passive AuditLeaked API Key & Frontend Secret Scanner
Scan your live HTML and JavaScript bundles for leaked Stripe, OpenAI, Anthropic, Gemini, AWS, and GitHub keys—without false-positive noise.
Open scanner Server Config · Dotfiles · Passive AuditExposed .env & .git File Checker
Check if your live website publicly exposes /.env, /.git/HEAD, or backup config files. Passive read-only URL scan with instant fixes. Zero signup.
Open scanner Firebase · Firestore · Passive AuditFirebase & Firestore Security Scanner
Passively audit live Firebase apps for leaked Admin SDK keys, exposed .env files, public source maps, and weak security headers without public apiKey noise.
Open scanner Cursor · Lovable · Bolt · v0 · Passive AuditSecurity Scanner for Vibe-Coded Apps
Free pre-launch security check for AI-built apps from Cursor, Claude Code, Lovable, Bolt, and v0. Catch leaked keys, open files, and missing headers.
Open scanner JavaScript Bundles · .js.map · Passive AuditProduction Source Map Exposure Checker
Check if your live Next.js, Vite, or React app publicly exposes .js.map source maps. Passive URL scan with framework-specific fixes and AI prompts.
Open scanner Headers · CORS · Cookies · Passive AuditHTTP Security Headers & CORS Checker
Check HSTS, CSP, SRI, COOP, CORS credential reflection, and cookie flags — plus JS secret & file checks that header-only scanners miss. Zero signup.
Open scanner