> 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-12.md).

# lab-12

## Basic Password Reset Poisoning

**Difficulty:** Apprentice

### 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 trusts the user-controlled `Host` header when generating password reset URLs. Instead of using a trusted, server-side configured domain, the application constructs the reset link using the value from the incoming HTTP request:

```
https://<Host>/forgot-password?temp-forgot-password-token=...
```

Because the `Host` header is fully controllable by the client, an attacker can replace it with a domain they control (the exploit server). The server then sends the victim a password reset email containing a link that points to the attacker's domain — while still including the victim's valid reset token. When Carlos clicks the link, his browser sends the request to the attacker's server, exposing the reset token. The attacker can then use that token on the legitimate application to reset Carlos's password.

### 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 replace the `Host` header value with your exploit server URL.
5. Send the request, then go to **Exploit Server → Access Log**.
6. Find the request containing `/forgot-password?temp-forgot-password-token=` and copy the 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 the token captured from Carlos's request.
9. Set a new password for Carlos and log in to complete the lab.

### Lesson Learned

* Never trust the client-supplied `Host` header when generating absolute URLs.
* Password reset links and other security-sensitive URLs must always use a predefined, trusted domain stored in application configuration or environment variables.
* Validate or ignore untrusted host-related headers such as `Host`, `X-Forwarded-Host`, and similar override headers unless they originate from trusted infrastructure.
* Deploy a strict allowlist of accepted hostnames at the web server, reverse proxy, and application layers.
* Audit all functionality that generates absolute URLs (password resets, email verification, redirects, canonical links) to ensure none rely on user-controlled request 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-12.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.
