fix(serve): bound n_docs to prevent unbounded-search OOM/DoS#122
Open
dex0shubham wants to merge 1 commit into
Open
fix(serve): bound n_docs to prevent unbounded-search OOM/DoS#122dex0shubham wants to merge 1 commit into
dex0shubham wants to merge 1 commit into
Conversation
n_docs had no limit and fetch_k = n_docs * 10 feeds FAISS's search k, so a request with a huge n_docs triggers a massive allocation on the public endpoint. Constrain to 1..1000 via pydantic Field (largest real caller uses 10). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
@dex0shubham is attempting to deploy a commit to the andylizf's projects Team on Vercel. A member of the Team first needs to authorize it. |
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.
Problem
SearchRequest.n_docshad no bound (n_docs: int = 10), and downstreamfetch_k = req.n_docs * 10feeds FAISS's searchk. A request like{"queries": [...], "n_docs": 100000000}forces a huge result-buffer allocation onthe public
/searchendpoint — a trivial OOM/DoS. Zero and negative values were alsoaccepted.
Fix
Constrain via pydantic:
n_docs: int = Field(default=10, ge=1, le=1000). The largestreal caller (README examples, web app, eval harness) uses
10, so the1000cap isgenerous. One line, declarative, no behavior change for valid requests; out-of-range
values now return a 422 instead of degrading the service.