Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -47,7 +47,12 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo
String relayState = UaaStringUtils.getCleanedUserControlString(request.getParameter(Saml2ParameterNames.RELAY_STATE), UaaStringUtils.EMPTY_STRING);
if (UaaStringUtils.hasText(relayState) && UaaUrlUtils.isUrl(relayState)) {
log.debug("Redirecting to relayState URI: {}", relayState);
this.getRedirectStrategy().sendRedirect(request, response, relayState);
java.util.List<String> samlRelayStateWhitelist = java.util.Optional.ofNullable(
org.cloudfoundry.identity.uaa.zone.IdentityZoneHolder.get().getConfig().getLinks().getLogout().getWhitelist()
).orElse(java.util.Collections.emptyList());
String fallbackUrl = this.getDefaultTargetUrl();
String matchingRedirectUri = UaaUrlUtils.findMatchingRedirectUri(samlRelayStateWhitelist, relayState, fallbackUrl);
this.getRedirectStrategy().sendRedirect(request, response, matchingRedirectUri);
Comment thread
joemahady-comm marked this conversation as resolved.
Outdated
Comment thread
joemahady-comm marked this conversation as resolved.
Outdated
} else {
super.onAuthenticationSuccess(request, response, authentication);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,35 @@ void invalidFormRedirectIsNotReturned() {
}

@Test
void onAuthenticationSuccess_noSavedRequest_hasRelayStateUrl() throws Exception {
void onAuthenticationSuccess_noSavedRequest_hasRelayStateUrl_notWhitelisted() throws Exception {
String redirectUri = "https://test.com/test2";
request.setParameter(Saml2ParameterNames.RELAY_STATE, redirectUri);

var response = new MockHttpServletResponse();
var authentication = mock(Authentication.class);
handler.onAuthenticationSuccess(request, response, authentication);

assertThat(response.getRedirectedUrl()).isEqualTo("/");
}

@Test
void onAuthenticationSuccess_noSavedRequest_hasRelayStateUrl_whitelisted() throws Exception {
String redirectUri = "https://test.com/test2";
request.setParameter(Saml2ParameterNames.RELAY_STATE, redirectUri);

org.cloudfoundry.identity.uaa.zone.IdentityZone zone = org.cloudfoundry.identity.uaa.zone.IdentityZoneHolder.get();
zone.getConfig().getLinks().getLogout().setWhitelist(java.util.List.of("https://test.com/test2"));
org.cloudfoundry.identity.uaa.zone.IdentityZoneHolder.set(zone);

var response = new MockHttpServletResponse();
var authentication = mock(Authentication.class);
handler.onAuthenticationSuccess(request, response, authentication);

assertThat(response.getRedirectedUrl()).isEqualTo(redirectUri);

// clean up
zone.getConfig().getLinks().getLogout().setWhitelist(null);
org.cloudfoundry.identity.uaa.zone.IdentityZoneHolder.clear();
}
Comment thread
joemahady-comm marked this conversation as resolved.

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ void relayStateRedirectFromIdpInitiatedLogin() {
webDriver.findElement(By.xpath(samlServerConfig.getLoginPromptXpathExpr()));
sendCredentials(testAccounts.getUserName(), testAccounts.getPassword());
Page.assertThatUrlEventuallySatisfies(webDriver,
assertUrl -> assertUrl.startsWith("https://www.google.com"));
assertUrl -> assertUrl.startsWith(baseUrl));

webDriver.get("%s/logout.do".formatted(baseUrl));
}
Expand Down Expand Up @@ -1228,7 +1228,7 @@ void backportFrom77RelayTest() {
sendCredentials(testAccounts.getUserName(), "koala");

Page.assertThatUrlEventuallySatisfies(webDriver,
assertUrl -> assertUrl.startsWith("https://www.google.com"));
assertUrl -> assertUrl.startsWith(zoneUrl));
webDriver.get(baseUrl + "/logout.do");
webDriver.get(zoneUrl + "/logout.do");
}
Expand Down
Loading