Skip to content
Web firewall middleware compatible with Express/Restify frameworks.
JavaScript
Branch: master
Clone or download
Latest commit 24d7b43 Jun 5, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore Uploading version 0.1.0 of the module. Nov 24, 2016
LICENSE Uploading version 0.1.0 of the module. Nov 24, 2016
README.md Adding strings comparison info. Nov 25, 2016
index.js using standard linting May 14, 2018
package-lock.json updating deps Jun 5, 2019
package.json updating deps Jun 5, 2019

README.md

Introduction

Web firewall middleware compatible with Express/Restify frameworks.

Install

npm install --save webfirewall

Config params example

The values on the params 'paths', 'ipAddresses', 'roles', 'origin' and 'users', can be regular expressions (RegExp). If strings, the comparison is done using the wildcard module.

const config = {
    populationStrategy: 'restify', // supported values: express/restify
    defaultAction: 'DROP', // supported values: ACCEPT/DROP 
    getUserPhone: (req) => Promise.resolve(req.user ? req.user.phone: null), // custom population strategy for user phone (optional)
    getUserEmail: (req) => Promise.resolve(req.user ? req.user.email: null), // custom population strategy for user email (optional)
    getUserRoles: (req) => Promise.resolve(req.user ? req.user.roles: null), // custom population strategy for user roles (optional)
    rules: [{
        methods: ['GET'],
        paths: ['/system/login'],
        ipAddresses: ['*'], // optional
        roles: ['*'], // optional
        origin: ['*'], // optional
        users: ['*'], // optional
        secure: true, // optional
        action: 'ACCEPT', // supported values: ACCEPT/DROP
        handler: (req) => Promise.resolve(true) // optional
    }, {
        methods: ['POST'],
        paths: ['/comments'],
        users: ['*'], 
        secure: true,
        action: 'ACCEPT'
    }, {
        methods: ['POST'],
        paths: ['/system/restart'],
        roles: ['ADMIN'], 
        secure: true,
        action: 'ACCEPT'
    }]
}

Usage

const restify = require('restify');
const server = restify.createServer({
    name: 'yourapp.com',
    version: ['1.0.0']
});
const firewall = require('webfirewall');

server.use(firewall({
    populationStrategy: 'restify',
    defaultAction: 'ACCEPT',
    rules: []
}));

JWT authentication

JSON Web Token authentication is a great candidate to be used in collaboration with this module. This module is fully integrated with the com.kyberneees.auth.jwt module.

You can’t perform that action at this time.