Skip to content
KitploitKITPLOIT
ToolsBlog
Submit
ToolsBlog
Submit

Hacking, PenTest, and Cybersecurity Tools for Your Security Arsenal!

Kitploit is a directory of hacking, cybersecurity, and pentesting tools. Discover the latest project updates to find vulnerabilities, analyze systems, automate testing, and strengthen your security.

··Feeds·Contact·Privacy·© 2026 Kitploit

Tool Directory

Categories

View all categories
Loading categories
Next.js_exploit_CVE-2024-34351 — Educational demo of a Server-Side Request Forgery (SSRF) vulnerability in Next.js (CVE-2024-34351), with step-by-step exploitation and mitigation examples. | Kitploit
Tools/GitHubGitHub/avergnaud/next.js_exploit_cve-2024-34351
Vulnerability AnalysisWeb Application ExploitationWeb SecurityLearning & EducationLabs & Practice
GitHubavergnaud/next.js_exploit_cve-2024-34351

Next.js_exploit_CVE-2024-34351

Educational demo of a Server-Side Request Forgery (SSRF) vulnerability in Next.js (CVE-2024-34351), with step-by-step exploitation and mitigation examples.

View Repository
12 years agoNot yet reviewed

Most Popular

View all →

Discover the most used tools by our community.

Explore all tools

Browse our collection of tools

View all tools →
Share

csr-rsc-ssg-isr-ssr-ssrf

This repo can be used as support to present one or more meetup(s). The path is as follows...

  • "CSR" Client Side Rendering: React as a standard SPA library
  • "RSC" React Server Components: execution of React components only on the server side
  • "SSG" Static Site Generation: execution of React components during the build
  • "ISR" Incremental Static Regeneration: regeneration of components on demand
  • "SSR" Server Side Rendering: pre-rendering on the server side then execution (hydration) on the client side
  • "SSRF" Server Side Request Forgery: a security vulnerability recently fixed in Next.JS

This work is mainly based on two sources:

  • https://demystifying-rsc.vercel.app/
  • https://www.assetnote.io/resources/research/digging-for-ssrf-in-nextjs-apps

mind map

CSR Client Side Rendering

1-csr-load-data vanilla react SPA loading data

mind map CSR

[!IMPORTANT] CSR (Client-Side Rendering): React code is delivered to the browser, which generates content that is inserted into the DOM.

client side rendering loading data

demo

root@kitploit:~
cd 1-csr-load-data
npm start

CSR load data gif

2-csr-router vanilla react SPA routing

[!IMPORTANT] After the page has been loaded for the first time, navigating to other pages on the same website uses JavaScript to re-render parts of the page without requiring a full page refresh.

demo

root@kitploit:~
cd 2-csr-router
npm start

client side rendering routing

RSC React Server Components

3-rsc-load-data React Server Components (Next.js impl) loading data

mind map CSR

[!IMPORTANT] React components which are written to run only on the server, rather than in the browser.

React Server Components loading data

demo

root@kitploit:~
cd 3-rsc-load-data
npm run build
npm run start

client side rendering routing

4-rsc-router React Server Components (Next.js impl) routing

mind map CSR

[!IMPORTANT] Components are executed only on the server. The default behavior is static rendering: components are executed at build time.

demo

root@kitploit:~
cd 4-rsc-router
npm run build
npm run start

React server components routing

5-SSR SSR Server Side Rendering

mind map SSR

[!IMPORTANT] SSR means prerendering client components on the server. React code runs at the time it is requested. The result may be cached for future requests.

Best practice: define 'use client'; components as far down the component tree as possible.

https://nextjs.org/docs/app/building-your-application/rendering/composition-patterns#moving-client-components-down-the-tree

Hydration

[!IMPORTANT] "In React, “hydration” is how React “attaches” to existing HTML that was already rendered by React in a server environment. During hydration, React will attempt to attach event listeners to the existing markup and take over rendering the app on the client. In apps fully built with React, you will usually only hydrate one “root”, once at startup for your entire app."

https://react.dev/reference/react-dom/client/hydrateRoot

https://www.gatsbyjs.com/docs/conceptual/partial-hydration/

demo

root@kitploit:~
cd 5-ssr
npm run build
npm run start

SSR

6-pages-router-ssg (Next.js impl)

mind map page router SSG

[!IMPORTANT] SSG (Static Site Generation) using the pages router: React code is run when you build your application, and the generated output is static.

demo

root@kitploit:~
cd 6-pages-router-ssg
npm run build
npm run start

7-pages-router-isr (Next.js impl)

mind map page router ISR

[!IMPORTANT] ISR (using pages router): "Next.js allows you to create or update static pages after you’ve built your site. Incremental Static Regeneration (ISR) enables you to use static-generation on a per-page basis, without needing to rebuild the entire site. With ISR, you can retain the benefits of static while scaling to millions of pages."

demo

root@kitploit:~
cd 7-pages-router-isr
npm run build
npm run start

Why ISR?

"the data could become stale at request time"

https://vercel.com/blog/nextjs-server-side-rendering-vs-static-generation

Server actions

https://react.dev/reference/rsc/server-actions

