Repository navigation
feat(auth): add per-IP rate limit for login and OAuth token endpoints - #9
Merged
Merged
Conversation
Replaces Cloudflare ruleset auth_rate_limit (F-05 c1), which stopped applying when torosaba.net left the Cloudflare Tunnel for the direct path on 2026-11-27. 20 requests per 10 seconds per client IP on /login, /oauth/register and /oauth/token; the 21st request starts a 10 second block answered with 429 and Retry-After: 10. Client IP comes from the X-Toro-Client-Ip header set by toro-edge (Caddy strips client-supplied values). No new dependency.
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.
概要
Cloudflare ruleset
auth-rate-limit(F-05 c1)の代替として、toro-auth にアプリケーションレベルのレート制限を実装する。2026-11-27 03:00 JST の torosaba.net 直接化(Cloudflare Tunnel 全廃)により、Cloudflare を経由しなくなったため同 ruleset は直接経路では適用されなくなった。Caddy では再現できないため、対象サービス自身に同等の制限を持つ。
内容
/login・/oauth/register・/oauth/token(ruleset と同一)Retry-After: 10を返す(Cloudflare の観測された block 応答と同一)X-Toro-Client-Ipヘッダーから取る(toro-edge がCf-Connecting-Ipから設定し、Caddy がクライアント供給値を除去するため偽装できない)answer()の/healthz早期復帰の直後、セマフォ取得と本文読み取りの前テスト
src/rate_limit.rs)と結合テスト 3 件(tests/rate_limit.rs)を新設health_checks_answer_even_when_every_slot_is_takenは、256 件の遅い要求が同一バケットで 21 件目以降 429 となりスロットを埋められなくなったため、要求ごとに別のクライアント IP を入れる形へ修正(判定の意図は不変)cargo fmt --check、cargo clippy --all-targets --locked -- -D warnings、cargo test --locked(154 件全合格)を確認済み