You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The join and diary sign-in throttles count before they record, so a burst of parallel requests goes past the limit #163
What is broken.JoinThrottle (server/app/security.py) guards the doors that take a guess:
POST /api/v1/join (class codes);
POST /api/v1/diary/login, where ten failed sign-ins per address per fifteen minutes is the thing standing between whoever holds a URL and the diary's password check from our address.
It works as check, then act, then record. It counts the caller's recent attempts, lets the request through if the count is under the limit, and records the attempt afterwards. Nothing makes the count and the record one step.
Every request that arrives before the first one has recorded therefore sees the same count, and all of them pass.
The failure scenario (on main).
From one address, send 40 wrong-password requests to /api/v1/diary/login at once, against an upstream that takes 0.2 s to answer.
Every request reads the same count of zero before any has written its row.
Far more than ten reach the upstream: 24 of 40 in a reproduction (assert 24 <= 10).
/join has the same shape, so a burst of guesses at eight-character class codes is limited only by how many requests fit before the first record commits. The limit is only as strong as the attacker's patience with parallelism.
Widened on PR #140's branch.POST /api/v1/diary/session shares /login's bucket, and the anonymous school directory (/api/v1/directory/school-regions) uses the same class. For the directory, the same race would let one address spend the whole anonymous share of DaData's daily allowance.
Fix.
Record first, then count. A new JoinThrottle.admit inserts the attempt, commits, then counts including it. It admits while the count is within the limit. Otherwise it deletes its own row and answers with a Retry-After of at least one second.
forgive hands back an attempt that should not count: a 403 invite-only /join, a lost invite race, a request where nothing upstream judged the password.
The test fires 40 concurrent wrong passwords and fails on the old code with assert 24 <= 10.
Unverified: the atomicity is proven on SQLite. On PostgreSQL it rests on READ COMMITTED showing each statement every earlier commit, and has not been run against a live database.
Activity
Close what an audit of the server half found before its migrations go…