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

express-ralphi

v3.2.0

Published

Rate limit and bruteforce prevention middleware for express

Downloads

12

Readme

Express-ralphi

Express middleware for ralphi pure Node.js rate limiting server

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.

For more info about Ralphi other components see ralphi

Plugin Installation

$ npm install -s ralphi-client
$ npm install -s express-ralphi

Usage

Integrate rate limiting in express

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.

Configuration Options

  • client RalphiClient required - Ralphi client, used to query Ralphi server.
  • bucket String required - bucket to use for rate limiting (required when allRoutes is true)
  • countSuccess Boolean default(true) - if true request are counted even if they are successful, when set to false only request that result in an error will be counted toward rate limiting.
  • getKey Function(request) - A Function that will get the unique client key out of the request object. By default request.info.remoteAddress is used.
  • addHeaders Boolean default(true) - Add the headers 'X-RateLimit-Limit', 'X-RateLimit-Remaining', 'X-RateLimit-Reset' for routes that enable rate liming +- headerLimit String default('X-RateLimit-Limit') - name of the header that indicates the request quota +- headerRemaining String default('X-RateLimit-Remaining') - name of the header that indicates the remaining request quota +- headerReset String default('X-RateLimit-Reset') - name of the header that indicates how long until the request quota is reset +- ttlTransform Function(ttl) - A Function that allows transformation of the ttl passed down from the Ralphi server.
  • message String default('you have exceeded your request limit') - Error message in case limit has exceeded
  • onError Function(error, rec, res, next) default(undefined) - if communication with Ralphi server results in an error, middleware will call this method and stop processing the request. By default request will be rate limited using errorSize and errorDelay settings errorSize Integer default(1) - default record size if Ralphi server is not available errorDelay Integer default(60) - default delay in seconds to send to the user if Ralphi server is not available
  • errorLog Function(error) default(undefined) - if communication with Ralphi server results in an error, error will be passed to this method for logging. unlike onError the middleware will keep processing the request

For convince each configuration option has a method that will create a new instance extending the exiting configuration. so it is easy to have specific route configuration -

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

const baseRateLimit = RateLimit({bucket: 'login', client, errorLog: e => console.log(e)});

app.use('/login', baseRateLimit);
app.get('/login', (rec, res) => res.send('Success'));

app.use('/recover', baseRateLimit.bucket('recover'));
app.get('/recover', (rec, res) => res.send('Success'));

app.use('/api', baseRateLimit.onError((e, req, res, next) => next()).bucket('api'));
app.get('/api', (rec, res) => res.send('Success'));