Skip to content

Commit

Permalink
Fix parsing of ipv6 addresses in HydraEmbeddedServletContainer
Browse files Browse the repository at this point in the history
Closes #980
  • Loading branch information
theotherp committed Jan 4, 2025
1 parent 3e86d4c commit 1e18cad
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static Result parseRequest(Request request) {
if (Strings.isNotBlank(forwardedHost)) {
String[] split = forwardedHost.split("[ ,]");
forwardedHost = split[0];
int colonIndex = forwardedHost.lastIndexOf(":");
int colonIndex = forwardedHost.endsWith("]") ? -1 : forwardedHost.lastIndexOf(":");
if (colonIndex > -1) {
if (originalPort == -1) {
originalPort = request.getServerPort();
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/resources/changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
date: "2025-01-05"
changes:
- type: "fix"
text: "Fix paging for search / download / notification history"
text: "Fix paging for search / download / notification history."
- type: "fix"
text: "Hopefully actually fix ipv6 reverse proxies access. See #980"
final: true
- version: "v7.11.3"
date: "2025-01-03"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ void shouldHandleIpv6ForwardedHost() {
assertThat(result.forwardedHost()).isEqualTo("[2001:db8:85a3:8d3:1319:8a2e:370:7348]");
}

@Test
void shouldHandleIpv6ForwardedHostWithoutPort() {
when(request.getHeader("X-Forwarded-Host")).thenReturn("[2001:db8:85a3:8d3:1319:8a2e:370:7348]");
when(serverNameMB.getString()).thenReturn("original.com");
when(request.getServerPort()).thenReturn(8080);

HydraEmbeddedServletContainer.Result result = parseRequest(request);

assertThat(result.originalPort()).isEqualTo(80);

Check failure on line 113 in core/src/test/java/org/nzbhydra/auth/HydraEmbeddedServletContainerTest.java

View workflow job for this annotation

GitHub Actions / Unit test report

org.nzbhydra.auth.HydraEmbeddedServletContainerTest ► shouldHandleIpv6ForwardedHostWithoutPort

Failed test found in: core/target/surefire-reports/TEST-org.nzbhydra.auth.HydraEmbeddedServletContainerTest.xml Error: org.opentest4j.AssertionFailedError:
Raw output
org.opentest4j.AssertionFailedError: 

expected: 80
 but was: -1
	at org.nzbhydra.auth.HydraEmbeddedServletContainerTest.shouldHandleIpv6ForwardedHostWithoutPort(HydraEmbeddedServletContainerTest.java:113)
assertThat(result.forwardedHost()).isEqualTo("[2001:db8:85a3:8d3:1319:8a2e:370:7348]");
}

@Test
void shouldHandleForwardedHostWithPort() {
when(request.getHeader("X-Forwarded-Host")).thenReturn("example.com:9443");
Expand Down

0 comments on commit 1e18cad

Please sign in to comment.