Vendure list queries that skip the limit when take is 0 or negative
In Vendure 3.8.2, take: 0 or a negative take returns every row and gets past shopListQueryLimit. How to check your APIs and guard them until a fix ships.
- Vendure
- Migrations
- Operations

You set shopListQueryLimit so nobody can pull more than 100 products in one request. Then an anonymous client sends products(options: { take: 0 }) to your public Shop API and gets the whole catalogue back in one response, plus one unbounded query against your database. No authentication or special headers are needed. Just a number the limit check never looks at.
That is the behaviour described in vendurehq/vendure#5920, reported against @vendure/core 3.8.2 (master) on Postgres. The reporter says a fix and tests are ready and a PR will follow. Until that is merged and released, assume your Shop and Admin APIs are affected and guard them yourself.
How the limits are supposed to work
Vendure has two caps on list queries. apiOptions.shopListQueryLimit defaults to 100. apiOptions.adminListQueryLimit defaults to 1000. Every paginated list query (products, collections, orders, customers and the rest) goes through ListQueryBuilder, which reads options.take and options.skip and turns them into a TypeORM query.
The intended contract has three cases:
takeomitted: you get up to the limit.takeat or below the limit: you get that many.takeabove the limit: you get aUserInputError("Cannot take more than N results from a list query").
The third case is what stops a client asking for 50,000 rows. The bug is that two other inputs skip it entirely.
Why zero and negative values get through
The issue points to ListQueryBuilder.parseTakeSkipParams:
if (options.take && options.take > takeLimit) {
throw new UserInputError('error.list-query-limit-exceeded', { limit: takeLimit });
}
...
let take = options.take == null ? takeLimit : Math.min(Math.max(options.take, 0), takeLimit);
It goes wrong in three steps:
options.take && ...is falsy whentakeis0, so the over-limit check never runs. A negative number is never greater than the limit, so it skips the check too.Math.max(options.take, 0)turns both0and-1into0.- TypeORM treats a
takeof0as "no LIMIT clause".
The reporter set shopListQueryLimit: 5 with 54 products and got these results:
options | result |
|---|---|
| (none) | 5 of 54 |
take: 5 | 5 of 54 |
take: 6 | error |
take: 0 | 54 of 54 |
take: -1 | 54 of 54 |
The existing e2e tests, "take zero is ignored" and "take negative is ignored", pass anyway. Their fixture table has 6 rows and the configured limit is 30, so "no limit" and "use the limit" both return the same 6 rows. Remember that when you write your own tests.
Checking your own Shop and Admin APIs
This takes five minutes. Against a staging instance, run:
curl -s https://staging.example.com/shop-api \
-H 'content-type: application/json' \
-d '{"query":"{ products(options: { take: 0 }) { totalItems items { id } } }"}' \
| jq '.data.products | {totalItems, returned: (.items | length)}'
If returned equals totalItems and that number is above your shopListQueryLimit, you are exposed. Repeat with take: -1. If your catalogue is smaller than the limit, the test proves nothing, for the same reason the upstream tests miss the bug. Lower shopListQueryLimit on staging or seed more products.
Then do the same on /admin-api with an authenticated session. Admin exposure needs credentials, but orders and customers with no cap can still take down a database during a busy period, and any compromised low-privilege admin account can dump them.
Also check your logs. If you log GraphQL variables, search for "take":0 and negative values. Some storefronts send take: 0 on purpose to fetch only totalItems. Those clients are currently downloading every row without knowing it, and a guard that rejects zero will break them. Find them before you deploy.
A stopgap guard at the API layer
The issue confirms there is no configuration workaround. You have two reasonable options.
Reject at the resolver boundary. A small plugin can register a global NestJS interceptor that inspects resolver arguments and throws on a non-positive take:
import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { GqlExecutionContext } from '@nestjs/graphql';
import { PluginCommonModule, UserInputError, VendurePlugin } from '@vendure/core';
@Injectable()
class ListTakeGuard implements NestInterceptor {
intercept(context: ExecutionContext, next: CallHandler) {
if (context.getType<string>() === 'graphql') {
const take = GqlExecutionContext.create(context).getArgs()?.options?.take;
if (take != null && take < 1) {
throw new UserInputError('options.take must be a positive integer');
}
}
return next.handle();
}
}
@VendurePlugin({
imports: [PluginCommonModule],
providers: [{ provide: APP_INTERCEPTOR, useClass: ListTakeGuard }],
})
export class ListTakeGuardPlugin {}
We recommend rejecting over clamping. If you silently turn 0 into the limit, the client never learns its request was invalid, and you are guessing at what it meant. An explicit error is easier to debug and matches what Vendure already does for an over-limit take.
The weak point is nested list fields, such as collection { productVariants(options: { take: 0 }) }. Whether a global interceptor runs on field resolvers depends on how the GraphQL module is configured, so don't assume it does. Test it (see below). If nested fields get through, use the second option.
Patch the core directly. patch-package (or your package manager's built-in patching) against the compiled ListQueryBuilder in node_modules/@vendure/core/dist closes every path at once, because every list query goes through it. Change the guard to throw when options.take != null && (options.take < 1 || options.take > takeLimit). Find the file with grep -rl parseTakeSkipParams node_modules/@vendure/core/dist. The downside is that the patch is tied to an exact version and fails loudly on upgrade, which in this case is what you want: it forces you to check whether the upstream fix has landed.
Tests that actually prove the guard works
Write the test the upstream suite is missing: more rows than the limit.
- Use
@vendure/testingwithshopListQueryLimit: 5andadminListQueryLimit: 5, and seed at least 10 products. - Assert that
take: 0andtake: -1onproductsreturn an error, not 10 items. - Assert that omitting
takereturns 5 and thattake: 5returns 5, so you haven't broken normal pagination. - Repeat the zero and negative cases on one nested list field and on one Admin API query such as
orders. - If you found storefront code that sends
take: 0for counts, add a test for its replacement (take: 1and readtotalItems).
At that size the tests run in seconds, and they will fail if a future upgrade or refactor reopens the hole.
What to do next
Run the curl check against staging today. If the row counts match, deploy the guard, fix any client that relied on take: 0, and add the tests to CI. Subscribe to the issue so you can remove your patch when a release with the upstream fix ships, then rerun the same tests against it.
If you are partway through a move to Vendure, add this to your pre-launch hardening list next to rate limiting and query complexity limits. It is the kind of thing we check on every legacy ecommerce to Vendure migration. If you want a second pair of eyes on your Shop API before go-live, get in touch.
Need this done on a real stack?
Magento 2, Adobe Commerce, migrations to Medusa.js or Vendure, enterprise Next.js, WordPress, and AI automation.
Contact us