Repository navigation
Add a generic request limiter and limit password resets - #1546
Merged
Merged
Conversation
Request limits had one implementation, tied to authenticated inference: one policy, keyed by the signed-in account. Routes with no signed-in caller could not use it, and under Transport V2 the edge cannot limit them either, because it sees one encrypted endpoint and the backend has no trusted client address. web/rate_limit.rs replaces the inference limiter with one Limiter type. Each limit is a field of RateLimits with its policy in Rust: admissions per rolling window, an optional fixed cooldown and a key capacity. The key is the account a request acts on: - an authenticated route mounts the enforce_user layer, which charges the verified caller; - an unauthenticated route's handler charges the account the request names, once it has resolved it, with Limiter::check. Limits run on the inner routes, so a rejection is an ordinary response and Transport V2 seals it. The generic one is a 429 with Retry-After and x-opensecret-error-code: rate_limit_exceeded. Inference admission is unchanged: same policy, environment settings and OpenAI-shaped error. Password reset, for user and platform accounts alike: - 5 reset requests per targeted account per rolling hour. Past that the route gives its usual generic answer but creates no request and sends no email. - 5 confirmation attempts per reset request for its 24-hour life. An attempt is charged to the request its secret belongs to; a secret that matches no request is refused uncounted, so only the party that started a request can spend its attempts. State is per process, so this is a guardrail, not a global quota. Part of #1486. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This was referenced Nov 10, 2026
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.
What
Generalizes the inference rate limiter into one in-memory limiter that any inner route can use, and applies it to password reset for user and platform accounts.
Under Transport V2 the edge sees one encrypted endpoint and the backend has no trusted client address, so request limits have to run on the inner routes, after the request is decrypted. The existing limiter did that, but only for authenticated inference: one policy, keyed by the signed-in account.
The limiter (
src/web/rate_limit.rs)Limitertype: admissions per rolling window, an optional fixed cooldown, a key capacity. Live keys are never evicted.RateLimitswith its policy written in Rust.enforce_userlayer, which charges the verified caller;Limiter::check.Retry-Afterandx-opensecret-error-code: rate_limit_exceeded.Inference admission is unchanged: same policy, same
INFERENCE_RATE_LIMIT_*settings, same OpenAI-shaped error.Password reset limits
The same two limits for
/password-reset/*and/platform/password-reset/*:An attempt is charged to the request its secret belongs to. A submission whose secret matches no request of that account cannot complete anything and is refused without being counted, so only the party that started a request can spend its attempts.
Limits of this version
confirm_password_reset.Not in this PR
Login attempt limits, a longer reset code, and cancelling an account's other live codes after a platform reset.
Verification
cargo fmt --check,cargo clippy --all-targets --all-features -- -D warningscargo test --locked --all-features: 1139 passed, 0 failed, 61 ignoredPart of #1486.
🤖 Generated with Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.