Repository navigation
Conversation
Failed admin logins were unbounded, so a single client could brute-force credentials against /api/admin/login. Unknown accounts and disabled accounts also answered faster or differently than active ones, which turned the endpoint into an account-enumeration oracle. Add an in-memory limiter that tracks failures per source address and per account identity, counting in-flight attempts so parallel bursts cannot skip the threshold, and answer with 429 plus Retry-After. Reserve a slot before verification and settle it by outcome; a successful login clears the account budget so operators who mistyped a password are not locked out. Make the credential check itself uninformative: spend comparable bcrypt work when the account is missing, verify the password before evaluating account status, and fall back to a dummy hash when the stored hash is not bcrypt so legacy rows cannot be distinguished by timing.
Author
|
CI shows I pre-ran the equivalent checks locally at this exact head ( Happy to adjust anything if you'd rather see a different shape. |
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.
Summary
POST /api/admin/loginaccepts an unlimited number of attempts. A single client can therefore brute-force an administrator password, and the endpoint also answers in distinguishable ways: an unknown identity returns quickly while an existing identity spends bcrypt time, and a disabled account returns403 admin_user_disabledbefore the password is checked. Together these turn the login form into an account-enumeration and password-guessing surface.This change bounds failed attempts and makes the credential check itself uninformative about account state.
Related Issue
N/A
Changes
429 login_rate_limitedwith aRetry-Afterheader.Type of Change
Verification
go build ./...passes.go vet ./internal/serverpasses.go test ./internal/server -run 'TestAdminLogin|TestAdminPasswords|TestLegacyAdminPassword|TestOversizeLegacyAdminPassword' -count=1passes.go test ./internal/serverstill fails only in pre-existing subscription-worker tests ("The subscription runtime stopped; retry the request"). The same failures reproduce on unmodifiedmain, so they are unrelated to this change.git diff --checkpasses;gofmt -lreports no files.Compatibility, Security, and Operations
429as a possible status withRetry-After.429, which is intentional: the limiter must not leak whether the credential was right.403 admin_user_disabled. Clients that relied on the previous immediate403will see403only after the password is verified.Checklist
.envfiles, databases, backups, or runtime logs are included.start.sh, and deployment documentation where applicable.data/model-catalog.yamlremains tracked and catalog changes were reviewed where applicable.git diff --checkpasses.