React and Next.js Stack
Table of Contents
A modern full-stack JavaScript framework built around React for the frontend and Next.js as the application framework. Next.js typically runs on Node.js and is commonly paired with Express.js for custom API logic, though Next.js has its own built-in API routes that can replace Express entirely.
Related: Mern Stack Web Application Testing Methodology API Testing Methodology XSS JWT Attacks
Components
| Layer | Technology | Role |
|---|---|---|
| Frontend | React | Component-based UI rendering |
| Framework | Next.js | SSR, SSG, routing, and API routes |
| Runtime | Node.js | JavaScript runtime |
| API | Express.js | Optional custom API layer alongside Next.js |
| Database | Varies | PostgreSQL, MongoDB, Prisma ORM common |
Architecture
Next.js extends React with server-side capabilities. Unlike a pure React SPA that renders entirely in the browser, Next.js can render pages on the server (SSR), at build time (SSG), or on the client depending on configuration.
Browser → Next.js (SSR/SSG/CSR) → API Routes or Express → Database
API routes live under /api/ by default and run as serverless
functions or on a Node.js server. Express is often added alongside
for more complex backend logic or when migrating an existing
Express API.
Rendering Modes
Understanding the rendering mode matters for testing — it affects where data is processed and what the server exposes.
| Mode | Description | Security relevance |
|---|---|---|
| SSR | Rendered per request on server | Server-side logic runs per request — injection targets |
| SSG | Rendered at build time | Static output — less dynamic attack surface |
| CSR | Rendered in browser | API calls visible in network tab |
| ISR | Static with periodic regeneration | Caching behaviour worth probing |
Attack Surface
Server-Side Rendering — SSRF and Injection
SSR pages fetch data server-side before rendering. If user input influences what URLs or queries are made server-side, SSRF and injection are possible.
# Test for SSRF via a parameter that influences server-side fetching curl "http://$IP/api/preview?url=http://169.254.169.254/latest/meta-data/"
Cloud metadata endpoints are a common SSRF target in hosted Next.js applications. See SSRF for full detail.
API Routes — Broken Access Control
Next.js API routes under /api/ are easy to miss during manual
browsing since they aren't linked in the UI. Enumerate them:
feroxbuster -u http://$IP/api \ -w /usr/share/wordlists/seclists/Discovery/Web-Content/api/objects.txt \ -x json
Common misconfigurations:
- Missing authentication middleware on individual routes
- Admin routes accessible without privilege check
- HTTP method not validated — a GET-only route may accept POST
Express.js Integration — Middleware Bypass
When Express sits alongside Next.js, authentication middleware applied to Express routes may not cover Next.js API routes and vice versa. Test both sets of endpoints independently:
# Next.js API route curl http://$IP/api/users -H "Authorization: Bearer $TOKEN" # Express route curl http://$IP/express/users -H "Authorization: Bearer $TOKEN" # Try without token on both curl http://$IP/api/users curl http://$IP/express/users
React — XSS via dangerouslySetInnerHTML
React escapes output by default but dangerouslySetInnerHTML
bypasses this. Search the bundled JavaScript for it:
dangerouslySetInnerHTML={{ __html: userInput }}
Next.js also supports raw HTML injection via the next/head
component if user input reaches it. See XSS for detail.
Prototype Pollution
Same risk as other Node.js applications — JSON bodies with
__proto__ or constructor.prototype payloads can pollute the
prototype chain.
curl -X POST http://$IP/api/data \ -H "Content-Type: application/json" \ -d '{"__proto__":{"admin":true}}'
JWT and Session Handling
Next.js applications commonly use next-auth for authentication,
which wraps JWT or database sessions. Common issues:
- JWT stored in localStorage — XSS leads to token theft
- Weak
NEXTAUTH_SECRET— used to sign sessions, crackable if weak - Session fixation if session tokens are not rotated on login
# Check for next-auth endpoints curl http://$IP/api/auth/session curl http://$IP/api/auth/providers curl http://$IP/api/auth/csrf
The /api/auth/session endpoint often returns the current user's
session data without authentication — worth checking for sensitive
information exposure.
Environment Variable Leakage
Next.js has two types of environment variables — server-side only
and client-side (prefixed NEXT_PUBLIC_). Misconfiguration can
expose secrets to the browser.
Check the bundled JavaScript for leaked variables:
# Download and search the main bundle curl http://$IP/_next/static/chunks/main.js | grep -i "secret\|key\|token\|password"
Also check for exposed .env files:
curl http://$IP/.env curl http://$IP/.env.local curl http://$IP/.env.production
Source Maps
Next.js may expose source maps in production, revealing the original unminified source code including business logic and comments.
# Check for source maps curl http://$IP/_next/static/chunks/main.js.map
If source maps are present, download and inspect them for API keys, internal endpoints, and logic flaws.
Dependency Vulnerabilities
Next.js applications pull in large npm dependency trees. If
package.json is exposed:
curl http://$IP/package.json
Check each dependency version against known CVEs. Pay attention
to next, react, next-auth, and any ORM packages like
prisma or mongoose.
Enumeration Tips
- Next.js exposes its version in the
X-Powered-Byheader and in/_next/static/paths — check for known CVEs for that version - All static assets live under
/_next/static/— browse it for JavaScript bundles worth inspecting /api/auth/endpoints are almost always present withnext-auth— enumerate them early- Check
/_next/data/for SSG page data exposed as JSON - robots.txt often lists paths Next.js should not index — worth reading
Tips
- Always check both
/api/Next.js routes and any/express/or custom backend routes separately - Source maps are a significant information disclosure — always check for them
next-authmisconfiguration is common — test all/api/auth/endpoints thoroughly- SSRF via SSR is underexplored in CTFs but increasingly common in real applications — always test parameters that look like they fetch remote content server-side
- Environment variable leakage via
NEXT_PUBLIC_prefixed secrets is a frequent developer mistake — search bundles carefully