SSRF (fixed in NextJS v14.1.1)

Definition of SSRF

...

Why?

  • If we have access to a vulnerable server but not directly to the target server (DMZ, FireWall...)
  • If we want to execute requests while hiding our own origin
  • ...

Demo 8-ssrf-14.1.0

Context

SSRF A

https://www.assetnote.io/resources/research/digging-for-ssrf-in-nextjs-apps

Objective

SSRF B, objective

Conditions to exploit CVE-2024-34351

  • A Next.JS-based application with version lower than 14.1.1
  • Use of the redirect function, with an absolute path. In the demo, in addTodo.js: redirect(/blog/${inputValue});

How the redirect function works

Source: https://www.assetnote.io/resources/research/digging-for-ssrf-in-nextjs-apps

  • The Next.JS redirect function does not send an HTTP 302 response to the browser.

Next.JS executes the request server-side, then returns the result to the browser:

  • To execute the request, Next.JS must construct the URL to call. In the demo, in addTodo.js: The redirect('/blog/123'); function constructs the URL http://207.154.209.99/blog/123. To construct this URL, Next.JS notably retrieves the host 207.154.209.99 from the HTTP header of the initial request.
  • Next.JS first queries the URL with an HTTP HEAD.
  • If the response returns a Content-Type: text/x-component header, then Next.JS queries the URL with an HTTP GET.

SSRF C, intro

Exploitation

To achieve an SSRF on the target server, we must therefore run another server:

  • that listens on all routes (query path)
  • that returns an HTTP 200 with a Content-Type: text/x-component header, for any HEAD request
  • that returns an HTTP 302 to the target server, for any GET request

SSRF D, exploit

CSR load data gif

Fix of the vulnerability in 8-ssrf-14.1.0

Solution 1 (not permanent): nginx configuration to force the host

In /etc/nginx/sites-available/nextjs

Before:

root@kitploit:~
server {
  listen 80 default_server;
  location / {
    proxy_pass http://localhost:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
  }
}

After:

root@kitploit:~
server {
  listen 80;
  server_name 207.154.209.99;
  location / {
    proxy_pass http://localhost:3000;
    proxy_set_header Host 207.154.209.99;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
  }
}

Risk of side effects...

https://nginxtutorials.com/nginx-proxy_set_header-directive/

Solution 2: update Next.js

https://github.com/vercel/next.js/security/advisories/GHSA-fr5h-rqp8-mj6g

Notes

"Extra attributes from the server"

https://stackoverflow.com/questions/75337953/what-causes-nextjs-warning-extra-attributes-from-the-server-data-new-gr-c-s-c

"getStaticProps" is not supported in app/. Read more: https://nextjs.org/docs/app/building-your-application/data-fetching

https://nextjs.org/docs/app/building-your-application/upgrading/app-router-migration#static-site-generation-getstaticprops

create-next-app

https://nextjs.org/docs/app/building-your-application/upgrading/app-router-migration#step-4-migrating-pages

Pages in the app directory are Server Components by default. This is different from the pages directory where pages are Client Components.

Upgrading to Next.js 13 does not require using the new App Router. You can continue using pages with new features that work in both directories

Performance

If we want to compare loading performance for the different solutions, we can add web core vital metrics in console.log.

https://web.dev/articles/fcp?hl=fr

other sources / references

https://rsc-parser.vercel.app/

https://stackoverflow.com/questions/76325862/what-is-the-difference-between-react-server-components-rsc-and-server-side-ren

https://github.com/reactjs/server-components-demo?tab=readme-ov-file#should-i-use-this-demo-for-benchmarks

https://github.com/reactjs/rfcs/blob/main/text/0188-server-components.md#does-this-replace-ssr

https://www.youtube.com/watch?v=jEJEFAc8tSI

ISR using App router ?

https://nextjs.org/docs/pages/building-your-application/data-fetching/incremental-static-regeneration

In the Next.js App Router, all fetched data is now static by default, rendered at build time. However, this can be changed easily: Next.js extends the fetch options object to provide flexibility in caching and revalidating rules. You can use the {next: {revalidate: number}} option to refresh static data at set intervals or when backend changes occur (Incremental Static Regeneration), while the {cache: 'no-store'} option can be passed in the fetch request for dynamic data (server-side rendering).

https://www.telerik.com/blogs/current-state-react-server-components-guide-perplexed

https://react.dev/blog/2023/03/22/react-labs-what-we-have-been-working-on-march-2023#react-server-components

https://github.com/reactjs/server-components-demo

https://dev.to/vteacher/let-s-make-a-web-application-with-react-server-components-5dmg

https://react.dev/blog/2024/04/25/react-19

https://react.dev/reference/rsc/server-components

https://www.youtube.com/watch?v=ePAPd9qzGyM

https://www.joshwcomeau.com/react/server-components/

https://nextjs.org/docs/app/building-your-application/rendering/server-components#server-rendering-strategies

https://nextjs.org/docs/pages/building-your-application/rendering/static-site-generation

https://nextjs.org/docs/pages/building-your-application/data-fetching/get-static-props

https://react.dev/reference/rsc/server-components#server-components-without-a-server

Download Tool