Skip to content
SSRF Write-up Intermediate

Hunting for SSRF vulnerabilities in Next.js targets

The article describes three SSRF issues in Next.js: the Image component can be abused when remote patterns allow any host, middleware can be tricked into fetching a Location header, and Server Actions in older self-hosted versions can be made to request an attacker-controlled host. An attacker could make the server send requests to arbitrary internal or external hosts.

intigriti.com

Published on intigriti.com

By blackbird-eu

The author, on intigriti.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 7 min read.

Next.js is an open-source React framework for building fast, interactive and SEO-friendly web applications. It ships with server-side rendering, API routes, middleware logic, routing and image optimisation, and it sees almost 13 million weekly downloads on NPM. That combination of breadth and complexity makes it a frequent target, and its extra server-side features create room for security misconfigurations. This article walks through three ways a vulnerable Next.js component can be induced to make outbound HTTP requests to arbitrary hosts: server-side request forgery.

Hunting for SSRF vulnerabilities in Next.js targets Header Image
Hunting for SSRF vulnerabilities in Next.js targets Header Image From the original on intigriti.com

Context

Next.js is a React-based framework that gives developers utilities and components for interactive web applications and APIs. The features relevant here are the Image component, Middleware and Server Actions. Each of them runs code on the server, and each can be pushed into making requests to hosts the developer never intended.

Setup

No accounts, roles or specific tooling are described for the three techniques. What matters are the preconditions of each target:

  • Image component: the /_next/image endpoint must be reachable, and the image configuration must either allow a wildcard hostname or whitelist a host that can be made to redirect.
  • Middleware (CVE-2025-57822): the middleware must pass unsanitised request input, including headers, into the next() method.
  • Server Actions (CVE-2024-34351): Next.js 14.1.1 or lower, self-hosted, Server Actions in use, and a Server Action that redirects to a relative path. Exploitation also needs a custom OAST server.

Finding it

The Image component endpoint

Image optimisation matters for SEO, so Next.js recommends its Image component, a server-side component that performs optimisation and caching. Because the processing happens on the server, including the component in a project, which is often done by default, exposes an additional API endpoint at /_next/image. When an image is included, its location is forwarded to that endpoint, which performs the optimisation and returns the optimised image.

The url parameter of that endpoint is the obvious place to test for SSRF, particularly when the project uses the wildcard scope configuration option:

JavaScript
/** @type {import('next').NextConfig} */
const nextConfig = {
  images: {
    remotePatterns: [
      {
        protocol: 'https',
        hostname: '**',
      },
      {
        protocol: 'http',
        hostname: '**',
      }
    ],
  },
}

module.exports = nextConfig

Developers use this to allow loading images from any host, and in doing so introduce a new attack vector. The misconfiguration lets an attacker make HTTP requests on behalf of the vulnerable server, which is a typical blind SSRF.

Even without a wildcard, the endpoint is still worth probing for whitelisted hosts such as CDNs. The underlying Image component, which pulls the initial version of the image, follows redirects by default, so an open URL redirect on an allowed host can in practice open a path to any arbitrary host.

Middleware

Next.js Middleware runs code before responses are returned to the client, which is useful for server-side redirects, authentication and authorisation checks. The vulnerability appears when a developer passes unsanitised user input to a Middleware method. The example used here comes from a previously hosted Intigriti CTF challenge that keeps track of UTM parameters, and in it the developer passes the entirety of an object, including unsanitised request headers, to the next() method. That makes next() evaluate all headers before returning the response, including checking for possible internal redirects initiated by the Location header. A request carrying an arbitrary Location header therefore makes Next.js load the resource named in that header.

This undocumented behaviour went unnoticed for years before the vendor acknowledged it and assigned CVE-2025-57822. According to research by Dominik Prodinger, over 5,000 potentially affected hosts have been identified on the internet. When testing Next.js applications, it is worth including checks for this CVE.

