Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

express-rate-limit

Package Overview
Dependencies
Maintainers
1
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-rate-limit - npm Package Compare versions

Comparing version 2.3.1 to 2.4.0

README.md

35

lib/express-rate-limit.js

@@ -15,2 +15,3 @@ 'use strict';

statusCode: 429, // 429 status = Too Many Requests (RFC 6585)
headers: true, //Send custom rate limit header with limit and remaining
// allows to create custom keys (by default user IP is used)

@@ -32,3 +33,2 @@ keyGenerator: function (req /*, res*/) {

// store to use for persisting rate limit data

@@ -53,16 +53,27 @@ options.store = options.store || new MemoryStore(options.windowMs);

options.store.incr(key, function(err, current) {
if (err) {
return next(err);
}
if (err) {
return next(err);
}
if (options.max && current > options.max) {
return options.handler(req,res, next);
}
req.rateLimit = {
limit: options.max,
remaining: Math.max(options.max - current, 0)
};
if (options.headers) {
res.setHeader('X-RateLimit-Limit', options.max);
res.setHeader('X-RateLimit-Remaining', req.rateLimit.remaining);
}
if (options.delayAfter && options.delayMs && current > options.delayAfter) {
if (options.max && current > options.max) {
return options.handler(req, res, next);
}
if (options.delayAfter && options.delayMs && current > options.delayAfter) {
var delay = (current - options.delayAfter) * options.delayMs;
setTimeout(next, delay);
} else {
next();
}
return setTimeout(next, delay);
}
next();
});

@@ -69,0 +80,0 @@ }

{
"name": "express-rate-limit",
"version": "2.3.1",
"version": "2.4.0",
"description": "Basic IP rate-limiting middleware for Express. Use to limit repeated requests to public APIs and/or endpoints such as password reset.",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/nfriedly/express-rate-limit",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc