diff --git a/core/src/main/java/org/nzbhydra/auth/HydraEmbeddedServletContainer.java b/core/src/main/java/org/nzbhydra/auth/HydraEmbeddedServletContainer.java index 98bf1661b..de875ba8b 100644 --- a/core/src/main/java/org/nzbhydra/auth/HydraEmbeddedServletContainer.java +++ b/core/src/main/java/org/nzbhydra/auth/HydraEmbeddedServletContainer.java @@ -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(); diff --git a/core/src/main/resources/changelog.yaml b/core/src/main/resources/changelog.yaml index ade78548e..3ab702d58 100644 --- a/core/src/main/resources/changelog.yaml +++ b/core/src/main/resources/changelog.yaml @@ -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" diff --git a/core/src/test/java/org/nzbhydra/auth/HydraEmbeddedServletContainerTest.java b/core/src/test/java/org/nzbhydra/auth/HydraEmbeddedServletContainerTest.java index d8810b183..459710ba3 100644 --- a/core/src/test/java/org/nzbhydra/auth/HydraEmbeddedServletContainerTest.java +++ b/core/src/test/java/org/nzbhydra/auth/HydraEmbeddedServletContainerTest.java @@ -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); + 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");