new: drive vas from your AI agent over MCP · Cursor, Claude Code, Windsurf
Security Analysis

Is Next.js Safe?

Last updated: April 20, 2026

An honest security analysis of Next.js for developers considering it for their projects.

Quick Answer

Safe - lowest critical rate in our data

Next.js is safe and had the lowest critical-finding rate of any stack we scan in volume, at 0.10 per app across 191 scans. The remaining risk is the server and client boundary: NEXT_PUBLIC_ variables end up in the browser bundle, and route handlers need their own auth checks.

What We Found Scanning Next.js Apps

Next.js apps had the lowest critical rate of any stack we scan in volume: 0.10 criticals per app across 191 scans, against 0.27 for Cloudflare-fronted apps and 0.39 for Supabase.

191 Next.js apps scanned, averaging 0.10 criticals and 0.50 highs each.

The framework defaults are doing real work here. Most of what remains is about the server and client boundary.

NEXT_PUBLIC_ prefixed values in the client bundle were the most common exposure, and usually one rename away from being safe.

Route handlers answering without a session check were the recurring high-severity finding.

Understanding Next.js Security

When evaluating whether Next.js is safe for your project, it's important to understand the distinction between platform security and application security. Next.js as a platform implements industry-standard security practices for its infrastructure, including encryption, access controls, and regular security audits.

However, the security of applications built with Next.js depends significantly on how developers use the platform. AI-generated code and rapid development workflows can introduce vulnerabilities that exist independently of the platform's underlying security. Research from Stanford University found that AI coding assistants produce vulnerable code approximately 40% of the time when working on security-sensitive tasks.

The most common security issues in Next.js applications stem from misconfigurations, exposed credentials, and missing security controls, problems that developers must address regardless of which platform they use. Understanding these patterns helps you make informed decisions about using Next.js for your specific use case.

Platform Security

Platform security refers to the security measures Next.js implements at the infrastructure level: how they protect their servers, encrypt data in transit and at rest, manage access to their systems, and respond to security incidents. These are controls the platform provider manages on your behalf.

Application Security

Application security is your responsibility as a developer. This includes properly configuring authentication, implementing authorization controls, protecting sensitive data, securing API endpoints, and avoiding common vulnerabilities like exposed credentials or SQL injection. These risks exist regardless of which platform you use.

Common Security Mistakes in Next.js Apps

Based on security scans of thousands of Next.js applications, these are the most frequently encountered vulnerabilities. Understanding these patterns helps you proactively secure your applications.

Exposed API Keys & Secrets

AI coding tools frequently embed API keys, database credentials, and other secrets directly in JavaScript bundles. These credentials become visible to anyone who inspects your application's source code in their browser.

Prevention: Use environment variables and server-side API routes to keep credentials secure.

Missing Database Security

Applications using Supabase or Firebase often launch without proper Row Level Security (RLS) policies or Security Rules. This allows unauthorized users to read, modify, or delete data they shouldn't have access to.

Prevention: Always enable and test RLS policies before deploying to production.

Insufficient Input Validation

AI-generated code often assumes valid input without implementing proper validation. This opens applications to injection attacks, XSS vulnerabilities, and data corruption.

Prevention: Validate all user input on both client and server side.

Missing Security Headers

HTTP security headers like Content-Security-Policy, X-Frame-Options, and Strict-Transport-Security are frequently missing from AI-generated applications, leaving them vulnerable to various attacks.

Prevention: Configure security headers in your hosting platform or application middleware.

Free first scan

Worried about your own Next.js app?

Run your first scan free and see where you stand: your overall security score, what you're already doing right, and every issue counted in about 2 minutes. Unlock every finding with a copy-paste fix on Go ($19/month).

Your score and issue counts in about 2 minutes. No card required.

Security Assessment

Security Strengths

  • Server components keep data fetching off the client by default
  • Environment variables are server-only unless explicitly prefixed NEXT_PUBLIC_
  • Built-in XSS protection through React's escaping in JSX
  • Security headers configurable centrally in next.config
  • Actively maintained with a fast security release cadence

Security Concerns

  • NEXT_PUBLIC_ variables are baked into the bundle and readable by anyone
  • Middleware runs before routes but is not a security perimeter - matchers are easy to bypass
  • Route handlers and server actions need their own auth checks, they inherit nothing
  • dangerouslySetInnerHTML bypasses React escaping and appears in AI-generated code
  • Cached responses can leak authenticated data if cache keys ignore the user

Security Checklist for Next.js

  • 1
    Search your client bundle for NEXT_PUBLIC_ values that should have stayed server-side
  • 2
    Add auth checks to every route handler and server action rather than relying on middleware
  • 3
    Confirm middleware matchers cover the paths you think they do
  • 4
    Look for dangerouslySetInnerHTML, which appears often in AI-generated components
  • 5
    Set security headers in next.config, they are not on by default

The Verdict

Next.js is safe, and it is the strongest result in our data: 0.10 criticals per app across 191 scans, well below anything else we measure at volume. The framework is not what puts apps at risk. What remains is the server and client boundary, and both common mistakes are cheap to find and cheap to fix.

Security Research & Industry Data

Understanding Next.js security in the context of broader industry trends and research.

10.3%

of Lovable applications (170 out of 1,645) had exposed user data in the CVE-2025-48757 incident

Source: CVE-2025-48757 security advisory

4.45 million USD

average cost of a data breach in 2023

Source: IBM Cost of a Data Breach Report 2023

500,000+

developers using vibe coding platforms like Lovable, Bolt, and Replit

Source: Combined platform statistics 2024-2025

What Security Experts Say

There's a new kind of coding I call 'vibe coding', where you fully give in to the vibes, embrace exponentials, and forget that the code even exists.

Andrej Karpathy, Former Tesla AI Director, OpenAI Co-founder

Vibe coding your way to a production codebase is clearly risky. Most of the work we do as software engineers involves evolving existing systems, where the quality and understandability of the underlying code is crucial.

Simon Willison, Security Researcher, Django Co-creator

Verify Your Next.js App Security

Don't guess - scan your app and know for certain. vas checks for all the common security issues in Next.js applications.