Server Actions

Server Actions let developers define asynchronous functions that run server-side and can be invoked directly from React components, covering data fetching, mutations and form handling without custom API routes or extra backend boilerplate. An incorrect implementation can lead to SSRF. The original discovery is credited to researchers at Assetnote, and a target is vulnerable only if all of the following hold:

  1. Next.js version 14.1.1 or lower is running in a self-hosted environment.
  2. The target uses Server Actions.
  3. The Server Action performs a redirect to a relative path.

The third condition is essential. Next.js 14.1.1 and earlier stream responses back to clients using a specific validation process: the framework first sends a HEAD request to the host specified in the incoming request's host header, validates the response's content-type, and then proceeds with the GET request to retrieve the actual content.

Exploitation

Step 1: Probe the image endpoint

Send a request to /_next/image with a url parameter pointing at a host you control, and watch for an outbound request from the server. A positive result is a request arriving at your listener, which confirms blind SSRF. If the wildcard is not configured, try URLs on hosts that are likely whitelisted, such as CDNs, and look for one that offers an open redirect you can chain.

Step 2: Abuse the Location header through middleware

Against a vulnerable middleware implementation, send a request with an arbitrary Location header. The next() method evaluates the headers before returning the response, and the framework follows the internal redirect named in Location, loading the resource you specified. A positive result is the server fetching the resource you named in that header.

Step 3: Prepare the OAST server for Server Actions

The exploitation phase requires a custom OAST server that responds with the appropriate content-type header to pass the initial validation check. Configure it to answer the HEAD request with a supported content-type, and to answer the subsequent GET request with a 302 redirect whose Location header points at the target resource, such as the AWS metadata endpoint URI.

Step 4: Trigger the Server Action

The first request triggers the vulnerable Server Action to initiate a HEAD HTTP request to the OAST server specified in the Host header. When the server then receives the GET request, it responds with the 302 redirect containing the target resource in Location. Because the OAST server answered the HEAD with the supported content-type, the framework proceeds to the GET, and the redirect sends it to the resource you chose.

Root cause

Each technique comes from a different design decision:

  • Image component: the wildcard remotePatterns configuration lets the server fetch images from any host. The component follows redirects by default, so even a restricted allowlist can be bypassed through an open redirect on an allowed host.
  • Middleware: passing the whole object, including unsanitised request headers, into next() makes the framework evaluate the Location header and follow it as an internal redirect.
  • Server Actions: the response streaming validation in 14.1.1 and earlier trusts the host from the incoming request's host header when it sends the HEAD request, and only checks the content-type before issuing the GET. A server that answers with the right content-type and then redirects controls where the GET goes.

Impact

All three techniques let an attacker make HTTP requests on behalf of the vulnerable server. The Image component case is described as a typical blind SSRF. The middleware case lets an attacker make Next.js load a resource of their choosing. The Server Actions case can reach internal resources such as the AWS metadata endpoint. The article notes that SSRF vulnerabilities can often be further weaponised to reach protected components or networks, disclose sensitive information, and even achieve remote code execution, and points to a separate article on weaponising blind SSRF. The Server Actions technique only applies under the three conditions listed above.

Fix

Variants to test

  • Image endpoint without a wildcard: look for whitelisted hosts such as CDNs that offer an open redirect, and chain it through /_next/image. A positive result is an outbound request to a host outside the allowlist.
  • Middleware header handling: send a request with an arbitrary Location header to any Next.js application whose middleware passes request headers into next(). A positive result is the server fetching the resource named in the header.
  • Server Actions on older self-hosted instances: check for Next.js 14.1.1 or lower, Server Actions in use, and a Server Action that redirects to a relative path. A positive result is a HEAD request arriving at your OAST server from the target.

Hunting notes

