0.6.0 β€’ Published 1 month ago

easy-waf v0.6.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

Easy WAF (Beta) 🧱

An easy-to-use Web Application Firewall (WAF) for Node.js. Can be used with Express, Fastify, NextJS, NuxtJS ... or Node.js http.

npm version npm downloads license Known Vulnerabilities CodeFactor codecov install size

import express from 'express';
import easyWaf from 'easy-waf'; // CommonJS: require('easy-waf').default;
const app = express();

app.use(easyWaf());

app.listen(3000);

!WARNING This software tries to defend many common attacks while keeping the rate of false positives low. There will always be methods to bypass this WAF. Therefore, using this package is not a reason to neglect security when developing an application. Always validate user input! This software should be used with caution and is more an educational tool than a professional security solution.

Features

  • Restrict allowed HTTP methods and add your own ip black- and whitelist
  • Blocks requests from bad bots and fake crawlers
  • Blocks malicious requests:
    • CRLF Injection
    • Cross-Site-Scripting (XSS)
    • Directory / Path Traversal
    • HTTP Parameter Pollution
    • Open Redirect / Server Side Request Forgery (SSRF) (queryUrlWhitelist option must be set)
    • Prototype Pollution
    • SQL Injections and NoSQL Injections
  • Can block requests from the Tor network (disabled by default)
  • Compatible with many popular web frameworks and with the integrated Node.js HTTP server
  • Supports ES modules and CommonJS

Installation

!TIP I strongly recommend to activate the "dryMode" at the beginning to be able to identify possible false positives from the logs. If EasyWAF should parse bodies, bind a body-parser middleware to your app before adding EasyWAF.

npm i easy-waf

In the examples folder you can find samples of how to integrate EasyAF into your application.

If you run your Node.js app behind a reverse proxy, don't forget to set the trustProxy option. To enable Open Redirect protection, configure the queryUrlWhitelist option.

Configuration

EasyWAF is easy to use without the need for much configuration, but there are still many customization options.

app.use(
    easyWaf({
        allowedHTTPMethods: ['GET', 'POST'],
        queryUrlWhitelist: ['github.com'],
        modules: {
            directoryTraversal: {
                enabled: true,
                excludePaths: /^\/exclude$/i,
            },
        },
    }),
);
OptionTypeDefaultDescription
allowedHTTPMethodsarrayundefinedList of all HTTP request methods that are allowed. All other request methods will be blocked. By default, all HTTP methods are allowed.
customBlockedPagestringundefinedAdd HTML code to override the default "Request blocked" page. View example with placeholders
queryUrlWhitelistarrayundefinedList of urls that are allowed to be included in the path or query of the request url. By default, all urls are allowed. (Open Redirect / SSRF)
disableLoggingbooleanfalseIf true, nothing is logged. This is not recommended!
dryModebooleanfalseIf true, suspicious requests are only logged and not blocked. In addition, the log format is changed to prevent an IPS from blocking the IP.
ipBlacklistarray[]All requests by ips on the blacklist are blocked. CIDR notation is supported (IPv4 and IPv6). On single addresses, a prefix of /32 or /128 is assumed.
ipWhitelistarray[]All requests by ips on the whitelist are never blocked. CIDR notation is supported.
modulesname.enabledbooleantrue, except "Block Tor Exit Nodes"This option allows you to completely disable a specific module.
modulesname.excludePathsbooleanundefinedExclude paths from being checked by this module with a regex.
postBlockHookcallbackundefinedRun your own code after a request is blocked. For example, you can send a notification.
preBlockHookcallbackundefinedRun your own code before a request is blocked. Return false if the request should not be blocked.
trustProxystring / array[]If a reverse proxy is used, this setting must be configured. See npm/proxy-addr for possible values.

What is checked?

The following table shows which user input is checked by which module:

NameURLBody*Headers**IP
Bad BotsβŒβŒβœ…βŒ
Block Tor Exit NodesβŒβŒβŒβœ…
CRLF Injectionβœ…βœ…βŒβŒ
Cross-Site-Scripting (XSS)βœ…βœ…βœ…βŒ
Directory Traversalβœ…βœ…βŒβŒ
Fake CrawlersβŒβŒβœ…βœ…
HTTP Parameter Pollutionβœ…***❌❌❌
NoSQL Injectionsβœ…βœ…βœ…βŒ
Open Redirect / SSRFβœ…βŒβŒβŒ
Prototype Pollutionβœ…βœ…βœ…βŒ
SQL Injectionsβœ…βœ…βœ…βŒ
XML Injections (Basic)βŒβœ…βŒβŒ

* Bodies are only checked if req.body is set by a middleware or the web framework itself before EasyWAF.
** Includes user agent and cookies
*** Only if req.query is set by a framework.

A short description of all modules can be found in src/modules.

Contact

If a public GitHub issue or discussion is not the right choice for your concern, you can contact me directly:

Sources

License

Β© Timo KΓΆssler 2024
Released under the MIT license

0.6.0

1 month ago

0.5.2

4 months ago

0.5.1

7 months ago

0.5.0

11 months ago

0.4.1

1 year ago

0.4.0

1 year ago

0.3.0

2 years ago

0.2.0

2 years ago

0.3.1

1 year ago

0.1.0

2 years ago