jochen-schweizer / express-prom-bundle

express middleware with standard prometheus metrics in one bundle
MIT License
303 stars 67 forks source link

Crash on unusual / malformed path in `normalizePath.js` #130

Open solymosi opened 1 month ago

solymosi commented 1 month ago

Given:

Then:

This makes it trivial to crash an Express instance that uses express-prom-bundle with includePath with a specifically crafted request.

Workaround for library users: set normalizePath to a custom function until this bug is fixed.

Easy fix: check if path is null before operating on it in normalizePath.js.

Proper fix: switch to the WHATWG URL API as url.parse has been deprecated for a while. This may be a breaking change in some edge cases. Or better yet, just use req.path which Express conveniently makes available.