New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

hapi-auth-ip-whitelist

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hapi-auth-ip-whitelist

Hapi.js plugin for authentication scheme of accepting connections only from certain IPs

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
238
increased by0.42%
Maintainers
1
Weekly downloads
 
Created
Source

hapi-auth-ip-whitelist

npm

Usage

Localhost

Only accept calls from localhost:

server.auth.strategy('localhost', 'ip-whitelist', ['127.0.0.1']);

NOTE: Third parameter of server.auth.strategy is options which must be an object.

To be used like

server.route({ 
  method: 'GET', 
  path: '/',
  handler(request, h) { return "That was from localhost!" }, 
  options: { auth: 'localhost' }
});

In the route receives a request from a different IP, it will respond a 401 unauthorized error with the message 192.168.0.102 is not a valid IP, where 192.168.0.102 is the IP of the request.

Address ranges

You can also specify several IPs by passing a list instead. CIDR notation is supported.

For example, consider the IPs to expect requests from, as specified by MercadoPago.

server.auth.strategy(
  'mercado-pago-webhook',
  'ip-whitelist',
  ['209.225.49.0/24', '216.33.197.0/24', '216.33.196.0/24', '63.128.82.0/24', '63.128.83.0/24', '63.128.94.0/24']  
);

Behind proxy

In case you are behind a proxy, use Hapi plugin therealyou. It will find the "real" IP in X-Forward headers and modify the request.info.remoteAddress.

server.register([
  {
    plugin: require('therealyou')
  },
  {
    plugin: require('hapi-auth-ip-whitelist')
  }
])

Example server

Start local example server with

npm start

then visit http://localhost:3000.

Successfully authenticated request http://localhost:3000/authenticated. Unauthenticated request http://localhost:3000/unauthenticated.

FAQs

Package last updated on 11 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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