Start with the /_next/image endpoint, since the Image component is often included by default. The url parameter of that endpoint is the obvious place to test for SSRF. If the wildcard is absent, look for CDN hosts in the allowlist and check them for open redirects. For middleware, look for applications that pass unsanitised request headers into next(), and test the Location header. For Server Actions, fingerprint the Next.js version and check whether the application is self-hosted and uses Server Actions with relative redirects. The Server Actions technique needs a custom OAST server that answers the HEAD with a supported content-type and the GET with a 302 redirect to the target resource.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 14 min read.

What happened, in plain words

This article is about a family of bugs called server-side request forgery, usually shortened to SSRF. To understand it, you only need one idea: a website is not just files sitting on a computer. Behind many websites there is a program running on a server (a computer in a data centre) that does work for visitors. Sometimes that program is asked to fetch something from another computer on the internet, for example an image to resize. SSRF happens when an attacker can influence which computer the server fetches from. Instead of fetching a harmless picture, the server can be tricked into contacting a machine the attacker should never be able to reach, such as an internal system that is not exposed to the public internet.

The article looks at Next.js, a toolkit that developers use to build websites. Next.js is popular: it is downloaded almost 13 million times a week from NPM, the main package store for JavaScript code. Because it does a lot of work on the server, small configuration mistakes can turn into SSRF bugs. The article walks through three such mistakes, in this order: the Image component, Middleware, and Server Actions. For each one it explains what the feature does, why the mistake happens, and how an attacker would test for it.

A few words you will meet constantly, explained once here:

  • Server: the computer that runs the website and answers visitors' requests.
  • Client: the browser on your own computer, which sends requests to the server.
  • Request: a message a browser sends to a server, for example "please give me this page".
  • Response: the message the server sends back.
  • HTTP: the language browsers and servers use to exchange requests and responses.
  • Endpoint: a specific address on a server that accepts requests, like a particular counter in a large building.
  • API: a way for one program to talk to another program, rather than to a human. An API endpoint is a URL that returns data or performs an action instead of showing a web page.
  • Framework: a ready-made set of building blocks that developers use to build an application faster, instead of writing everything from scratch.
Hunting for SSRF vulnerabilities in Next.js targets Header Image
Hunting for SSRF vulnerabilities in Next.js targets Header Image From the original on intigriti.com

Context

Next.js is built on React, a library for building user interfaces. On top of React, Next.js adds features that run on the server: server-side rendering (building the page on the server before sending it to the browser), API routes, middleware logic, routing and image optimisation. The three features relevant to this article are the Image component, Middleware and Server Actions. Each of them runs code on the server, and each can be pushed into making requests to hosts the developer never intended.

Setup

The article does not describe any accounts, roles or specific tooling for the three techniques. What matters are the preconditions of each target:

  • Image component: the /_next/image endpoint must be reachable, and the image configuration must either allow a wildcard hostname or whitelist a host that can be made to redirect.
  • Middleware (CVE-2025-57822): the middleware must pass unsanitised request input, including headers, into the next() method.
  • Server Actions (CVE-2024-34351): Next.js 14.1.1 or lower, self-hosted, Server Actions in use, and a Server Action that redirects to a relative path. Exploitation also needs a custom OAST server.

Two terms from that list need explaining. A wildcard is a setting that matches anything, like writing "any name" on a guest list instead of listing names one by one. Self-hosted means the organisation runs Next.js on its own servers rather than on a managed hosting platform. An OAST server is a server the attacker controls and watches, used to confirm that the target really did make a request out to it; OAST stands for out-of-band application security testing, and the point is that the confirmation arrives on a channel separate from the normal response.

Finding it

The Image component endpoint

Images matter for search engine ranking, so Next.js recommends its Image component. This is a server-side component that performs optimisation and caching: when a page shows a picture, the server fetches the original, shrinks or converts it, stores a copy, and sends the smaller version to the browser. Because the processing happens on the server, including the component in a project, which is often done by default, exposes an additional API endpoint at /_next/image. When an image is included, its location is forwarded to that endpoint, which performs the optimisation and returns the optimised image.

