Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Address User-Controlled Data Risk in isAuthenticated() #27562

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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 @@ -117,15 +117,15 @@ public class AuthenticateController {
<%_ } _%>

/**
* {@code GET /authenticate} : check if the user is authenticated, and return its login.
* {@code GET /authenticate} : check if the user is authenticated, and return a boolean value.
*
* @param principal the authentication principal.
* @return the login if the user is authenticated.
* @return a boolean indicating if the user is authenticated.
*/
@GetMapping(value = "/authenticate", produces = MediaType.TEXT_PLAIN_VALUE)
public String isAuthenticated(Principal principal) {
@GetMapping(value = "/authenticate")
public Boolean isAuthenticated(Principal principal) {
LOG.debug("REST request to check if the current user is authenticated");
return principal == null ? null : principal.getName();
return principal != null;
}

public String createToken(Authentication authentication, boolean rememberMe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,17 @@ class AccountResourceIT {
<%_ if (reactive) { _%>
void testNonAuthenticatedUser() {
accountWebTestClient.get().uri("/api/authenticate")
.accept(MediaType.TEXT_PLAIN)
.exchange()
.expectStatus().isOk()
.expectBody().isEmpty();
.expectStatus()
.isOk()
.expectBody(Boolean.class)
.isEqualTo(false);
<%_ } else { _%>
void testNonAuthenticatedUser() throws Exception {
restAccountMockMvc
.perform(get("/api/authenticate").accept(MediaType.TEXT_PLAIN))
.perform(get("/api/authenticate"))
.andExpect(status().isOk())
.andExpect(content().string(""));
.andExpect(content().string(Boolean.FALSE.toString()));
<%_ } _%>
}

Expand All @@ -192,17 +193,20 @@ class AccountResourceIT {
<%_ if (reactive) { _%>
void testAuthenticatedUser() {
accountWebTestClient
.get().uri("/api/authenticate")
.accept(MediaType.TEXT_PLAIN)
.get()
.uri("/api/authenticate")
.exchange()
.expectStatus().isOk()
.expectBody(String.class).isEqualTo(TEST_USER_LOGIN);
.expectStatus()
.isOk()
.expectBody(Boolean.class)
.isEqualTo(true);
<%_ } else { _%>
void testAuthenticatedUser() throws Exception {
restAccountMockMvc
.perform(get("/api/authenticate").with(request -> request).accept(MediaType.TEXT_PLAIN))
.perform(get("/api/authenticate")
.with(request -> request))
.andExpect(status().isOk())
.andExpect(content().string(TEST_USER_LOGIN));
.andExpect(content().string(Boolean.TRUE.toString()));
<%_ } _%>
}

Expand Down
Loading