Unbounded Query
.findMany() / .select('*') with no limit
warningPerformance
no-unbounded-queryWhy this matters
A query without a LIMIT returns every row in the table. As your data grows, this query gets slower, uses more memory, and eventually crashes your server or browser.
Example
app/api/users/route.tsexport async function GET() {
// Returns ALL users — could be millions
const users = await db.user.findMany();
return Response.json(users);
}app/api/users/route.tsexport async function GET(req: Request) {
const url = new URL(req.url);
const page = parseInt(url.searchParams.get("page") ?? "1");
const users = await db.user.findMany({
take: 50,
skip: (page - 1) * 50,
orderBy: { createdAt: "desc" },
});
return Response.json(users);
}How to fix
Add a LIMIT (take) and pagination to every query that returns a list. Default to a reasonable page size (20-100 items).
Reference
- In the output
- Findings carry
"ruleId": "no-unbounded-query"in--jsonand the same id in SARIF and in the terminal. - Silence one line
// prodlint-disable-next-line no-unbounded-query- Silence a whole file
// prodlint-disable no-unbounded-queryat the top of the file- How it works
- Matches text patterns. Source on GitHub