The url parameter of that endpoint is the obvious place to test for SSRF, particularly when the project uses the wildcard scope configuration option:

JavaScript
/** @type {import('next').NextConfig} */
const nextConfig = {
  images: {
    remotePatterns: [
      {
        protocol: 'https',
        hostname: '**',
      },
      {
        protocol: 'http',
        hostname: '**',
      }
    ],
  },
}

module.exports = nextConfig

Line by line:

  • /** @type {import('next').NextConfig} */ is a comment that tells the code editor what kind of object follows. It has no effect on how the site behaves.
  • const nextConfig = { starts a settings object named nextConfig. Everything inside the braces is configuration for the Next.js application.
  • images: { opens the section of settings that controls image handling.
  • remotePatterns: [ opens a list of allowed remote sources for images. Each entry in the list describes one permitted kind of address.
  • { protocol: 'https', hostname: '**', }, is the first entry: allow the https protocol (encrypted web traffic) from any hostname, because ** matches everything.
  • { protocol: 'http', hostname: '**', }, is the second entry: the same, for plain unencrypted http.
  • ], closes the list, }, closes the images section, and } closes the whole settings object.
  • module.exports = nextConfig hands this object to Next.js so it can apply the settings.

Developers use this to allow loading images from any host, and in doing so introduce a new attack vector. An attack vector is simply a way in. The misconfiguration lets an attacker make HTTP requests on behalf of the vulnerable server, which is a typical blind SSRF. Blind here means the attacker does not see the fetched content in the response; they only know the server made the request, for example because it arrives at a server they control.

Even without a wildcard, the endpoint is still worth probing for whitelisted hosts such as CDNs. A CDN, or content delivery network, is a service that hosts copies of files close to users around the world. The underlying Image component, which pulls the initial version of the image, follows redirects by default. A redirect is a server's way of saying "the thing you asked for is over there, go to this other address instead". So an open URL redirect on an allowed host can in practice open a path to any arbitrary host: the attacker asks for an allowed address, that address redirects to an internal one, and the Image component obediently follows.

Middleware

Next.js Middleware runs code before responses are returned to the client, which is useful for server-side redirects, authentication and authorisation checks. Authentication is checking who you are; authorisation is checking what you are allowed to do. The vulnerability appears when a developer passes unsanitised user input to a Middleware method. Unsanitised means the input has not been cleaned or checked, so whatever the visitor sends is used as-is.

The example used here comes from a previously hosted Intigriti CTF challenge that keeps track of UTM parameters. A CTF, or capture the flag, is a practice challenge where participants try to find a deliberately planted flaw. UTM parameters are little labels added to links so that marketing tools can tell which campaign brought a visitor in. In the example, the developer passes the entirety of an object, including unsanitised request headers, to the next() method. A header is a small piece of metadata attached to a request or response, such as the browser type or the address the request came from. next() is the middleware function that says "carry on to the next step".

That makes next() evaluate all headers before returning the response, including checking for possible internal redirects initiated by the Location header. The Location header is normally used by a server to tell a browser where to go next. A request carrying an arbitrary Location header therefore makes Next.js load the resource named in that header.

This undocumented behaviour went unnoticed for years before the vendor acknowledged it and assigned CVE-2025-57822. A CVE is a public identifier for a known security flaw, so people can refer to the same bug unambiguously. According to research by Dominik Prodinger, over 5,000 potentially affected hosts have been identified on the internet. When testing Next.js applications, it is worth including checks for this CVE.

Server Actions

Server Actions let developers define asynchronous functions that run server-side and can be invoked directly from React components, covering data fetching, mutations and form handling without custom API routes or extra backend boilerplate. In plain terms: a developer writes a function that runs on the server, and a button or form in the page can call it directly. Asynchronous means the function can take time and the rest of the page does not have to freeze while waiting. A mutation is any change to stored data, such as saving a form. Boilerplate is repetitive setup code you would otherwise have to write yourself.

