Skip to content

Commit e52b104

Browse files
hoseajzheaux
authored andcommitted
Encode postLogoutRedirectUri query params
Now encodes already encoded queryparameters in postLogoutRedirectUrl correctly Closes gh-9511
1 parent 0228570 commit e52b104

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/oidc/web/logout/OidcClientInitiatedLogoutSuccessHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ private URI postLogoutRedirectUri(HttpServletRequest request) {
100100
.replaceQuery(null)
101101
.fragment(null)
102102
.build();
103-
return UriComponentsBuilder.fromUriString(this.postLogoutRedirectUri)
103+
return URI.create (UriComponentsBuilder.fromUriString(this.postLogoutRedirectUri)
104104
.buildAndExpand(Collections.singletonMap("baseUrl", uriComponents.toUriString()))
105-
.toUri();
105+
.toUriString());
106106
}
107107

108108

oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/oidc/web/logout/OidcClientInitiatedLogoutSuccessHandlerTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,17 @@ public void logoutWhenUsingPostLogoutRedirectUriTemplateThenBuildsItForRedirect(
165165
"post_logout_redirect_uri=https://rp.example.org");
166166
}
167167

168+
@Test
169+
public void logoutWhenUsingPostLogoutRedirectUriWithQueryParametersThenBuildItForRedirectWithEncodedQueryParameters() throws IOException, ServletException {
170+
OAuth2AuthenticationToken token = new OAuth2AuthenticationToken(TestOidcUsers.create(),
171+
AuthorityUtils.NO_AUTHORITIES, this.registration.getRegistrationId());
172+
this.handler.setPostLogoutRedirectUri("https://rp.example.org/context?forwardUrl=secured%3Fparam%3Dtrue");
173+
this.request.setUserPrincipal(token);
174+
this.handler.onLogoutSuccess(this.request, this.response, token);
175+
assertThat(this.response.getRedirectedUrl()).isEqualTo(
176+
"https://endpoint?" + "id_token_hint=id-token&" + "post_logout_redirect_uri=https://rp.example.org/context?forwardUrl%3Dsecured%253Fparam%253Dtrue");
177+
}
178+
168179
@Test
169180
public void setPostLogoutRedirectUriWhenGivenNullThenThrowsException() {
170181
assertThatThrownBy(() -> this.handler.setPostLogoutRedirectUri((URI) null))

0 commit comments

Comments
 (0)