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

registerWebInterface() redirect ignores X-Forwarded-Port header #1490

Closed
Mihail-K opened this Issue May 12, 2016 · 3 comments

Comments

Projects
None yet
2 participants
@Mihail-K
Contributor

Mihail-K commented May 12, 2016

Minimal case to reproduce,

@path("/users")
class Users {
    void index() {
        render!"index.dt";
    }
}

shared static this() {
    URLRouter router = new URLRouter;

    // . . .

    router.registerWebInterface(new Users);
}

Requests made to /users are redirected to /users/, however, the redirect includes the port number the vibe app accepted the request on. This is problematic for environments where the internal port number (which vibed is bound to) does not match the external port number (which requests arrive on). For example if the app listens on port 5000, but incoming requests are actually accepted on port 80.

I've set up a Heroku app that demonstrates this behavior. Note that it is running on a free dyno, and may take a while to spin up.

Works correctly: http://testrig.herokuapp.com/users/
Problem redirect: http://testrig.herokuapp.com/users
(May redirect to something like: http://testrig.herokuapp.com:48669/users/)

In the case of Heroku, this is particularly problematic as there is no control over what the internal port number is. It is assigned (via environment variable) whenever the app is deployed, and is usually different every time.

@s-ludwig

This comment has been minimized.

Show comment
Hide comment
@s-ludwig

s-ludwig May 12, 2016

Member

Currently the server expects the "X-Forwarded-Host" header to be set by the proxy server - if that is given, it will ignore the local port. This works for simple setups, but should definitely be made customizable in the future. Does Heroku set any similar headers, or can it be made to?

Member

s-ludwig commented May 12, 2016

Currently the server expects the "X-Forwarded-Host" header to be set by the proxy server - if that is given, it will ignore the local port. This works for simple setups, but should definitely be made customizable in the future. Does Heroku set any similar headers, or can it be made to?

@Mihail-K

This comment has been minimized.

Show comment
Hide comment
@Mihail-K

Mihail-K May 12, 2016

Contributor

It appears Heroku does not set the X-Forwarded-Host header, but instead all of these,
https://devcenter.heroku.com/articles/http-routing#heroku-headers

Other major HTTP servers appear to support these, but this is probably the cause of the issue.

EDIT: Looking at vibe/http/server.d, it appears to check for X-Forwarded-Host and disregard related headers if it's not present.

Contributor

Mihail-K commented May 12, 2016

It appears Heroku does not set the X-Forwarded-Host header, but instead all of these,
https://devcenter.heroku.com/articles/http-routing#heroku-headers

Other major HTTP servers appear to support these, but this is probably the cause of the issue.

EDIT: Looking at vibe/http/server.d, it appears to check for X-Forwarded-Host and disregard related headers if it's not present.

Mihail-K added a commit to Mihail-K/vibe.d that referenced this issue May 12, 2016

Mihail-K added a commit to Mihail-K/vibe.d that referenced this issue May 12, 2016

Mihail-K added a commit to Mihail-K/vibe.d that referenced this issue May 12, 2016

Mihail-K added a commit to Mihail-K/vibe.d that referenced this issue May 12, 2016

Mihail-K added a commit to Mihail-K/vibe.d that referenced this issue May 12, 2016

@Mihail-K Mihail-K changed the title from registerWebInterface() redirects include internal port number. to registerWebInterface() redirects ignores X-Forwarded-Port header May 16, 2016

@Mihail-K Mihail-K changed the title from registerWebInterface() redirects ignores X-Forwarded-Port header to registerWebInterface() redirect ignores X-Forwarded-Port header May 16, 2016

s-ludwig added a commit that referenced this issue May 18, 2016

Merge pull request #1491 from Mihail-K/master
#1490 Add support for X-Forwarded-Port header.
@Mihail-K

This comment has been minimized.

Show comment
Hide comment
@Mihail-K

Mihail-K May 19, 2016

Contributor

Resolved by #1491

Contributor

Mihail-K commented May 19, 2016

Resolved by #1491

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment