Skip to content

fix(a4): prevent brute force in password recovery - #658

Open
gabrielesequeira wants to merge 1 commit into
globocom:masterfrom
gabrielesequeira:feature/a4-insecure-design
Open

gabrielesequeira wants to merge 1 commit into
globocom:masterfrom
gabrielesequeira:feature/a4-insecure-design

Conversation

@gabrielesequeira

Copy link
Copy Markdown

This solution refers to which of the apps?

A4 - Insecure Design - Super Recovery Password.

What did you do to mitigate the vulnerability?

I implemented a rate limiter to make brute-force attacks against the password recovery feature more difficult.

First, I created a new file, rate_limiter.go, inside src/api/security/. It tracks failed attempts for each username and allows a maximum of 5 failed attempts within 15 minutes.

Then, I modified RecoveryPassword.go to integrate this protection into the recovery process. Before checking the security answers, the application verifies whether the user has reached the attempt limit. If so, it blocks the request and returns HTTP 429 (Too Many Requests).

Every failed attempt is recorded, and the counter is reset when the password recovery is successful.

Did you test your changes? What commands did you run?

Yes. I manually tested the /recovery endpoint using PowerShell's Invoke-RestMethod, with the existing username thiago and incorrect security answers.

After 5 failed attempts, the sixth request was blocked, returning:

{
  "message": "too many attempts. Try again later."
}

After that, I ran make bruteforce to test the protection using the application's own brute-force script.

The script continued sending requests and counting attempts because it was designed to stop only when it received HTTP status 200 (OK), which indicates a successful password recovery. It did not check for HTTP status 429 (Too Many Requests), so it kept trying even after the API started blocking the requests.

This showed that the rate limiter was working on the server side, rejecting additional attempts, even though the brute-force script itself did not stop automatically.

@vitor-mauricio

Copy link
Copy Markdown

Hi @gabrielesequeira , while testing the application with your proposed solution, I was no longer able to perform a brute-force attack to recover a password. However, I was still able to successfully carry out a user enumeration attack.

Additionally, I noticed that the solution introduces a scenario in which a legitimate user could be prevented from recovering their own account password. For example, an attacker could repeatedly trigger password recovery requests for a specific account, effectively blocking the legitimate user from completing the recovery process.

Given this potential issue, do you believe this is the most effective approach, or are there alternative mitigations we should consider 🤔 ?

@gabrielesequeira

Copy link
Copy Markdown
Author

Thanks for the feedback! You're right, the current approach could allow an attacker to lock a legitimate user out of the recovery process. I think we could explore alternatives, such as limiting attempts by IP address instead of only by username. Do you think it would be a better approach?

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