Skip to content

Commit 94d36ee

Browse files
committed
Throw exception if URL does not include context path when context relative
Issue: gh-8399
1 parent 1b4f6bb commit 94d36ee

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

web/src/main/java/org/springframework/security/web/DefaultRedirectStrategy.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ protected String calculateRedirectUrl(String contextPath, String url) {
7474
}
7575

7676
if (!url.contains(contextPath)) {
77-
return "";
77+
throw new IllegalArgumentException("The fully qualified URL does not include context path.");
7878
}
7979

8080
// Calculate the relative URL from the fully qualified URL, minus the last

web/src/test/java/org/springframework/security/web/DefaultRedirectStrategyTests.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public void contextRelativeUrlWithMultipleSchemesInHostnameIsHandledCorrectly()
5757
assertThat(response.getRedirectedUrl()).isEqualTo("remainder");
5858
}
5959

60-
@Test
61-
public void contextRelativeShouldRedirectToRootIfURLDoesNotContainContextPath()
60+
@Test(expected = IllegalArgumentException.class)
61+
public void contextRelativeShouldThrowExceptionIfURLDoesNotContainContextPath()
6262
throws Exception {
6363
DefaultRedirectStrategy rds = new DefaultRedirectStrategy();
6464
rds.setContextRelative(true);
@@ -68,7 +68,5 @@ public void contextRelativeShouldRedirectToRootIfURLDoesNotContainContextPath()
6868

6969
rds.sendRedirect(request, response,
7070
"https://redirectme.somewhere.else");
71-
72-
assertThat(response.getRedirectedUrl()).isEqualTo("");
7371
}
7472
}

0 commit comments

Comments
 (0)