Repository navigation
fix: issue #926 — race conditions in rate limit and failed_login_attempts counters - #1015
Open
Ibochkarev wants to merge 1 commit into
Open
Ibochkarev wants to merge 1 commit into
Ibochkarev wants to merge 1 commit into
Conversation
Ibochkarev
force-pushed
the
fix/926-race-condition-rate-limit
branch
from
November 15, 2026 13:49
8b1a646 to
ed7dc9c
Compare
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.
fix: issue #926 — race conditions in rate limit and failed_login_attempts counters
Problem
Counters for brute-force protection operate via read-modify-write without locking, allowing parallel requests to lose increments.
FileRateLimitStoreread the counter, incremented by 1, wrote back — withoutflockon the entire cycle.RateLimiter(cache-based) read from cache manager, incremented in PHP, then wrote back.AuthManager::handleFailedLogin()read$customer->get('failed_login_attempts') + 1and saved in separate call.A batch of synchronous login requests for the same email counted as fewer attempts than sent. The password-bruteforce window grew, and the lockout triggered after the threshold was passed.
Classification: CWE-362. Severity: Medium for default file store, Low with Redis/Memcached (atomic
INCRavailable).Solution
1.
src/Services/RateLimit/FileRateLimitStore.phpincrement()now usesflock(LOCK_EX)on the entire read-modify-write cycle for atomicity.2.
src/Services/Customer/RateLimiter.phpcheck()now uses$modx->cacheManager->add()for the first attempt (atomic if key doesn't exist).INCR.3.
src/Services/Customer/AuthManager.phphandleFailedLogin()now uses SQLUPDATE ... SET failed_login_attempts = failed_login_attempts + 1, is_blocked = CASE WHEN ...for atomic increment.exec/getTableNameuses the original object-method approach.Affected files
core/components/minishop3/src/Services/RateLimit/FileRateLimitStore.php— atomicflockinincrement()core/components/minishop3/src/Services/Customer/RateLimiter.php— atomicadd()for first attemptcore/components/minishop3/src/Services/Customer/AuthManager.php— atomic SQL UPDATE forfailed_login_attemptsRelated issues
Testing
fix/926-race-condition-rate-limittoproject.test.failed_login_attemptsequals N (not less).ms3_customer_max_login_attemptsattempts exactly.composer test— no regressions expected.Changelog
Branch:
fix/926-race-condition-rate-limitBased on:
beta