> For the complete documentation index, see [llms.txt](https://ganesha-hk.gitbook.io/cybersecurity-writeups/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ganesha-hk.gitbook.io/cybersecurity-writeups/port-swigger-authentication-labs/lab-14.md).

# lab-14

## Password Reset Poisoning via Middleware

**Difficulty:** Practitioner

### Lab Description

This lab is vulnerable to password reset poisoning. The user `carlos` will carelessly click on any links in emails he receives.

**Objective:** Log in to Carlos's account.

**Credentials:** `wiener:peter` (emails readable via the exploit server's email client)

### Root Cause

The application is deployed behind a reverse proxy or load balancer. While the `Host` header itself may be protected (e.g. restricted to a predefined domain), middleware components also accept and trust host-override headers such as `X-Forwarded-Host`. The middleware sends the domain from the override header to the backend application rather than the original `Host` header value — and these override headers are fully user-controllable.

If an attacker supplies their own domain via `X-Forwarded-Host`, the backend uses it when constructing the password reset link:

```
https://attacker.com/forgot-password/reset/?token=hxhschsjc
```

When the victim clicks this link, the reset token is sent to the attacker's server, allowing the attacker to reset the victim's password and take over their account.

### Exploitation

1. Go to the forgot-password page and submit `username: wiener`.
2. Intercept the `POST /forgot-password` request and send it to Repeater.
3. Send it once as-is to generate a reset email for `wiener`.
4. Replace the `username` value with `carlos` and add the header `X-Forwarded-Host` with your exploit server URL as the value.
5. Send the request, then go to **Exploit Server → Access Log**.
6. Find the request containing `/forgot-password?temp-forgot-password-token=` and copy Carlos's token.
7. Go to **Exploit Server → Email**, open the reset email for `wiener`, and click the reset link.
8. In the URL, replace `wiener`'s token with Carlos's captured token.
9. Set a new password for Carlos and log in to complete the lab.

### Lesson Learned

* Never trust client-supplied host override headers such as `X-Forwarded-Host` when generating absolute URLs.
* Password reset links and other security-sensitive URLs must always use a predefined, trusted domain stored in server-side configuration.
* Validate or ignore untrusted host-related headers unless they originate from known, trusted infrastructure (e.g. your own reverse proxy).
* Deploy a strict allowlist of accepted hostnames at the web server, reverse proxy, and application layers.
* Audit all functionality that generates absolute URLs to ensure none rely on user-controlled request headers — including middleware-level headers.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ganesha-hk.gitbook.io/cybersecurity-writeups/port-swigger-authentication-labs/lab-14.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
