marblejs / marble

Marble.js - functional reactive Node.js framework for building server-side applications, based on TypeScript and RxJS.
https://marblejs.com
MIT License
2.15k stars 73 forks source link

`URIError: URI malformed` exception crashes server for named route parameters #309

Closed alexanderbartels closed 3 years ago

alexanderbartels commented 3 years ago

Hi, thanks for the great work on this project. It looks very promising and i have choosen it to build a framework for microfrontends on top of it. While developing it i faced the following problem:

Describe the bug Server with a named route parameter crashes if an invalid parameter is defined. Before the server is terminated it shows a URIError: URI malformed Exception.

/.../src/server/node_modules/@marblejs/core/dist/http/router/http.router.resolver.v2.js:73
        const resolvedRoute = find(urlPath, req.method);
                              ^
URIError: URI malformed
    at decodeURIComponent (<anonymous>)
    at /.../src/server/node_modules/@marblejs/core/dist/http/router/http.router.matcher.js:18:55
    at resolve (/.../src/server/node_modules/@marblejs/core/dist/http/router/http.router.resolver.v2.js:73:31)
    at Server.handle (/.../src/server/node_modules/@marblejs/core/dist/http/server/http.server.listener.js:22:9)
    at Server.emit (events.js:326:22)
    at Server.EventEmitter.emit (domain.js:486:12)
    at parserOnIncoming (_http_server.js:863:12)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:126:17)
error Command failed with exit code 1.

To Reproduce

I pass a string like @some-name/another-name but before i use encodeURIComponent("@some-name/another-name") to use it in a url. So it results in a Request like: GET /mf/%40some-name%2Fanother-name. The parameter is passed decoded and everything works as expected!

But if the URL contains invalid characters, e.g. GET /mf/%mf-test%2Ffoobar, the decoding fails with an exception and the whole server crashes.

Expected behavior Instead of crashing the whole server it should keep running stable and return a Bad-Request Error.

Desktop (please complete the following information):

If you can point me in the right direction, i'm happy to implement a change and submit a pull request.

JozefFlakus commented 3 years ago

Thanks for detecting this nasty bug! I've just created a PR. It should be fixed with version 3.4.8

alexanderbartels commented 3 years ago

great! Thanks i will try it once it is released. 👍

JozefFlakus commented 3 years ago

Version 3.4.8 released. 🚀

alexanderbartels commented 3 years ago

updated my project, everything works as expected now. Thanks for the fast fix!