Password Reset Poisoning: A Working Lab, the Exploit and the Fix

December 4, 2026

19 min read

Password Reset Poisoning: A Working Lab, the Exploit and the Fix

Table of contents

21

By Salman Khan, OSCP+, Founder of XHack, SRT (Synack Red Team member)

Read this in 30 seconds: Password reset poisoning happens when an app builds the link in its reset email from the request’s Host header, so an attacker can make a real email carry a link to the attacker’s own server. I built a small lab to prove it, break it and fix it, all on localhost.

  • The token is fine but it goes to the wrong place. In my lab the reset token was random, single use and valid, and the attacker still took over the test account in 4 steps.
  • Two headers worked, not one. Both Host and X-Forwarded-Host produced a poisoned link in the vulnerable build, and the fixed build stopped both.
  • The password reset poisoning bug is two lines, and so is the fix. The link base came from the request, and pinning it to a server-side constant removed the problem.
  • A regression test catches password reset poisoning. Three tests fail 2 of 3 on the vulnerable code and pass 3 of 3 on the fixed code, in about 1.5 seconds.
  • It is not a lab curiosity. In an XHack web application engagement the same flaw allowed full takeover of any account, including administrators, and scored CVSS 8.1.

Password reset poisoning is an account takeover that needs no stolen password and no guessed token: the attacker asks for a reset, and the app mails the victim a valid link that points at the attacker. The victim still has to click, which is why the bug survives reviews, but a reset email is one of the few messages people click without suspicion.

This guide walks through password reset poisoning on code you can run yourself, with a vulnerable build, the exploit, a two-layer fix and a test that keeps it fixed. Everything runs on 127.0.0.1 with the Python standard library, against accounts I made up for the purpose, and the only thing the “attacker” sends is a request header. Use it on your own code or on a system you have written permission to test.

What Password Reset Poisoning Is

Password reset poisoning is the abuse of an app that builds absolute URLs in emails from attacker-controlled request headers. The reset feature needs the full link, for example https://app.example.test/reset?token=..., and the easy way to get the first half is to ask the current request what host it was sent to.

PortSwigger’s Web Security Academy describes the attack in the same terms: the attacker changes the Host header of a reset request to a domain they control, the victim receives a genuine email with a link to that domain, and the token reaches the attacker when the victim clicks it, or when a mail scanner fetches the link. The attacker then uses the token on the real site.

Password reset poisoning has four parts:

  1. The attacker requests a reset for the victim’s email address, with a modified header.
  2. The app creates a real token and emails the victim a link built from the header.
  3. The victim opens the link, and the token arrives in the attacker’s server logs.
  4. The attacker redeems the token on the real site and sets a new password.

The weakness is catalogued as CWE-640, Weak Password Recovery Mechanism for Forgotten Password. Nothing about the token’s strength matters here, because the flaw does not attack the token. Password reset poisoning hands a perfectly good token to the wrong recipient.

The Lab: What I Built and the Ground Rules

The lab is four small Python files and a deliberate mistake. I ran it on 4 December 2026 with Python 3.12.14 and no third-party packages.

FileLinesWhat it does
app.py89A reset service with vulnerable and fixed modes, plus an attacker listener
client.py24Raw http.client helpers so every header is under my control
exploit.py34Runs the four attack steps against either mode
test_reset_link.py40The regression test, written to assert the safe behaviour

Four ground rules keep the password reset poisoning lab safe and honest:

  • Everything binds to 127.0.0.1. No packet leaves the machine.
  • The victim is a fake account, victim@example.test, and the “email” is a list in memory that the lab can read.
  • Hostnames are simulated. The “browser” maps attacker.example.test to the attacker’s local port, which stands in for DNS. TLS is skipped.
  • The only “payload” is a header value. There is no shellcode and no third-party target.

To run the service yourself, start it on a fixed port and read the “emails” it sends:

python3 app.py vulnerable 8765        # or: python3 app.py fixed 8765
curl -s http://127.0.0.1:8765/outbox  # the emails the app has "sent"

The Vulnerable Code Behind Password Reset Poisoning

The bug is the method that decides what the link starts with. Here is the whole decision in the vulnerable build.

def reset_base(self):
    if mode == "vulnerable":
        host = self.headers.get("X-Forwarded-Host") or self.headers.get("Host")
        return f"https://{host}"               # BUG: the caller chooses this
    return CANONICAL                           # FIX: pinned, server-side

The handler that uses it looks innocent, which is the point:

