Skip to content

823 Corrigir retorno de status ao realizar login com usuário inexistente#851

Open
joaomonte01 wants to merge 2 commits into
devfrom
823-fix-corrigir-retorno-de-status-ao-realizar-login-com-usuário-inexistente

Hidden character warning

The head ref may contain hidden characters: "823-fix-corrigir-retorno-de-status-ao-realizar-login-com-usu\u00e1rio-inexistente"
Open

823 Corrigir retorno de status ao realizar login com usuário inexistente#851
joaomonte01 wants to merge 2 commits into
devfrom
823-fix-corrigir-retorno-de-status-ao-realizar-login-com-usuário-inexistente

Conversation

@joaomonte01

Copy link
Copy Markdown
Contributor

Qual é o objetivo desta PR?

Esta Pull Request resolve uma vulnerabilidade de segurança conhecida como "Enumeração de Usuários" mapeada nas Issues 822 e 823. O sistema estava retornando 404 Not Found quando um e-mail não existia e 400 Bad Request quando a senha estava incorreta. Esse comportamento expunha indiretamente quais e-mails estavam ou não na base de dados do sistema. O objetivo foi padronizar o retorno para 401 Unauthorized com uma mensagem genérica, fortalecendo a segurança da API.

O que foi feito?

  • Unificação no Serviço: A classe AuthApplicationServiceImpl foi alterada para capturar as exceções UserNotFoundException e InvalidPasswordException simultaneamente, mascarando o erro real e lançando sempre um erro genérico de "E-mail ou senha incorretos".

  • Ajuste no Manipulador de Exceções: A classe AuthExceptionHandler foi atualizada para mapear a InvalidPasswordException diretamente para o status HTTP 401 Unauthorized.

  • Ajustes nos Testes Unitários: Os testes shouldReturnUnauthorizedWhenCredentialsAreInvalid e shouldReturnUnauthorizedWhenUserDoesNotExist da classe AuthControllerTest foram atualizados para simular o novo fluxo genérico do serviço, validando perfeitamente o retorno 401.

@joaomonte01 joaomonte01 self-assigned this Jun 9, 2026
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0f467312-0b5d-4202-bb22-b6050e31c034

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 823-fix-corrigir-retorno-de-status-ao-realizar-login-com-usuário-inexistente

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

void shouldReturnUnauthorizedWhenCredentialsAreInvalid() throws Exception {
SignInDTO requestDto = new SignInDTO(
"[email protected]",
"senha-incorreta"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverta todas as alterações nesse arquivo AuthControllerTest.

when(authService.signIn(requestDto))
.thenThrow(new UserNotFoundException());
when(authService.signIn(any(SignInDTO.class)))
.thenThrow(new InvalidPasswordException("E-mail ou senha incorretos"));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retire a string de dentro de todos os InvalidPasswordException (as edições de retorno sempre devem ser feitas dentro do exception em si), e volte com o requestDto dentro dos signIn

.thenThrow(new InvalidPasswordException("E-mail ou senha incorretos"));

mockMvc.perform(post(BASE_URL + "/signin")
mockMvc.perform(post("/auth/signin")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverta todos esses /auth para BASE_URL + "/signin"

@@ -35,136 +35,136 @@

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverta todas as alterações nesse arquivo AuthApplicationService

@JoaoGabrielCosta2004 JoaoGabrielCosta2004 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolver todos os problemas comentados

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants