Skip to content

Add express rate limiting #8170

Closed
Closed
@mtrezza

Description

@mtrezza

New Feature / Enhancement Checklist

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions