Repository navigation
Conversation
The current-password check of the profile password change had no limit: a
session could guess the password without a bound, and a correct guess both
changes the password and gives the secret that 2fa/disable and
recovery-codes/regenerate ask for, so the limit added to those two could be
sidestepped. The OAuth2 profile update reaches the same check.
- UserService::update: a wrong or missing current_password consumes the
password_confirm limit of the acting user (the counter 2fa/disable and
recovery-codes/regenerate share), keyed by the (int) user id the service
already resolves, so it also works on a token request with no session
- the attempt is reserved first and refunded when the password is right: a
successful change never counts, and a user over the limit gets the 429
without learning if the password was right; a save without password is
never limited
- new TwoFactorRateLimitedException, mapped to 429 with Retry-After in
APICRUDController::_update (PUT admin/api/v1/users/me and users/{id}) and
OAuth2UserApiController::_update (PUT api/v1/users/me), which turned it
into a 500
- tests with the whole middleware stack for the admin routes, the shared
counter and the OAuth2 route with a token and no session
ClickUp 1k5eh578uwa
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
📘 OpenAPI / Swagger preview ➡️ https://OpenStackweb.github.io/openstackid/openapi/pr-211/ This page is automatically updated on each push to this PR. |
ref: https://app.clickup.com/t/1k5eh578uwa
Summary
The current-password check of the profile password change had no rate limit. A signed-in session could guess the account password without a bound, and a correct guess both changes the password and gives the secret that
2fa/disableandrecovery-codes/regenerateask for, so the limit added to those two could be sidestepped. The OAuth2 profile update reaches the same check, so a stolen access token could guess the password the same way.A failed current-password check now counts against the same per-user
password_confirmlimit as2fa/disableandrecovery-codes/regenerate(5 failures per 15 minutes), on every entry point of that check, and answers429withRetry-Afteronce the limit is reached.The base is the MFA branch (
feat/mfa-phase1---migrations--and--interfaces), notmain: thepassword_confirmlimiter introduced by #187 only exists there.Changes
UserService::update: a wrong or missingcurrent_passwordconsumes thepassword_confirmlimit of the acting user. The counter is keyed by the(int)user id the service already resolves (resource-server context first, then the session), so it is the same cache key the2fa.rate:password_confirmmiddleware uses and it also works on a token request with no session.passwordis never limited.TwoFactorRateLimitedException, mapped to429(Retry-After,X-RateLimit-*, themfa_rate_limitbody of the middleware) inAPICRUDController::_update(PUT admin/api/v1/users/meandPUT admin/api/v1/users/{id}) and inOAuth2UserApiController::_update(PUT api/v1/users/me), which otherwise turned it into a 500.PUT api/v1/users/{id}of the OAuth2 API goes through the same_update.2fa.rate:password_confirmmiddleware is deliberately not put on these routes: it counts every non-2xx response, so the validation errors of an ordinary profile save would use up the limit, and its limiter returns no limit whenAuth::id()is null, which is the case with a token.Tests
tests/UserUpdatePasswordRateLimitTest.php(8 tests, the router and the whole middleware stack): sixth wrong guess answers 429 withRetry-Afterand the password is unchanged; a missingcurrent_passwordcounts; one counter shared with2fa/disablein both directions; a save withoutpasswordand validation errors never count; a correct password changes it and does not count; forusers/{id}the counter is the acting user's, not the target's.tests/OAuth2UserUpdatePasswordRateLimitTest.php(2 tests): with a valid access token and no session (Auth::id()is null), the sixth wrong guess answers 429 withRetry-After, not 500; a correct password within the limit changes it and does not count.OAuth2UserApiTest,OAuth2UserUpdateApiTest,DisableTwoFactorEndpointTest,RecoveryCodeRegenerationTest,PasswordChangeRevokeTokenTest,AdminUserTwoFactorUpdateTest.current_password is not correct.(412) and the sixth showsToo many attempts. Please try again later.(429) in the existing error dialog.Notes
2fa/disable, the 429 carriesRetry-After, and "forgot password" still works.DoctrineTransactionServiceretries it after a lost connection a failure could count twice, which errs on the safe side.PUT users/me, rate limiting of the sign-in form, the password policy, how event-site shows the 429.idp-mfa.md§4.12) update is in the docs repo and goes separately.Summary by CodeRabbit