Closed
Description
New Feature / Enhancement Checklist
- I am not disclosing a vulnerability.
- I am not just asking a question.
- I have searched through existing issues.
Current Limitation
Rate limiting an API is something that is usually done by a separate part in an architecture, before it even reaches Parse Server. The earlier a rate limiting is enforced to prevent DOS attacks, the lower the impact of such an attack. However, not every developer may have the experience or availability of such rate-limiting components.
Feature / Enhancement Description
Parse Server should offer a basic feature for rate limiting:
- Rate limiting should be on by default, and allow to be turned off in case a custom rate-limiter is used. To achieve this, a new Parse Server option should be introduced.
- The feature should be phased by defaulting to being deactivated, with a deprecation warning that it will be activated by default.
- Some (specifically internal) API routes may need to be excluded from limiting.
Example Use Case
The following example shows an Express application that serves static files without rate limiting:
var express = require('express');
var app = express();
app.get('/:path', function(req, res) {
let path = req.params.path;
if (isValidPath(path))
res.sendFile(path);
});
To prevent denial-of-service attacks, the express-rate-limit package can be used:
var express = require('express');
var app = express();
// set up rate limiter: maximum of five requests per minute
var RateLimit = require('express-rate-limit');
var limiter = new RateLimit({
windowMs: 1*60*1000, // 1 minute
max: 5
});
// apply rate limiter to all requests
app.use(limiter);
app.get('/:path', function(req, res) {
let path = req.params.path;
if (isValidPath(path))
res.sendFile(path);
});
Alternatives / Workarounds
Require developer to implement a custom rate-limiter.
3rd Party References
- OWASP: Denial of Service Cheat Sheet.
- Wikipedia: Denial-of-service attack.
- NPM: express-rate-limit.
- Common Weakness Enumeration: CWE-770.
- Common Weakness Enumeration: CWE-307.
- Common Weakness Enumeration: CWE-400.