An incorrect implementation can lead to SSRF. The original discovery is credited to researchers at Assetnote, and a target is vulnerable only if all of the following hold:

  1. Next.js version 14.1.1 or lower is running in a self-hosted environment.
  2. The target uses Server Actions.
  3. The Server Action performs a redirect to a relative path.

A relative path is an address that is not complete, like /dashboard rather than https://example.com/dashboard; it only makes sense relative to the site you are already on.

The third condition is essential. Next.js 14.1.1 and earlier stream responses back to clients using a specific validation process: the framework first sends a HEAD request to the host specified in the incoming request's host header, validates the response's content-type, and then proceeds with the GET request to retrieve the actual content. A HEAD request is like a GET request but asks only for the headers, not the body, so it is a cheap way to check something. The host header tells the server which site name the visitor typed. The content-type header says what kind of data is being returned, for example an image or a web page.

Exploitation

Step 1: Probe the image endpoint

Send a request to /_next/image with a url parameter pointing at a host you control, and watch for an outbound request from the server. A positive result is a request arriving at your listener, which confirms blind SSRF. If the wildcard is not configured, try URLs on hosts that are likely whitelisted, such as CDNs, and look for one that offers an open redirect you can chain. The reason for each step: you need a destination you can observe, otherwise you cannot tell whether the server fetched anything; and if the allowlist blocks you, a redirect on an allowed host is a way around it.

Step 2: Abuse the Location header through middleware

Against a vulnerable middleware implementation, send a request with an arbitrary Location header. The next() method evaluates the headers before returning the response, and the framework follows the internal redirect named in Location, loading the resource you specified. A positive result is the server fetching the resource you named in that header. The reason: the developer passes the whole object, including unsanitised request headers, to next().

Step 3: Prepare the OAST server for Server Actions

The exploitation phase requires a custom OAST server that responds with the appropriate content-type header to pass the initial validation check. Configure it to answer the HEAD request with a supported content-type, and to answer the subsequent GET request with a 302 redirect whose Location header points at the target resource, such as the AWS metadata endpoint URI. A 302 is the standard status code for a temporary redirect. The AWS metadata endpoint is an address that only the cloud server itself can normally reach, and it hands out information about that server; reaching it from outside is a classic SSRF goal. The reason for the two-step answer: the framework checks the content-type first, and only if that check passes does it send the real request, which you then redirect.

Step 4: Trigger the Server Action

The first request triggers the vulnerable Server Action to initiate a HEAD HTTP request to the OAST server specified in the Host header. When the server then receives the GET request, it responds with the 302 redirect containing the target resource in Location. Because the OAST server answered the HEAD with the supported content-type, the framework proceeds to the GET, and the redirect sends it to the resource you chose. The reason this works: the framework sends a HEAD request to the host in the incoming request's host header, and only checks the content-type before the GET.

Root cause

Each technique comes from a different design decision:

  • Image component: the wildcard remotePatterns configuration lets the server fetch images from any host. The component follows redirects by default, so even a restricted allowlist can be bypassed through an open redirect on an allowed host.
  • Middleware: passing the whole object, including unsanitised request headers, into next() makes the framework evaluate the Location header and follow it as an internal redirect.
  • Server Actions: the response streaming validation in 14.1.1 and earlier trusts the host from the incoming request's host header when it sends the HEAD request, and only checks the content-type before issuing the GET. A server that answers with the right content-type and then redirects controls where the GET goes.

Impact

All three techniques let an attacker make HTTP requests on behalf of the vulnerable server. The Image component case is described as a typical blind SSRF. The middleware case lets an attacker make Next.js load a resource of their choosing. The Server Actions case can reach internal resources such as the AWS metadata endpoint. The article notes that SSRF vulnerabilities can often be further weaponised to reach protected components or networks, disclose sensitive information, and even achieve remote code execution, and points to a separate article on weaponising blind SSRF. Remote code execution means running the attacker's own commands on the target server, the most serious outcome. The Server Actions technique only applies under the three conditions listed above.

