Skip to content
SSRF Write-up Intermediate

Finding an SSRF in Next.js Server Actions

Next.js Server Action forwarding code could use the attacker-controlled X-Forwarded-Host header to build an internal request URL when a custom server deployment lacked the private origin setting. An attacker could make the Next.js server send a request to a host they control, carrying the original request headers and body.

medium.com

Published on medium.com

Bug Bounty

toast, on medium.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. 3 min read.

Context

Next.js Server Actions let a client invoke a server-side function by sending a request that carries an action ID. In deployments that use a custom server, Next.js forwards that request internally, and the forwarding code has to decide which host to send it to. The write-up looks at how that host is chosen and shows that a request header can influence it.

The researcher was reading the Next.js codebase, specifically base-server.ts and the Server Action forwarding path. The report does not name a specific affected version.

Setup

The testing was done locally: a local Next.js instance plus a small HTTP listener that would record any request arriving at it. No accounts, roles or third-party services are involved. The relevant context is a custom server deployment where __NEXT_PRIVATE_ORIGIN is not set, because then the host can fall back to request headers.

Finding it

Reading the Server Action forwarding code, the researcher noticed that X-Forwarded-Host could influence the host used for an internal request. Three observations built the case:

  1. In base-server.ts, Next.js preserves the X-Forwarded-Host header.
  2. The internal IPC header filtering did not remove it either.
  3. In the Server Action forwarding code, parseHostHeader() could use that value when constructing the internal URL.

If __NEXT_PRIVATE_ORIGIN was not set, the host could fall back to the request headers. That gave the researcher a way to control where Next.js would send the request, which is the shape of a server-side request forgery.

Exploitation

Step 1: Stand up the target and a listener

A local Next.js instance was run alongside a small HTTP listener. The listener is the destination that a successful SSRF would reach.

Step 2: Trigger a Server Action and capture the action ID

A Server Action was triggered normally, and the action ID was taken from the request. That ID is what identifies the action on replay.

Step 3: Replay with a controlled X-Forwarded-Host

The captured request was replayed with a controlled X-Forwarded-Host value. The report does not include the raw request, so the exact header value and URL are not reproduced here.

Step 4: Confirm the listener was hit

The listener received the request.

From the original on medium.com

The request came from the Next.js server, not from the browser. It also carried the original request context, including the headers and body. That confirmed the SSRF.

From the original on medium.com

Root cause

The chain is short: X-Forwarded-Host survives into the internal forwarding logic, parseHostHeader() accepts it when building the internal URL, and the __NEXT_PRIVATE_ORIGIN fallback allows request headers to supply the host. The existing header handling did not stop it, because the header was preserved in base-server.ts and the IPC header filtering did not strip it. The report describes the behaviour in custom server deployments where __NEXT_PRIVATE_ORIGIN is unset; whether other deployment modes are affected is not stated.

Impact

An attacker who can send a Server Action request with a chosen X-Forwarded-Host can make the Next.js server issue a request to a host the attacker controls. The forwarded request carries the original request context, including headers and body, so that context reaches the attacker's endpoint. The report does not go further into what an attacker could reach internally or which data would be exposed beyond that context.

Fix

The report does not describe a fix or a patch. The takeaway it gives is the mechanism itself: X-Forwarded-Host making its way from the incoming request into an internal URL was enough to make Next.js send a request to an attacker-controlled host.

Variants to test

Reporting

The issue was reported to Vercel through HackerOne in May 2026. It was marked as a duplicate of a report from November 2025, rated High (8.3). No bounty was paid. The researcher notes that a custom harness and skills assisted with navigating the Next.js codebase and reasoning about the request flow, while the reproduction and SSRF were tested and verified locally by the researcher.

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. 9 min read.

What happened, in plain words

A security researcher was reading the source code of Next.js, a popular tool for building websites, and spotted a way to make a Next.js server send a request to a place of the attacker's choosing. That kind of flaw is called SSRF, short for Server-Side Request Forgery. The researcher built a small test on their own computer, proved the trick worked, and reported it to Vercel, the company behind Next.js, through the bug bounty platform HackerOne in May 2026. The report was closed as a duplicate: someone else had found the same issue in November 2025, and it had been rated High with a score of 8.3. No bounty was paid, but the researcher still wrote up how it worked.

