Skip to content

Commit cc64042

Browse files
committed
fix(sec): set default maximum batching size to 1000 to prevent Denial of Service
Signed-off-by: hainenber <[email protected]>
1 parent 77c2cd7 commit cc64042

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

.changeset/silent-cooks-visit.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'dataloader': minor
3+
---
4+
5+
set default maximum batching size to 1000 to prevent Denial of Service.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ Create a new `DataLoader` given a batch loading function and options.
395395
| Option Key | Type | Default | Description |
396396
| ----------------- | -------- | ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
397397
| `batch` | Boolean | `true` | Set to `false` to disable batching, invoking `batchLoadFn` with a single load key. This is equivalent to setting `maxBatchSize` to `1`. |
398-
| `maxBatchSize` | Number | `Infinity` | Limits the number of items that get passed in to the `batchLoadFn`. May be set to `1` to disable batching. |
398+
| `maxBatchSize` | Number | `1000` | Limits the number of items that get passed in to the `batchLoadFn`. May be set to `1` to disable batching. |
399399
| `batchScheduleFn` | Function | See [Batch scheduling](#batch-scheduling) | A function to schedule the later execution of a batch. The function is expected to call the provided callback in the immediate future. |
400400
| `cache` | Boolean | `true` | Set to `false` to disable memoization caching, creating a new Promise and new key in the `batchLoadFn` for every load of the same key. This is equivalent to setting `cacheMap` to `null`. |
401401
| `cacheKeyFn` | Function | `key => key` | Produces cache key for a given load key. Useful when objects are keys and two objects should be considered equivalent. |

src/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ declare namespace DataLoader {
9595
batch?: boolean;
9696

9797
/**
98-
* Default `Infinity`. Limits the number of items that get passed in to the
98+
* Default `1000`. Limits the number of items that get passed in to the
9999
* `batchLoadFn`. May be set to `1` to disable batching.
100100
*/
101101
maxBatchSize?: number;

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ function getValidMaxBatchSize(options: ?Options<any, any, any>): number {
412412
}
413413
const maxBatchSize = options && options.maxBatchSize;
414414
if (maxBatchSize === undefined) {
415-
return Infinity;
415+
return 1000;
416416
}
417417
if (typeof maxBatchSize !== 'number' || maxBatchSize < 1) {
418418
throw new TypeError(

0 commit comments

Comments
 (0)