if self.path == "/forgot-password":
    email = body.get("email")
    if email in state["users"]:
        token = secrets.token_urlsafe(16)
        state["tokens"][token] = email
        state["outbox"].append({"to": email, "link": f"{self.reset_base()}/reset?token={token}"})
    return self.reply(200, {"message": "If the account exists, an email was sent."})

Read it as a reviewer. The token comes from secrets, so it is unguessable. The response is the same whether the account exists or not, which is what OWASP’s Forgot Password Cheat Sheet asks for. A scanner would find nothing wrong with the token, and a code review that stops at “is the token secure?” would pass it.

Running the Exploit: Four Steps to Takeover

With the vulnerable build running, the attack takes one modified request and one click. This is the real output of python3 exploit.py vulnerable:

[vulnerable] app on :56427, attacker listener on :56428

1. Attacker requests a reset for the victim, poisoning Host: HTTP 200
2. The victim's email contains: https://attacker.example.test/reset?token=<token>
3. The victim clicks. The attacker's server logs the token (1shBtH...).
4. The attacker redeems it on the real app: HTTP 200
   Victim's password is now: 'attacker-chose-this'

You can reproduce step 1 and 2 with curl, which is closer to what a tester does:

curl -s -X POST http://127.0.0.1:8765/forgot-password \
  -H 'Host: attacker.example.test' -d '{"email":"victim@example.test"}'
curl -s http://127.0.0.1:8765/outbox
[{"to": "victim@example.test", "link": "https://attacker.example.test/reset?token=MWU_i_qBR4Ob63ffd9f0kQ"}]

In password reset poisoning the attacker never sees the victim’s inbox. They send the request, and the victim receives the email. The only thing the attacker needs is the victim’s registered email address and a click.

Password reset poisoning attack flow: the attacker requests a reset with a poisoned Host header, the app emails the victim a link to the attacker's host, the victim clicks, and the attacker redeems the token
The four steps of password reset poisoning in the lab, and the point where the token leaves the real site

Why the click in password reset poisoning is easier to get than it sounds

The victim never asked for this email, but it looks exactly like a real reset because it is one. It comes from the real sender, at a moment the attacker chose. Mail security scanners that follow links can also deliver the token without any human click, which is why PortSwigger notes both cases.

The Proxy Variant: X-Forwarded-Host

Sending a correct Host header does not protect you if the framework prefers a forwarded one. Behind a reverse proxy, the original hostname arrives in X-Forwarded-Host, and many frameworks read it first when it is present. PortSwigger’s guidance on Host header attacks lists X-Host, X-Forwarded-Server, X-HTTP-Host-Override and Forwarded as similar override headers, and warns that some third-party software enables them by default.

My lab reproduces this by sending the correct Host and a poisoned X-Forwarded-Host. The second round of exploit.py vulnerable shows the same four steps succeeding.

1. Attacker requests a reset for the victim, poisoning X-Forwarded-Host: HTTP 200
2. The victim's email contains: https://attacker.example.test/reset?token=<token>
3. The victim clicks. The attacker's server logs the token (sTr2yA...).
4. The attacker redeems it on the real app: HTTP 200
   Victim's password is now: 'attacker-chose-this'

This is the case in password reset poisoning that fools teams who only validate Host. A defence that checks one header while the code reads another is no defence, which is why the fix below stops reading either one.

The Real-World Version of Password Reset Poisoning

The lab is simple, and so was the real password reset poisoning finding. In a web application engagement for an e-learning platform, XHack found that the reset email’s link came from the Host header and, behind the client’s reverse proxy, from X-Forwarded-Host. The published case study, The Reset Link That Pointed at Us, records the facts.

  • Impact: full account takeover of any user, including instructor and administrator accounts, demonstrated only against test accounts XHack created. No real user was targeted.
  • Severity: CVSS 8.1, High, with user interaction required. The classes are OWASP A07:2021 and CWE-640 and CWE-644.
  • Cause: the feature asked the request for its base URL, which is correct in development and in normal use, so nobody noticed where the hostname came from.
  • Fix: links pinned to one canonical base URL on the day of disclosure, host allow-listing at the proxy within the week, and the email-verification link, which had the same flaw, fixed in the same release.

The client’s own team said the reset URL had been built from the request since the feature was first written, and that no earlier review had questioned where the hostname came from. That is the password reset poisoning pattern to look for in your own code, and I did not cite a separate public CVE here because I could not confirm one to a primary source.

The Fix for Password Reset Poisoning: Two Layers

The fix is to stop letting the request decide, and then to refuse requests that look wrong. Both layers are in the fixed mode of the lab.

Layer 1, a pinned base URL. The link is built from a constant that lives in server-side configuration.