Fix

Variants to test

  • Image endpoint without a wildcard: look for whitelisted hosts such as CDNs that offer an open redirect, and chain it through /_next/image. A positive result is an outbound request to a host outside the allowlist.
  • Middleware header handling: send a request with an arbitrary Location header to any Next.js application whose middleware passes request headers into next(). A positive result is the server fetching the resource named in the header.
  • Server Actions on older self-hosted instances: check for Next.js 14.1.1 or lower, Server Actions in use, and a Server Action that redirects to a relative path. A positive result is a HEAD request arriving at your OAST server from the target.

Hunting notes

Start with the /_next/image endpoint, since the Image component is often included by default. During recon, a url parameter on that endpoint is the signal to test. Recon, short for reconnaissance, is the early phase of looking around a target to see what it is made of. If the wildcard is absent, look for CDN hosts in the allowlist and check them for open redirects. For middleware, look for applications that pass unsanitised request headers into next(), and test the Location header. For Server Actions, fingerprint the Next.js version and check whether the application is self-hosted and uses Server Actions with relative redirects. Fingerprinting means working out which software and version a site runs. The Server Actions technique needs a custom OAST server that answers the HEAD with a supported content-type and the GET with a 302 redirect to the target resource.

Glossary

  • Asynchronous: a function that can take time without freezing the rest of the page while it waits.
  • Attack vector: a way in for an attacker.
  • Authentication: checking who a user is.
  • Authorisation: checking what a user is allowed to do.
  • Blind SSRF: SSRF where the attacker does not see the fetched content in the response, only evidence that the request was made.
  • Boilerplate: repetitive setup code a developer would otherwise write by hand.
  • CDN: content delivery network, a service that hosts copies of files close to users around the world.
  • Client: the browser or program making requests to a server.
  • Content-type: a header saying what kind of data a response contains.
  • CVE: a public identifier for a known security flaw.
  • Endpoint: a specific address on a server that accepts requests.
  • Fingerprinting: working out which software and version a site runs.
  • Framework: a ready-made set of building blocks for building an application.
  • HEAD request: a request that asks only for the headers of a resource, not its body.
  • Header: a small piece of metadata attached to a request or response.
  • Host header: the header that tells a server which site name the visitor typed.
  • Location header: a header a server uses to tell a browser or client where to go next.
  • Middleware: code that runs before a response is returned to the client.
  • Mutation: any change to stored data, such as saving a form.
  • OAST server: a server the attacker controls and watches, used to confirm that a target made a request out to it.
  • Open URL redirect: a redirect that will send a visitor to any address supplied in the request.
  • Recon: reconnaissance, the early phase of looking around a target.
  • Redirect: a server's instruction to go to a different address instead.
  • Relative path: an address that is not complete and only makes sense relative to the current site.
  • Remote code execution: running the attacker's own commands on the target server.
  • Request: a message a client sends to a server.
  • Response: a message a server sends back to a client.
  • Self-hosted: running the software on your own servers rather than on a managed platform.
  • Server-side rendering: building the page on the server before sending it to the browser.
  • SSRF: server-side request forgery, a bug where an attacker can influence which host the server contacts.
  • 302: the standard HTTP status code for a temporary redirect.
  • Unsanitised: input that has not been cleaned or checked before use.
  • UTM parameters: labels added to links so marketing tools can tell which campaign brought a visitor in.
  • Wildcard: a setting that matches anything, such as ** matching every hostname.

Similar reports

View all

Same bug class and techniques, clearest first.

Server-side request forgery (SSRF)

The lesson behind this report.

The server can be made to fetch an address the attacker chooses, reaching internal services, cloud metadata or other customers' data.