aiwaf 1.1.5 → 1.2.0
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 +366 -44
- package/bin/aiwaf.js +23 -4
- package/index.js +3 -0
- package/lib/geoBlocker.js +1 -7
- package/lib/hapiPlugin.js +5 -2
- package/lib/injectionAnalysis.js +600 -0
- package/lib/nativePipeline.js +370 -23
- package/lib/nativeRateCounter.js +45 -0
- package/lib/nativeSettings.js +242 -0
- package/lib/pathManifest.js +17 -1
- 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 +71 -6
- package/lib/wasmAdapter.js +8 -1
- package/lib/wasmChecks.js +40 -0
- package/package.json +6 -41
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.
|
|
42
|
+
Python 1.2.0, Rust/Python 0.2.9, Node.js 1.2.0, WASM 0.2.7, and Java 1.3.6 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.
|
|
47
|
-
| Node.js | [`aiwaf`](https://www.npmjs.com/package/aiwaf) | `1.
|
|
48
|
-
| Rust/Python | [`aiwaf-rust`](https://pypi.org/project/aiwaf-rust/) | `0.2.
|
|
49
|
-
| WebAssembly | [`aiwaf-wasm`](https://www.npmjs.com/package/aiwaf-wasm) | `0.2.
|
|
50
|
-
| Java | `io.github.aiwaf-project:aiwaf-java` | `1.3.
|
|
46
|
+
| Python | [`aiwaf`](https://pypi.org/project/aiwaf/) | `1.2.0` | Django, Flask, and FastAPI protection |
|
|
47
|
+
| Node.js | [`aiwaf`](https://www.npmjs.com/package/aiwaf) | `1.2.0` | Express and Node framework middleware |
|
|
48
|
+
| Rust/Python | [`aiwaf-rust`](https://pypi.org/project/aiwaf-rust/) | `0.2.9` | Native Python acceleration and JSON model inference |
|
|
49
|
+
| WebAssembly | [`aiwaf-wasm`](https://www.npmjs.com/package/aiwaf-wasm) | `0.2.7` | Rust detection and model primitives for JavaScript |
|
|
50
|
+
| Java | `io.github.aiwaf-project:aiwaf-java` | `1.3.6` | 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,167 @@ 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
|
+
## 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
|
+
|
|
71
232
|
## Repository layout
|
|
72
233
|
|
|
73
234
|
```text
|
|
@@ -95,7 +256,7 @@ pip install "aiwaf[django]"
|
|
|
95
256
|
pip install "aiwaf[flask]"
|
|
96
257
|
pip install "aiwaf[fastapi]"
|
|
97
258
|
|
|
98
|
-
# Backward-compatible alias; Python 1.
|
|
259
|
+
# Backward-compatible alias; Python 1.2.0 already installs aiwaf-rust
|
|
99
260
|
pip install "aiwaf[rust]"
|
|
100
261
|
|
|
101
262
|
# Node.js middleware
|
|
@@ -105,13 +266,13 @@ npm install aiwaf
|
|
|
105
266
|
npm install aiwaf-wasm
|
|
106
267
|
```
|
|
107
268
|
|
|
108
|
-
Java 1.3.
|
|
269
|
+
Java 1.3.6, after it is published to Maven Central:
|
|
109
270
|
|
|
110
271
|
```xml
|
|
111
272
|
<dependency>
|
|
112
273
|
<groupId>io.github.aiwaf-project</groupId>
|
|
113
274
|
<artifactId>aiwaf-java</artifactId>
|
|
114
|
-
<version>1.3.
|
|
275
|
+
<version>1.3.6</version>
|
|
115
276
|
</dependency>
|
|
116
277
|
```
|
|
117
278
|
|
|
@@ -119,7 +280,7 @@ Java 1.3.5, after it is published to Maven Central:
|
|
|
119
280
|
|
|
120
281
|
The Python package requires Python 3.10 or newer. Framework dependencies are optional, so install only the extra needed by the application.
|
|
121
282
|
|
|
122
|
-
Python 1.
|
|
283
|
+
Python 1.2.0 requires `aiwaf-rust>=0.2.9`; the `rust` extra remains an installation
|
|
123
284
|
alias. Publish the matching Rust wheel with `NativeCSVPipeline` support before
|
|
124
285
|
the Python release. The Rust release workflow builds Linux x86_64/aarch64,
|
|
125
286
|
musl x86_64, macOS x86_64/arm64 and Windows x86_64 wheels and checks the native
|
|
@@ -171,13 +332,81 @@ MIDDLEWARE = [
|
|
|
171
332
|
```
|
|
172
333
|
|
|
173
334
|
The configuration uses a dedicated lowercase profile; existing uppercase
|
|
174
|
-
framework settings, `AIWAFConfig` dictionaries,
|
|
175
|
-
|
|
335
|
+
framework settings, `AIWAFConfig` dictionaries, custom stores and policy callbacks
|
|
336
|
+
are not imported into it. Unknown keys are rejected. Path rules and the route
|
|
337
|
+
manifest work as in the regular chain, through three adapter keys:
|
|
338
|
+
|
|
339
|
+
- `path_rules`: the same rules as `AIWAF_PATH_RULES`. `DISABLE` turns stages off for
|
|
340
|
+
a prefix, and `RATE_LIMIT` (`WINDOW`, `MAX`, `FLOOD`) replaces the profile's rate
|
|
341
|
+
limits there. Invalid limits fail at startup.
|
|
342
|
+
- `manifest_path`: default `.aiwaf/paths.json`. Its route rules are added after
|
|
343
|
+
`path_rules`, and the route-specific checks saved by `init` run on matching requests.
|
|
344
|
+
- `injection_risk_mode`: `block` (default), `log` or `off`, defaulting to
|
|
345
|
+
`AIWAF_INJECTION_RISK_MODE`. A blocked request is logged with the matched rule.
|
|
176
346
|
Route decorators for full/partial exemptions and required middleware are read
|
|
177
347
|
once. Required decorators override decorator exemptions; profile-level path/IP
|
|
178
348
|
exemptions remain global. The profile is immutable: construct a new engine and
|
|
179
349
|
reload workers to change it.
|
|
180
350
|
|
|
351
|
+
**The regular setup runs as the native pipeline by default** when the installed aiwaf-rust
|
|
352
|
+
has every native feature (0.2.9 or newer) and every setting carries over exactly,
|
|
353
|
+
so the report below lists no differences. Nothing in the app changes:
|
|
354
|
+
- **Django:** the regular AIWAF classes in `MIDDLEWARE` run as one native middleware, at
|
|
355
|
+
the place of the last of them, so sessions and authentication have run before it. The
|
|
356
|
+
others step aside with `MiddlewareNotUsed`.
|
|
357
|
+
- **Flask and FastAPI:** `AIWAF(app)` installs the native pipeline instead of the regular
|
|
358
|
+
middleware, with the same stages its plan would register.
|
|
359
|
+
|
|
360
|
+
Request logs go to `aiwaf_native_access.csv` in the regular log directory, which the Flask
|
|
361
|
+
and FastAPI trainers read. A model the regular middleware has loaded carries over if
|
|
362
|
+
aiwaf-rust made it; an sklearn model, or a Flask model still held back for lack of logs,
|
|
363
|
+
is a difference. AIWAF logs one line on the `aiwaf.native` logger when it switches. To keep
|
|
364
|
+
the regular middleware, set `AIWAF_NATIVE_PIPELINE = False` in Django settings or Flask
|
|
365
|
+
config, pass `native_pipeline=False` to Flask's or FastAPI's `AIWAF(...)`, or set the
|
|
366
|
+
`AIWAF_NATIVE_PIPELINE=false` environment variable. `aiwaf init` says whether a project
|
|
367
|
+
switches and, if not, why.
|
|
368
|
+
|
|
369
|
+
To start from the settings the regular middleware already uses explicitly, pass
|
|
370
|
+
`"from_settings"`: `NativeAIWAF(app, "from_settings")` in Flask,
|
|
371
|
+
`AIWAF_CSV_PIPELINE = "from_settings"` in Django, or
|
|
372
|
+
`app.add_middleware(NativeAIWAFMiddleware, config="from_settings")` in FastAPI, which
|
|
373
|
+
converts the `AIWAFConfig` the regular middleware uses (or one passed as `aiwaf_config`). `{"from_settings": True, ...}` converts
|
|
374
|
+
and then applies the other keys on top. The same `AIWAF_*` names are read with the same
|
|
375
|
+
defaults, including Django's built-in login and admin exemptions and keyword list, and
|
|
376
|
+
Django's stages follow the regular classes in `MIDDLEWARE`. At startup AIWAF logs, on the
|
|
377
|
+
`aiwaf.native` logger, how many settings carried over unchanged and every one that didn't,
|
|
378
|
+
with the reason: for example, Flask's `*.css`-style exemptions and IP ranges in
|
|
379
|
+
`AIWAF_EXEMPT_IPS`, which the native pipeline can't match. It also uses the regular
|
|
380
|
+
stores (below), so blocks, exemptions and keywords already stored carry over, and Flask's
|
|
381
|
+
pattern exemptions and FastAPI's private-range exemptions keep working. FastAPI's header-only `exempt_paths` become path rules
|
|
382
|
+
that turn off header validation alone, and its private-range auto-exemptions are reported
|
|
383
|
+
because only exact addresses carry over. `aiwaf.core.native_settings.native_config()` and
|
|
384
|
+
`native_config_fastapi()` return the same profile and report without starting anything.
|
|
385
|
+
|
|
386
|
+
By default the native pipeline keeps its blocklist, exemptions, learned keywords and
|
|
387
|
+
blocked countries in CSV files in `data_dir`. To use the stores the rest of the app
|
|
388
|
+
already uses, set `"store"` in the native config: `"django"`, `"flask"` or `"fastapi"` use
|
|
389
|
+
that framework's regular stores, following its storage settings (`AIWAF_STORAGE_MODE`,
|
|
390
|
+
`AIWAF_USE_CSV` or `AIWAF_DATA_DIR`, or `AIWAFConfig`'s `storage`), so the native and regular
|
|
391
|
+
middleware and the management commands share one blocklist. Flask's store also matches its
|
|
392
|
+
`*.css`-style exemptions, and FastAPI's its private-range IP exemptions, which native
|
|
393
|
+
profiles can't. `"from_settings"` turns this on when the installed aiwaf-rust supports it.
|
|
394
|
+
Elsewhere, pass `stores=` to `CSVPipeline`. Before
|
|
395
|
+
each decision AIWAF reads what that request's stages use: whether it's exempt, then, if
|
|
396
|
+
not, whether the IP is blocked (IP/keyword and anomaly stages), the learned keywords
|
|
397
|
+
(IP/keyword stage) and blocked countries (geo stage). A route whose path rules turn those
|
|
398
|
+
stages off reads nothing. Answers are cached for `store_cache_seconds` (default 5):
|
|
399
|
+
keywords and countries, and the blocklist and exemption answers per IP and path, up to
|
|
400
|
+
10,000 of each. So a block or exemption made in another worker, the admin or the CLI can
|
|
401
|
+
take that long to apply; blocks this worker makes apply at once. `store_cache_seconds: 0`
|
|
402
|
+
reads the stores on every request. It then
|
|
403
|
+
writes the blocks and keywords the decision produced back through the stores. The
|
|
404
|
+
decision itself still runs in aiwaf-rust. A custom store is any object with
|
|
405
|
+
`is_blocked(ip)`, `is_exempted(ip, path)`, `top_keywords(n)`, `blocked_countries()`,
|
|
406
|
+
`block(ip, reason)` and `learn(keywords)`; `aiwaf.core.csv_pipeline.PipelineStores`
|
|
407
|
+
documents them. Rate limits, honeypot timing, UUID scores and anomaly history stay in
|
|
408
|
+
the engine.
|
|
409
|
+
|
|
181
410
|
Common profile keys and defaults:
|
|
182
411
|
|
|
183
412
|
| Setting | Default / meaning |
|
|
@@ -185,11 +414,12 @@ Common profile keys and defaults:
|
|
|
185
414
|
| `enabled` | All eight names: `geo_block`, `ip_keyword_block`, `rate_limit`, `ai_anomaly`, `honeypot`, `uuid_tamper`, `header_validation`, `logging` |
|
|
186
415
|
| `data_dir` | `aiwaf_data`; policy CSVs use the shared allowlist/blocklist/keyword/geo/path schemas |
|
|
187
416
|
| `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 |
|
|
188
|
-
| `sql_mode`, `max_bytes` | `block`, `65536`; `
|
|
417
|
+
| `sql_mode`, `max_bytes` | `block`, `65536`; also `monitor`, which logs findings on the `aiwaf.payload` logger without blocking, and `off`. Structured JSON/form bodies and nested escaped strings are inspected with bounded traversal |
|
|
189
418
|
| `learning`, `top_n` | `True`, `10`; presence keywords use a sorted, stable subset instead of Python set iteration order |
|
|
190
419
|
| `static_keywords`, `legitimate_keywords`, `exempt_keywords`, `safe_prefixes` | Native policy defaults or explicit arrays; set route-specific safe vocabulary in the profile |
|
|
191
420
|
| `geo_allow`, `geo_block` | Empty lists; includes stored blocked countries. Unknown country remains allowed |
|
|
192
|
-
| `rate_backend`, `rate_key_mode` | `memory`, `ip_path`; `csv` shares buckets across workers; `ip` aggregates paths
|
|
421
|
+
| `rate_backend`, `rate_key_mode` | `memory`, `ip_path`; `csv` shares buckets across workers; `redis` and `django_cache` (Django) share counts through a cache, below; `ip` aggregates paths |
|
|
422
|
+
| `rate_redis_url`, `rate_cache_namespace`, `rate_cache_alias` | Required for `rate_backend="redis"`; key prefix, default `aiwaf:native:rate:v1`; Django cache alias for `django_cache`, default `default` |
|
|
193
423
|
| `rate_window`, `rate_max`, `rate_flood` | `10`, `20`, `40`; throttle at 429, flood at 403 with blocklist persistence |
|
|
194
424
|
| `soft_block_blocklist`, `ip_blocking`, `block_duration` | `False`, `True`, reputation-based duration; explicit seconds or nonpositive permanent duration |
|
|
195
425
|
| `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 |
|
|
@@ -218,6 +448,22 @@ transfer timestamps automatically. Keep `csv` for shared or persistent timing;
|
|
|
218
448
|
CSV writes remain immediately synced. Blocklist, keyword, geo and allowlist
|
|
219
449
|
policy files and immediate request logging keep their configured CSV behavior.
|
|
220
450
|
|
|
451
|
+
### Shared native rate limits
|
|
452
|
+
|
|
453
|
+
With `rate_backend: "memory"` each worker counts on its own, so N workers allow N times
|
|
454
|
+
the limit. `rate_backend: "redis"` with `rate_redis_url` counts in Redis instead, with the
|
|
455
|
+
regular limiter's atomic sliding-window script, and in Django `"django_cache"` counts in a
|
|
456
|
+
Django cache (`rate_cache_alias`), as the regular rate limiter does. Only the count is
|
|
457
|
+
shared: aiwaf-rust still applies `rate_max`, `rate_flood` and path-rule limits to it.
|
|
458
|
+
`CSVPipeline(config, rate_counter=...)` with `rate_backend: "counter"` takes any object
|
|
459
|
+
with a synchronous, atomic `count(key, now, window_seconds)` that records the request and
|
|
460
|
+
returns the window's count. A failing counter answers 503, as the regular limiter does.
|
|
461
|
+
`from_settings` carries this over: Django counts in its default cache, and Flask
|
|
462
|
+
(`AIWAF_RATE_CACHE_BACKEND="redis"` with `AIWAF_REDIS_URL`) and FastAPI
|
|
463
|
+
(`rate_limiting.cache_backend`, `rate_limiting.redis_url`) count in the same Redis. It
|
|
464
|
+
needs `aiwaf-rust` 0.2.9 or newer; with 0.2.8 a counter fails at startup and `from_settings`
|
|
465
|
+
reports that rate limits stay per worker.
|
|
466
|
+
|
|
221
467
|
### Flask and FastAPI native honeypot cache
|
|
222
468
|
|
|
223
469
|
Both native adapters accept Redis or a supplied synchronous cache. CSV remains
|
|
@@ -425,6 +671,12 @@ aiwaf init --framework django --settings project.settings
|
|
|
425
671
|
aiwaf init --framework flask --app app:app --output .aiwaf/paths.json
|
|
426
672
|
```
|
|
427
673
|
|
|
674
|
+
`aiwaf init` then prints how to run the native pipeline for that framework, the
|
|
675
|
+
recommended setup for new installs, with the conversion report for the project's own
|
|
676
|
+
settings: what carries over and what wouldn't. In a Django project already using the
|
|
677
|
+
regular middleware, it says how to switch; nothing changes until you do. `--no-native`
|
|
678
|
+
skips this part.
|
|
679
|
+
|
|
428
680
|
Run the command in the same environment and checkout used to start the application. If it discovers only `/` and Flask's static route, verify the imported file and live route table:
|
|
429
681
|
|
|
430
682
|
```bash
|
|
@@ -553,12 +805,10 @@ Check the installed extension without touching application data:
|
|
|
553
805
|
python scripts/check_native_csv_runtime.py
|
|
554
806
|
```
|
|
555
807
|
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
pending checks first, preserving first-finding order. Django, Flask, and FastAPI
|
|
561
|
-
use the shared path; older extensions retain single-string checks.
|
|
808
|
+
`policy_sql_inspect` runs the whole SQL request check in one call, and Django, Flask and
|
|
809
|
+
FastAPI use it for every request. `RouteRiskChecker` and `policy_route_rule` run the
|
|
810
|
+
route-specific checks saved by `init`. `policy_sql_tokenizer` checks one value.
|
|
811
|
+
`policy_sql_signatures` and `csv_geo_policy` remain for older releases.
|
|
562
812
|
|
|
563
813
|
Flask with CSV geo state and an explicit allow/block list can read dynamic countries
|
|
564
814
|
and evaluate the geo policy in one native call. Django CSV and FastAPI CSV use
|
|
@@ -784,7 +1034,7 @@ npm run aiwaf -- manifest --framework express --routes routes.json --output .aiw
|
|
|
784
1034
|
| Logging | `AIWAF_MIDDLEWARE_LOGGING`, `AIWAF_MIDDLEWARE_LOG_PATH`, DB/CSV options |
|
|
785
1035
|
| WASM | `AIWAF_WASM_VALIDATION`, `AIWAF_WASM_VALIDATE_RECENT` |
|
|
786
1036
|
|
|
787
|
-
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.
|
|
1037
|
+
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.
|
|
788
1038
|
|
|
789
1039
|
The Python filesystem CSV transactions and retained training bindings remain
|
|
790
1040
|
PyO3-specific. Node now also has an **explicit stateful WASM request pipeline**;
|
|
@@ -831,22 +1081,91 @@ serializes the request envelope, emits responses, and appends the returned rows
|
|
|
831
1081
|
using cached file descriptors. Logging is immediate, not queued or batched.
|
|
832
1082
|
|
|
833
1083
|
The dedicated lowercase `profile` rejects unknown keys. It does not import legacy
|
|
834
|
-
settings
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
1084
|
+
settings or Redis state on its own; see `from_settings` and `stores` below. Missing native support fails startup with no JavaScript policy fallback.
|
|
1085
|
+
Install this adapter instead of the existing chain, not alongside it. Body parsers
|
|
1086
|
+
can run before or after it. A parsed `req.body` is inspected as it is. An unparsed body
|
|
1087
|
+
is handled as in Python: uploads and other bodies that aren't JSON, form or XML
|
|
1088
|
+
(multipart, binary) pass through unread, so upload middleware such as multer still
|
|
1089
|
+
gets the whole stream. An unparsed JSON, form or XML body is read up to `max_bytes`,
|
|
1090
|
+
inspected, and put back on the stream for the parsers after it. A larger one is
|
|
1091
|
+
refused with 413 (`payload_inspection_limit`), or logged in monitor mode. A compressed
|
|
1092
|
+
or already-consumed inspectable body can't be read, and is refused with 413 as
|
|
1093
|
+
before. `uuidResolver(uid, req)`, as in the regular middleware, is asked
|
|
1094
|
+
whether the record named by a well-formed UUID under `uuid_prefix` exists. It can be
|
|
1095
|
+
async; only those requests wait for it, `false` blocks with `uuid_not_found`, and a
|
|
1096
|
+
failing resolver lets the request through. `countryLookup(req)`, `authenticated(req)` and `routeExists(req)`
|
|
840
1097
|
are optional synchronous fact callbacks; country defaults to unknown and route
|
|
841
1098
|
existence to `Boolean(req.route)`. Supply accurate facts when the firewall runs
|
|
842
1099
|
before Express resolves routes. Country headers are not implicitly trusted.
|
|
843
1100
|
|
|
1101
|
+
**`aiwaf(options)` runs the native pipeline by default** when two things hold: the
|
|
1102
|
+
installed aiwaf-wasm is 0.2.7 or newer (it has every native feature), and every option
|
|
1103
|
+
carries over exactly, so the conversion report below lists no differences. Otherwise it
|
|
1104
|
+
runs the regular middleware, as before. It logs one line when it picks the native
|
|
1105
|
+
pipeline. To keep the regular middleware, set `AIWAF_NATIVE_PIPELINE: false` in the
|
|
1106
|
+
options or `AIWAF_NATIVE_PIPELINE=false` in the environment. A model saved by
|
|
1107
|
+
`aiwaf train` carries over; the sample model shipped in `resources/model.json` doesn't,
|
|
1108
|
+
since it's in the old format and only a sample. Another model in the old format, or one
|
|
1109
|
+
kept in the database or cache, is a difference, so those apps stay on the regular
|
|
1110
|
+
middleware. The client address is resolved as the regular middleware resolves it,
|
|
1111
|
+
through `AIWAF_TRUSTED_PROXIES` (the native adapter's `trustedProxies` option).
|
|
1112
|
+
|
|
1113
|
+
To start from the options the regular middleware already takes explicitly, add
|
|
1114
|
+
`AIWAF_NATIVE_PIPELINE: 'from_settings'` to them, as in Python: `aiwaf({ MAX_REQ: 50, ...,
|
|
1115
|
+
AIWAF_NATIVE_PIPELINE: 'from_settings' })`. Options are read through the same
|
|
1116
|
+
normalization, defaults and environment variables, so the regular defaults (60-second
|
|
1117
|
+
windows, no static keywords, header validation off) carry over rather than the native
|
|
1118
|
+
ones. `{ fromSettings: true, dataDir, logger, profile: {...} }` also passes native options,
|
|
1119
|
+
and its `profile` keys win. The startup report has the same form as Python's: how many
|
|
1120
|
+
options carried over unchanged, then every one that didn't, with the reason, written to
|
|
1121
|
+
`logger.warn` (or `logger.info` when nothing differs). `aiwaf.nativeOptionsFromSettings(options)`
|
|
1122
|
+
returns the converted `config`, ready for `aiwaf.native()`, with its `report()`, `notes` and
|
|
1123
|
+
`differences()`, without starting anything.
|
|
1124
|
+
|
|
1125
|
+
By default blocks and learned keywords stay in the adapter's own files (below). To share
|
|
1126
|
+
them with the regular middleware and its CLI, pass `stores: 'regular'`. The adapter
|
|
1127
|
+
then uses Node's regular blocklist, exemption, dynamic keyword and geo stores, from the
|
|
1128
|
+
database when one is configured or otherwise their CSV files. Their blocks apply,
|
|
1129
|
+
their IP and path exemptions keep logging only, a learned keyword applies once its count
|
|
1130
|
+
passes `dynamicTopN`, and blocked countries add to `geo_block`. `from_settings` turns
|
|
1131
|
+
this on, carrying `dynamicTopN` and `AIWAF_EXEMPTIONS_DB`. `stores` also takes any object
|
|
1132
|
+
with six methods, each sync or async:
|
|
1133
|
+
`isBlocked(ip)`, `isExempted(ip, path)`, `topKeywords(limit)`, `blockedCountries()`,
|
|
1134
|
+
`block(ip, reason, expiresAt)` and `learn(keyword)`. The adapter reads them before the
|
|
1135
|
+
engine decides, only for the stages the request runs, and keywords, countries and the
|
|
1136
|
+
blocklist and exemption answers are cached for `storeCacheSeconds` (default 5), so a block
|
|
1137
|
+
or exemption made elsewhere can take that long to apply; this worker's own blocks apply at
|
|
1138
|
+
once. A failed read goes to `onError` and counts as not blocked, not exempt and nothing
|
|
1139
|
+
learned. Blocks and keywords are written after the response, so a block applies from
|
|
1140
|
+
the client's next request once the write lands. The decision itself stays in aiwaf-wasm.
|
|
1141
|
+
Stores need `aiwaf-wasm` 0.2.7 or newer. With an older build, `stores` fails at startup, and
|
|
1142
|
+
`from_settings` (which adds `storesFallback: 'csv'`) keeps the adapter's own files and
|
|
1143
|
+
warns.
|
|
1144
|
+
|
|
1145
|
+
Rate limits are counted in each worker unless `rateCounter` is set. `aiwaf.redisRateCounter(client)`
|
|
1146
|
+
takes a node-redis v4 or ioredis client and counts in Redis atomically, with the same
|
|
1147
|
+
script and key format as Python's native Redis backend, so every worker shares one
|
|
1148
|
+
limit. Any object with `count(key, now, windowSeconds)`, sync or async, also works. The
|
|
1149
|
+
count is read before the engine decides, and the engine still applies the profile's and
|
|
1150
|
+
path rules' limits to it; exempt requests aren't counted. A failing counter answers 503,
|
|
1151
|
+
or lets the request through with `rateFailureMode: 'open'`. `from_settings` uses the
|
|
1152
|
+
regular middleware's `cache` option when it's a Redis client, and carries
|
|
1153
|
+
`AIWAF_RATE_CACHE_FAILURE_MODE`; with an older aiwaf-wasm it counts per worker and warns.
|
|
1154
|
+
|
|
1155
|
+
Path rules and the route manifest work as in the regular middleware, through three
|
|
1156
|
+
adapter options. `pathRules` takes the same rules as `AIWAF_PATH_RULES`: `DISABLE`
|
|
1157
|
+
turns stages off for a prefix, and `RATE_LIMIT` replaces the profile's rate limits
|
|
1158
|
+
there, with invalid limits failing at startup. `manifestPath` (default
|
|
1159
|
+
`AIWAF_PATH_MANIFEST`, then `.aiwaf/paths.json`) adds the manifest's route rules and
|
|
1160
|
+
the route-specific checks saved by `init`. `injectionRiskMode` is `block` (default),
|
|
1161
|
+
`log` or `off`, defaulting to `AIWAF_INJECTION_RISK_MODE`.
|
|
1162
|
+
|
|
844
1163
|
All eight stages are enabled by default. Native defaults include:
|
|
845
1164
|
|
|
846
1165
|
| Profile setting | Default / scope |
|
|
847
1166
|
| --- | --- |
|
|
848
1167
|
| `exempt_paths`, `exempt_ips` | `/health`, `/robots.txt`, `/sitemap.xml`; no IPs; literal case-insensitive path prefixes |
|
|
849
|
-
| `sql_mode`, `max_bytes` | `block`, `65536`; `
|
|
1168
|
+
| `sql_mode`, `max_bytes` | `block`, `65536`; also `monitor`, which logs `{event: 'aiwaf.payload', rule, mode}` through the `logger` option (default `console`) without blocking, and `off`; bounded nested JSON/form values and double URL decoding |
|
|
850
1169
|
| `static_keywords`, `dynamic_keywords`, `legitimate_keywords`, `learning` | Native vocabulary, empty dynamic set, legitimate exact route names, `true`; learned probe segments capped at 4096 |
|
|
851
1170
|
| `geo_allow`, `geo_block`, `blocklist` | Empty; blocklist maps IP to Unix expiry seconds (`0` permanent) |
|
|
852
1171
|
| `rate_window`, `rate_max`, `rate_flood`, `rate_key_mode` | `10` seconds, `20`, `40`, `ip_path`; `ip` also supported |
|
|
@@ -856,8 +1175,8 @@ All eight stages are enabled by default. Native defaults include:
|
|
|
856
1175
|
| `anomaly_window`, `max_history`, `max_clients`, `max_pending` | `60` seconds, `1000`, `100000`, `10000`; periodic cleanup and bounded state |
|
|
857
1176
|
| `block_duration` | `86400` seconds for newly generated blocks |
|
|
858
1177
|
|
|
859
|
-
Rate counters, honeypot timestamps, UUID scores, anomaly history and loaded policy
|
|
860
|
-
snapshots are local to each engine/worker and reset on restart.
|
|
1178
|
+
Rate counters (without `rateCounter`), honeypot timestamps, UUID scores, anomaly history and loaded policy
|
|
1179
|
+
snapshots are local to each engine/worker and reset on restart. Without `stores`, blocks and learned
|
|
861
1180
|
keywords append to dedicated `native_blocks.csv`/`native_keywords.csv`, synced
|
|
862
1181
|
immediately, and replay at startup (`persistBlocks: false` disables this disk
|
|
863
1182
|
history). Policy files are **not live synchronized across workers**; do not share
|
|
@@ -1027,7 +1346,7 @@ cp -R ../licenses crates/aiwaf_wasm/pkg/
|
|
|
1027
1346
|
|
|
1028
1347
|
## Java package
|
|
1029
1348
|
|
|
1030
|
-
AIWAF Java 1.3.
|
|
1349
|
+
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.
|
|
1031
1350
|
|
|
1032
1351
|
### Core engine
|
|
1033
1352
|
|
|
@@ -1096,7 +1415,7 @@ aiwaf.storage.redis-pool-min-idle=0
|
|
|
1096
1415
|
aiwaf.storage.redis-pool-max-wait-millis=250
|
|
1097
1416
|
```
|
|
1098
1417
|
|
|
1099
|
-
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.
|
|
1418
|
+
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.
|
|
1100
1419
|
|
|
1101
1420
|
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:
|
|
1102
1421
|
|
|
@@ -1116,7 +1435,7 @@ UUID protection uses Python-compatible weighted signals: malformed input, valid
|
|
|
1116
1435
|
Generate a route manifest from the live Spring application rather than supplying controller methods manually:
|
|
1117
1436
|
|
|
1118
1437
|
```bash
|
|
1119
|
-
java -cp "your-app.jar:aiwaf-java-1.3.
|
|
1438
|
+
java -cp "your-app.jar:aiwaf-java-1.3.6.jar" \
|
|
1120
1439
|
com.aiwaf.cli.AiwafConsole init \
|
|
1121
1440
|
--app com.example.Application \
|
|
1122
1441
|
--output .aiwaf/paths.json
|
|
@@ -1287,7 +1606,7 @@ Do not train directly on unreviewed sensitive request bodies or authentication h
|
|
|
1287
1606
|
- Configure the outermost proxy to overwrite client-supplied forwarding headers.
|
|
1288
1607
|
- Use Redis, a database, or another shared backend when multiple workers must share rate-limit, blocklist, or exemption state.
|
|
1289
1608
|
- Keep health checks, static assets, and trusted webhook routes explicitly scoped instead of disabling protection globally.
|
|
1290
|
-
-
|
|
1609
|
+
- Tune anomaly detection with representative normal traffic before relying on it in production.
|
|
1291
1610
|
- Rotate logs and exclude secrets, authorization headers, cookies, and personal data.
|
|
1292
1611
|
- Sign model/configuration artifacts where the runtime supports HMAC verification.
|
|
1293
1612
|
- Run AIWAF alongside normal secure-development controls and an edge/reverse-proxy layer.
|
|
@@ -1347,11 +1666,11 @@ Release versions and tags must match the relevant manifest.
|
|
|
1347
1666
|
|
|
1348
1667
|
| Package | Manifest | Tag | Workflow |
|
|
1349
1668
|
| --- | --- | --- | --- |
|
|
1350
|
-
| Python `aiwaf` | `pyproject.toml` | `python-v1.
|
|
1351
|
-
| npm `aiwaf` | `js/package.json` | `js-v1.
|
|
1352
|
-
| PyPI `aiwaf-rust` | `rust/pyproject.toml` + `rust/Cargo.toml` | `rust-v0.2.
|
|
1353
|
-
| npm `aiwaf-wasm` | `rust/crates/aiwaf_wasm/Cargo.toml` | `wasm-v0.2.
|
|
1354
|
-
| Maven `aiwaf-java` | `java/pom.xml` | `java-v1.3.
|
|
1669
|
+
| Python `aiwaf` | `pyproject.toml` | `python-v1.2.0` | `python-publish.yml` |
|
|
1670
|
+
| npm `aiwaf` | `js/package.json` | `js-v1.2.0` | `npm-publish.yml` |
|
|
1671
|
+
| PyPI `aiwaf-rust` | `rust/pyproject.toml` + `rust/Cargo.toml` | `rust-v0.2.9` | `rust-publish.yml` |
|
|
1672
|
+
| npm `aiwaf-wasm` | `rust/crates/aiwaf_wasm/Cargo.toml` | `wasm-v0.2.7` | `wasm-publish.yml` |
|
|
1673
|
+
| Maven `aiwaf-java` | `java/pom.xml` | `java-v1.3.6` | `java-publish.yml` |
|
|
1355
1674
|
|
|
1356
1675
|
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.
|
|
1357
1676
|
|
|
@@ -1359,11 +1678,14 @@ Java publishing uses the protected `maven-publish` environment plus `GPG_PRIVATE
|
|
|
1359
1678
|
|
|
1360
1679
|
Registry releases are immutable. Increment the relevant manifest version before publishing another release.
|
|
1361
1680
|
|
|
1362
|
-
For this release, publish `aiwaf-rust 0.2.
|
|
1363
|
-
`aiwaf-wasm 0.2.
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1681
|
+
For this release, publish `aiwaf-rust 0.2.9` before Python `aiwaf 1.2.0`, and
|
|
1682
|
+
`aiwaf-wasm 0.2.7` before npm `aiwaf 1.2.0`. Python `aiwaf` 1.2.0 requires
|
|
1683
|
+
`aiwaf-rust>=0.2.9`, so its CI installs need 0.2.9 published first. npm `aiwaf` 1.2.0
|
|
1684
|
+
needs `aiwaf-wasm` 0.2.7, but its dependency and lockfile still name 0.2.6 so that
|
|
1685
|
+
`npm ci` keeps working until 0.2.7 is published. After WASM publication, run
|
|
1686
|
+
`npm install aiwaf-wasm@^0.2.7` in `js/` to update both, commit that, run `npm ci`
|
|
1687
|
+
and the release checks, and only then publish npm `aiwaf`. Java has no changes since
|
|
1688
|
+
1.3.6, which is already published.
|
|
1367
1689
|
|
|
1368
1690
|
## Security and limitations
|
|
1369
1691
|
|
package/bin/aiwaf.js
CHANGED
|
@@ -155,7 +155,9 @@ function parseManifestArgs(args = []) {
|
|
|
155
155
|
const options = {
|
|
156
156
|
framework: 'express',
|
|
157
157
|
output: process.env.AIWAF_PATH_MANIFEST || '.aiwaf/paths.json',
|
|
158
|
-
routes: []
|
|
158
|
+
routes: [],
|
|
159
|
+
source: '.',
|
|
160
|
+
audit: true
|
|
159
161
|
};
|
|
160
162
|
for (let index = 0; index < args.length; index += 1) {
|
|
161
163
|
const arg = args[index];
|
|
@@ -163,6 +165,10 @@ function parseManifestArgs(args = []) {
|
|
|
163
165
|
options.framework = args[++index] || options.framework;
|
|
164
166
|
} else if (arg === '--output' || arg === '-o') {
|
|
165
167
|
options.output = args[++index] || options.output;
|
|
168
|
+
} else if (arg === '--source') {
|
|
169
|
+
options.source = args[++index] || options.source;
|
|
170
|
+
} else if (arg === '--no-audit') {
|
|
171
|
+
options.audit = false;
|
|
166
172
|
} else if (arg === '--routes' || arg === '-r') {
|
|
167
173
|
const routeFile = args[++index];
|
|
168
174
|
options.routes = routeFile ? readJsonFile(routeFile) : [];
|
|
@@ -304,12 +310,17 @@ async function main() {
|
|
|
304
310
|
'whois <domain|ip>',
|
|
305
311
|
'diagnose <ip>',
|
|
306
312
|
'reset [--blocklist] [--keywords] [--exemptions] [--all] --confirm',
|
|
307
|
-
'pathshell'
|
|
313
|
+
'pathshell',
|
|
314
|
+
'audit [path] [--format text|json] [--output file] [--include-tests] [--fail-on-findings]'
|
|
308
315
|
]
|
|
309
316
|
});
|
|
310
317
|
return;
|
|
311
318
|
}
|
|
312
319
|
|
|
320
|
+
if (cmd === 'audit') {
|
|
321
|
+
process.exitCode = require('../lib/injectionAnalysis').runAuditCommand([subcmd, ...args].filter(item => item !== undefined));
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
313
324
|
if (cmd === 'train') return runTrain();
|
|
314
325
|
if (cmd === 'pathshell') return runPathShell();
|
|
315
326
|
if (cmd === 'reset') return runReset([subcmd, ...args].filter(Boolean));
|
|
@@ -361,9 +372,17 @@ async function main() {
|
|
|
361
372
|
options.framework,
|
|
362
373
|
null,
|
|
363
374
|
options.output,
|
|
364
|
-
{ routes: options.routes }
|
|
375
|
+
{ routes: options.routes, auditSource: options.audit ? options.source : null }
|
|
365
376
|
);
|
|
366
|
-
|
|
377
|
+
const audit = manifest.injection_audit;
|
|
378
|
+
return print({
|
|
379
|
+
ok: true,
|
|
380
|
+
output: options.output,
|
|
381
|
+
framework: options.framework,
|
|
382
|
+
routes: Object.keys(manifest.routes || {}).length,
|
|
383
|
+
injection_check_routes: Object.values(manifest.routes || {}).filter(entry => entry && entry.injection_risks).length,
|
|
384
|
+
unlinked_findings: audit ? audit.unlinked_findings : null
|
|
385
|
+
});
|
|
367
386
|
}
|
|
368
387
|
|
|
369
388
|
if (cmd === 'list' && subcmd === 'blocklist') {
|