Open redirect in fastify-static via mishandled user's input when attempt to redirect
When fastify-static is mounted at the root with the redirect option enabled, a request path beginning with a double forward slash is turned into a redirect Location header pointing at another site. An attacker could craft such a link to send users to an arbitrary website, mainly for phishing.
- Triaged in 2 days
- Fixed in 7 days
- Disclosed after 13 days
Summary:
When fastify-static is mounted at root and the register option redirect: true, the following 2 lines cause open redirect bug: https://github.com/fastify/fastify-static/blob/master/index.js#L156-L157. A remote attackers can redirect users to arbitrary web sites via a double forward slash: //, for example if attacker wants to redirect to google.com: http://<domain_name>//google.com/%2e%2e.
This bug is similar to CVE-2015-1164 in ExpressJS, they published on their page about the security bugs here (you can Ctrl+F and search for CVE-2015-1164): https://expressjs.com/en/advanced/security-updates.html
Steps To Reproduce:
- Download my PoC here
bash run.sh- Use Firefox to navigate to
http://localhost:3000//google.com/%2e%2e. You will see that you are redirected to https://www.google.com/
Request:
GET //google.com/%2e%2e HTTP/1.1
Host: localhost:3000
Accept-Encoding: gzip, deflate
Connection: close
Response:
HTTP/1.1 301 Moved Permanently
location: //google.com/%2e%2e/
content-length: 0
Date: Wed, 29 Sep 2021 03:34:22 GMT
Connection: close
I tested and it only works in Firefox but not in Chrome, Edge, Opera, Safari 😂, it is because different browsers handle the response differently.
Impact
The most straight-forward impact is phishing. However, open redirect is a gadget that enables attackers to be able to exploit further, for example:
- Bypassing SSRF protection
- Token stealing in OAuth
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the redirect logic concatenates the user-supplied path onto the Location header without validating it, so a path starting with a double slash is treated as a protocol-relative URL pointing to another host.
Impact
The most direct impact is phishing, and the text notes it could also help bypass SSRF protections or aid token theft in OAuth; the exploit only worked in Firefox, not in Chrome, Edge, Opera or Safari.
What the attacker needed
Fastify-static mounted at root; redirect option set to true; victim uses Firefox; victim clicks a crafted link
How it was found
- Download and run the provided proof-of-concept server.
- Open Firefox and request the crafted path with a double slash and encoded dot segments.
- Observe that the browser is redirected to an external site.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A web server can answer a request with a redirect, telling the browser to go to a different address. Here the server built that new address from part of the incoming URL without checking it, so a link starting with two slashes made the browser leave the site and go somewhere else. Attackers use this to make convincing links that look like they belong to the real site but end up on a fake one.
What is Open redirect?
A trusted site forwards users to any address an attacker picks; rarely paid alone, often the missing link in a chain.