Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
solymosi opened this issue Aug 29, 2024 · 0 comments
Open

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

solymosi opened this issue Aug 29, 2024 · 0 comments

Comments

@solymosi
Copy link

solymosi commented Aug 29, 2024

Given:

  • the latest version (7.0.0) of express-prom-bundle
  • includePath set to true in the options
  • a request with the following path: //%5Cfoo.bar:[email protected]

Then:

  • in normalizePath.js the call to url.parse(...).pathname returns null
  • and depending on whether normalizePath is an array or not, the following code crashes either
    • in UrlValueParser:
      TypeError: Cannot read properties of null (reading 'split')
          at UrlValueParser.getPathChunks (/.../node_modules/url-value-parser/src/UrlValueParser.js:13:8)
      
    • or already in normalizePath.js:
      TypeError: Cannot read properties of null (reading 'replace')
          at module.exports [as normalizePath] (/.../node_modules/express-prom-bundle/src/normalizePath.js:23:19)
      

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant