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

ralphi

v3.2.0

Published

Rate limit and bruteforce prevention api server

Downloads

24

Readme

Ralphi

npm version Build Status codecov Known Vulnerabilities License

Ralphi is a simple rate limiting server intended to prevent bruteforce attacks on logins and other sensitive assets. it is very loosely base on limitd but it is much more simple.

Main difference to limitd -

  • Memory only. no persistence.
  • Simple drip only and frame interval only
  • No wait, count or other advance features you can only take or reset a record
  • HTTP interface

Ralphi currently has 4 independent npm modules to it

Installation

$ npm install -s ralphi
$ npm install -s ralphi-client
# if you wish to use it with hapi install the hapi plugin
$ npm install -s hapi-ralphi

Usage

Start Ralphi server

$ npx ralphi login,5,10m

The above command will start Ralphi with a single login bucket that allows for 5 request every 10 minutes For more information see the Config section or run ralphi --help

Integrate rate limiting in hapi.js

const plugin = require('hapi-ralphi');
const client = new require('ralphi-client')();
const server = new require('hapi').Server();

async function init () {
    await server.register({plugin, options: {client}});
    server.route({
        method: 'POST',
        path: '/login',
        config: {
            plugins: {
                ralphi: {
                    bucket: 'login'
                }
            }
        },
        handler () {
            return 'Success';
        }
    });
}
init();

login root will be rate limited according to the bucket settings, and rate limiting headers will be sent with the response.

For more information see hapi-ralphi

Integrate rate limiting in express js

const express   = require('express');
const app       = express();
const RateLimit = require('express-ralphi');
const client    = new require('ralphi-client')();

app.use('/login', RateLimit({bucket: 'login', client}));
app.get('/login', (rec, res) => res.send('Success'));

login root will be rate limited according to the bucket settings, and rate limiting headers will be sent with the response.

For more information see express-ralphi

Integrate rate limiting in other frameworks

const client = new require('ralphi-client')();

async function handler (req, res) { //in your handler code
    const limit = await client.take('login', req.ip);
    if (limit.conformant) {
        //allow access
        return `Request was done. You have ${limit.remaining} more requests until ${new Date(limit.ttl * 1000)}`;
    } else {
        //reject access
        throw new Error(`You have made too many requests. You can send ${limit.size} requests after ${new Date(limit.ttl * 1000)}`);
    }
}

For more information see ralphi-client

Config

You can use the following command line flags to configure Ralphi -

  • -h, --host [localhost] - Ip address or host to listen to. by default ralphi only listen on localhost. if you have reason to listen on an external address make sure it is not publicly accessible.
  • -p, --port [8910] - port server will listen on
  • l, --log-level [info] - log level (debug,info,error,silent, ralphi will json logs to stdout.
  • -i, --clean-interval - if set ralphi will try to remove expired records every X seconds. -c, --config - JSON format config file to be used to load configuration (see the following section for the config file format)

Other than settings the flags Ralphi requires you to define buckets to be used for rate limiting -

$ ralphi login,10,30m token,2,1h

Using the above command Ralphi will start with two buckets defined

  • Login bucket allowing for 10 requests ever 30 minutes
  • Token bucket allowing for 2 request every hour

bucket name must be alphanumeric and ttl value can have a unit prefix (ms,s,m,h) or it will default to seconds

Config file

Config need to be in a json format.

{
    "host": "localhost",
    "port": 8910,
    "cleanInterval": 1800,
    "buckets": {
        "login": {
            "size": 10,
            "ttl": "30m"
        }
    },
}