CANONICAL = "https://app.example.test"   # the only base the fixed version will use

OWASP’s Forgot Password Cheat Sheet says not to rely on the Host header when building reset URLs, and that the URL should be hard-coded or checked against a list of trusted domains. PortSwigger’s guidance says setting the trusted domain in a config file removes password reset poisoning for absolute links. Layer 1 is that advice.

Layer 2, a host allow-list. The service rejects any request whose Host is not one of its own names.

ALLOWED_HOSTNAMES = {"app.example.test"}

if mode == "fixed" and self.headers.get("Host", "").split(":")[0] not in ALLOWED_HOSTNAMES:
    return self.reply(400, {"error": "unknown host"})

Frameworks ship this. Django’s ALLOWED_HOSTS matches the Host header exactly, ignoring case and port, and raises SuspiciousOperation when neither Host nor an enabled X-Forwarded-Host matches. Django’s documentation notes that the check runs through get_host(), so code that reads request.META directly bypasses it. That is a good reason to use the pinned constant for anything security relevant instead of trusting the allow-list alone.

Here is the same exploit against the fixed build:

[fixed] app on :56200, attacker listener on :56201

1. Attacker requests a reset for the victim, poisoning Host: HTTP 400
   No email was sent. Request refused.

1. Attacker requests a reset for the victim, poisoning X-Forwarded-Host: HTTP 200
2. The victim's email contains: https://app.example.test/reset?token=<token>
3. The link points at the real site. The attacker captured nothing.

The two layers of the password reset poisoning fix did different jobs. The allow-list refused the poisoned Host outright. The pinned constant ignored the poisoned X-Forwarded-Host and still sent a normal email to the real victim, which means the attack attempt cost them nothing but also gained nothing.

A Regression Test That Fails on the Old Code

A password reset poisoning fix you cannot re-run is a fix that quietly stops working. The test below asserts the safe behaviour, so it fails against the vulnerable build and passes against the fixed one.

class ResetLinkTests(unittest.TestCase):
    def setUp(self):
        self.app, self.state = start_app(MODE)

    def tearDown(self):
        self.app.shutdown()
        self.app.server_close()

    def link_for(self, headers):
        post(self.app, "/forgot-password", {"email": "victim@example.test"}, headers)
        return self.state["outbox"][-1]["link"] if self.state["outbox"] else None

    def test_normal_request_uses_the_canonical_base(self):
        link = self.link_for({"Host": "app.example.test"})
        self.assertTrue(link.startswith(CANONICAL + "/reset?token="))

    def test_host_header_cannot_choose_the_link_host(self):
        link = self.link_for({"Host": "attacker.example.test"})
        self.assertTrue(link is None or link.startswith(CANONICAL + "/"), link)

    def test_x_forwarded_host_is_ignored(self):
        link = self.link_for({"Host": "app.example.test", "X-Forwarded-Host": "attacker.example.test"})
        self.assertTrue(link.startswith(CANONICAL + "/"), link)

I ran it in both modes. The vulnerable build fails the two poisoning tests and passes the normal-request test, and the fixed build passes all three.

Regression test results for password reset poisoning: the vulnerable build fails 2 of 3 tests and the fixed build passes 3 of 3
The same three tests run against the vulnerable and the fixed build of the lab, each run taking about 1.5 seconds

The first test in a password reset poisoning suite is the one people forget. It proves the fix did not break the normal reset, because a security fix that blocks real users gets reverted. In your own project, point the same three tests at a staging copy with the production base URL setting and run them in CI, as the case study’s longer-term recommendations also suggest.

Where Password Reset Poisoning Hides Beyond the Reset Email

The reset email is the famous case, but any feature that puts an absolute URL in a message can have the same flaw. In the XHack engagement the email-verification link had it too. Audit every place your app builds a link that leaves the app:

  • Email verification and confirmation links, which carry a token like the reset link.
  • Invitation links, which let someone join a workspace.
  • Share and magic-link emails, which grant access to a resource.
  • Password-change and security notifications that include a link back to the account.
  • Any template that calls a “base URL” helper instead of a configuration value.

A quick way to find them is to search the codebase for the helper that returns the request’s host or base URL, and list every caller. The password reset poisoning fix is the same in each: one canonical setting and no request-derived hostnames.

What Does Not Fix Password Reset Poisoning

Making the token stronger, shorter-lived or rate-limited helps with other attacks but does not stop this one. The poisoned link carries a legitimate token, so the attacker is not guessing anything.

  • A stronger token changes nothing, because the attacker receives the real one.
  • A shorter lifetime shrinks the window but does not remove it, since the attacker can redeem within seconds of the click.
  • HTTPS does not help, because the attacker’s host can have its own valid certificate.
  • Uniform “if the account exists” messages protect against account enumeration, not poisoning. My lab already used one, and the attack still worked.

Those controls still belong in the flow. OWASP’s cheat sheet asks for single-use tokens, an appropriate expiry, a uniform response, and invalidating sessions and outstanding links after a successful recovery. They are the second line, and the pinned base URL is the first.

How to Test Your Own App for Password Reset Poisoning

You need two accounts you own and a way to read their email. Do this on your own application or a system where you have written permission, and only against accounts you created.

  1. Create a test account with an email address you control, and request a reset normally. Note the host in the link.
  2. Replay the reset request with a different Host header, and again with an X-Forwarded-Host header.
  3. Read the new email. If the link’s host changed, you have password reset poisoning.
  4. Repeat for every override header your stack could honour, and for every other emailed link.
  5. Check what happens to a rejected host. A 400 with no email is the clean result.
  6. Write the regression test from the previous section before you fix anything, and watch it fail.

Reset flows change often and carry a high blast radius, which is why the case study recommends periodic testing of authentication specifically. Our guide to bug bounty methodology shows where authentication testing fits in a full engagement, and the SSO, OAuth and JWT testing guide covers the neighbouring login attacks.

How XHack Delivers Password Reset Poisoning Testing Differently

I am biased, it is my company, so read this as the brand section. XHack combines three things most providers sell separately: expert human testers, an autonomous AI agent and a continuous security platform.

For bugs like password reset poisoning, here is what is on our public pages.

  • Authentication flows are in scope by default. In the engagement above the scope included registration, login and password reset, and the reset flaw was found by reading the reset email and replaying the request with one changed header.
  • Fixes are checked. The case study records a re-test confirming links always point at the application’s own domain, whatever Host or X-Forwarded-Host is sent.
  • The agent finds, then exploitation unlocks once your identity is verified. From the start the agent finds vulnerabilities and helps with your work, and exploitation unlocks once you are verified. There is a 7-day free trial, nothing is charged for the trial period itself, what you need to start depends on current requirements, and there is one trial per person.
  • Plans from $20 a month. Starter is $20, Professional is $49 and Elite is $150. Managed testing by our researchers starts at $2,500 per engagement, scoped to your application.

If you want a cheap one-time scan with a cover page, we are not the right fit. If you want a person to read your emails and replay your headers, start with the identity verification guide for the agent or the pricing page for managed testing, and read the case study for what a finished write-up looks like. Brutal honesty is kind of our thing.

FAQ: Password Reset Poisoning Questions Answered

What is password reset poisoning?

Password reset poisoning is an attack where the attacker changes a request header, usually Host or X-Forwarded-Host, so the app builds the reset link in its email around the attacker’s domain. The victim receives a real email with a valid token in a link that points at the attacker, and the attacker uses the token on the real site after the victim clicks.

Usually yes, which is why the CVSS score for password reset poisoning carries a user-interaction requirement. A mail security scanner that fetches links can also deliver the token without a human click, which is why PortSwigger notes both routes.

Is password reset poisoning the same as host header injection?

Host header injection is the broader class, where an app trusts the Host header for something it should not. Password reset poisoning is the most common and most damaging use of it, because the header ends up inside a link carrying a valid token.

How do I fix password reset poisoning?

Build the reset link from one canonical base URL in server-side configuration and never from the request, then add a host allow-list so unknown hosts are rejected. OWASP and PortSwigger both recommend a hard-coded or configured domain, and a regression test keeps the fix in place.

Do strong tokens or HTTPS prevent password reset poisoning?

No. The attacker receives a legitimate token, and the attacker’s own domain can serve HTTPS with its own certificate. Strong tokens and short expiries are worth having, but they address different attacks, so the pinned base URL has to carry the fix.

Testing your own application, or one where you have written permission, is legal and routine. Testing someone else’s system without permission is a crime in most countries, even when the only thing you send is a header. This is not legal advice, so check your local law and your scope document.

The Bottom Line

Password reset poisoning is a two-line bug with an account-takeover result, and it hides in any feature that builds a link from the request. The fix is to pin the base URL on the server and reject unknown hosts, and a three-test regression keeps it fixed.

Run the password reset poisoning lab once, watch the token leave for the wrong host, then search your own code for every place a link is built. The ten minutes it takes is cheaper than the incident, and the same search finds the verification and invitation links the reset email was hiding behind.


Categories