npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ddos-express

v0.1.7

Published

Configurable Denial-Of-Service prevention library for Express

Downloads

162

Readme

Configurable Denial-Of-Service prevention library for Express

This module is outdated. Please, use DDDoS instead.

Example

var expresss = require("express");
var ddos = require("ddos-express");

var app = express();

app.use(ddos({
    /*Configuration options*/
}));

Configuration

errorData

Data to be passes to the client on DDoS detection. Default: "Not so fast!".

errorCode

HTTP error code to be set on DDoS detection. Default: 429 (Too Many Requests).

weight

Default request weight. 1 by default.

maxWeight

Default maximum allowed weight per IP. 10 by default.

checkInterval

Interval (in milliseconds) to check connections and decrement weights. Default: 1000 (1 second).

rules

List of rules to apply to each request. Example:

    rules: [
        { /*Allow 4 requests accessing the application API per checkInterval*/
            regexp: "^/api.*",
            flags: "i",
            maxWeight: 4,
            queueSize: 4 /*If request limit is exceeded, new requests are added to the queue*/
        },
        { /*Only allow 1 search request per check interval.*/
            string: "/action/search",
            maxWeight: 1
        },
        { /*Allow up to 16 other requests per check interval.*/
            regexp: ".*",
            maxWeight: 16
        }
]

logFunction

A function used for logging detected DDoS. The following arguments are passes to the function:

  • req.ip — user's IP address
  • req.path — request path
  • user.weight — current weight
  • rule.maxWeight — maximum allowed weight
  • rule.regexp || rule.string — rule pattern

How this module works

Every request is checked against a chain of rules. Rules with a string path pattern are checked first. They are added to a map for the sake of performance. Then the request is checked against every regexp-based rules.

If request path (req.path) matches the rule's pattern, that rule is applied. Other rules are not checked.

User IP is retrieved from the req.ip property. You have to handle proxies (X-Forwarded-For header and such) yourself.

A weight is assigned to each user. Every time a new request is made, the weight is increased. If the weight becomes larger than maxWeight, the errorData is returned to the user along with the errorCode.

Requests which did not match any rule or have passed the test are forwarded to the next middleware/router.

Every checkInterval milliseconds all users are checked. The weights are decremented by the maxWegight. If user's weight becomes less than or equal to 0, that user is deleted from the map.

Example situation

Say weight is 1, maxWeight is 10 and checkInterval is 1000.

A user makes 35 requests in one second. First 10 request pass the module, the other 25 do not. The weight is 35 for now. Then the user stops sending requests.

After 1 second passes by, the weight is decremented by 10 and becomes 25. The user attempts to make one more request, which does not pass. The weight becomes 26.

Two sceonds later (after two checks) the weight is decreased twice and becomes 6. The user attempts to make a request, which now successfully passes the check. The weight becomes 7.