Login throttling and lockout (release blocker for #136) #138
Labels
No labels
Area/Backend
Area/Database
Area/Docs
Area/Frontend
Area/Infra
Area/Security
Area/Tests
Area/Tooling
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Lang/Python
Lang/Rust
Lang/Shell
Lang/SQL
Lang/TypeScript
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Routing
Auto
Routing
Hold
Routing
Human
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Grimoirix/grimoire-of-digital-signage#138
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Security review on release PR #136 (Aegis, REQUEST_CHANGES) found that login has no throttling and no lockout.
plan/server/users-and-permissions.md"Login" lists both for this release (not in its "Later" table). The server is on the internet behind the reverse proxy, and the one admin account controls every screen on every campus.Scope (MVP, keep it small)
POST /api/v1/session, keyed by account (email) and by client IP. Client IP is the one fromclient_ip.rs(trusted-proxy aware), never the raw header.429withRetry-AfterbeforePasswordHasher::verifyruns. Threshold and window come from config (SIGNAGE_*env + config file, with defaults; GRI-1884 rule: no hard-coded values the operator cannot change). Suggested defaults: 5 failures per account per 15 min, 20 per IP per 15 min.Out of scope here, follow-up later: per-IP cap on pending device registrations, audit log, upload magic-byte check (all non-blocking in the review).
Done when
PR to
dev, required CI green, Vivy merges, then Aegis re-reviews #136. Deadline: build by 11-17, so this is the top item now.Fixed the race Vivy's 13:50 review found:
check()and the failure count were two separate operations, so concurrent requests could all passcheck()before any of them was counted.Change:
LoginThrottle::checknow reserves the attempt's slot atomically with the threshold test (test-and-increment under one lock, inBucket::reserve). A success (record_success) releases the IP's reserved slot — so a successful login still never counts against the IP's budget — and resets the account counter entirely. A failure leaves the reservation in place;record_failureis gone, since the reservation itself is now the count.Also pruned expired entries on every reservation, so the maps can't grow without bound (per the review).
Added
concurrent_attempts_past_the_threshold_let_through_exactly_the_threshold: 50 threads hammercheck()for one account withmax_attempts = 5; exactly 5 succeed. This fails against the old code (far more than 5 get through) and passes now.Verified:
cargo test -p server --lib throttle::— 9/9 pass (including the new concurrency test).cargo test -p server --test auth_integration— 12/12 pass, incl.the_attempt_after_the_account_threshold_is_throttled_before_the_password_is_checkedanda_successful_login_resets_the_account_counter, unchanged.cargo clippy -p server --all-targets -- -D warnings— clean.cargo fmt --check -p server— clean.scripts/local-gates.sh --rust-onlyon commitc8544bain wt-GRI-1922: every gate passed (fmt, clippy -D warnings, cargo deny, cargo test incl. DB-backed integration suites, repo-boundary, pre-push hook).Pushed to the existing branch — PR #139 updated: #139
Fixed by PR #139, merged into dev (atomic reserve, concurrency test, expired-entry sweep).