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

express-slow-down

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-slow-down - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

23

lib/express-slow-down.js
"use strict";
var defaults = require("defaults");
var MemoryStore = require("./memory-store");
const defaults = require("defaults");
const MemoryStore = require("./memory-store");

@@ -41,3 +41,3 @@ function SlowDown(options) {

var key = options.keyGenerator(req, res);
const key = options.keyGenerator(req, res);

@@ -49,12 +49,17 @@ options.store.incr(key, function(err, current, resetTime) {

var delay = 0;
let delay = 0;
if (current > options.delayAfter) {
delay = (current - options.delayAfter) * options.delayMs;
const delayAfter =
typeof options.delayAfter === "function"
? options.delayAfter(req, res)
: options.delayAfter;
if (current > delayAfter) {
delay = (current - delayAfter) * options.delayMs;
}
req.slowDown = {
limit: options.delayAfter,
limit: delayAfter,
current: current,
remaining: Math.max(options.delayAfter - current, 0),
remaining: Math.max(delayAfter - current, 0),
resetTime: resetTime,

@@ -64,3 +69,3 @@ delay: delay

if (current - 1 === options.delayAfter) {
if (current - 1 === delayAfter) {
options.onLimitReached(req, res, options);

@@ -67,0 +72,0 @@ }

{
"name": "express-slow-down",
"version": "1.1.1",
"version": "1.2.0",
"description": "Basic IP rate-limiting middleware for Express that slows down responses rather than blocking the user.",

@@ -38,11 +38,11 @@ "homepage": "https://github.com/nfriedly/express-slow-down",

"devDependencies": {
"eslint": "^5.2.0",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-prettier": "^2.6.2",
"express": "^4.16.3",
"husky": "^0.14.3",
"eslint": "^5.12.0",
"eslint-config-prettier": "^3.3.0",
"eslint-plugin-prettier": "^3.0.1",
"express": "^4.16.4",
"husky": "^1.3.1",
"mocha": "^5.2.0",
"prettier": "1.14.0",
"pretty-quick": "^1.6.0",
"supertest": "^3.1.0"
"prettier": "^1.15.3",
"pretty-quick": "^1.8.0",
"supertest": "^3.3.0"
},

@@ -49,0 +49,0 @@ "scripts": {

@@ -33,8 +33,8 @@ # Express Slow Down

```js
const slowDown = require('express-slow-down');
const slowDown = require("express-slow-down");
app.enable('trust proxy'); // only if you're behind a reverse proxy (Heroku, Bluemix, AWS if you use an ELB, custom Nginx setup, etc)
app.enable("trust proxy"); // only if you're behind a reverse proxy (Heroku, Bluemix, AWS if you use an ELB, custom Nginx setup, etc)
const speedLimiter = slowDown({
windowMs: 15*60*1000, // 15 minutes
windowMs: 15 * 60 * 1000, // 15 minutes
delayAfter: 100, // allow 100 requests per 15 minutes, then...

@@ -84,3 +84,3 @@ delayMs: 500 // begin adding 500ms of delay per request above 100:

- **windowMs**: milliseconds - how long to keep records of requests in memory. Defaults to `60000` (1 minute).
- **delayAfter**: max number of connections during `windowMs` before starting to delay responses. Defaults to `1`. Set to `0` to disable delaying.
- **delayAfter**: max number of connections during `windowMs` before starting to delay responses. Number or function that returns a number. Defaults to `1`. Set to `0` to disable delaying.
- **delayMs**: milliseconds - how long to delay the response, multiplied by (number of recent hits - `delayAfter`). Defaults to `1000` (1 second). Set to `0` to disable delaying.

@@ -87,0 +87,0 @@ - **skipFailedRequests**: when `true` failed requests (response status >= 400) won't be counted. Defaults to `false`.

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