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
One very common use case for Cloud Code is sending push notifications to particular users. In general, clients can't be trusted to send push notifications directly, because they could modify the alert text, or push to people they shouldn't be able to. Your app's settings will allow you to set whether "client push" is enabled or not; we recommend that you make sure it's disabled. Instead, you should write Cloud Code functions that validate the data to be pushed and sent before sending a push.
564
564
565
+
## Rate Limiting
566
+
567
+
* Available on Parse Server >=6.0.0 *
568
+
569
+
It's important to restrict how often a client can call the Parse Server API. This prevents malicious attacks that could:
570
+
- overwhelm server resources by exceeding expected API traffic
571
+
- collect large amounts of data ("data scraping")
572
+
- repeatedly guess passwords, object IDs, installation IDs or other data ("brute force")
573
+
574
+
Parse Sever offers a mechanism to enforce rate limits by setting the Parse Server option `rateLimit`, or by specifying a `rateLimit` object on a Cloud Function validator.
575
+
576
+
The valid options for a rate limit are:
577
+
578
+
-`requestPath`: The path of the API route to be rate limited.
579
+
-`requestMethods`: Optional, the HTTP request methods to be rate limited.
580
+
-`requestTimeWindow`: The window of time in milliseconds within which the number of requests set in `requestCount` can be made before the rate limit is applied.
581
+
-`requestCount`: The number of requests that can be made per IP address within the time window set in `requestTimeWindow` before the rate limit is applied.
582
+
-`errorResponseMessage`: The error message that should be returned in the body of the HTTP 429 response when the rate limit is hit. Default is `Too many requests.`.
583
+
-`includeInternalRequests`: Optional, whether the rate limit will also apply to requests that are made in by Cloud Code.
584
+
-`includeMasterKey`: Optional, whether the rate limit will also apply to requests using the `masterKey`
585
+
-`redisUrl` Optional, the URL of the Redis server to store rate limit data.
586
+
587
+
To specify a server-wide rate limit of 200 requests per 15 minute window:
588
+
589
+
```js
590
+
constparseServer=newParseServer({
591
+
rateLimit: {
592
+
requestPath:'*',
593
+
requestTimeWindow:15*60*1000,
594
+
requestCount:200,
595
+
},
596
+
});
597
+
```
598
+
599
+
To specify a cloud function specific rate limit of 3 request per hour:
600
+
601
+
```js
602
+
Parse.Cloud.define('someFunction', () => {
603
+
return'Hello world';
604
+
}, {
605
+
rateLimit: {
606
+
requestTimeWindow:60*60*1000,
607
+
requestCount:3,
608
+
}
609
+
});
610
+
```
611
+
612
+
Rate limits can also be applied to `beforeSave` triggers to restrict how often a given class is written to:
613
+
614
+
```js
615
+
Parse.Cloud.beforeSave('TestObject', () => {}, {
616
+
rateLimit: {
617
+
requestTimeWindow:1*60*1000// one write per minute,,
618
+
requestCount:1,
619
+
errorResponseMessage:'Too many requests!',
620
+
},
621
+
});
622
+
```
623
+
624
+
> ⚠️ Rate limits should be enforced as far away from Parse Server as possible to mitigate possible impacts on resource costs, availability and integrity. While Parse Server offers a rate limiting mechanism as a conveniently available security feature without requiring a deep level of expertise, it is *not considered best practice* to enforce rate limits only after requests already reached the server. For better protection we advice to examine your network architecture an consider enforcing rate limits on the outer edge of the cloud if using a content delivery network, or at least before requests reach the server resource. Consult your cloud service provider for recommended rate limit and firewall solutions for your resources.
625
+
565
626
## Parse Security Summary
566
627
567
628
Parse provides a number of ways for you to secure data in your app. As you build your app and evaluate the kinds of data you will be storing, you can make the decision about which implementation to choose.
0 commit comments