Throttle counters move from an actor's dictionary into Postgres.
Why. Every restart cleared them, so a deploy, a crash or an OOM kill handed out a fresh registration budget from every address. Found by exploiting it — restarting the accounts container to get past the limit during testing worked, and anything that works for me works for a script.
What changed
SQL/030_rate_limits.sql — rate_hits plus rate_allow/rate_reset/rate_sweep. One row per attempt, because the window slides and only timestamps answer "three in the last hour".
The decision happens inside rate_allow under a per-bucket advisory lock. Counting in the service and inserting afterwards is a check-then-act race. Negative control: without the lock, 40 concurrent callers against a limit of 5 admitted 7.
AddRateLimitCounters is a new migration, never an edit to an applied one.
allow throws rather than failing open — a limiter weakest when the database is sick is weakest exactly when it is most wanted.
The in-memory limiter stays as the reference implementation the unit tests pin.
Testing
scripts/test-rate-limits.sh — 18 checks against a real Postgres.
scripts/test-throttle-restart.sh — 11 checks driving the real binary over HTTP, ending in a restart that confirms the budget is still spent.
⚠️ The second script exists because the first was not enough: the SQL tests passed while the service returned 500 on every sign-in. psql sends literals the parser coerces; the driver binds binary with a declared type, so text and bigint reached a function taking interval and integer and no call resolved. Fixed with explicit casts.
Deploy.accounts-migrate runs before accounts starts, so the table is in place first. ENCLAVE_AUTO_MIGRATE is not set in prod and is not needed.
Throttle counters move from an actor's dictionary into Postgres.
**Why.** Every restart cleared them, so a deploy, a crash or an OOM kill handed out a fresh registration budget from every address. Found by exploiting it — restarting the accounts container to get past the limit during testing worked, and anything that works for me works for a script.
**What changed**
- `SQL/030_rate_limits.sql` — `rate_hits` plus `rate_allow`/`rate_reset`/`rate_sweep`. One row per attempt, because the window slides and only timestamps answer "three in the last hour".
- The decision happens inside `rate_allow` under a per-bucket advisory lock. Counting in the service and inserting afterwards is a check-then-act race. Negative control: without the lock, 40 concurrent callers against a limit of 5 admitted **7**.
- `AddRateLimitCounters` is a new migration, never an edit to an applied one.
- `allow` throws rather than failing open — a limiter weakest when the database is sick is weakest exactly when it is most wanted.
- The in-memory limiter stays as the reference implementation the unit tests pin.
**Testing**
- `scripts/test-rate-limits.sh` — 18 checks against a real Postgres.
- `scripts/test-throttle-restart.sh` — 11 checks driving the real binary over HTTP, ending in a restart that confirms the budget is still spent.
⚠️ The second script exists because the first was not enough: the SQL tests passed while the service returned **500 on every sign-in**. psql sends literals the parser coerces; the driver binds binary with a declared type, so `text` and `bigint` reached a function taking `interval` and `integer` and no call resolved. Fixed with explicit casts.
**Deploy.** `accounts-migrate` runs before `accounts` starts, so the table is in place first. `ENCLAVE_AUTO_MIGRATE` is not set in prod and is not needed.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Throttle counters move from an actor's dictionary into Postgres.
Why. Every restart cleared them, so a deploy, a crash or an OOM kill handed out a fresh registration budget from every address. Found by exploiting it — restarting the accounts container to get past the limit during testing worked, and anything that works for me works for a script.
What changed
SQL/030_rate_limits.sql—rate_hitsplusrate_allow/rate_reset/rate_sweep. One row per attempt, because the window slides and only timestamps answer "three in the last hour".rate_allowunder a per-bucket advisory lock. Counting in the service and inserting afterwards is a check-then-act race. Negative control: without the lock, 40 concurrent callers against a limit of 5 admitted 7.AddRateLimitCountersis a new migration, never an edit to an applied one.allowthrows rather than failing open — a limiter weakest when the database is sick is weakest exactly when it is most wanted.Testing
scripts/test-rate-limits.sh— 18 checks against a real Postgres.scripts/test-throttle-restart.sh— 11 checks driving the real binary over HTTP, ending in a restart that confirms the budget is still spent.⚠️ The second script exists because the first was not enough: the SQL tests passed while the service returned 500 on every sign-in. psql sends literals the parser coerces; the driver binds binary with a declared type, so
textandbigintreached a function takingintervalandintegerand no call resolved. Fixed with explicit casts.Deploy.
accounts-migrateruns beforeaccountsstarts, so the table is in place first.ENCLAVE_AUTO_MIGRATEis not set in prod and is not needed.mentioned in commit
784ba853c8