Repository navigation
fix(auth): hermetic runs allow ten times each rate limit (#1019) - #1026
Merged
Merged
Conversation
…es past ten sign-ins pass (#1019) Every fixture in a hermetic run (test, audit, benchmark, --local-review validate/routes) comes from one client address within seconds, so Better Auth's 10 sign-ins a minute answered 429 on a site whose fixtures sign in more than ten times (store-booking + store-credits merged: 12). An instance activated with the operator host's hermetic flag now multiplies every rate-limit rule's max by ten (default, customRules and a rule function's answer; a disabled rule stays disabled). The limiter stays on, database-stored and keyed by the admitted address, so a fixture can still reach the 429. serve, dev and a pinned validate never set the flag and keep every limit as configured; nothing in YAML or the environment can raise it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Fixes #1019
Problem
In a hermetic run (
urlcode test,audit,benchmark,validate/routes --local-review), every fixture comes from one client address within seconds. Better Auth's limit of 10 sign-ins a minute therefore answered429on the eleventh sign-in, so a site whose fixtures sign in more than ten times (store-booking + store-credits merged withrecipes add: 12; store-credits + store-approval: 14) could not passurlcode test.Design
betterAuthOptionsnow passes the limiter throughrateLimitFor(rateLimit, hermetic). WhenAuthSettings.hermeticis true, every rule'smaxis multiplied byhermeticRateLimitFactor(10): the defaultmax(100 → 1,000), everycustomRulesentry (sign-in 10 → 100, sign-up 5 → 50, and an operator's own rules alike), and the rule a rule function returns. A rule the operator disabled (false) stays disabled.enabled: true,storage: 'database', keyed by the admitted client address, so the rate-limit path is still exercised in hermetic runs and a fixture can still reach the429past the raised bound.hermeticis set only by the operator host'sHostContext.hermetic(RIM-EXT-HERMETIC-001), which also gives the run a throwaway database and random secret. Nothing inurlcode.yamlor the environment reaches it.serve,devand a pinnedvalidateactivate without it and keep every limit as configured.Tests
packages/auth/test/auth.test.ts: a served, non-hermetic mount answers[200 ×10, 429]on 11 sign-ins. The hermetic options are checked: served rules are unchanged, hermetic rules are ×10, operator rules and rule functions are scaled, and disabled stays disabled. A hermetic server with an operator sign-in rule of 2 still answers429on the 21st sign-in.packages/auth/test/recipes.test.ts: authenticated-json-api with its fixtures repeated 12 times (12 sign-ins) passesurlcode test --local-reviewtwice. It fails on main with 429.packages/store/test/recipes.test.ts: store-booking + store-credits and store-credits + store-approval, merged withrecipes add --project, validate, passtesttwice and audit ready.npm run verifyandnpm run test:packagepass locally.Docs
Updated the auth README and SECURITY.md, docs/READINESS.md (rate limits, test data), the RIM-EXT-HERMETIC-001 card, the auth CHANGELOG and the store-booking README.
Limitations
The factor is fixed, so a site with more than 100 fixture sign-ins a minute would still hit the limit. Nothing is reset per fixture, because core exposes no per-fixture hook to extensions.
🤖 Generated with Claude Code