What is the issue with the URL Standard?
Hi,
I would like to share with you a common scenario:
- A request is recevied via NodeJs Express or Fastify server
- Request is forwarded to another service using an http client that uses the URL class to build the target URL using the service hostname + the incoming request.pathname
This scenario can lead to path traversal vulnerabilities as Express and Fastify do not evaluate ../ and ./ but the whatwg URL does. So the route checks of express / fastify match another path. This situation is not good at all, because the developer need to know about the different parsing / evaluation logic.
Example
I have prepared a sample application with fastify.
https://github.com/stefanbeigel/whatwg-fastify-path-traversal/blob/main/index.mjs
Call the app with curl --path-as-is localhost:3000/abc/../foobar
Possible solutions
- Http server libraries parses the URL with the whatwg URL standard
- Whatwg URL drops the path shortening or gives an option to disable it
As this behavior was introduced by the URL class I created this issue, even you can argue that this is a problem of fastify / express / nodejs.