This article walks through that write-up from the beginning, assuming you have never done security work before. Every term is explained where it first appears, and there is a glossary at the end.

Some background you need first

What Next.js and Server Actions are

Next.js is a framework: a set of tools and conventions that developers use to build web applications. A website built with Next.js usually has two halves. One half runs in your browser (the page you see and click). The other half runs on a server, a computer somewhere that stores data and does the heavy work.

A Server Action is a feature of Next.js that lets the browser ask the server to run a function. Think of a restaurant: you (the browser) do not walk into the kitchen; you give your order to a waiter, and the kitchen (the server) prepares it. A Server Action is that order slip. When you click a button that saves a form, for example, the browser sends a request to the server saying "please run the function with this data".

Each Server Action has an identifier, an action ID, so the server knows which function the request is for. It is like the item number on a menu: the kitchen sees the number and knows which dish to make.

What a request header is

Every time your browser talks to a server, it sends a request: a message asking for something. The message has a few parts. The body is the main content, such as the data you typed into a form. The headers are small labelled notes attached to the message, like the label on a parcel. They say things such as what kind of content is inside, or which website the request came from.

One header that matters here is X-Forwarded-Host. Websites are often placed behind an intermediary, a proxy or load balancer, which sits between visitors and the real server, the way a receptionist sits between visitors and staff. When the receptionist passes a message on, they may add a note saying "this originally came addressed to example.com". X-Forwarded-Host is exactly that kind of note: it tells the server which host name the visitor originally used. Servers often trust it, because normally only the receptionist writes it.

What a custom server and __NEXT_PRIVATE_ORIGIN are

Next.js can run in different setups. In a custom server deployment, the developer runs Next.js inside their own server program rather than using the default one. In that setup, Next.js sometimes needs to forward a request internally, from one part of the server to another. To do that it has to decide which address, which host, to send the request to.

__NEXT_PRIVATE_ORIGIN is a setting, an environment variable, that a developer can define to tell Next.js the canonical address of the site. Environment variables are configuration values kept outside the code, like the address printed on a company's letterhead. If this setting is present, Next.js knows the address and uses it. If it is absent, Next.js has to work the address out some other way, and that is where things get interesting.

What SSRF means

SSRF, Server-Side Request Forgery, is a vulnerability where an attacker can make a server send a request to an address the attacker chooses. The everyday comparison: imagine a company's mailroom that will fetch any parcel you ask for. If you can write the address on the slip, you can make the mailroom walk into a locked back office and bring something out. The attacker never touches the internal system directly; the trusted server does it on their behalf.

Finding it

The researcher was reading the part of the Next.js code that handles forwarding Server Action requests. Reading source code is a normal way to hunt for bugs: you look for places where something supplied from outside is used without being checked.

Three observations built the case:

  1. In a file called base-server.ts, Next.js preserves the X-Forwarded-Host header. In other words, it keeps that note from the receptionist rather than throwing it away.
  2. The internal filtering of headers used for communication between parts of the server (called IPC, inter-process communication) did not remove it either. So the note survived a second checkpoint.
  3. In the Server Action forwarding code, a function called parseHostHeader() could use that value when constructing the internal URL. A URL is a web address, like the address on an envelope; constructing one means deciding where the request will be sent.

And if __NEXT_PRIVATE_ORIGIN was not set, the host could fall back to the request headers. "Fall back" means: if the proper setting is missing, use this other thing instead. Here the other thing was whatever the incoming request said.

Put together, that gave the researcher a way to control where Next.js would send the request. That is the shape of an SSRF.

Testing it

The researcher set up a local Next.js instance and a small HTTP listener. A listener is a tiny program that sits waiting for incoming requests and writes down whatever arrives. It is like leaving a phone switched on and recording every call. If the trick works, the listener is where the evidence will appear.

The test had three steps:

  1. Trigger a Server Action normally, and grab the action ID from the request. This is the menu number from earlier: you need it to place the same order again.
  2. Replay the request with a controlled X-Forwarded-Host. Replaying means sending the same request again, possibly with small changes, like photocopying a letter and altering one line before posting it.
  3. Watch the listener.

The listener received the request.

From the original on medium.com

