aiwaf 1.1.4 → 1.1.6
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 +313 -202
- package/bin/aiwaf.js +84 -61
- package/lib/blacklistManager.js +2 -358
- package/lib/blocklistManager.js +364 -0
- package/lib/csvStore.js +1 -1
- package/lib/geoBlocker.js +1 -7
- package/lib/injectionAnalysis.js +600 -0
- package/lib/nativePipeline.js +18 -3
- package/lib/pathManifest.js +17 -1
- package/lib/rateLimiter.js +4 -4
- package/lib/routeRisks.js +181 -0
- package/lib/runtimeUtils.js +201 -6
- package/lib/settingsCompat.js +2 -0
- package/lib/sqlInjection.js +55 -49
- package/lib/wafMiddleware.js +22 -12
- package/lib/wasmAdapter.js +15 -2
- package/lib/wasmChecks.js +40 -0
- package/package.json +7 -44
- package/train.js +6 -6
package/README.md
CHANGED
|
@@ -39,22 +39,21 @@ 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.1.
|
|
43
|
-
[upgrade notes](docs/releases/2026-10-elv2.md).
|
|
42
|
+
Python 1.1.9, Rust/Python 0.2.8, Node.js 1.1.6, WASM 0.2.6, and Java 1.3.6 are local source targets. See the package table below and [CHANGELOG](CHANGELOG.md) for release changes.
|
|
44
43
|
|
|
45
44
|
| Runtime | Package | Repository version | Primary use |
|
|
46
45
|
| --- | --- | ---: | --- |
|
|
47
|
-
| Python | [`aiwaf`](https://pypi.org/project/aiwaf/) | `1.1.
|
|
48
|
-
| Node.js | [`aiwaf`](https://www.npmjs.com/package/aiwaf) | `1.1.
|
|
49
|
-
| Rust/Python | [`aiwaf-rust`](https://pypi.org/project/aiwaf-rust/) | `0.2.
|
|
50
|
-
| WebAssembly | [`aiwaf-wasm`](https://www.npmjs.com/package/aiwaf-wasm) | `0.2.
|
|
51
|
-
| Java | `io.github.aiwaf-project:aiwaf-java` | `1.3.
|
|
46
|
+
| Python | [`aiwaf`](https://pypi.org/project/aiwaf/) | `1.1.9` | Django, Flask, and FastAPI protection |
|
|
47
|
+
| Node.js | [`aiwaf`](https://www.npmjs.com/package/aiwaf) | `1.1.6` | Express and Node framework middleware |
|
|
48
|
+
| Rust/Python | [`aiwaf-rust`](https://pypi.org/project/aiwaf-rust/) | `0.2.8` | Native Python acceleration and JSON model inference |
|
|
49
|
+
| WebAssembly | [`aiwaf-wasm`](https://www.npmjs.com/package/aiwaf-wasm) | `0.2.6` | Rust detection and model primitives for JavaScript |
|
|
50
|
+
| Java | `io.github.aiwaf-project:aiwaf-java` | `1.3.6` | Spring MVC and Jakarta Servlet protection |
|
|
52
51
|
|
|
53
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.
|
|
54
53
|
|
|
55
54
|
## What AIWAF provides
|
|
56
55
|
|
|
57
|
-
- IP
|
|
56
|
+
- IP blocklist, exemption, reputation, expiry, and progressive-block handling
|
|
58
57
|
- Sliding-window rate limiting and flood detection
|
|
59
58
|
- Header, method, request-size, content-type, and parameter validation
|
|
60
59
|
- Static and learned malicious keyword detection
|
|
@@ -69,6 +68,167 @@ Supported framework integrations include Django, Flask, FastAPI, Express, Fastif
|
|
|
69
68
|
|
|
70
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.
|
|
71
70
|
|
|
71
|
+
## Client IP addresses and proxies
|
|
72
|
+
|
|
73
|
+
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.
|
|
74
|
+
|
|
75
|
+
By default, Python and Node.js trust loopback, RFC 1918, link-local, and IPv6 unique-local peers, so a proxy on a private network needs no configuration. Java trusts loopback only. Set `AIWAF_TRUSTED_PROXIES` to a list or comma-separated string of addresses and CIDR ranges to replace those defaults. An empty value trusts no proxy. Two names can be used alongside addresses: `default` for the runtime's built-in ranges and `cloudflare` for [Cloudflare's published ranges](https://www.cloudflare.com/ips/). Behind Cloudflare, use `AIWAF_TRUSTED_PROXIES=default,cloudflare` to keep trusting a local proxy as well.
|
|
76
|
+
|
|
77
|
+
When a peer that isn't trusted sends `X-Forwarded-For` or `X-Real-IP`, all three runtimes log one warning per process naming that peer. If the peer is your proxy or CDN, add it to `AIWAF_TRUSTED_PROXIES`. A client sending the header directly causes the same warning, and then no action is needed.
|
|
78
|
+
|
|
79
|
+
| Runtime | Where to set it |
|
|
80
|
+
| --- | --- |
|
|
81
|
+
| Django | `AIWAF_TRUSTED_PROXIES` in settings, or the environment variable |
|
|
82
|
+
| Flask | `app.config["AIWAF_TRUSTED_PROXIES"]`, or the environment variable |
|
|
83
|
+
| FastAPI | The environment variable |
|
|
84
|
+
| Node.js | The `AIWAF_TRUSTED_PROXIES` or `trustedProxies` option, or the environment variable |
|
|
85
|
+
| Java | `aiwaf.trusted-proxies` in Spring properties, the environment variable, `security.trusted_proxies` in the JSON config file, or the `trustedProxyCidrs` field |
|
|
86
|
+
|
|
87
|
+
> [!IMPORTANT]
|
|
88
|
+
> If your proxy or CDN connects from a public address (Cloudflare or Google Cloud load balancers, for example), add its ranges to `AIWAF_TRUSTED_PROXIES`. Otherwise every visitor appears to come from the proxy, and rate limiting or a block can then affect all of them. The `cloudflare` name trusts every Cloudflare address, and anyone can send requests through Cloudflare. If clients could also send requests through Cloudflare to your origin from outside your zone, restrict the origin to your zone, for example with authenticated origin pulls.
|
|
89
|
+
|
|
90
|
+
If untrusted hosts can reach the application directly from your private network, narrow the list to your proxy's addresses. Addresses already resolved by Flask's `ProxyFix`, Uvicorn's `--proxy-headers`, or Express `trust proxy` are respected, except that AIWAF still walks the headers when the resolved address is itself in a trusted range. The Rust-owned Node pipeline uses `req.ip` only, so configure `trust proxy` there.
|
|
91
|
+
|
|
92
|
+
## Injection audit
|
|
93
|
+
|
|
94
|
+
`audit` reads your source code and reports where request input can reach SQL, NoSQL,
|
|
95
|
+
shell commands, file paths, outbound requests, code evaluation, templates or
|
|
96
|
+
deserialization. It parses files without running them, and it doesn't change how
|
|
97
|
+
requests are handled.
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
aiwaf audit path/to/app # Python
|
|
101
|
+
npx aiwaf audit path/to/app # Node.js
|
|
102
|
+
java -cp <classpath> com.aiwaf.cli.AiwafConsole audit src # Java, needs a JDK
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
| Language | Frameworks | Parser |
|
|
106
|
+
| --- | --- | --- |
|
|
107
|
+
| Python | Django, Flask, FastAPI | `ast` |
|
|
108
|
+
| Node.js | Express, Fastify, Hapi, Koa, NestJS, Next.js, AdonisJS, Sails | `@babel/parser` |
|
|
109
|
+
| Java | Spring, Jakarta Servlet, JAX-RS parameters | JDK Compiler Tree API |
|
|
110
|
+
|
|
111
|
+
All three accept `--format text|json`, `--output <file>`, `--include-tests` and
|
|
112
|
+
`--fail-on-findings` and `--manifest <file>`. The exit status is 0 when the scan completes, 1 with
|
|
113
|
+
`--fail-on-findings` when something is found, and 2 for a bad path or argument.
|
|
114
|
+
|
|
115
|
+
A finding is a path worth reading, not a confirmed vulnerability. A reverse proxy, for
|
|
116
|
+
example, will report its upstream request because forwarding input is its job. A clean
|
|
117
|
+
report doesn't prove the code is safe: input that crosses files, classes or dynamic
|
|
118
|
+
calls can be missed, because helpers are only followed within one file or class.
|
|
119
|
+
|
|
120
|
+
Java can also build a route manifest from source, without starting the application.
|
|
121
|
+
This is how plain Servlet applications get a manifest:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
java -cp <classpath> com.aiwaf.cli.AiwafConsole init --source src --output .aiwaf/paths.json
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### SQL detection
|
|
128
|
+
|
|
129
|
+
AIWAF checks request values for SQL injection with a tokenizer. It tries each value as a
|
|
130
|
+
bare number, inside single quotes, and inside double quotes, and flags it only when the
|
|
131
|
+
value closes that SQL value and what follows reads as SQL. It catches `1 OR 1=1` and
|
|
132
|
+
`1 AND SLEEP(5)`, which have no quote, and MySQL's executed comments such as
|
|
133
|
+
`/*!50000UNION*/`. It passes text like `"Item" #3`, `o'reilly`, `union select committee`
|
|
134
|
+
and `Drop table tennis; update your set list`.
|
|
135
|
+
|
|
136
|
+
Text such as `union select password` on its own isn't flagged, because without a value to
|
|
137
|
+
close it can't change a query.
|
|
138
|
+
|
|
139
|
+
Besides the query string and body, the check reads the URL path and the headers, where SQL
|
|
140
|
+
injection also reaches applications. The path is checked one segment at a time, as in
|
|
141
|
+
`/post/1 OR 1=1`. Cookies are checked by their names and values, and the `Referer`,
|
|
142
|
+
`X-Original-URL` and `X-Rewrite-URL` by their path and query string. Every other header is
|
|
143
|
+
checked as one value, such as `User-Agent`, `X-Forwarded-For`, `Accept-Language` or an app's own
|
|
144
|
+
`X-` headers. Headers that hold credentials, framing or browser-set values aren't checked:
|
|
145
|
+
`Authorization`, `Accept`, `Content-*`, `Sec-*`, `If-*`, `Host`, CSRF tokens and tracing IDs.
|
|
146
|
+
Values are decoded the same way, including IIS `%uXXXX` escapes and null bytes, and JSON and XML
|
|
147
|
+
documents are checked by their values. Real browser, app, crawler, client and proxy headers,
|
|
148
|
+
analytics and session cookies, and search referers are in `tests/fixtures/sql_header_cases.json`,
|
|
149
|
+
and ordinary and attack paths in `tests/fixtures/sql_path_cases.json`. Every implementation runs
|
|
150
|
+
both. None of the 11,743 URL paths found in the documentation of this project's dependencies is
|
|
151
|
+
flagged. `AIWAF_SQL_INJECTION_MODE` still chooses whether a finding
|
|
152
|
+
blocks (the default), is only logged, or is ignored.
|
|
153
|
+
|
|
154
|
+
In Python, the whole request check runs in `aiwaf-rust`, which is required: one call walks
|
|
155
|
+
the query and body, decodes values, reads JSON bodies by their values, applies the size limits
|
|
156
|
+
and runs the tokenizer. It runs whatever `AIWAF_USE_RUST` says, because there's no Python copy.
|
|
157
|
+
Node.js runs the same Rust code through `aiwaf-wasm`, which it requires in the same way, so
|
|
158
|
+
`AIWAF_DISABLE_WASM` doesn't turn these checks off. Java has its own copy.
|
|
159
|
+
|
|
160
|
+
The cases in `tests/fixtures/sql_injection_cases.json` run against every copy in CI, and
|
|
161
|
+
`python scripts/sql_accuracy.py` reports the result. They were written alongside the
|
|
162
|
+
tokenizer, so passing them doesn't prove real-world accuracy. Add any miss or false block you
|
|
163
|
+
see there.
|
|
164
|
+
|
|
165
|
+
Outside test data is measured too. `python scripts/sql_benchmark.py` runs the whole SQL check
|
|
166
|
+
against the OWASP Core Rule Set's SQL injection tests and libinjection's test data, and CI
|
|
167
|
+
fails if the results get worse:
|
|
168
|
+
|
|
169
|
+
| Test set | Attacks caught | Ordinary values flagged |
|
|
170
|
+
| --- | --- | --- |
|
|
171
|
+
| libinjection `sqli-*.txt` | 84,830 of 85,791 (98.9%) | 1 of 421 in `false_positives.txt` |
|
|
172
|
+
| CRS 942, paranoia level 1 | 230 of 324 (71%) | 0 of 49 |
|
|
173
|
+
| CRS 942, paranoia level 2 | 209 of 498 (42%) | 2 of 90 |
|
|
174
|
+
|
|
175
|
+
CRS also matches SQL keywords and function names on their own, such as `concat(` or
|
|
176
|
+
`cast(`, especially at higher paranoia levels. AIWAF flags values that break out of a
|
|
177
|
+
SQL value, plus names that only appear in SQL such as `pg_sleep(` and `information_schema`, so
|
|
178
|
+
it misses many of those CRS fragments by design: matching them would block code snippets and
|
|
179
|
+
ordinary text. Each CRS test's whole request is checked, including its path and headers. Three
|
|
180
|
+
CRS tests marked benign carry SQL injection, such as `/post/foo/24 union all select 1,2,3 from aa`,
|
|
181
|
+
because CRS only means that one rule shouldn't match them. AIWAF flags them, and the benchmark
|
|
182
|
+
lists them apart from false positives.
|
|
183
|
+
|
|
184
|
+
The SQL tokenizer, request walker and route checks are fuzzed: for two minutes per target on
|
|
185
|
+
each pull request, and for 30 minutes each week (`rust/fuzz`). Short random-input tests also
|
|
186
|
+
run with every `cargo test`.
|
|
187
|
+
|
|
188
|
+
### Route-specific checks from init
|
|
189
|
+
|
|
190
|
+
`init` audits your source as it builds the route manifest, and saves which operation each
|
|
191
|
+
route's input reaches. Requests to those routes are then checked for patterns that matter to
|
|
192
|
+
that operation, in the parameter that reaches it. A route whose input reaches a file path is
|
|
193
|
+
checked for traversal, and a route whose input reaches SQL gets the SQL tokenizer on its route
|
|
194
|
+
values too. A match blocks the request with `403` and logs an event like this:
|
|
195
|
+
|
|
196
|
+
```json
|
|
197
|
+
{"event": "aiwaf.injection_risk", "mode": "block", "method": "GET", "route": "/files", "sink": "path", "input": "name", "rule": "path_traversal", "confidence": "medium"}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
aiwaf init --framework flask --app app:app # audits the current folder
|
|
202
|
+
aiwaf init --framework flask --app app:app --source src # audits another folder
|
|
203
|
+
aiwaf init --framework flask --app app:app --no-audit # saves no route checks
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Node.js `aiwaf manifest` accepts `--source` and `--no-audit` too. Java `init --source` uses
|
|
207
|
+
the same parse for routes and findings, and `init --app` audits `src/main/java` (or
|
|
208
|
+
`--audit-source`). `aiwaf audit --manifest <file>` refreshes the saved findings without
|
|
209
|
+
rebuilding the manifest.
|
|
210
|
+
|
|
211
|
+
`AIWAF_INJECTION_RISK_MODE` is `block` by default. Set it to `log` to only log matches, or
|
|
212
|
+
`off` to skip route checks. Flask and Django settings and the Node.js options accept the same
|
|
213
|
+
name, Spring uses `aiwaf.injection-risk-mode`, and the Java config file uses
|
|
214
|
+
`security.injection_risk_mode`. The Node.js native pipeline reads `AIWAF_INJECTION_RISK_MODE`
|
|
215
|
+
and `AIWAF_PATH_MANIFEST` from the environment.
|
|
216
|
+
|
|
217
|
+
- **Only routes with findings:** a route with no saved findings keeps its normal checks, and
|
|
218
|
+
saved findings never turn a protection off.
|
|
219
|
+
- **Logs hold no request values:** events contain route, rule and parameter names from the
|
|
220
|
+
manifest only.
|
|
221
|
+
- **What it reads:** query strings, route values, and buffered JSON or form bodies. Headers,
|
|
222
|
+
cookies and multipart uploads aren't checked.
|
|
223
|
+
- **Unlinked findings:** `init` reports findings it can't tie to a manifest route, and those
|
|
224
|
+
get no route-specific checks. Handlers are matched by path or function name, so routes
|
|
225
|
+
missing from the manifest, or reused function names in Node.js, can stay unlinked.
|
|
226
|
+
- **Stale results:** run `init` again when code changes, for example in your build.
|
|
227
|
+
- **Where they run:** route checks run in Rust: through `aiwaf-rust` in Python and
|
|
228
|
+
`aiwaf-wasm` in Node.js. Java has its own copy.
|
|
229
|
+
- **Accuracy isn't measured on real traffic yet:** if a rule blocks real users on a route,
|
|
230
|
+
set `AIWAF_INJECTION_RISK_MODE=log` while you report it.
|
|
231
|
+
|
|
72
232
|
## Repository layout
|
|
73
233
|
|
|
74
234
|
```text
|
|
@@ -79,7 +239,6 @@ The runtimes share policy intent and training feature names, but their framework
|
|
|
79
239
|
│ └── crates/aiwaf_wasm/ WebAssembly bindings
|
|
80
240
|
├── java/ Java 17 package
|
|
81
241
|
├── tests/ Python integration and parity tests
|
|
82
|
-
├── benchmarks/ Python middleware benchmarks
|
|
83
242
|
├── examples/ Focused Python examples
|
|
84
243
|
├── .github/workflows/ Tests, security checks, and releases
|
|
85
244
|
├── README.md Canonical project documentation
|
|
@@ -97,7 +256,7 @@ pip install "aiwaf[django]"
|
|
|
97
256
|
pip install "aiwaf[flask]"
|
|
98
257
|
pip install "aiwaf[fastapi]"
|
|
99
258
|
|
|
100
|
-
# Backward-compatible alias; Python 1.1.
|
|
259
|
+
# Backward-compatible alias; Python 1.1.9 already installs aiwaf-rust
|
|
101
260
|
pip install "aiwaf[rust]"
|
|
102
261
|
|
|
103
262
|
# Node.js middleware
|
|
@@ -107,13 +266,13 @@ npm install aiwaf
|
|
|
107
266
|
npm install aiwaf-wasm
|
|
108
267
|
```
|
|
109
268
|
|
|
110
|
-
Java 1.3.
|
|
269
|
+
Java 1.3.6, after it is published to Maven Central:
|
|
111
270
|
|
|
112
271
|
```xml
|
|
113
272
|
<dependency>
|
|
114
273
|
<groupId>io.github.aiwaf-project</groupId>
|
|
115
274
|
<artifactId>aiwaf-java</artifactId>
|
|
116
|
-
<version>1.3.
|
|
275
|
+
<version>1.3.6</version>
|
|
117
276
|
</dependency>
|
|
118
277
|
```
|
|
119
278
|
|
|
@@ -121,7 +280,7 @@ Java 1.3.4, after it is published to Maven Central:
|
|
|
121
280
|
|
|
122
281
|
The Python package requires Python 3.10 or newer. Framework dependencies are optional, so install only the extra needed by the application.
|
|
123
282
|
|
|
124
|
-
Python 1.1.
|
|
283
|
+
Python 1.1.9 requires `aiwaf-rust>=0.2.8`; the `rust` extra remains an installation
|
|
125
284
|
alias. Publish the matching Rust wheel with `NativeCSVPipeline` support before
|
|
126
285
|
the Python release. The Rust release workflow builds Linux x86_64/aarch64,
|
|
127
286
|
musl x86_64, macOS x86_64/arm64 and Windows x86_64 wheels and checks the native
|
|
@@ -136,7 +295,7 @@ Install it **instead of the existing eight-middleware chain**. The existing
|
|
|
136
295
|
they do not switch automatically to this pipeline.
|
|
137
296
|
|
|
138
297
|
Rust owns the immutable configuration, enforcement order, SQL and keyword
|
|
139
|
-
inspection, geo and
|
|
298
|
+
inspection, geo and blocklist decisions, rate buckets, form timing state, UUID
|
|
140
299
|
scores, anomaly inference/history, keyword learning and CSV logging. Python
|
|
141
300
|
supplies framework routing/authentication facts, obtains GeoIP country data,
|
|
142
301
|
buffers a bounded body prefix and constructs responses. Each request crosses
|
|
@@ -185,17 +344,20 @@ Common profile keys and defaults:
|
|
|
185
344
|
| Setting | Default / meaning |
|
|
186
345
|
| --- | --- |
|
|
187
346
|
| `enabled` | All eight names: `geo_block`, `ip_keyword_block`, `rate_limit`, `ai_anomaly`, `honeypot`, `uuid_tamper`, `header_validation`, `logging` |
|
|
188
|
-
| `data_dir` | `aiwaf_data`; policy CSVs use the shared
|
|
347
|
+
| `data_dir` | `aiwaf_data`; policy CSVs use the shared allowlist/blocklist/keyword/geo/path schemas |
|
|
189
348
|
| `exempt_paths`, `exempt_ips` | `/health`, `/robots.txt`, `/sitemap.xml`; empty IP list. Paths are literal, case-insensitive prefixes, not globs. Stored path exemptions use the same literal-prefix rule |
|
|
190
349
|
| `sql_mode`, `max_bytes` | `block`, `65536`; `off` supported, `monitor` rejected. Structured JSON/form bodies and nested escaped strings are inspected with bounded traversal |
|
|
191
350
|
| `learning`, `top_n` | `True`, `10`; presence keywords use a sorted, stable subset instead of Python set iteration order |
|
|
192
351
|
| `static_keywords`, `legitimate_keywords`, `exempt_keywords`, `safe_prefixes` | Native policy defaults or explicit arrays; set route-specific safe vocabulary in the profile |
|
|
193
352
|
| `geo_allow`, `geo_block` | Empty lists; includes stored blocked countries. Unknown country remains allowed |
|
|
194
353
|
| `rate_backend`, `rate_key_mode` | `memory`, `ip_path`; `csv` shares buckets across workers; `ip` aggregates paths. Redis is rejected |
|
|
195
|
-
| `rate_window`, `rate_max`, `rate_flood` | `10`, `20`, `40`; throttle at 429, flood at 403 with
|
|
196
|
-
| `
|
|
197
|
-
| `honeypot_backend` | `
|
|
198
|
-
| `
|
|
354
|
+
| `rate_window`, `rate_max`, `rate_flood` | `10`, `20`, `40`; throttle at 429, flood at 403 with blocklist persistence |
|
|
355
|
+
| `soft_block_blocklist`, `ip_blocking`, `block_duration` | `False`, `True`, reputation-based duration; explicit seconds or nonpositive permanent duration |
|
|
356
|
+
| `honeypot_backend` | Django defaults to `django_cache`; Flask/FastAPI and direct construction default to `csv`. Optional `memory` is local to one engine; `redis` and `cache` delegate timestamp I/O while Rust enforces timing |
|
|
357
|
+
| `honeypot_cache_alias` | Django-only; `default`. Uses the named `CACHES` entry for honeypot timestamps, not other policy or rate state |
|
|
358
|
+
| `honeypot_redis_url` | Required for `honeypot_backend="redis"`; stripped before native profile serialization. `rediss://` requires redis-py |
|
|
359
|
+
| `honeypot_cache_namespace` | Redis/custom cache key prefix, default `aiwaf:native:honeypot:v1`; use the same value across workers and a distinct value for unrelated applications |
|
|
360
|
+
| `min_form_time`, `max_page_time`, `skip_authenticated` | `1.0`, `240`, `True`; native Rust applies the timing policy |
|
|
199
361
|
| `uuid_score_enabled`, `uuid_window`, `uuid_threshold` | `True`, `60`, `5`; weights: `uuid_malformed_weight=5`, `uuid_not_found_weight=1`, `uuid_success_decay=2` |
|
|
200
362
|
| `required_headers`, `header_min_score` | `HTTP_USER_AGENT` and `HTTP_ACCEPT`, `3`; empty required list disables required-header/quality checks, retains safety caps |
|
|
201
363
|
| `anomaly_window`, `anomaly_keywords` | `60`, standard anomaly vocabulary; history/scoring is held in Rust per worker |
|
|
@@ -214,26 +376,98 @@ timestamps in an expiring map and evaluates/clears POST timing atomically,
|
|
|
214
376
|
avoiding a durable CSV rewrite on each GET. Timing state is isolated per engine,
|
|
215
377
|
is not shared across workers and resets on restart. Backend switches do not
|
|
216
378
|
transfer timestamps automatically. Keep `csv` for shared or persistent timing;
|
|
217
|
-
CSV writes remain immediately synced.
|
|
379
|
+
CSV writes remain immediately synced. Blocklist, keyword, geo and allowlist
|
|
218
380
|
policy files and immediate request logging keep their configured CSV behavior.
|
|
219
381
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
382
|
+
### Flask and FastAPI native honeypot cache
|
|
383
|
+
|
|
384
|
+
Both native adapters accept Redis or a supplied synchronous cache. CSV remains
|
|
385
|
+
their default. This changes honeypot timestamp storage only; other policies and
|
|
386
|
+
rate-limit backends retain their configured behavior.
|
|
387
|
+
|
|
388
|
+
```python
|
|
389
|
+
import os
|
|
390
|
+
from aiwaf.flask.csv_pipeline import NativeAIWAF
|
|
391
|
+
|
|
392
|
+
profile = {
|
|
393
|
+
"data_dir": "aiwaf_data",
|
|
394
|
+
"honeypot_backend": "redis",
|
|
395
|
+
"honeypot_redis_url": os.environ["AIWAF_REDIS_URL"],
|
|
396
|
+
"honeypot_cache_namespace": "myapp:honeypot:v1",
|
|
397
|
+
}
|
|
398
|
+
NativeAIWAF(app, config=profile) # Flask
|
|
399
|
+
|
|
400
|
+
# FastAPI alternative:
|
|
401
|
+
# from aiwaf.fast.csv_pipeline import NativeAIWAFMiddleware
|
|
402
|
+
# app.add_middleware(NativeAIWAFMiddleware, config=profile)
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
For an existing Flask-Caching instance or another compatible object, select
|
|
406
|
+
`honeypot_backend="cache"` and pass `honeypot_cache=cache` to either native adapter.
|
|
407
|
+
The contract is `get(key)` returning a stored value or `None`, and
|
|
408
|
+
`set(key, value, timeout=seconds)` returning success or `None`. Explicit `False`
|
|
409
|
+
means failure. Methods must be synchronous, preserve a timestamp/expiry pair,
|
|
410
|
+
honor TTL, and propagate storage errors. Disable any ignored-error option;
|
|
411
|
+
no-op cache backends are unsuitable. Custom adapters must translate their own
|
|
412
|
+
cache's TTL argument if it differs. A local cache still isolates workers.
|
|
413
|
+
|
|
414
|
+
Rust retains timing decisions, exemptions and logical expiry. Entries have a
|
|
415
|
+
300-second TTL; misses/evictions permit the POST timing check, while exceptions,
|
|
416
|
+
invalid records and failed writes return generic HTTP 503. Expired-page POSTs
|
|
417
|
+
return 409 until a new GET or TTL expiry, without deleting a concurrent refresh.
|
|
418
|
+
FastAPI offloads the cache-backed native request check to its worker thread pool
|
|
419
|
+
so synchronous network I/O does not block the event loop. Pool saturation and
|
|
420
|
+
cache latency still affect request latency. Existing CSV/memory timing behavior
|
|
421
|
+
and the legacy middleware chain are unchanged.
|
|
422
|
+
|
|
423
|
+
To exercise independent workers against a dedicated test Redis instance, set
|
|
424
|
+
`AIWAF_TEST_REDIS_URL` and run
|
|
425
|
+
`python -m pytest tests/integration/test_native_honeypot_cache.py`.
|
|
426
|
+
|
|
427
|
+
### Django native honeypot cache
|
|
428
|
+
|
|
429
|
+
Starting with Python 1.1.7 / aiwaf-rust 0.2.6, Django's native middleware uses
|
|
430
|
+
the existing Django cache for honeypot GET timestamps by default. Rust calls a
|
|
431
|
+
small Python storage adapter; form timing, logical expiry, exemptions and block
|
|
432
|
+
decisions remain native. Other policies retain their configured CSV storage.
|
|
223
433
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
434
|
+
```python
|
|
435
|
+
AIWAF_CSV_PIPELINE = {
|
|
436
|
+
"data_dir": "aiwaf_data",
|
|
437
|
+
"honeypot_cache_alias": "default", # optional; uses CACHES["default"]
|
|
438
|
+
}
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
Use a shared Django cache backend for cross-worker timing. For example, Django's
|
|
442
|
+
built-in Redis cache can be configured as follows (install its Redis Python
|
|
443
|
+
driver and configure the URL for your deployment):
|
|
444
|
+
|
|
445
|
+
```python
|
|
446
|
+
CACHES = {
|
|
447
|
+
"default": {
|
|
448
|
+
"BACKEND": "django.core.cache.backends.redis.RedisCache",
|
|
449
|
+
"LOCATION": "redis://127.0.0.1:6379/1",
|
|
450
|
+
"KEY_PREFIX": "my-service",
|
|
451
|
+
},
|
|
452
|
+
}
|
|
453
|
+
```
|
|
229
454
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
455
|
+
LocMemCache remains supported with a startup warning: it is worker-local and
|
|
456
|
+
resets on restart. DummyCache is rejected when the honeypot stage is enabled.
|
|
457
|
+
Configured ignored cache errors are rejected; runtime read/write failures,
|
|
458
|
+
failed writes and invalid timestamp records produce generic HTTP 503, without
|
|
459
|
+
silently selecting memory or CSV. Cache methods must be synchronous.
|
|
460
|
+
|
|
461
|
+
Timestamp entries use a 300-second TTL and bounded, hashed client-IP keys under
|
|
462
|
+
Django's key prefix/version. Expired-page POSTs return 409 until a fresh GET or
|
|
463
|
+
TTL expiry. The pipeline does not delete an expired snapshot, so it cannot erase
|
|
464
|
+
a concurrent GET refresh. As before, no timestamp means the timing check allows
|
|
465
|
+
the POST; cache outages are distinguished from misses. Backends can evict entries
|
|
466
|
+
before their TTL. Changing backends does not migrate existing timestamps.
|
|
467
|
+
|
|
468
|
+
Set `"honeypot_backend": "csv"` explicitly to retain shared filesystem timing,
|
|
469
|
+
or `"memory"` for the per-engine Rust map. Install the matching native extension
|
|
470
|
+
before upgrading Django workers. Flask and FastAPI defaults are unchanged.
|
|
237
471
|
|
|
238
472
|
Flask/FastAPI accept synchronous `country_lookup(ip)` and
|
|
239
473
|
`authenticated(request)` callbacks for adapter facts. Default GeoIP uses the
|
|
@@ -251,30 +485,6 @@ available. Session/route handlers, response construction, GeoIP lookup and legac
|
|
|
251
485
|
custom integrations still execute in Python; the whole Python package has not
|
|
252
486
|
been rewritten in Rust.
|
|
253
487
|
|
|
254
|
-
Measure this path with `scripts/benchmark_release_http.py --pipeline`, alongside
|
|
255
|
-
the existing chain and `--plain` framework baseline. Native execution and both
|
|
256
|
-
SQL/PHP protection probes are checked by the harness; the benchmark report
|
|
257
|
-
records workload details and subtracts the framework baseline for added overhead.
|
|
258
|
-
|
|
259
|
-
Matched WSL tests of the complete pipeline (three alternating runs of 300
|
|
260
|
-
requests per framework/mode, one client, all eight stages and immediate CSV
|
|
261
|
-
logging) measured the following **added overhead**, after subtracting the same
|
|
262
|
-
framework-only baseline. The comparison is against the current legacy chain.
|
|
263
|
-
|
|
264
|
-
| Framework | Current chain, AI off | Native pipeline, AI off | Current chain, AI on | Native pipeline, AI on |
|
|
265
|
-
| --- | ---: | ---: | ---: | ---: |
|
|
266
|
-
| Flask | 10.60 ms | 3.77 ms | 14.53 ms | 3.56 ms |
|
|
267
|
-
| Django | 14.18 ms | 3.52 ms | 18.98 ms | 3.66 ms |
|
|
268
|
-
| FastAPI | 11.83 ms | 3.52 ms | 12.21 ms | 3.67 ms |
|
|
269
|
-
|
|
270
|
-
These are medians of per-run mean server times. Native and legacy run ranges
|
|
271
|
-
were separated in all six protected comparisons. All 13,500 measured requests
|
|
272
|
-
returned 200 and both protected modes blocked SQL/PHP probes. The AI fixture
|
|
273
|
-
used a seeded 100-tree Rust forest and 200 initial history records per client.
|
|
274
|
-
The dedicated profile, storage layout and adapter semantics differ from some
|
|
275
|
-
legacy configurations; this is a synthetic comparison of the documented modes,
|
|
276
|
-
not a production latency guarantee or a drop-in migration result.
|
|
277
|
-
|
|
278
488
|
### Flask
|
|
279
489
|
|
|
280
490
|
```python
|
|
@@ -433,7 +643,7 @@ the new capabilities. Older extensions retain the compatible Python fallback.
|
|
|
433
643
|
|
|
434
644
|
- **CSV storage:** bounded snapshot caches and indexed IP/key lookups avoid repeated
|
|
435
645
|
parsing and copying entire tables into Python. Native readers validate file
|
|
436
|
-
metadata and use shared OS locks; mutations use exclusive locks.
|
|
646
|
+
metadata and use shared OS locks; mutations use exclusive locks. Blocklist
|
|
437
647
|
reputation updates, keyword increments/removals, exemptions, audit entries, and
|
|
438
648
|
geo-list changes use atomic transactions. Unchanged policy rows skip rewriting
|
|
439
649
|
and disk synchronization. Changed policy writes still synchronize to disk.
|
|
@@ -441,7 +651,7 @@ the new capabilities. Older extensions retain the compatible Python fallback.
|
|
|
441
651
|
signatures, geo decisions, rate-window filtering, form timing, UUID format
|
|
442
652
|
validation, reputation scoring, wildcard/CIDR exemptions, and longest-prefix
|
|
443
653
|
route plans. Flask CSV keyword retrieval, evaluation, and learning share one
|
|
444
|
-
native call. SQL checks and
|
|
654
|
+
native call. SQL checks and blocklist updates retain their existing order;
|
|
445
655
|
custom evaluators and unsupported Unicode behavior use the Python adapter.
|
|
446
656
|
- **Exemption reuse:** Flask reuses CSV exemption results within a request and
|
|
447
657
|
checks file identity, size, timestamps, and configuration before each reuse.
|
|
@@ -504,12 +714,10 @@ Check the installed extension without touching application data:
|
|
|
504
714
|
python scripts/check_native_csv_runtime.py
|
|
505
715
|
```
|
|
506
716
|
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
pending checks first, preserving first-finding order. Django, Flask, and FastAPI
|
|
512
|
-
use the shared path; older extensions retain single-string checks.
|
|
717
|
+
`policy_sql_inspect` runs the whole SQL request check in one call, and Django, Flask and
|
|
718
|
+
FastAPI use it for every request. `RouteRiskChecker` and `policy_route_rule` run the
|
|
719
|
+
route-specific checks saved by `init`. `policy_sql_tokenizer` checks one value.
|
|
720
|
+
`policy_sql_signatures` and `csv_geo_policy` remain for older releases.
|
|
513
721
|
|
|
514
722
|
Flask with CSV geo state and an explicit allow/block list can read dynamic countries
|
|
515
723
|
and evaluate the geo policy in one native call. Django CSV and FastAPI CSV use
|
|
@@ -519,17 +727,10 @@ extra policy input. ORM-only Django operation remains separate. FastAPI geo
|
|
|
519
727
|
middleware honors its `use_rust` option, passed from the application's Rust flags.
|
|
520
728
|
Dynamic-only FastAPI policy and custom getters/evaluators retain their fallback
|
|
521
729
|
path. Native reads respect TTLs and observe updates/removals; disabled native geo
|
|
522
|
-
reads refresh the Python CSV snapshot. Exemptions and
|
|
730
|
+
reads refresh the Python CSV snapshot. Exemptions and blocklist writes still run
|
|
523
731
|
at their original stages. Rebuild the extension from this checkout to test these
|
|
524
732
|
unpublished capabilities.
|
|
525
733
|
|
|
526
|
-
Run `python scripts/benchmark_native_request_batches.py` for the focused comparison.
|
|
527
|
-
Three alternating Windows runs of 500 checks measured 100-field SQL inspection at
|
|
528
|
-
0.650 ms combined versus 0.989 ms previous, and the CSV geo binding at 0.286 ms
|
|
529
|
-
versus 0.367 ms. Early SQL rejection measured 0.067 ms versus 0.066 ms. These
|
|
530
|
-
isolated, warmed checks exclude the complete middleware chain, networking, model
|
|
531
|
-
scoring, and concurrent load.
|
|
532
|
-
|
|
533
734
|
### Request-time anomaly acceleration (development)
|
|
534
735
|
|
|
535
736
|
With a matching rebuilt extension and a real Rust Isolation Forest, Flask and
|
|
@@ -554,16 +755,6 @@ building a dictionary per historical record. No native process-local object is
|
|
|
554
755
|
stored in Django's cache. These changes do not introduce model auto-reload or
|
|
555
756
|
shared histories for Flask/FastAPI.
|
|
556
757
|
|
|
557
|
-
Run `python scripts/benchmark_anomaly_runtime.py` to compare the previous bridge,
|
|
558
|
-
tuple analysis, and native histories with a real seeded forest. Five alternating
|
|
559
|
-
Windows runs of 300 evaluations, a 100-tree forest, and 200 prior requests measured
|
|
560
|
-
anomalous evaluation at 0.175 ms versus 0.486 ms (2.78x) and benign evaluation at
|
|
561
|
-
0.040 ms versus 0.146 ms (3.61x). The same WSL benchmark measured anomalous
|
|
562
|
-
evaluation at 0.178 ms versus 0.533 ms (2.99x) and benign evaluation at
|
|
563
|
-
0.036 ms versus 0.126 ms (3.46x). These isolated engine timings exclude networking,
|
|
564
|
-
CSV writes, real route-resolution costs, the full middleware chain, and concurrent
|
|
565
|
-
load. They are not deployed-site speedup claims.
|
|
566
|
-
|
|
567
758
|
Further request-path refinements use the existing native CSV log writer for
|
|
568
759
|
Flask/FastAPI anomaly training logs when supported. Each row is flushed before
|
|
569
760
|
returning; there is no background queue. `AIWAF_CSV_LOG_FSYNC=True` additionally
|
|
@@ -581,15 +772,7 @@ worker performs no background cleanup. Django continues to use cache timeouts.
|
|
|
581
772
|
Rust recent-behavior analysis now counts symmetric ten-second bursts with a
|
|
582
773
|
linear sweep after sorting finite timestamps, replacing two binary searches per
|
|
583
774
|
record. Non-finite timestamps retain the established search path. This shared-core
|
|
584
|
-
change also applies to the WASM recent-behavior API.
|
|
585
|
-
`python scripts/benchmark_request_refinements.py` for isolated logging, route, and
|
|
586
|
-
burst-analysis timings; these do not measure deployed-site throughput.
|
|
587
|
-
With five runs of 300 operations in WSL, immediate CSV writes measured 0.030 ms
|
|
588
|
-
versus 0.173 ms, repeated route checks 0.0175 ms versus 0.0266 ms, and analysis of
|
|
589
|
-
1,000 history records 0.663 ms versus 0.787 ms. The route comparison uses the
|
|
590
|
-
previous implementation with its exception import corrected; burst timings
|
|
591
|
-
include Python-to-Rust tuple conversion. These benchmarks use local files and
|
|
592
|
-
synthetic inputs, without concurrent load.
|
|
775
|
+
change also applies to the WASM recent-behavior API.
|
|
593
776
|
|
|
594
777
|
### Python operations
|
|
595
778
|
|
|
@@ -604,26 +787,17 @@ rebuild the profile; CSV state remains live. Flask/FastAPI can use one native ca
|
|
|
604
787
|
for supported query requests. Django keeps SQL inspection before route resolution,
|
|
605
788
|
then uses the compiled keyword/CSV stage with the resolved route facts.
|
|
606
789
|
|
|
607
|
-
Framework extraction, body buffering/replay, exemptions,
|
|
790
|
+
Framework extraction, body buffering/replay, exemptions, blocklist enforcement,
|
|
608
791
|
rate limits, honeypot/UUID hooks, header enforcement, and response processing keep
|
|
609
792
|
their existing positions. Structured SQL bodies, Unicode paths/decoding, monitor
|
|
610
793
|
mode, custom policy/storage hooks, custom Django converters, older extensions,
|
|
611
794
|
and dynamic-keyword subsets whose ranking requires Python retain the established
|
|
612
795
|
path. The engine does not replace the whole eight-middleware chain.
|
|
613
796
|
|
|
614
|
-
Three alternating WSL runs of 300 requests through the full chain, at concurrency
|
|
615
|
-
one with AI scoring off, observed server-time medians of 12.88 to 12.46 ms for
|
|
616
|
-
Flask, 16.09 to 15.60 ms for Django, and 13.41 to 13.17 ms for FastAPI. Run ranges
|
|
617
|
-
overlapped; these do not establish a dependable speedup. The opt-in default avoids
|
|
618
|
-
assuming that fewer boundaries alone remove the remaining request cost. Compare
|
|
619
|
-
`scripts/benchmark_release_http.py` with and without `--engine` using identical
|
|
620
|
-
dependencies and traffic. `--plain` measures an endpoint without AIWAF, and the
|
|
621
|
-
harness reports server processing time separately from HTTP latency.
|
|
622
|
-
|
|
623
797
|
```bash
|
|
624
798
|
# Auto-detected CLI (one supported framework installed)
|
|
625
799
|
aiwaf --help
|
|
626
|
-
aiwaf
|
|
800
|
+
aiwaf blocklist migrate
|
|
627
801
|
aiwaf status
|
|
628
802
|
|
|
629
803
|
# Django management commands
|
|
@@ -769,7 +943,7 @@ npm run aiwaf -- manifest --framework express --routes routes.json --output .aiw
|
|
|
769
943
|
| Logging | `AIWAF_MIDDLEWARE_LOGGING`, `AIWAF_MIDDLEWARE_LOG_PATH`, DB/CSV options |
|
|
770
944
|
| WASM | `AIWAF_WASM_VALIDATION`, `AIWAF_WASM_VALIDATE_RECENT` |
|
|
771
945
|
|
|
772
|
-
AIWAF loads `aiwaf-wasm` when available and falls back to the JavaScript implementation when WASM initialization or conversion is not worthwhile. Small, object-heavy operations can be faster in JavaScript because crossing the JS/WASM boundary and serializing objects has a fixed cost. WASM is most useful for sufficiently large feature batches and model scoring workloads.
|
|
946
|
+
AIWAF loads `aiwaf-wasm` when available and falls back to the JavaScript implementation when WASM initialization or conversion is not worthwhile. The SQL check and route checks are the exception: they run only in `aiwaf-wasm`, and a request fails with an install message if it can't load. Small, object-heavy operations can be faster in JavaScript because crossing the JS/WASM boundary and serializing objects has a fixed cost. WASM is most useful for sufficiently large feature batches and model scoring workloads.
|
|
773
947
|
|
|
774
948
|
The Python filesystem CSV transactions and retained training bindings remain
|
|
775
949
|
PyO3-specific. Node now also has an **explicit stateful WASM request pipeline**;
|
|
@@ -833,7 +1007,7 @@ All eight stages are enabled by default. Native defaults include:
|
|
|
833
1007
|
| `exempt_paths`, `exempt_ips` | `/health`, `/robots.txt`, `/sitemap.xml`; no IPs; literal case-insensitive path prefixes |
|
|
834
1008
|
| `sql_mode`, `max_bytes` | `block`, `65536`; `off` supported, monitor rejected; bounded nested JSON/form values and double URL decoding |
|
|
835
1009
|
| `static_keywords`, `dynamic_keywords`, `legitimate_keywords`, `learning` | Native vocabulary, empty dynamic set, legitimate exact route names, `true`; learned probe segments capped at 4096 |
|
|
836
|
-
| `geo_allow`, `geo_block`, `
|
|
1010
|
+
| `geo_allow`, `geo_block`, `blocklist` | Empty; blocklist maps IP to Unix expiry seconds (`0` permanent) |
|
|
837
1011
|
| `rate_window`, `rate_max`, `rate_flood`, `rate_key_mode` | `10` seconds, `20`, `40`, `ip_path`; `ip` also supported |
|
|
838
1012
|
| `min_form_time`, `max_page_time`, `skip_authenticated`, `honeypot_field` | `1.0`, `240` seconds, `true`, empty field; local Rust timing state |
|
|
839
1013
|
| `allowed_methods`, `uuid_prefix`, `uuid_window`, `uuid_threshold` | Empty method restriction, `/user/`, `60` seconds, `5` repeated UUID 404s; malformed UUID denied immediately |
|
|
@@ -885,23 +1059,7 @@ installed before enforcement; required middleware overrides decorator exemptions
|
|
|
885
1059
|
while profile-level exemptions remain global. Next integration is Node API routes,
|
|
886
1060
|
not Edge/Fetch middleware.
|
|
887
1061
|
|
|
888
|
-
Run `npm run test:native` in `js/` against the built WASM package
|
|
889
|
-
`node scripts/benchmark_js_pipeline.js` for full HTTP comparisons. The benchmark
|
|
890
|
-
subtracts bare Express server processing latency and includes synchronous response
|
|
891
|
-
finalization/logging. Its legacy comparison uses SQLite policy lookups and JSONL
|
|
892
|
-
logging, while native uses Rust state and CSV output; this is an integration
|
|
893
|
-
comparison with different persistence/policy semantics, not a pure language test.
|
|
894
|
-
|
|
895
|
-
The matched Windows HTTP benchmark (Node v22.18.0, Express 4.22.1) measured:
|
|
896
|
-
|
|
897
|
-
| Mode | Server processing | Added overhead |
|
|
898
|
-
| --- | ---: | ---: |
|
|
899
|
-
| Express only | 0.37 ms | 0.00 ms |
|
|
900
|
-
| Legacy, AI off | 3.86 ms | 3.48 ms |
|
|
901
|
-
| Native, AI off | 0.60 ms | 0.22 ms |
|
|
902
|
-
| Native, AI on | 0.64 ms | 0.27 ms |
|
|
903
|
-
|
|
904
|
-
Server samples include synchronous finalization and immediate logging. Overhead subtracts the matched bare Express baseline; figures are medians of per-run means. Legacy uses SQLite policy lookups and one immediate JSONL append; native uses Rust state and one immediate CSV append. These stores/policies have different persistence semantics, so this is an integration comparison, not a pure Rust-versus-JavaScript equivalence test. GeoIP is an unknown-country fixture, not a real database lookup. Synthetic local latency does not establish production throughput or latency.
|
|
1062
|
+
Run `npm run test:native` in `js/` against the built WASM package to validate the native integrations.
|
|
905
1063
|
|
|
906
1064
|
### JavaScript training and operations
|
|
907
1065
|
|
|
@@ -910,8 +1068,8 @@ cd js
|
|
|
910
1068
|
|
|
911
1069
|
AIWAF_ACCESS_LOG=/path/to/access.log npm run train
|
|
912
1070
|
npm run aiwaf -- status
|
|
913
|
-
npm run aiwaf -- list
|
|
914
|
-
npm run aiwaf -- add
|
|
1071
|
+
npm run aiwaf -- list blocklist
|
|
1072
|
+
npm run aiwaf -- add blocklist 203.0.113.9 "manual block"
|
|
915
1073
|
npm run aiwaf -- add ip-exemption 203.0.113.10 "trusted monitor"
|
|
916
1074
|
npm run aiwaf -- geo summary
|
|
917
1075
|
npm run aiwaf -- model info
|
|
@@ -1028,7 +1186,7 @@ cp -R ../licenses crates/aiwaf_wasm/pkg/
|
|
|
1028
1186
|
|
|
1029
1187
|
## Java package
|
|
1030
1188
|
|
|
1031
|
-
AIWAF Java 1.3.
|
|
1189
|
+
AIWAF Java 1.3.6 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.
|
|
1032
1190
|
|
|
1033
1191
|
### Core engine
|
|
1034
1192
|
|
|
@@ -1097,7 +1255,7 @@ aiwaf.storage.redis-pool-min-idle=0
|
|
|
1097
1255
|
aiwaf.storage.redis-pool-max-wait-millis=250
|
|
1098
1256
|
```
|
|
1099
1257
|
|
|
1100
|
-
Set `aiwaf.config-file=/etc/aiwaf/config.json` (or `AIWAF_CONFIG_FILE`) to load the same nested JSON configuration used by the Python runtime. Environment variables and Spring properties override file values. `AiwafConfigFileCore` also exposes load, save, deep-merge, and validation APIs for non-Spring applications.
|
|
1258
|
+
Set `aiwaf.config-file=/etc/aiwaf/config.json` (or `AIWAF_CONFIG_FILE`) to load the same nested JSON configuration used by the Python runtime. Environment variables and Spring properties override file values. Java-only keys include `security.trusted_proxies`, a list such as `["default", "cloudflare"]` or a comma-separated string; an empty list trusts no proxy, and loading fails on an entry that isn't an address, a CIDR range, `default`, or `cloudflare`. `AiwafConfigFileCore` also exposes load, save, deep-merge, and validation APIs for non-Spring applications.
|
|
1101
1259
|
|
|
1102
1260
|
Define an `AiwafConfig`, `AiwafEngine`, or `AiwafFilter` bean only when the application needs a custom replacement. For plain Spring MVC without Boot, register the filter directly; passing the application context enables the same live route discovery:
|
|
1103
1261
|
|
|
@@ -1117,7 +1275,7 @@ UUID protection uses Python-compatible weighted signals: malformed input, valid
|
|
|
1117
1275
|
Generate a route manifest from the live Spring application rather than supplying controller methods manually:
|
|
1118
1276
|
|
|
1119
1277
|
```bash
|
|
1120
|
-
java -cp "your-app.jar:aiwaf-java-1.3.
|
|
1278
|
+
java -cp "your-app.jar:aiwaf-java-1.3.6.jar" \
|
|
1121
1279
|
com.aiwaf.cli.AiwafConsole init \
|
|
1122
1280
|
--app com.example.Application \
|
|
1123
1281
|
--output .aiwaf/paths.json
|
|
@@ -1154,9 +1312,9 @@ The generic servlet filter uses request-time evaluation. Spring applications sho
|
|
|
1154
1312
|
| Storage | `storageBackend`, `storageFilePath`, `storageRedisUrl`, `storageKeyPrefix`, `storageRedisFailureMode`, Redis timeout and pool limits |
|
|
1155
1313
|
| Telemetry | `observabilityEnabled` |
|
|
1156
1314
|
|
|
1157
|
-
GeoIP uses the bundled MMDB through the native Java reader; it does not require the external `mmdblookup` executable. A valid `X-Country` value is accepted only from a peer in `trustedProxyCidrs`; otherwise AIWAF resolves the client address itself. Default
|
|
1315
|
+
GeoIP uses the bundled MMDB through the native Java reader; it does not require the external `mmdblookup` executable. A valid `X-Country` value is accepted only from a peer in `trustedProxyCidrs`; otherwise AIWAF resolves the client address itself. Default blocklist calls use Python-compatible reputation scoring and temporary escalation (15 minutes, 1 hour, then 24 hours). Use `BlocklistManager.blockPermanent(ip, reason)` for an explicit permanent administrative block.
|
|
1158
1316
|
|
|
1159
|
-
`storageBackend="redis"` makes rate-limit buckets, honeypot timing, weighted UUID scores, recent-request anomaly state,
|
|
1317
|
+
`storageBackend="redis"` makes rate-limit buckets, honeypot timing, weighted UUID scores, recent-request anomaly state, blocklist data, exemptions, geo policy, and learned keywords visible to every application instance using the same key prefix. Redis enforcement updates use atomic server-side scripts. Memory, file, CSV, and SQLite engines keep request state isolated per `AiwafEngine`; constructing another engine no longer replaces an existing engine's stores. The static `RuntimeStorage` and `BlocklistManager` methods remain compatibility facades for command-line and administrative code.
|
|
1160
1318
|
|
|
1161
1319
|
The Java 1.3 Redis backend supports **standalone Redis only**. Sentinel and Cluster configurations are rejected during validation instead of silently operating with incomplete semantics. `fail_closed` is the default: an unavailable Redis instance prevents startup or raises a request-path storage failure, which results in the application denying availability rather than bypassing protection. `fail_open` permits startup and returns non-blocking enforcement fallbacks while Redis is unavailable; failed mutations return `false` at the `StorageBackend` boundary. Connection, socket, pool size, and pool wait limits are bounded and configurable. `RedisStorage.diagnostics()` reports operation/failure counts, latency, and live pool utilization.
|
|
1162
1320
|
|
|
@@ -1199,13 +1357,13 @@ Replaying old logs cannot extend an active block or recreate one after expiry
|
|
|
1199
1357
|
or manual removal. Fresh traffic must independently satisfy the blocking rules.
|
|
1200
1358
|
|
|
1201
1359
|
CLI listing filters expired blocks for display without rewriting its snapshot
|
|
1202
|
-
back to the
|
|
1360
|
+
back to the blocklist. This prevents concurrent training updates from being
|
|
1203
1361
|
erased by an older cleanup snapshot. Default first blocks last 900 seconds.
|
|
1204
1362
|
|
|
1205
|
-
Keep the receipt file across restarts, log rotation, and
|
|
1363
|
+
Keep the receipt file across restarts, log rotation, and blocklist clearing.
|
|
1206
1364
|
Receipts do not expire and grow with the distinct requests used in block
|
|
1207
1365
|
decisions. `AIWAF_TRAINING_STATE_DIR` can select a durable shared directory;
|
|
1208
|
-
trainers sharing a
|
|
1366
|
+
trainers sharing a blocklist must also share this directory. Missing native
|
|
1209
1367
|
capabilities or corrupt receipt state stop training visibly. A crash between
|
|
1210
1368
|
writing a block and committing its receipt can still require recovery; the two
|
|
1211
1369
|
writes are not a single transaction.
|
|
@@ -1220,9 +1378,9 @@ disappearing before its expiry.
|
|
|
1220
1378
|
Node.js 1.1.4 with aiwaf-wasm 0.2.4 uses the same Rust receipt algorithm as
|
|
1221
1379
|
Python. The shared trainer applies this protection across JavaScript framework
|
|
1222
1380
|
adapters. The WASM `NativeTrainingEvidence` API hashes and filters evidence;
|
|
1223
|
-
Node persists `node_training_evidence.json` in the
|
|
1381
|
+
Node persists `node_training_evidence.json` in the blocklist CSV directory, or
|
|
1224
1382
|
the directory selected by `AIWAF_TRAINING_STATE_DIR`. Preserve this file across
|
|
1225
|
-
expiry, unblocking,
|
|
1383
|
+
expiry, unblocking, blocklist clearing, and log rotation. Sharing a blocklist
|
|
1226
1384
|
also requires sharing the evidence directory. Model fitting and keyword learning
|
|
1227
1385
|
still use full history; 404 and anomaly enforcement use fresh evidence only.
|
|
1228
1386
|
Log records without a valid stable timestamp are excluded from training.
|
|
@@ -1239,15 +1397,15 @@ storage errors. Programmatic callers can await `require('aiwaf/train')()`.
|
|
|
1239
1397
|
Publish the matching WASM package before the Node package; `test:wasm-real`
|
|
1240
1398
|
checks receipt restoration against the installed dependency, not just a fixture.
|
|
1241
1399
|
|
|
1242
|
-
Java's `train-model` operation fits and saves a model without adding
|
|
1400
|
+
Java's `train-model` operation fits and saves a model without adding blocklist
|
|
1243
1401
|
entries. Servlet and Spring use that shared Java core. Retraining alone therefore
|
|
1244
1402
|
cannot extend or recreate their runtime blocks; a regression test verifies this.
|
|
1245
1403
|
|
|
1246
|
-
|
|
1404
|
+
Blocklist expiry is also protected against concurrent updates. Node request
|
|
1247
1405
|
checks and listings do not delete expired snapshots. Explicit cleanup checks
|
|
1248
1406
|
expiry in the database DELETE, or inside the CSV mutation lock after reading
|
|
1249
|
-
the current rows. CSV
|
|
1250
|
-
the file. A crashed writer can leave `<
|
|
1407
|
+
the current rows. CSV blocklist writers use the same lock and atomically replace
|
|
1408
|
+
the file. A crashed writer can leave `<blocklist CSV path>.lock`; stop its owner
|
|
1251
1409
|
before removing that lock directory. Lock acquisition times out after 60 seconds
|
|
1252
1410
|
and reports an error rather than proceeding without protection.
|
|
1253
1411
|
|
|
@@ -1286,9 +1444,9 @@ Do not train directly on unreviewed sensitive request bodies or authentication h
|
|
|
1286
1444
|
|
|
1287
1445
|
- Configure the application to trust forwarding headers only from known proxy CIDRs.
|
|
1288
1446
|
- Configure the outermost proxy to overwrite client-supplied forwarding headers.
|
|
1289
|
-
- Use Redis, a database, or another shared backend when multiple workers must share rate-limit,
|
|
1447
|
+
- Use Redis, a database, or another shared backend when multiple workers must share rate-limit, blocklist, or exemption state.
|
|
1290
1448
|
- Keep health checks, static assets, and trusted webhook routes explicitly scoped instead of disabling protection globally.
|
|
1291
|
-
-
|
|
1449
|
+
- Tune anomaly detection with representative normal traffic before relying on it in production.
|
|
1292
1450
|
- Rotate logs and exclude secrets, authorization headers, cookies, and personal data.
|
|
1293
1451
|
- Sign model/configuration artifacts where the runtime supports HMAC verification.
|
|
1294
1452
|
- Run AIWAF alongside normal secure-development controls and an edge/reverse-proxy layer.
|
|
@@ -1342,67 +1500,17 @@ pytest -q rust/tests/test_python_api.py
|
|
|
1342
1500
|
mvn -f java/pom.xml test
|
|
1343
1501
|
```
|
|
1344
1502
|
|
|
1345
|
-
### Benchmark
|
|
1346
|
-
|
|
1347
|
-
The in-process Flask benchmark compares a baseline app, `auto` middleware selection, and the full middleware chain:
|
|
1348
|
-
|
|
1349
|
-
```bash
|
|
1350
|
-
python -m benchmarks.benchmark_auto_middleware
|
|
1351
|
-
python -m benchmarks.benchmark_auto_middleware --path-rules 250
|
|
1352
|
-
python -m benchmarks.benchmark_auto_middleware --requests 200 --rounds 3 --warmup 50
|
|
1353
|
-
```
|
|
1354
|
-
|
|
1355
|
-
Use the same machine, environment, request count, and background load when comparing results. These measurements exclude network and production-server overhead.
|
|
1356
|
-
|
|
1357
|
-
The latest native optimization measurements used three alternating runs. Timestamp
|
|
1358
|
-
and feature/model tests used 10,000 synthetic records; the model test used a
|
|
1359
|
-
20-tree forest and compared the previous Rust-feature/Python-matrix path with
|
|
1360
|
-
retained native features.
|
|
1361
|
-
|
|
1362
|
-
| Scoped workload | Windows speedup | WSL Linux speedup |
|
|
1363
|
-
| --- | ---: | ---: |
|
|
1364
|
-
| Unique Apache timestamp parsing | 4.57× | 3.65× |
|
|
1365
|
-
| Feature extraction + Rust fit/predict boundary | 1.55× | 1.35× |
|
|
1366
|
-
|
|
1367
|
-
Native ISO parsing was slower on both platforms, so it remains optional. An
|
|
1368
|
-
offline Windows Flask test-client workload with IP/keyword enforcement and CSV
|
|
1369
|
-
logging measured 5.95 ms/request native versus 9.18 ms/request Python (1.54×),
|
|
1370
|
-
using 100 initial blacklist rows and 20 requests per trial. These measurements
|
|
1371
|
-
exclude networking, production-server overhead, and concurrent request load;
|
|
1372
|
-
they do not establish a complete training or deployed-site speedup.
|
|
1373
|
-
|
|
1374
|
-
Reproduce the focused measurements and concurrency smoke check locally:
|
|
1375
|
-
|
|
1376
|
-
```bash
|
|
1377
|
-
python scripts/benchmark_native_training_boundary.py
|
|
1378
|
-
python scripts/benchmark_native_csv_training.py
|
|
1379
|
-
python scripts/benchmark_native_csv_workloads.py
|
|
1380
|
-
python scripts/benchmark_csv_request_reuse.py
|
|
1381
|
-
python scripts/profile_csv_logging.py
|
|
1382
|
-
python scripts/check_csv_release_concurrency.py
|
|
1383
|
-
```
|
|
1384
|
-
|
|
1385
|
-
Validation of the development changes passed 282 Django tests, 134 FastAPI tests
|
|
1386
|
-
(one skipped), and 247 Flask/core optimization tests in separate processes.
|
|
1387
|
-
Coverage includes timestamp fallbacks, gzip/quoted CSV, seeded model parity,
|
|
1388
|
-
chunk equivalence, concurrent mutations, no-op writes, and log rotation/reopening.
|
|
1389
|
-
An installed-wheel Linux smoke check with four processes retained all 160 access
|
|
1390
|
-
rows and 80 blacklist entries. Local wheels were checked on Windows Python 3.13
|
|
1391
|
-
and WSL Python 3.10; the locally built Linux wheel requires glibc 2.34 or newer.
|
|
1392
|
-
The complete supported platform/version matrix and production load validation
|
|
1393
|
-
remain release checks.
|
|
1394
|
-
|
|
1395
1503
|
## Release automation
|
|
1396
1504
|
|
|
1397
1505
|
Release versions and tags must match the relevant manifest.
|
|
1398
1506
|
|
|
1399
1507
|
| Package | Manifest | Tag | Workflow |
|
|
1400
1508
|
| --- | --- | --- | --- |
|
|
1401
|
-
| Python `aiwaf` | `pyproject.toml` | `python-v1.1.
|
|
1402
|
-
| npm `aiwaf` | `js/package.json` | `js-v1.1.
|
|
1403
|
-
| PyPI `aiwaf-rust` | `rust/pyproject.toml` + `rust/Cargo.toml` | `rust-v0.2.
|
|
1404
|
-
| npm `aiwaf-wasm` | `rust/crates/aiwaf_wasm/Cargo.toml` | `wasm-v0.2.
|
|
1405
|
-
| Maven `aiwaf-java` | `java/pom.xml` | `java-v1.3.
|
|
1509
|
+
| Python `aiwaf` | `pyproject.toml` | `python-v1.1.9` | `python-publish.yml` |
|
|
1510
|
+
| npm `aiwaf` | `js/package.json` | `js-v1.1.6` | `npm-publish.yml` |
|
|
1511
|
+
| PyPI `aiwaf-rust` | `rust/pyproject.toml` + `rust/Cargo.toml` | `rust-v0.2.8` | `rust-publish.yml` |
|
|
1512
|
+
| npm `aiwaf-wasm` | `rust/crates/aiwaf_wasm/Cargo.toml` | `wasm-v0.2.6` | `wasm-publish.yml` |
|
|
1513
|
+
| Maven `aiwaf-java` | `java/pom.xml` | `java-v1.3.6` | `java-publish.yml` |
|
|
1406
1514
|
|
|
1407
1515
|
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.
|
|
1408
1516
|
|
|
@@ -1410,11 +1518,12 @@ Java publishing uses the protected `maven-publish` environment plus `GPG_PRIVATE
|
|
|
1410
1518
|
|
|
1411
1519
|
Registry releases are immutable. Increment the relevant manifest version before publishing another release.
|
|
1412
1520
|
|
|
1413
|
-
For
|
|
1414
|
-
`aiwaf-wasm 0.2.
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1521
|
+
For this release, publish `aiwaf-rust 0.2.8` before Python `aiwaf 1.1.9`, and
|
|
1522
|
+
`aiwaf-wasm 0.2.6` before npm `aiwaf 1.1.6`. npm `aiwaf` 1.1.6 needs `aiwaf-wasm`
|
|
1523
|
+
0.2.6, but its dependency and lockfile still name 0.2.5 so that `npm ci` keeps
|
|
1524
|
+
working until 0.2.6 is published. After WASM publication, run
|
|
1525
|
+
`npm install aiwaf-wasm@^0.2.6` in `js/` to update both, commit that, run `npm ci`
|
|
1526
|
+
and the release checks, and only then publish npm `aiwaf`.
|
|
1418
1527
|
|
|
1419
1528
|
## Security and limitations
|
|
1420
1529
|
|
|
@@ -1438,6 +1547,8 @@ Original AIWAF project code in this checkout uses the unmodified [Elastic Licens
|
|
|
1438
1547
|
|
|
1439
1548
|
This migration applies to this checkout and future releases expressly distributed under ELv2. Previously distributed MIT copies retain their permissions; version numbers do not retroactively change their license. Do not republish an existing version with new licensing terms. Independently versioned packages record their license in their release artifacts.
|
|
1440
1549
|
|
|
1550
|
+
Initial ELv2 release boundaries are Python/Node.js `1.1.2`, Rust/Python and WASM `0.2.2`, and Java `1.3.3`. Earlier MIT distributions retain their MIT permissions.
|
|
1551
|
+
|
|
1441
1552
|
Retained MIT contributions keep their rights and notices in [licenses/MIT.txt](licenses/MIT.txt). The bundled IPinfo Lite database is provided by [IPinfo](https://ipinfo.io/) under [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/); ELv2 restrictions do not apply to that data. Package metadata uses an `AND` expression where separately licensed components are included; this does not offer a choice to license the entire package under MIT. Dependencies retain their respective terms.
|
|
1442
1553
|
|
|
1443
1554
|
Redistributions must include the applicable LICENSE, NOTICE, and licenses/ files. See [NOTICE](NOTICE) for historical rights, contributor notices, and attribution.
|