aiwaf 1.2.4 → 1.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -39,15 +39,15 @@ the supported Redis backends when sharing limits across workers.
39
39
 
40
40
  Each package is versioned and released independently.
41
41
 
42
- Python 1.2.5, Rust/Python 0.2.12, Node.js 1.2.4, WASM 0.2.9, and Java 1.3.8 are local source targets. See the package table below and [CHANGELOG](CHANGELOG.md) for release changes.
42
+ Python 1.2.6, Rust/Python 0.2.13, Node.js 1.2.5, WASM 0.2.10, and Java 1.3.9 are local source targets. See the package table below and [CHANGELOG](CHANGELOG.md) for release changes.
43
43
 
44
44
  | Runtime | Package | Repository version | Primary use |
45
45
  | --- | --- | ---: | --- |
46
- | Python | [`aiwaf`](https://pypi.org/project/aiwaf/) | `1.2.5` | Django, Flask, and FastAPI protection |
47
- | Node.js | [`aiwaf`](https://www.npmjs.com/package/aiwaf) | `1.2.4` | Express and Node framework middleware |
48
- | Rust/Python | [`aiwaf-rust`](https://pypi.org/project/aiwaf-rust/) | `0.2.12` | Native Python acceleration and JSON model inference |
49
- | WebAssembly | [`aiwaf-wasm`](https://www.npmjs.com/package/aiwaf-wasm) | `0.2.9` | Rust detection and model primitives for JavaScript |
50
- | Java | `io.github.aiwaf-project:aiwaf-java` | `1.3.8` | Spring MVC and Jakarta Servlet protection |
46
+ | Python | [`aiwaf`](https://pypi.org/project/aiwaf/) | `1.2.6` | Django, Flask, and FastAPI protection |
47
+ | Node.js | [`aiwaf`](https://www.npmjs.com/package/aiwaf) | `1.2.5` | Express and Node framework middleware |
48
+ | Rust/Python | [`aiwaf-rust`](https://pypi.org/project/aiwaf-rust/) | `0.2.13` | Native Python acceleration and JSON model inference |
49
+ | WebAssembly | [`aiwaf-wasm`](https://www.npmjs.com/package/aiwaf-wasm) | `0.2.10` | Rust detection and model primitives for JavaScript |
50
+ | Java | `io.github.aiwaf-project:aiwaf-java` | `1.3.9` | Spring MVC and Jakarta Servlet protection |
51
51
 
52
52
  Supported framework integrations include Django, Flask, FastAPI, Express, Fastify, Hapi, Koa, NestJS, Next.js API routes, AdonisJS, Sails.js, Spring MVC, and Jakarta Servlet.
53
53
 
@@ -68,6 +68,24 @@ Supported framework integrations include Django, Flask, FastAPI, Express, Fastif
68
68
 
69
69
  The runtimes share policy intent and training feature names, but their framework adapters and model implementations remain language-native. Model artifacts are not generally interchangeable across languages.
70
70
 
71
+ ## Profiles
72
+
73
+ `AIWAF_PROFILE` sets sensible defaults with one setting, in Django and Flask settings,
74
+ FastAPI's `AIWAFConfig` (or `AIWAF(app, profile=...)`), the Node.js options, the Java config
75
+ (`profile`) or the environment. A setting you give explicitly always wins over the profile.
76
+
77
+ | Profile | What it does |
78
+ | --- | --- |
79
+ | `balanced` (default) | Every default as it is. |
80
+ | `strict` | Halves the rate and flood limits (Django, Flask, FastAPI and Java: 10 and 20 a window; Node.js: 50 and 100), turns on UUID scoring, header validation and the method policy where the runtime has them as settings, and keeps the SQL and route checks blocking. |
81
+ | `monitor` | A dry run. Every check runs, and what it would block is logged instead, as `AIWAF monitor: would block GET /.env from 203.0.113.9 with 403 (...)`. Nothing is blocked and no IP is added to the blocklist. |
82
+
83
+ Use `monitor` to try AIWAF on real traffic before turning it on. Its log lines go to the
84
+ `aiwaf.monitor` logger in Python, `console.warn` in Node.js and `com.aiwaf.monitor` in Java.
85
+ Monitor runs the regular middleware, where every block decision can be logged instead: the
86
+ automatic native pipeline stays off, and a native pipeline chosen explicitly refuses to start.
87
+ Java's request body size limit still applies.
88
+
71
89
  ## Client IP addresses and proxies
72
90
 
73
91
  Blocks, exemptions, rate limits, and geo policies all depend on the client address. Python, Node.js, and Java read `X-Forwarded-For` and `X-Real-IP` only when the connecting peer is a trusted proxy. They walk `X-Forwarded-For` from the right and stop at the first untrusted address, because anything further left is client-supplied. `CF-Connecting-IP` and other vendor headers are not read for this purpose. In Python and Node.js the walk runs in `aiwaf-rust` and `aiwaf-wasm`, which also write IPv6 addresses in canonical form.
@@ -235,6 +253,25 @@ values too. A match blocks the request with `403` and logs an event like this:
235
253
  {"event": "aiwaf.injection_risk", "mode": "block", "method": "GET", "route": "/files", "sink": "path", "input": "name", "rule": "path_traversal", "confidence": "medium"}
236
254
  ```
237
255
 
256
+ | Operation | Rules: what a value must contain to match |
257
+ | --- | --- |
258
+ | `sql` | The SQL tokenizer: a value that closes its SQL literal and continues as SQL |
259
+ | `command` | `command_chain`, `command_substitution`: `;`, `&` or `\|` and a command, `$(...)`, backticks |
260
+ | `path` | `path_traversal`, `path_sensitive_location`, `path_null_byte` |
261
+ | `ssrf` | `ssrf_scheme`, `ssrf_internal_host`: `file://` and similar, private and metadata hosts |
262
+ | `nosql`, `code`, `template`, `deserialization` | operators like `$ne`, `eval(`, `{{ }}`, serialized object markers |
263
+ | `xss` | `xss_markup`, `xss_event_handler`, `xss_script_url`: `<script`, `onerror=`, `javascript:` |
264
+ | `redirect` | `redirect_external`: `//host`, `/\host`, `javascript:`, `user@host` and `https:host` targets |
265
+ | `ldap` | `ldap_filter`: `)(`, `(|(`, a leading `*)` |
266
+ | `xpath` | `xpath_quote_break`, `xpath_tautology`: `' or 'a'='a`, `or 1=1` |
267
+ | `xxe` | `xxe_entity`: `<!DOCTYPE` or `<!ENTITY` |
268
+ | `redos` | `redos_nested_quantifier`: `(a+)+` and similar |
269
+ | `prototype` | `prototype_key`: `__proto__`, `constructor.prototype` |
270
+
271
+ Every rule is checked against a shared list of ordinary values (names, addresses, prose with
272
+ quotes and parentheses) that must never match. A plain absolute URL passes the redirect rule,
273
+ because the site's own host isn't known there.
274
+
238
275
  ```bash
239
276
  aiwaf init --framework flask --app app:app # audits the current folder
240
277
  aiwaf init --framework flask --app app:app --source src # audits another folder
@@ -294,7 +331,7 @@ pip install "aiwaf[django]"
294
331
  pip install "aiwaf[flask]"
295
332
  pip install "aiwaf[fastapi]"
296
333
 
297
- # Backward-compatible alias; Python 1.2.5 already installs aiwaf-rust
334
+ # Backward-compatible alias; Python 1.2.6 already installs aiwaf-rust
298
335
  pip install "aiwaf[rust]"
299
336
 
300
337
  # Node.js middleware
@@ -304,13 +341,13 @@ npm install aiwaf
304
341
  npm install aiwaf-wasm
305
342
  ```
306
343
 
307
- Java 1.3.8, after it is published to Maven Central:
344
+ Java 1.3.9, after it is published to Maven Central:
308
345
 
309
346
  ```xml
310
347
  <dependency>
311
348
  <groupId>io.github.aiwaf-project</groupId>
312
349
  <artifactId>aiwaf-java</artifactId>
313
- <version>1.3.8</version>
350
+ <version>1.3.9</version>
314
351
  </dependency>
315
352
  ```
316
353
 
@@ -318,7 +355,7 @@ Java 1.3.8, after it is published to Maven Central:
318
355
 
319
356
  The Python package requires Python 3.10 or newer. Framework dependencies are optional, so install only the extra needed by the application.
320
357
 
321
- Python 1.2.5 requires `aiwaf-rust>=0.2.12`; the `rust` extra remains an installation
358
+ Python 1.2.6 requires `aiwaf-rust>=0.2.13`; the `rust` extra remains an installation
322
359
  alias. Publish the matching Rust wheel with `NativeCSVPipeline` support before
323
360
  the Python release. The Rust release workflow builds Linux x86_64/aarch64,
324
361
  musl x86_64, macOS x86_64/arm64 and Windows x86_64 wheels and checks the native
@@ -1388,7 +1425,7 @@ cp -R ../licenses crates/aiwaf_wasm/pkg/
1388
1425
 
1389
1426
  ## Java package
1390
1427
 
1391
- AIWAF Java 1.3.8 targets Java 17, Spring Framework 7.0, and Jakarta Servlet 6.1. It is a native Java implementation and does not load the Rust library.
1428
+ AIWAF Java 1.3.9 targets Java 17, Spring Framework 7.0, and Jakarta Servlet 6.1. It is a native Java implementation and does not load the Rust library.
1392
1429
 
1393
1430
  ### Core engine
1394
1431
 
@@ -1477,7 +1514,7 @@ UUID protection uses Python-compatible weighted signals: malformed input, valid
1477
1514
  Generate a route manifest from the live Spring application rather than supplying controller methods manually:
1478
1515
 
1479
1516
  ```bash
1480
- java -cp "your-app.jar:aiwaf-java-1.3.8.jar" \
1517
+ java -cp "your-app.jar:aiwaf-java-1.3.9.jar" \
1481
1518
  com.aiwaf.cli.AiwafConsole init \
1482
1519
  --app com.example.Application \
1483
1520
  --output .aiwaf/paths.json
@@ -1705,11 +1742,11 @@ Release versions and tags must match the relevant manifest.
1705
1742
 
1706
1743
  | Package | Manifest | Tag | Workflow |
1707
1744
  | --- | --- | --- | --- |
1708
- | Python `aiwaf` | `pyproject.toml` | `python-v1.2.5` | `python-publish.yml` |
1709
- | npm `aiwaf` | `js/package.json` | `js-v1.2.4` | `npm-publish.yml` |
1710
- | PyPI `aiwaf-rust` | `rust/pyproject.toml` + `rust/Cargo.toml` | `rust-v0.2.12` | `rust-publish.yml` |
1711
- | npm `aiwaf-wasm` | `rust/crates/aiwaf_wasm/Cargo.toml` | `wasm-v0.2.9` | `wasm-publish.yml` |
1712
- | Maven `aiwaf-java` | `java/pom.xml` | `java-v1.3.8` | `java-publish.yml` |
1745
+ | Python `aiwaf` | `pyproject.toml` | `python-v1.2.6` | `python-publish.yml` |
1746
+ | npm `aiwaf` | `js/package.json` | `js-v1.2.5` | `npm-publish.yml` |
1747
+ | PyPI `aiwaf-rust` | `rust/pyproject.toml` + `rust/Cargo.toml` | `rust-v0.2.13` | `rust-publish.yml` |
1748
+ | npm `aiwaf-wasm` | `rust/crates/aiwaf_wasm/Cargo.toml` | `wasm-v0.2.10` | `wasm-publish.yml` |
1749
+ | Maven `aiwaf-java` | `java/pom.xml` | `java-v1.3.9` | `java-publish.yml` |
1713
1750
 
1714
1751
  Python and Rust publish to PyPI with trusted publishing. The npm workflows use npm trusted publishing and stage packages for approval. Configure the trusted publisher with organization `aiwaf-project`, repository `aiwaf`, the exact workflow filename, and the environment used by that workflow.
1715
1752
 
@@ -1717,12 +1754,12 @@ Java publishing uses the protected `maven-publish` environment plus `GPG_PRIVATE
1717
1754
 
1718
1755
  Registry releases are immutable. Increment the relevant manifest version before publishing another release.
1719
1756
 
1720
- This release is Python `aiwaf 1.2.5`, npm `aiwaf 1.2.4` and Java `aiwaf-java 1.3.8`, with
1721
- the injection audit changes. Python 1.2.4, Java 1.3.7, `aiwaf-rust 0.2.12` and
1722
- `aiwaf-wasm 0.2.9` are already published, and the engines are unchanged. Python now requires
1723
- `aiwaf-rust>=0.2.12` and npm `aiwaf` `aiwaf-wasm ^0.2.9`, so every native feature is available
1724
- after an install. npm `aiwaf` 1.2.3 was staged but never released, and npm doesn't reuse a
1725
- version, so npm `aiwaf 1.2.4` also ships the Node.js changes listed under Python 1.2.4.
1757
+ This release is Python `aiwaf 1.2.6`, npm `aiwaf 1.2.5`, Java `aiwaf-java 1.3.9`,
1758
+ `aiwaf-rust 0.2.13` and `aiwaf-wasm 0.2.10`: `AIWAF_PROFILE` and the route checks for the new
1759
+ operations. Python 1.2.5, npm 1.2.4, Java 1.3.8, `aiwaf-rust 0.2.12` and `aiwaf-wasm 0.2.9` are
1760
+ already published. Publish the two engines first: they carry the new route rules, and Python
1761
+ requires `aiwaf-rust>=0.2.13`. npm `aiwaf` keeps `aiwaf-wasm ^0.2.9`, which picks up 0.2.10
1762
+ once it's published.
1726
1763
 
1727
1764
  ## Security and limitations
1728
1765
 
@@ -155,6 +155,7 @@ module.exports = {
155
155
  async block(ip, reason = 'WAF blocked', options = {}) {
156
156
  const normalizedIp = String(ip || '').trim();
157
157
  if (!normalizedIp) return false;
158
+ if (require('./profiles').skipBlocklist(normalizedIp, reason)) return false;
158
159
  if (options.checkExemptions !== false) {
159
160
  try {
160
161
  const exemptionStore = require('./exemptionStore');
@@ -0,0 +1,53 @@
1
+ 'use strict';
2
+
3
+ // AIWAF_PROFILE: one setting for sensible defaults.
4
+ // - balanced (the default) keeps every default as it is.
5
+ // - strict halves the rate limits and turns the method policy on.
6
+ // - monitor is a dry run: every check runs, and what it would block is logged instead, as
7
+ // "AIWAF monitor: would block ...". Nothing is blocked and no IP is added to the blocklist.
8
+ // A setting given explicitly always wins over the profile.
9
+
10
+ const PROFILES = ['strict', 'balanced', 'monitor'];
11
+ let active = null;
12
+
13
+ function resolve(value) {
14
+ const raw = value === undefined || value === null || value === '' ? process.env.AIWAF_PROFILE : value;
15
+ const name = String(raw || 'balanced').trim().toLowerCase();
16
+ if (!PROFILES.includes(name)) throw new Error(`AIWAF_PROFILE must be one of ${PROFILES.join(', ')}, not ${JSON.stringify(raw)}`);
17
+ return name;
18
+ }
19
+
20
+ function activate(value) {
21
+ active = resolve(value);
22
+ return active;
23
+ }
24
+
25
+ function monitoring() {
26
+ try {
27
+ return (active || resolve()) === 'monitor';
28
+ } catch (_error) {
29
+ return false;
30
+ }
31
+ }
32
+
33
+ // The defaults a profile sets, given Node's own defaults.
34
+ function defaultsFor(profile) {
35
+ if (profile === 'strict') {
36
+ return { MAX_REQ: 50, FLOOD_REQ: 100, AIWAF_METHOD_POLICY_ENABLED: true, AIWAF_SQL_INJECTION_MODE: 'block', AIWAF_INJECTION_RISK_MODE: 'block' };
37
+ }
38
+ if (profile === 'monitor') return { AIWAF_SQL_INJECTION_MODE: 'monitor', AIWAF_INJECTION_RISK_MODE: 'log' };
39
+ return {};
40
+ }
41
+
42
+ function wouldBlock(method, path, ip, status, reason) {
43
+ console.warn(`AIWAF monitor: would block ${method || '-'} ${path || '-'} from ${ip || '-'} with ${status} (${reason || 'blocked'})`);
44
+ }
45
+
46
+ // True in monitor mode, after logging the IP that would have been added to the blocklist.
47
+ function skipBlocklist(ip, reason) {
48
+ if (!monitoring()) return false;
49
+ console.warn(`AIWAF monitor: would add ${ip} to the blocklist (${reason})`);
50
+ return true;
51
+ }
52
+
53
+ module.exports = { PROFILES, activate, defaultsFor, monitoring, resolve, skipBlocklist, wouldBlock };
package/lib/routeRisks.js CHANGED
@@ -8,7 +8,10 @@ const { bodyBytes } = require('./sqlInjection');
8
8
  const wasmChecks = require('./wasmChecks');
9
9
 
10
10
  // The operations a saved finding can name. The rules for each run in aiwaf-wasm.
11
- const SINKS = ['sql', 'nosql', 'command', 'path', 'ssrf', 'code', 'template', 'deserialization'];
11
+ const SINKS = [
12
+ 'sql', 'nosql', 'command', 'path', 'ssrf', 'code', 'template', 'deserialization', 'xss', 'redirect', 'ldap', 'xpath', 'xxe',
13
+ 'redos', 'prototype'
14
+ ];
12
15
 
13
16
  /** Returns the first rule for this operation that matches the value. Needs aiwaf-wasm loaded. */
14
17
  function ruleFor(sink, value) {
@@ -65,6 +65,9 @@ function toPathRules(value, defaultValue = []) {
65
65
 
66
66
  function normalizeSettings(rawOpts = {}) {
67
67
  const legacy = rawOpts.AIWAF_SETTINGS || {};
68
+ // AIWAF_PROFILE supplies the defaults below; a setting given explicitly still wins.
69
+ const profile = require('./profiles').resolve(firstDefined(rawOpts.AIWAF_PROFILE, rawOpts.profile));
70
+ const preset = require('./profiles').defaultsFor(profile);
68
71
 
69
72
  const normalized = {
70
73
  ...rawOpts,
@@ -72,8 +75,8 @@ function normalizeSettings(rawOpts = {}) {
72
75
  dynamicTopN: toNumber(firstDefined(rawOpts.dynamicTopN, rawOpts.DYNAMIC_TOP_N, legacy.keywords?.dynamicTopN), 10),
73
76
 
74
77
  WINDOW_SEC: toNumber(firstDefined(rawOpts.WINDOW_SEC, rawOpts.windowSec, rawOpts.AIWAF_WINDOW_SECONDS, legacy.rate?.window, process.env.AIWAF_RATE_WINDOW), 60),
75
- MAX_REQ: toNumber(firstDefined(rawOpts.MAX_REQ, rawOpts.maxReq, legacy.rate?.max, process.env.AIWAF_RATE_MAX), 100),
76
- FLOOD_REQ: toNumber(firstDefined(rawOpts.FLOOD_REQ, rawOpts.floodReq, legacy.rate?.flood, process.env.AIWAF_RATE_FLOOD), 200),
78
+ MAX_REQ: toNumber(firstDefined(rawOpts.MAX_REQ, rawOpts.maxReq, legacy.rate?.max, process.env.AIWAF_RATE_MAX), preset.MAX_REQ ?? 100),
79
+ FLOOD_REQ: toNumber(firstDefined(rawOpts.FLOOD_REQ, rawOpts.floodReq, legacy.rate?.flood, process.env.AIWAF_RATE_FLOOD), preset.FLOOD_REQ ?? 200),
77
80
 
78
81
  HONEYPOT_FIELD: firstDefined(rawOpts.HONEYPOT_FIELD, rawOpts.honeypotField, legacy.honeypot?.field),
79
82
  AIWAF_MIN_FORM_TIME: toNumber(firstDefined(rawOpts.AIWAF_MIN_FORM_TIME, rawOpts.minFormTime, legacy.honeypot?.minFormTime, process.env.AIWAF_MIN_FORM_TIME), 0),
@@ -81,7 +84,7 @@ function normalizeSettings(rawOpts = {}) {
81
84
  AIWAF_LOGIN_PATH_PREFIXES: toArray(firstDefined(rawOpts.AIWAF_LOGIN_PATH_PREFIXES, rawOpts.loginPathPrefixes, legacy.honeypot?.loginPathPrefixes, process.env.AIWAF_LOGIN_PATH_PREFIXES), [...loginPathPrefixes]),
82
85
  AIWAF_POST_ONLY_SUFFIXES: toArray(firstDefined(rawOpts.AIWAF_POST_ONLY_SUFFIXES, rawOpts.postOnlySuffixes, legacy.honeypot?.postOnlySuffixes, process.env.AIWAF_POST_ONLY_SUFFIXES), undefined),
83
86
  AIWAF_ALLOWED_METHODS: toArray(firstDefined(rawOpts.AIWAF_ALLOWED_METHODS, rawOpts.allowedMethods, legacy.honeypot?.allowedMethods, process.env.AIWAF_ALLOWED_METHODS), undefined),
84
- AIWAF_METHOD_POLICY_ENABLED: toBool(firstDefined(rawOpts.AIWAF_METHOD_POLICY_ENABLED, rawOpts.methodPolicyEnabled, legacy.honeypot?.methodPolicyEnabled, process.env.AIWAF_METHOD_POLICY_ENABLED), false),
87
+ AIWAF_METHOD_POLICY_ENABLED: toBool(firstDefined(rawOpts.AIWAF_METHOD_POLICY_ENABLED, rawOpts.methodPolicyEnabled, legacy.honeypot?.methodPolicyEnabled, process.env.AIWAF_METHOD_POLICY_ENABLED), preset.AIWAF_METHOD_POLICY_ENABLED ?? false),
85
88
 
86
89
  AIWAF_EXEMPT_PATHS: toArray(firstDefined(rawOpts.AIWAF_EXEMPT_PATHS, rawOpts.exemptPaths, legacy.exemptions?.paths, process.env.AIWAF_EXEMPT_PATHS), []),
87
90
  AIWAF_EXEMPT_IPS: toArray(firstDefined(rawOpts.AIWAF_EXEMPT_IPS, rawOpts.exemptIps, legacy.exemptions?.ips, process.env.AIWAF_EXEMPT_IPS), []),
@@ -134,7 +137,9 @@ function normalizeSettings(rawOpts = {}) {
134
137
  AIWAF_DISABLE_MIDDLEWARES: toArray(firstDefined(rawOpts.AIWAF_DISABLE_MIDDLEWARES, rawOpts.disableMiddlewares, rawOpts.disabledMiddlewares, legacy.middlewares?.disabled, process.env.AIWAF_DISABLE_MIDDLEWARES), []),
135
138
  AIWAF_PATH_RULES: toPathRules(firstDefined(rawOpts.AIWAF_PATH_RULES, rawOpts.pathRules, legacy.pathRules, process.env.AIWAF_PATH_RULES), []),
136
139
  AIWAF_PATH_MANIFEST: firstDefined(rawOpts.AIWAF_PATH_MANIFEST, rawOpts.pathManifest, legacy.pathManifest, process.env.AIWAF_PATH_MANIFEST, '.aiwaf/paths.json'),
137
- AIWAF_INJECTION_RISK_MODE: firstDefined(rawOpts.AIWAF_INJECTION_RISK_MODE, rawOpts.injectionRiskMode, process.env.AIWAF_INJECTION_RISK_MODE, 'block'),
140
+ AIWAF_INJECTION_RISK_MODE: firstDefined(rawOpts.AIWAF_INJECTION_RISK_MODE, rawOpts.injectionRiskMode, process.env.AIWAF_INJECTION_RISK_MODE, preset.AIWAF_INJECTION_RISK_MODE, 'block'),
141
+ AIWAF_SQL_INJECTION_MODE: firstDefined(rawOpts.AIWAF_SQL_INJECTION_MODE, rawOpts.sqlInjectionMode, process.env.AIWAF_SQL_INJECTION_MODE, preset.AIWAF_SQL_INJECTION_MODE),
142
+ AIWAF_PROFILE: profile,
138
143
  AIWAF_ROUTE_PLAN_VERSION: firstDefined(rawOpts.AIWAF_ROUTE_PLAN_VERSION, rawOpts.routePlanVersion, legacy.routePlanVersion, process.env.AIWAF_ROUTE_PLAN_VERSION, 0),
139
144
  AIWAF_ACCESS_LOG: firstDefined(rawOpts.AIWAF_ACCESS_LOG, rawOpts.accessLog, process.env.AIWAF_ACCESS_LOG, process.env.NODE_LOG_PATH),
140
145
 
@@ -225,6 +225,18 @@ const recentRequests = limit => Promise.resolve().then(() => requestLogStore.rec
225
225
  .catch(error => { storeFailed('request log read', error); return []; });
226
226
 
227
227
  module.exports = function aiwaf(rawOpts = {}) {
228
+ const profiles = require('./profiles');
229
+ if (profiles.activate(rawOpts.AIWAF_PROFILE ?? rawOpts.profile) === 'monitor') {
230
+ // Monitor runs the regular middleware, whose every block can be logged instead.
231
+ if (rawOpts.AIWAF_NATIVE_PIPELINE !== undefined && rawOpts.AIWAF_NATIVE_PIPELINE !== false) {
232
+ throw new Error('AIWAF_PROFILE=monitor runs the regular middleware: leave AIWAF_NATIVE_PIPELINE unset.');
233
+ }
234
+ if (rawOpts.AIWAF_NATIVE_PIPELINE === undefined) {
235
+ staysRegular('AIWAF_PROFILE is monitor, which logs what it would block instead of blocking.');
236
+ console.warn('AIWAF monitor: nothing is blocked; what would be blocked is logged.');
237
+ }
238
+ rawOpts = { ...rawOpts, AIWAF_NATIVE_PIPELINE: false };
239
+ }
228
240
  if (rawOpts.AIWAF_NATIVE_PIPELINE === false) {
229
241
  const { AIWAF_NATIVE_PIPELINE: _off, ...regularOpts } = rawOpts;
230
242
  rawOpts = regularOpts;
@@ -388,6 +400,11 @@ module.exports = function aiwaf(rawOpts = {}) {
388
400
  markRequestStart(req);
389
401
 
390
402
  const deny = (status, code, reason, country = '') => {
403
+ if (opts.AIWAF_PROFILE === 'monitor') {
404
+ // A dry run: say what would be blocked, and let the request through.
405
+ require('./profiles').wouldBlock(method, path, ip, status, reason || code);
406
+ return next();
407
+ }
391
408
  middlewareLogger.markBlocked(res, reason || code, country);
392
409
  if (process.env.AIWAF_DEBUG_MIDDLEWARE) {
393
410
  console.error(`[AIWAF-BLOCK] status=${status} code=${code} reason=${reason} ip=${ip}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aiwaf",
3
- "version": "1.2.4",
3
+ "version": "1.2.5",
4
4
  "description": "AIWAF Web Application Firewall for JavaScript applications and major Node.js frameworks",
5
5
  "main": "index.js",
6
6
  "files": [