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 🙏

© 2026 – Pkg Stats / Ryan Hefner

aiwaf-js

v0.0.4

Published

Adaptive Web Application Firewall middleware for Node.js (Express, Fastify, Hapi, Next.js)

Readme

aiwaf‑js

Adaptive Web Application Firewall middleware for Node.js & Express
Self‑learning, plug‑and‑play WAF with rate‑limiting, static & dynamic keyword blocking, honeypot traps, UUID‑tamper protection, and IsolationForest anomaly detection—fully configurable and trainable on your own access logs. Now Redis‑powered and ready for distributed, multiprocess use.

npm version
Build Status
License


Features

  • ✅ Rate Limiting (Redis-based or fallback to memory)
  • ✅ Static Keyword Blocking
  • ✅ Dynamic Keyword Learning (auto-adaptive)
  • ✅ Honeypot Field Detection
  • ✅ UUID‑Tamper Protection
  • ✅ Anomaly Detection (Isolation Forest)
  • ✅ Redis Support for multiprocess environments
  • ✅ Offline Training from access logs
  • Custom Cache Logic Support

Installation

npm install aiwaf-js --save

Train the Model (Optional but recommended)

You can train the anomaly detector and keyword learner using real access logs.

NODE_LOG_PATH=/path/to/access.log npm run train

If NODE_LOG_PATH is not provided, it defaults to /var/log/nginx/access.log.


Quick Start

const express = require('express')
const aiwaf   = require('aiwaf-js')

const app = express()
app.use(express.json())
app.use(aiwaf())
app.get('/', (req, res) => res.send('Protected'))
app.listen(3000)

Redis Support (Recommended for Production)

AIWAF‑JS supports Redis for distributed rate limiting and keyword caching.

# On Unix/Linux/macOS
export REDIS_URL=redis://localhost:6379

# On Windows PowerShell
$env:REDIS_URL = "redis://localhost:6379"

If Redis is unavailable, it gracefully falls back to in-memory mode.


Custom Cache Logic (Advanced)

You can inject your own cache logic (in-memory, Redis, hybrid, or file-based) by passing a cache object implementing the following interface:

const myCustomCache = {
  get: async (key) => { /* return cached value */ },
  set: async (key, value, options) => { /* store with optional TTL */ },
  del: async (key) => { /* delete entry */ }
}

app.use(aiwaf({
  cache: myCustomCache,
  staticKeywords: ['.php'],
  dynamicTopN: 5,
  MAX_REQ: 10,
  WINDOW_SEC: 15,
  FLOOD_REQ: 20,
}))

This overrides Redis/in-memory usage with your custom strategy for all cache operations.


Configuration

app.use(aiwaf({
  staticKeywords: ['.php', '.env', '.git'],
  dynamicTopN: 10,
  WINDOW_SEC: 10,
  MAX_REQ: 20,
  FLOOD_REQ: 10,
  HONEYPOT_FIELD: 'hp_field',
  cache: myCustomCache, // optional custom cache injection
}));

| Option | Env Var | Default | Description | |--------------------|---------------------|-----------------------------|----------------------------------------------------------| | staticKeywords | — | [".php",".xmlrpc","wp-"] | Substrings to block immediately. | | dynamicTopN | DYNAMIC_TOP_N | 10 | Number of dynamic keywords to match. | | windowSec | WINDOW_SEC | 10 | Time window in seconds for rate limiting. | | maxReq | MAX_REQ | 20 | Max allowed requests per window. | | floodReq | FLOOD_REQ | 10 | Hard limit triggering IP block. | | honeypotField | HONEYPOT_FIELD | "hp_field" | Hidden bot trap field. | | anomalyThreshold | ANOMALY_THRESHOLD | 0.5 | Threshold for IsolationForest-based anomaly detection. | | logPath | NODE_LOG_PATH | "/var/log/nginx/access.log" | Path to access log file. | | logGlob | NODE_LOG_GLOB | "${logPath}.*" | Glob pattern to include rotated/gzipped logs. | | cache | — | undefined | Custom cache implementation (overrides Redis/memory) |


Optimization Note

Tip: In high-volume environments, caching the feature vector extractor (especially if Redis is unavailable) can reduce redundant computation and significantly boost performance.


📄 License

MIT License © 2025 Aayush Gauba