The request was coming from the Next.js server, not from the browser. That distinction is the whole point. If the request had come from the browser, nothing would be wrong: browsers make requests all the time. The problem is that the server made it, on the attacker's instruction.

It also contained the original request context, including the headers and body. In other words, the note the attacker had attached, and the content of the original message, travelled along to the attacker's listener. That confirmed the SSRF.

From the original on medium.com

The report does not include the raw request, so the exact header value and URL used in the test are not shown here.

Why it works

The chain is short, and each link is worth understanding on its own:

  • X-Forwarded-Host survives into the internal forwarding logic. The note from the receptionist is not discarded.
  • parseHostHeader() accepts it when building the internal URL. The code reads the note and uses it as the destination address.
  • The __NEXT_PRIVATE_ORIGIN fallback allows request headers to supply the host. When the proper setting is missing, the note is trusted.

The existing header handling did not stop it, because the header was preserved in base-server.ts and the IPC header filtering did not strip it. The report describes the behaviour in custom server deployments where __NEXT_PRIVATE_ORIGIN is unset; whether other deployment modes are affected is not stated.

What an attacker could do with it

An attacker who can send a Server Action request with a chosen X-Forwarded-Host can make the Next.js server issue a request to a host the attacker controls. The forwarded request carries the original request context, including headers and body, so that context reaches the attacker's endpoint. The report does not go further into what an attacker could reach internally or which data would be exposed beyond that context.

Was there a fix?

The report does not describe a fix or a patch. The takeaway it gives is the mechanism itself: X-Forwarded-Host making its way from the incoming request into an internal URL was enough to make Next.js send a request to an attacker-controlled host.

Other things worth testing

Reporting it

The issue was reported to Vercel through HackerOne in May 2026. It was marked as a duplicate of a report from November 2025, rated High (8.3). No bounty was paid.

A duplicate means someone else reported the same problem first. Bug bounty platforms track reports so that the first valid report gets the credit and the reward. A severity rating is a score for how serious a flaw is; 8.3 on the CVSS scale is in the High range. CVSS is a standard way of scoring vulnerabilities from 0 to 10.

The researcher notes that a custom harness and skills assisted with navigating the Next.js codebase and reasoning about the request flow, while the reproduction and SSRF were tested and verified locally by the researcher. A harness here means a set of personal tools and notes that help someone work through a large codebase.

Glossary

  • Action ID: the identifier attached to a Server Action request so the server knows which function to run.
  • API: a defined way for one piece of software to ask another to do something, like a menu of available requests.
  • Body: the main content of a request, such as form data.
  • Bug bounty: a programme that pays or credits people for reporting security flaws responsibly.
  • Custom server: a deployment where a developer runs Next.js inside their own server program instead of the default one.
  • CVSS: a standard scoring system for the severity of a vulnerability, from 0 to 10.
  • Duplicate: a report of a flaw that someone else has already reported.
  • Environment variable: a configuration value kept outside the code, such as a site's canonical address.
  • Header: a small labelled note attached to a request or response, carrying metadata.
  • Host: the address of a server on a network, such as a domain name.
  • HackerOne: a platform where researchers report vulnerabilities to companies.
  • Harness: a set of personal tools and notes used to work through a codebase or test a theory.
  • IPC: inter-process communication, the way different parts of a server program talk to each other.
  • Listener: a small program that waits for incoming requests and records them.
  • Load balancer: an intermediary that spreads incoming traffic across several servers.
  • Next.js: a framework for building web applications with code that runs in the browser and on a server.
  • __NEXT_PRIVATE_ORIGIN: a Next.js environment variable that sets the site's canonical address.
  • Proxy: an intermediary that sits between a visitor and a server and passes messages along.
  • Replay: sending a captured request again, possibly with small changes.
  • Request: a message a client sends to a server asking for something.
  • Server Action: a Next.js feature that lets the browser ask the server to run a function.
  • Severity: how serious a vulnerability is, often expressed as a score.
  • SSRF (Server-Side Request Forgery): a flaw where an attacker can make a server send a request to an address the attacker chooses.
  • URL: a web address identifying where a request should go.
  • Vercel: the company behind Next.js.
  • X-Forwarded-Host: a request header that records the host name a visitor originally used, often added by a proxy.

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.