Skip to content

Commit

Permalink
Don't use the local port of "X-Forwarded-Host" was used. See #1490.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-ludwig committed May 22, 2016
1 parent cc1cf6a commit b9e3019
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions source/vibe/http/server.d
Original file line number Diff line number Diff line change
Expand Up @@ -708,8 +708,12 @@ final class HTTPServerRequest : HTTPRequest {
const {
URL url;

auto xfh = this.headers.get("X-Forwarded-Host");
auto xfp = this.headers.get("X-Forwarded-Port");
auto xfpr = this.headers.get("X-Forwarded-Proto");

// Set URL host segment.
if (auto xfh = this.headers.get("X-Forwarded-Host")) {
if (xfh) {
url.host = xfh;
} else if (!this.host.empty) {
url.host = this.host;
Expand All @@ -720,7 +724,7 @@ final class HTTPServerRequest : HTTPRequest {
}

// Set URL schema segment.
if (auto xfp = this.headers.get("X-Forwarded-Proto")) {
if (auto xfpr) {
url.schema = xfp;
} else if (this.tls) {
url.schema = "https";
Expand All @@ -729,17 +733,19 @@ final class HTTPServerRequest : HTTPRequest {
}

// Set URL port segment.
if (auto xfp = this.headers.get("X-Forwarded-Port")) {
if (xfp) {
try {
url.port = xfp.to!ushort;
} catch (ConvException) {
// TODO : Consider responding with a 400/etc. error from here.
logWarn("X-Forwarded-Port header was not valid port (%s)", xfp);
}
} else if (url.schema == "https") {
if (m_port != 443U) url.port = m_port;
} else {
if (m_port != 80U) url.port = m_port;
} else if (!xfh) {
if (url.schema == "https") {
if (m_port != 443U) url.port = m_port;
} else {
if (m_port != 80U) url.port = m_port;
}
}

url.host = url.host.split(":")[0];
Expand Down

0 comments on commit b9e3019

Please sign in to comment.