Repository navigation
Throttle repeated failed Studio logins - #18
Merged
Merged
Conversation
Five failed attempts from one address within 15 minutes now get a 429 until the window ends, the same limit the wire protocol uses. Each attempt runs a PBKDF2 hash, so unlimited retries were also an easy way to burn CPU.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4
POST /api/loginaccepted any number of attempts. It now tracks failures per client address: after 5 failures within 15 minutes the endpoint answers 429 with a short message saying when to try again, and a successful login clears the count. That matches the 5 attempt limit on the wire protocol.The throttle lives in its own small class (
LoginThrottle) with an injectable clock, so the window logic is tested without sleeping. The tracking map drops expired entries once it holds a few thousand addresses, so it can't grow without bound.One thing to keep in mind: behind a reverse proxy every client shares the proxy's address. I didn't trust
X-Forwarded-Forhere since anyone can send it.Tests:
LoginThrottleTest, plusrepeatedFailedLoginsAreThrottledinStudioTest(the sixth attempt gets 429 even with the right password). Full./mvnw installpasses locally.