Repository navigation
Conversation
When DEFAULT_RATE_LIMIT_MAX is set, chatflows with no configured limit get a default per-minute limit on /prediction. Identified callers (optional auth from the previous commits) get their own bucket; anonymous callers are counted by IP. Configured chatflow limits and /vectors are unchanged. Auth now runs before the limiter so the key can use req.user. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch had an error being deployed
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.
Why
/api/v1/predictionhas no limit unless someone configures one per chatflow (utils/rateLimit.ts: no limiter →next()). Anyone with the id of a public chatflow can call it without limit, and every call runs the flow (an LLM call we pay for).Stacked on #1095 (optional auth on
/prediction). Pairs with #1096 (TRUST_PROXY=1), which stops callers from faking their IP; without #1096 the IP-keyed part of this limit can be bypassed the same way configured limits are today.What changes
DEFAULT_RATE_LIMIT_MAXis a positive integer, a chatflow with no configured limit getsDEFAULT_RATE_LIMIT_MAXrequests perDEFAULT_RATE_LIMIT_WINDOW_SECONDS(default 60). Unset or invalid (0,-1,1.5,abc) → no change from today.<chatflowId>:user:<userId>or<chatflowId>:ip:<ip>. People behind one office IP using the extension don't share a bucket. The key never contains the email./prediction./vectors/upsertkeeps today's behavior (bulk ingestion scripts call it many times a minute).rl:default:), same as configured limits.req.user. Cost: a forged JWT pays one signature check (no DB) before the 429.addRateLimiterbody moved to a privatecreateLimiter; behavior unchanged.Tests (all local)
test/utils/rateLimit, 15, realexpress-rate-limit): default off, invalid values ignored, limit hit on the 3rd call, per chatflow, two users on one IP separate, anonymous on one IP shared, configured limit wins and keys by IP,/vectorspath ignores the default, no id doesn't throw, Redis store prefix, no email in key. Router: auth runs before the limiter.test/integration/rateLimit, Postgres 16 + real RS256 tokens,DEFAULT_RATE_LIMIT_MAX=2): alice 200,200,429 then bob on the same IP 200; anonymous 200,200,429; forged token lands in the anonymous IP bucket and creates no user. With the router order reverted, bob gets 429 (the test catches it).sendCommand, the no-id bucket name,max >= 0which express-rate-limit 6.11.2 also treats as unlimited, and two pre-existing route strings). A first run found a real gap (invalidDEFAULT_RATE_LIMIT_MAXvalues); test added.stagingbefore this branch (documentstore3 tests,auth/middlewaresuite fails to load), all new tests pass.tscandeslintexit 0.test/integration/auth0Fixture.ts;test/integration/predictionuses it and still passes 9/9.Rollout
Off everywhere until
DEFAULT_RATE_LIMIT_MAXis set. Plan: after #1096 is deployed and/api/v1/ipis verified onstaging.ias, set it there first. The number comes from Langfuse peaks (3× the real per-minute peak per person, min 20) and needs Max's OK before IAS production.🤖 Generated with Claude Code