Skip to content

Commit

Permalink
Encode URL in OIDC cookie
Browse files Browse the repository at this point in the history
Fix #31802
  • Loading branch information
gsmet committed Aug 22, 2024
1 parent c75c0f4 commit 3ffa6ec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import static io.quarkus.oidc.runtime.OidcIdentityProvider.REFRESH_TOKEN_GRANT_RESPONSE;

import java.net.URI;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.security.PrivateKey;
import java.security.SecureRandom;
Expand Down Expand Up @@ -940,7 +942,7 @@ private CodeAuthenticationStateBean getCodeAuthenticationBean(String[] parsedSta
Authentication authentication = configContext.oidcConfig.authentication;
boolean pkceRequired = authentication.pkceRequired.orElse(false);
if (!pkceRequired && !authentication.nonceRequired) {
bean.setRestorePath(parsedStateCookieValue[1]);
bean.setRestorePath(URLDecoder.decode(parsedStateCookieValue[1], StandardCharsets.UTF_8));
return bean;
}

Expand Down Expand Up @@ -1177,7 +1179,7 @@ private String encodeExtraStateValue(CodeAuthenticationStateBean extraStateValue
throw new AuthenticationCompletionException(ex);
}
} else {
return extraStateValue.getRestorePath();
return URLEncoder.encode(extraStateValue.getRestorePath(), StandardCharsets.UTF_8);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import java.io.IOException;
import java.net.URI;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.Base64;
Expand Down Expand Up @@ -1561,12 +1562,12 @@ private String getStateCookieStateParam(Cookie stateCookie) {

private String getStateCookieSavedPath(WebClient webClient, String tenantId) {
String[] parts = getStateCookie(webClient, tenantId).getValue().split("\\|");
return parts.length == 2 ? parts[1] : null;
return parts.length == 2 ? URLDecoder.decode(parts[1], StandardCharsets.UTF_8) : null;
}

private String getStateCookieSavedPath(Cookie stateCookie) {
String[] parts = stateCookie.getValue().split("\\|");
return parts.length == 2 ? parts[1] : null;
return parts.length == 2 ? URLDecoder.decode(parts[1], StandardCharsets.UTF_8) : null;
}

private Cookie getSessionCookie(WebClient webClient, String tenantId) {
Expand Down

0 comments on commit 3ffa6ec

Please sign in to comment.