|
@@ -1,5 +1,5 @@
|
|
|
/*
|
|
|
- * Copyright 2020-2022 the original author or authors.
|
|
|
+ * Copyright 2020-2023 the original author or authors.
|
|
|
*
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
* you may not use this file except in compliance with the License.
|
|
@@ -18,9 +18,7 @@ package org.springframework.security.oauth2.server.authorization.web;
|
|
|
import java.io.IOException;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.util.Arrays;
|
|
|
-import java.util.HashMap;
|
|
|
import java.util.HashSet;
|
|
|
-import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
|
|
|
import jakarta.servlet.FilterChain;
|
|
@@ -67,6 +65,7 @@ import org.springframework.util.Assert;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.filter.OncePerRequestFilter;
|
|
|
import org.springframework.web.util.UriComponentsBuilder;
|
|
|
+import org.springframework.web.util.UriUtils;
|
|
|
|
|
|
/**
|
|
|
* A {@code Filter} for the OAuth 2.0 Authorization Code Grant,
|
|
@@ -301,13 +300,11 @@ public final class OAuth2AuthorizationEndpointFilter extends OncePerRequestFilte
|
|
|
.queryParam(OAuth2ParameterNames.CODE, authorizationCodeRequestAuthentication.getAuthorizationCode().getTokenValue());
|
|
|
String redirectUri;
|
|
|
if (StringUtils.hasText(authorizationCodeRequestAuthentication.getState())) {
|
|
|
- uriBuilder.queryParam(OAuth2ParameterNames.STATE, "{state}");
|
|
|
- Map<String, String> queryParams = new HashMap<>();
|
|
|
- queryParams.put(OAuth2ParameterNames.STATE, authorizationCodeRequestAuthentication.getState());
|
|
|
- redirectUri = uriBuilder.build(queryParams).toString();
|
|
|
- } else {
|
|
|
- redirectUri = uriBuilder.toUriString();
|
|
|
+ uriBuilder.queryParam(
|
|
|
+ OAuth2ParameterNames.STATE,
|
|
|
+ UriUtils.encode(authorizationCodeRequestAuthentication.getState(), StandardCharsets.UTF_8));
|
|
|
}
|
|
|
+ redirectUri = uriBuilder.build(true).toUriString(); // build(true) -> Components are explicitly encoded
|
|
|
this.redirectStrategy.sendRedirect(request, response, redirectUri);
|
|
|
}
|
|
|
|
|
@@ -341,13 +338,11 @@ public final class OAuth2AuthorizationEndpointFilter extends OncePerRequestFilte
|
|
|
}
|
|
|
String redirectUri;
|
|
|
if (StringUtils.hasText(authorizationCodeRequestAuthentication.getState())) {
|
|
|
- uriBuilder.queryParam(OAuth2ParameterNames.STATE, "{state}");
|
|
|
- Map<String, String> queryParams = new HashMap<>();
|
|
|
- queryParams.put(OAuth2ParameterNames.STATE, authorizationCodeRequestAuthentication.getState());
|
|
|
- redirectUri = uriBuilder.build(queryParams).toString();
|
|
|
- } else {
|
|
|
- redirectUri = uriBuilder.toUriString();
|
|
|
+ uriBuilder.queryParam(
|
|
|
+ OAuth2ParameterNames.STATE,
|
|
|
+ UriUtils.encode(authorizationCodeRequestAuthentication.getState(), StandardCharsets.UTF_8));
|
|
|
}
|
|
|
+ redirectUri = uriBuilder.build(true).toUriString(); // build(true) -> Components are explicitly encoded
|
|
|
this.redirectStrategy.sendRedirect(request, response, redirectUri);
|
|
|
}
|
|
|
|