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

hapi-ralphi

v3.2.0

Published

Rate limit and bruteforce prevention plugin for hapi

Downloads

270

Readme

hapi-ralphi

hapi plugin 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 hapi-ralphi

Usage

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.

Configuration Options

  • client RalphiClient required - Ralphi client, used to query Ralphi server.
  • ext String default(onPreHandler) - request flow hook when plugin should check rate limiting can be one of ('onPreAuth', 'onPostAuth', 'onPreHandler')
  • allRoutes Boolean default(false) - if true rate limiting will be enabled by default on all routes
  • bucket String - 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(request, reply, Error) default(undefined) - if communication with Ralphi server results in an error, plugin 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

All configuration options other than client,ext,allRoutes can be overridden in the route settings. When allRoutes is false(default), you'll need to set a config object in config.plugins.ralphi to enable the route. If allRoutes is true you can disable a specific route by setting config.plugins.ralphi to false.