1-click DOS in fastify-static via directly passing user's input to new URL() of NodeJS without try/catch
When fastify-static is mounted at the root with the redirect option enabled, it passes the raw request URL straight into Node's URL constructor without error handling. A crafted request path makes that constructor throw, crashing the server, and a related path can also cause an open redirect.
- Triaged in 5 days
- Fixed in 5 days
- Disclosed after 5 days
Summary:
When fastify-static is mounted at root and registered the option { redirect: true } (default of redirect option is false), the following line directly feed user's input which is req.raw.url to URL API without try/catch: https://github.com/fastify/fastify-static/blob/master/index.js#L439. A remote attacker can send a GET request to server with path = //^/.., this will cause the URL API to throw error and eventually crash the server.
Steps To Reproduce:
- Download
fastify-dos.zip - bash run.sh
- Open your terminal and run:
curl --path-as-is "http://localhost:3000//^/.."
After that the server will crash and return error TypeError [ERR_INVALID_URL]: Invalid URL: //^/...
Fix proposal
You can add a try/catch to prevent crash. However, if you only fix by adding try/catch, attacker can still cause open redirect.
- Run the server in my
fastify-dos.zipagain - Use Google Chrome and navigate to
http://localhost:3000//a//youtube.com/%2e%2e%2f%2e%2e(I tested on Chrome, Firefox, Safari, Opera, Edge, worked on all of them) - You will see that you get redirected to
https://www.youtube.com/..%2F..
I like the idea of fixing open redirect by having a base URL = http://localhost.com/ as second parameter in https://github.com/fastify/fastify-static/blob/master/index.js#L439. However, I looked up on MDN spec about the URL API and I got surprised when I saw the last example at: https://developer.mozilla.org/en-US/docs/Web/API/URL/URL#examples, which is new URL("//foo.com", "https://example.com") // => 'https://foo.com' (see relative URLs), this is the main reason why the open redirect bug is still persist.
To fix this bug, I think we can check leading slash of req.raw.url, and allow at most 1 leading slash / before attempt to redirect.
Impact
- Denial of service
- Open redirect
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 plugin passes the untrusted request URL directly to the URL constructor without a try/catch and without validating leading slashes.
Impact
A remote attacker can crash the server (denial of service), and a related crafted path can redirect users to an attacker-chosen site.
What the attacker needed
Fastify-static mounted at root; redirect option enabled; no authentication needed
The fix
The plugin should validate that the request URL has at most one leading slash before redirecting, and wrap the URL parsing in a try/catch.
How it was found
- Set up and start the provided vulnerable server.
- Send a GET request whose path begins with two slashes followed by special characters.
- Observe the server crash with an invalid URL error.
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 plugin takes the path part of an incoming request and hands it to a built-in function that parses web addresses. Some paths are not valid addresses, so the function throws an error, and because nothing catches that error the whole server process stops. The same code can also be tricked into sending visitors to another website.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.