senecajs / seneca-transport

Seneca micro-services message transport over TCP and HTTP.
MIT License
63 stars 45 forks source link

http: path not parsed properly, 404 left unanswered #157

Closed tswaters closed 5 years ago

tswaters commented 7 years ago

I was playing around with explicitly calling listen to set up a health check port and wanted to see what effect providing different paths was. First I tried / and I was kind of flummoxed when an accidental curl to /act still worked.

Turns out the path checking only searches for the path being at the beginning, it is thus possible under the default options to access the act routes via, e.g.:

/act-some-extra-text-who-cares-lol?cmd=test

The code here: https://github.com/senecajs/seneca-transport/blob/v2.1.1/lib/http.js#L210-L212 should probably be run through url.parse and use the pathname to compare against provided path.... e.g,:

-if (req.url.indexOf(listenOptions.path) !== 0) {
+if (Url.parse(req.url).pathname !== listenOptions.path) {

And on that note, if that condition is true, the request is never responded to and will time out. This should probably return 404 and end the request.

-    return
+    res.statusCode = 404
+    return res.end()