You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A rate limiter added directly to DDP. The DDPRateLimiter allows you to add rules to limit calls by one or more of user IDs, IP addresses, method names and/or subscription names. The rate limiter is called on every method and subscription invocation. A default rule of limiting 'login' attempts to 5 calls every 10 seconds per IP address has been added to the [`Accounts base package`](#accounts_api). The rule can be removed by calling [`Accounts.removeDefaultRateLimit()`].
185
+
The DDPRateLimiter allows users to add rules to limit calls to Meteor methods
186
+
and subscriptions by one or more of user IDs, IP addresses, sessions, and
187
+
method & subscription names. The rate limiter is called on every method and
188
+
subscription invocation. A default rule of limiting login, password reset and
189
+
new user creation attempts to 5 calls every 10 seconds per session has been
190
+
added to the [`accounts package`](#accounts_api). The rule can be removed by
191
+
calling `Accounts.removeDefaultRateLimit()`.
192
+
193
+
The DDPRateLimiter is configured with a set of rules. Each rule is a set of
194
+
keys to be inspected with filters on those keys to specify all DDP messages
195
+
that satisfy the rule. Each of these possible messages that satisfy the rule
196
+
is given a bucket by creating a unique string composed of all the keys in the
197
+
rule and the values from the message. After each rule's specified time
198
+
interval, all the buckets are deleted. A rate limit is said to have been hit
199
+
when a bucket has reached the rule's capacity, at which point errors will be
200
+
returned for that input until the buckets are reset.
Copy file name to clipboardExpand all lines: packages/ddp-rate-limiter/ddp-rate-limiter.js
+16-6Lines changed: 16 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,9 @@
1
1
// Rate Limiter built into DDP with a default error message.
2
2
DDPRateLimiter={
3
3
errorMessage : function(rateLimitResult){
4
-
return"Error, too many requests. Please slow down. You must wait "+Math.ceil(
5
-
rateLimitResult.timeToReset/1000)+" seconds before trying again.";
4
+
return"Error, too many requests. Please slow down. You must wait "+
5
+
Math.ceil(rateLimitResult.timeToReset/1000)+" seconds before trying "+
6
+
"again.";
6
7
},
7
8
rateLimiter : newRateLimiter()
8
9
}
@@ -15,17 +16,24 @@ DDPRateLimiter.getErrorMessage = function (rateLimitResult) {
15
16
}
16
17
/**
17
18
* @summary Update the error message returned when call is rate limited.
18
-
* @param {string|function} message Function that takes an object with a timeToReset field that specifies the first time a method or subscription call is allowed
19
+
* @param {string|function} message Function that takes an object with a
20
+
* timeToReset field that specifies the first time a method or subscription
21
+
* call is allowed.
19
22
*/
20
23
DDPRateLimiter.setErrorMessage=function(message){
21
24
this.errorMessage=message;
22
25
}
23
26
24
27
/**
25
28
* @summary Adds a rule with a number of requests allowed per time interval.
26
-
* @param {object} rule Rule should be an object where the keys are one or more of `['userId', 'ipAddr', 'type', 'name'] ` and the values are either `null`, a primitive, or a function that returns true if the rule should apply to the provided input for that key.
27
-
* @param {integer} numRequests number of requests allowed per time interval. Default = 10.
28
-
* @param {integer} timeInterval time interval in milliseconds after which rule's counters are reset. Default = 1000.
29
+
* @param {object} rule Rule should be an object where the keys are one or
30
+
* more of `['userId', 'ipAddr', 'type', 'name', 'sessionId'] ` and the values
31
+
* are either `null`, a primitive, or a function that returns true if the rule
32
+
* should apply to the provided input for that key.
33
+
* @param {integer} numRequests number of requests allowed per time interval.
34
+
* Default = 10.
35
+
* @param {integer} timeInterval time interval in milliseconds after which
36
+
* rule's counters are reset. Default = 1000.
29
37
* @return {string} Returns unique `ruleId` that can be passed to `removeRule`.
0 commit comments