Bug Report: Unbounded limit Parameter Allows Full Dataset Retrieval
Description
The GET /api/models endpoint accepts a limit query parameter that is
validated against NaN (tracked separately) but has no upper bound. A caller
can pass limit=100000 to retrieve the entire model database in a single
HTTP response, bypassing rate limiting intent and causing the Next.js API
route to load the full Prisma result set into memory.
Steps to Reproduce
- Call the API with an extreme limit:
GET /api/models?limit=100000&offset=0
- Observe all records are returned in one response.
- Monitor the Next.js server process memory during the request.
Root Cause
The limit parameter is parsed with parseInt but validated only for NaN,
not for an upper boundary. The Prisma query's take is set directly to the
parsed value.
Impact
The entire AI model directory can be bulk-scraped with a single request,
defeating any rate-limiting strategy based on per-request cost. Large result
sets also cause memory spikes in the serverless function runtime.
Proposed Fix
Cap the limit parameter at a reasonable maximum:
const limit = Math.min(Math.max(parseInt(searchParams.get("limit") ?? "20"), 1), 100);
const offset = Math.max(parseInt(searchParams.get("offset") ?? "0"), 0);
if (isNaN(limit) || isNaN(offset)) {
return NextResponse.json({ error: "Invalid pagination parameters" }, { status: 400 });
}
Bug Report: Unbounded limit Parameter Allows Full Dataset Retrieval
Description
The
GET /api/modelsendpoint accepts alimitquery parameter that isvalidated against NaN (tracked separately) but has no upper bound. A caller
can pass
limit=100000to retrieve the entire model database in a singleHTTP response, bypassing rate limiting intent and causing the Next.js API
route to load the full Prisma result set into memory.
Steps to Reproduce
Root Cause
The
limitparameter is parsed withparseIntbut validated only for NaN,not for an upper boundary. The Prisma query's
takeis set directly to theparsed value.
Impact
The entire AI model directory can be bulk-scraped with a single request,
defeating any rate-limiting strategy based on per-request cost. Large result
sets also cause memory spikes in the serverless function runtime.
Proposed Fix
Cap the
limitparameter at a reasonable maximum: