redbird icon indicating copy to clipboard operation
redbird copied to clipboard

req.originalUrl is modified

Open runekm opened this issue 7 years ago • 5 comments

If I register this route: proxy.register("mydomain.com", "http://localhost:3000"); and navigate to f.ex.: http://mydomain.com///mypage//// in my browser, then http://localhost:3000/mypage/ is served from Redbird.

In my app req.originalUrl will be /mypage/, so I have no way to know that the user is at http://mydomain.com///mypage////, and not http://mydomain.com/mypage/

It would be better if Redbird just had served http://localhost:3000///mypage//// instead, as I then could've shown a 404 page or used a 301 redirect.

runekm avatar Feb 28 '18 11:02 runekm

you are assuming that redbird knows that the original url is //mypage///, have you checked that the browser is not striping all the extra / before sending the request to the server?

manast avatar Feb 28 '18 11:02 manast

Yes, the browser is displaying http://mydomain.com///mypage//// in the address bar while req.originalUrl in my node app says /mypage/

If I navigate directly to http://localhost:3000///mypage//// instead (not through Redbird), req.originalUrl says ///mypage////

runekm avatar Feb 28 '18 12:02 runekm

After a little bit of digging around, it seams that this behaviour is caused by .replace(//+/g, '/') on line 191 of /node_modules/http-proxy/lib/http-proxy/common.js

runekm avatar Feb 28 '18 13:02 runekm

ok, then it is an issue for the http-proxy project: https://github.com/nodejitsu/node-http-proxy

manast avatar Feb 28 '18 13:02 manast

Yes. But it was also a problem with path.join in /lib/proxy.js. path.join results in back slashes in Windows, and it also replaces multiple succeeding slashes. When I commented out line 191 in /node_modules/http-proxy/lib/http-proxy/common.js and rewrote path.join in /lib/proxy.js as path = {join: function( a, b ) {return a + b.substring(1)}}, I got the behaviour that I wanted.

This fix might have some unintended consequences, but so far it seams to work fine for me.

runekm avatar Feb 28 '18 13:02 runekm