Skip to content
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

bugfix for X-Forward-Port multiple value #1822

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,11 @@ static int getOriginalPort(SessionContext context, Headers headers, int serverPo
}
String portStr = headers.getFirst(HttpHeaderNames.X_FORWARDED_PORT);
if (portStr != null && !portStr.isEmpty()) {
int idx = portStr.indexOf(",");
if (idx != -1) {
//get most left value
portStr = portStr.substring(0, idx).trim();
}
return Integer.parseInt(portStr);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,14 @@ void getOriginalPort_EmptyXFFPort() throws URISyntaxException {
assertEquals(9999, HttpRequestMessageImpl.getOriginalPort(new SessionContext(), headers, 9999));
}

@Test
void getOriginalPort_multipleXFFPort() throws URISyntaxException {
Headers headers = new Headers();
headers.add(HttpHeaderNames.X_FORWARDED_PORT, "9999,11000");
// Default to using server port
assertEquals(9999, HttpRequestMessageImpl.getOriginalPort(new SessionContext(), headers, 1000));
}

@Test
void getOriginalPort_respectsProxyProtocol() throws URISyntaxException {
SessionContext context = new SessionContext();
Expand Down