aiwaf 1.2.3 → 1.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -39,15 +39,15 @@ the supported Redis backends when sharing limits across workers.
39
39
 
40
40
  Each package is versioned and released independently.
41
41
 
42
- Python 1.2.4, Rust/Python 0.2.12, Node.js 1.2.3, WASM 0.2.9, and Java 1.3.7 are local source targets. See the package table below and [CHANGELOG](CHANGELOG.md) for release changes.
42
+ Python 1.2.6, Rust/Python 0.2.13, Node.js 1.2.5, WASM 0.2.10, and Java 1.3.9 are local source targets. See the package table below and [CHANGELOG](CHANGELOG.md) for release changes.
43
43
 
44
44
  | Runtime | Package | Repository version | Primary use |
45
45
  | --- | --- | ---: | --- |
46
- | Python | [`aiwaf`](https://pypi.org/project/aiwaf/) | `1.2.4` | Django, Flask, and FastAPI protection |
47
- | Node.js | [`aiwaf`](https://www.npmjs.com/package/aiwaf) | `1.2.3` | Express and Node framework middleware |
48
- | Rust/Python | [`aiwaf-rust`](https://pypi.org/project/aiwaf-rust/) | `0.2.12` | Native Python acceleration and JSON model inference |
49
- | WebAssembly | [`aiwaf-wasm`](https://www.npmjs.com/package/aiwaf-wasm) | `0.2.9` | Rust detection and model primitives for JavaScript |
50
- | Java | `io.github.aiwaf-project:aiwaf-java` | `1.3.7` | Spring MVC and Jakarta Servlet protection |
46
+ | Python | [`aiwaf`](https://pypi.org/project/aiwaf/) | `1.2.6` | Django, Flask, and FastAPI protection |
47
+ | Node.js | [`aiwaf`](https://www.npmjs.com/package/aiwaf) | `1.2.5` | Express and Node framework middleware |
48
+ | Rust/Python | [`aiwaf-rust`](https://pypi.org/project/aiwaf-rust/) | `0.2.13` | Native Python acceleration and JSON model inference |
49
+ | WebAssembly | [`aiwaf-wasm`](https://www.npmjs.com/package/aiwaf-wasm) | `0.2.10` | Rust detection and model primitives for JavaScript |
50
+ | Java | `io.github.aiwaf-project:aiwaf-java` | `1.3.9` | Spring MVC and Jakarta Servlet protection |
51
51
 
52
52
  Supported framework integrations include Django, Flask, FastAPI, Express, Fastify, Hapi, Koa, NestJS, Next.js API routes, AdonisJS, Sails.js, Spring MVC, and Jakarta Servlet.
53
53
 
@@ -68,6 +68,24 @@ Supported framework integrations include Django, Flask, FastAPI, Express, Fastif
68
68
 
69
69
  The runtimes share policy intent and training feature names, but their framework adapters and model implementations remain language-native. Model artifacts are not generally interchangeable across languages.
70
70
 
71
+ ## Profiles
72
+
73
+ `AIWAF_PROFILE` sets sensible defaults with one setting, in Django and Flask settings,
74
+ FastAPI's `AIWAFConfig` (or `AIWAF(app, profile=...)`), the Node.js options, the Java config
75
+ (`profile`) or the environment. A setting you give explicitly always wins over the profile.
76
+
77
+ | Profile | What it does |
78
+ | --- | --- |
79
+ | `balanced` (default) | Every default as it is. |
80
+ | `strict` | Halves the rate and flood limits (Django, Flask, FastAPI and Java: 10 and 20 a window; Node.js: 50 and 100), turns on UUID scoring, header validation and the method policy where the runtime has them as settings, and keeps the SQL and route checks blocking. |
81
+ | `monitor` | A dry run. Every check runs, and what it would block is logged instead, as `AIWAF monitor: would block GET /.env from 203.0.113.9 with 403 (...)`. Nothing is blocked and no IP is added to the blocklist. |
82
+
83
+ Use `monitor` to try AIWAF on real traffic before turning it on. Its log lines go to the
84
+ `aiwaf.monitor` logger in Python, `console.warn` in Node.js and `com.aiwaf.monitor` in Java.
85
+ Monitor runs the regular middleware, where every block decision can be logged instead: the
86
+ automatic native pipeline stays off, and a native pipeline chosen explicitly refuses to start.
87
+ Java's request body size limit still applies.
88
+
71
89
  ## Client IP addresses and proxies
72
90
 
73
91
  Blocks, exemptions, rate limits, and geo policies all depend on the client address. Python, Node.js, and Java read `X-Forwarded-For` and `X-Real-IP` only when the connecting peer is a trusted proxy. They walk `X-Forwarded-For` from the right and stop at the first untrusted address, because anything further left is client-supplied. `CF-Connecting-IP` and other vendor headers are not read for this purpose. In Python and Node.js the walk runs in `aiwaf-rust` and `aiwaf-wasm`, which also write IPv6 addresses in canonical form.
@@ -91,10 +109,9 @@ If untrusted hosts can reach the application directly from your private network,
91
109
 
92
110
  ## Injection audit
93
111
 
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.
112
+ `audit` reads your source code and reports where request input can reach a dangerous
113
+ operation. It parses files without running them, and it doesn't change how requests are
114
+ handled.
98
115
 
99
116
  ```bash
100
117
  aiwaf audit path/to/app # Python
@@ -104,18 +121,57 @@ java -cp <classpath> com.aiwaf.cli.AiwafConsole audit src # Java, needs a JDK
104
121
 
105
122
  | Language | Frameworks | Parser |
106
123
  | --- | --- | --- |
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 |
124
+ | Python | Django, Flask, FastAPI, Graphene, Strawberry, Ariadne, Channels, Flask-SocketIO | `ast` |
125
+ | Node.js | Express, Fastify, Hapi, Koa, NestJS, Next.js (routes and server actions), Remix, tRPC, GraphQL resolvers, AdonisJS, Sails, ws and Socket.IO | `@babel/parser` |
126
+ | Java | Spring MVC and WebFlux, Spring GraphQL, Netflix DGS, Jakarta Servlet, JAX-RS, Spring messaging and Jakarta WebSocket | JDK Compiler Tree API |
127
+
128
+ It reports these operations:
110
129
 
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.
130
+ | Operation | Examples |
131
+ | --- | --- |
132
+ | `sql`, `nosql` | `cursor.execute`, `db.query`, `jdbcTemplate.update`, `collection.find` |
133
+ | `command` | `os.system`, `exec`, `Runtime.exec`, `ProcessBuilder` |
134
+ | `path` | `open`, `fs.readFile`, `new File`, `Path.read_text` |
135
+ | `ssrf` | `requests.get`, `fetch`, `RestTemplate` |
136
+ | `code`, `template`, `deserialization` | `eval`, `render_template_string`, `pickle.loads` |
137
+ | `xss` | text returned from a Flask view, `res.send`, `ctx.body`, `response.getWriter()` |
138
+ | `redirect` | `redirect`, `res.redirect`, `sendRedirect` |
139
+ | `ldap`, `xpath` | `conn.search`, `client.search`, `xpath`, `XPath.evaluate` |
140
+ | `xxe` | XML parsers with external entities turned on |
141
+ | `redos` | regular expressions built from input |
142
+ | `prototype` (Node.js) | `obj[key] = value` with a key from input, `_.merge` |
143
+
144
+ It follows input through helpers, return values, other files and classes, objects that
145
+ keep input in fields, middleware that keeps input on the request, and callbacks such as
146
+ `.then()` and `.map()`. It understands checks: `if not name.isalnum(): return`, allowlists,
147
+ regex tests and `'..'` checks make a value safe, and encoders such as `html.escape` make
148
+ it safe only for what they encode for (HTML, not SQL). Values decided before the program
149
+ runs, dict keys and list positions are followed, so `m['safe']` isn't confused with
150
+ `m['input']`.
151
+
152
+ On the [OWASP Benchmark](https://owasp.org/www-project-benchmark/), whose labelled test
153
+ cases are real vulnerabilities or safe look-alikes, the Java audit finds every one of
154
+ 1,572 injection cases with no false alarms, and the Python audit every one of 677
155
+ (scores of +100 on OWASP's scale). The benchmarks are small synthetic cases, so this isn't
156
+ proof of the same on real applications; `scripts/audit_benchmark.py` repeats the
157
+ measurement on a checkout of either.
158
+
159
+ All three accept `--format text|json|sarif`, `--output <file>`, `--include-tests`,
160
+ `--fail-on-findings`, `--manifest <file>` and `--baseline <file>`. The exit status is 0
161
+ when the scan completes, 1 with `--fail-on-findings` when something is found, and 2 for a
162
+ bad path or argument.
163
+
164
+ - `--format sarif` writes SARIF 2.1.0, which GitHub code scanning and other tools read.
165
+ - `--baseline report.json` leaves out findings already in an earlier JSON report, so CI
166
+ fails only on new ones. Findings match by file, operation, call, function and input,
167
+ not line, so moved code still matches.
168
+ - A comment `aiwaf: ignore` on a finding's line or the line above leaves it out, and
169
+ `aiwaf: ignore[sql, xss]` leaves out only those operations. The report counts them.
114
170
 
115
171
  A finding is a path worth reading, not a confirmed vulnerability. A reverse proxy, for
116
172
  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.
173
+ report doesn't prove the code is safe: reflection, dynamic calls and library code can be
174
+ missed, and helpers are followed three calls deep.
119
175
 
120
176
  Java can also build a route manifest from source, without starting the application.
121
177
  This is how plain Servlet applications get a manifest:
@@ -197,6 +253,25 @@ values too. A match blocks the request with `403` and logs an event like this:
197
253
  {"event": "aiwaf.injection_risk", "mode": "block", "method": "GET", "route": "/files", "sink": "path", "input": "name", "rule": "path_traversal", "confidence": "medium"}
198
254
  ```
199
255
 
256
+ | Operation | Rules: what a value must contain to match |
257
+ | --- | --- |
258
+ | `sql` | The SQL tokenizer: a value that closes its SQL literal and continues as SQL |
259
+ | `command` | `command_chain`, `command_substitution`: `;`, `&` or `\|` and a command, `$(...)`, backticks |
260
+ | `path` | `path_traversal`, `path_sensitive_location`, `path_null_byte` |
261
+ | `ssrf` | `ssrf_scheme`, `ssrf_internal_host`: `file://` and similar, private and metadata hosts |
262
+ | `nosql`, `code`, `template`, `deserialization` | operators like `$ne`, `eval(`, `{{ }}`, serialized object markers |
263
+ | `xss` | `xss_markup`, `xss_event_handler`, `xss_script_url`: `<script`, `onerror=`, `javascript:` |
264
+ | `redirect` | `redirect_external`: `//host`, `/\host`, `javascript:`, `user@host` and `https:host` targets |
265
+ | `ldap` | `ldap_filter`: `)(`, `(|(`, a leading `*)` |
266
+ | `xpath` | `xpath_quote_break`, `xpath_tautology`: `' or 'a'='a`, `or 1=1` |
267
+ | `xxe` | `xxe_entity`: `<!DOCTYPE` or `<!ENTITY` |
268
+ | `redos` | `redos_nested_quantifier`: `(a+)+` and similar |
269
+ | `prototype` | `prototype_key`: `__proto__`, `constructor.prototype` |
270
+
271
+ Every rule is checked against a shared list of ordinary values (names, addresses, prose with
272
+ quotes and parentheses) that must never match. A plain absolute URL passes the redirect rule,
273
+ because the site's own host isn't known there.
274
+
200
275
  ```bash
201
276
  aiwaf init --framework flask --app app:app # audits the current folder
202
277
  aiwaf init --framework flask --app app:app --source src # audits another folder
@@ -256,7 +331,7 @@ pip install "aiwaf[django]"
256
331
  pip install "aiwaf[flask]"
257
332
  pip install "aiwaf[fastapi]"
258
333
 
259
- # Backward-compatible alias; Python 1.2.4 already installs aiwaf-rust
334
+ # Backward-compatible alias; Python 1.2.6 already installs aiwaf-rust
260
335
  pip install "aiwaf[rust]"
261
336
 
262
337
  # Node.js middleware
@@ -266,13 +341,13 @@ npm install aiwaf
266
341
  npm install aiwaf-wasm
267
342
  ```
268
343
 
269
- Java 1.3.7, after it is published to Maven Central:
344
+ Java 1.3.9, after it is published to Maven Central:
270
345
 
271
346
  ```xml
272
347
  <dependency>
273
348
  <groupId>io.github.aiwaf-project</groupId>
274
349
  <artifactId>aiwaf-java</artifactId>
275
- <version>1.3.7</version>
350
+ <version>1.3.9</version>
276
351
  </dependency>
277
352
  ```
278
353
 
@@ -280,7 +355,7 @@ Java 1.3.7, after it is published to Maven Central:
280
355
 
281
356
  The Python package requires Python 3.10 or newer. Framework dependencies are optional, so install only the extra needed by the application.
282
357
 
283
- Python 1.2.4 requires `aiwaf-rust>=0.2.11`; the `rust` extra remains an installation
358
+ Python 1.2.6 requires `aiwaf-rust>=0.2.13`; the `rust` extra remains an installation
284
359
  alias. Publish the matching Rust wheel with `NativeCSVPipeline` support before
285
360
  the Python release. The Rust release workflow builds Linux x86_64/aarch64,
286
361
  musl x86_64, macOS x86_64/arm64 and Windows x86_64 wheels and checks the native
@@ -1103,7 +1178,7 @@ existence to `Boolean(req.route)`. Supply accurate facts when the firewall runs
1103
1178
  before Express resolves routes. Country headers are not implicitly trusted.
1104
1179
 
1105
1180
  **`aiwaf(options)` runs the native pipeline by default** when two things hold: the
1106
- installed aiwaf-wasm is 0.2.8 or newer (it has every native feature), and every option
1181
+ installed aiwaf-wasm is 0.2.9 or newer (it has every native feature), and every option
1107
1182
  carries over exactly, so the conversion report below lists no differences. Otherwise it
1108
1183
  runs the regular middleware, as before. It logs one line when it picks the native
1109
1184
  pipeline. To keep the regular middleware, set `AIWAF_NATIVE_PIPELINE: false` in the
@@ -1350,7 +1425,7 @@ cp -R ../licenses crates/aiwaf_wasm/pkg/
1350
1425
 
1351
1426
  ## Java package
1352
1427
 
1353
- AIWAF Java 1.3.7 targets Java 17, Spring Framework 7.0, and Jakarta Servlet 6.1. It is a native Java implementation and does not load the Rust library.
1428
+ AIWAF Java 1.3.9 targets Java 17, Spring Framework 7.0, and Jakarta Servlet 6.1. It is a native Java implementation and does not load the Rust library.
1354
1429
 
1355
1430
  ### Core engine
1356
1431
 
@@ -1439,7 +1514,7 @@ UUID protection uses Python-compatible weighted signals: malformed input, valid
1439
1514
  Generate a route manifest from the live Spring application rather than supplying controller methods manually:
1440
1515
 
1441
1516
  ```bash
1442
- java -cp "your-app.jar:aiwaf-java-1.3.7.jar" \
1517
+ java -cp "your-app.jar:aiwaf-java-1.3.9.jar" \
1443
1518
  com.aiwaf.cli.AiwafConsole init \
1444
1519
  --app com.example.Application \
1445
1520
  --output .aiwaf/paths.json
@@ -1635,14 +1710,11 @@ python aiwaf_test.py --python-only
1635
1710
  python aiwaf_test.py --rust-only
1636
1711
  python aiwaf_test.py --js-only
1637
1712
  python aiwaf_test.py --wasm-only
1713
+ python aiwaf_test.py --java-only
1638
1714
  ```
1639
1715
 
1640
- Java is tested separately:
1641
-
1642
- ```bash
1643
- cd java
1644
- mvn test
1645
- ```
1716
+ Full runs include the Java suite, which needs a JDK 17 or newer and Maven. Use `--no-java`
1717
+ to skip it on a machine without them, or run it directly with `mvn -f java/pom.xml test`.
1646
1718
 
1647
1719
  ### Direct package commands
1648
1720
 
@@ -1670,11 +1742,11 @@ Release versions and tags must match the relevant manifest.
1670
1742
 
1671
1743
  | Package | Manifest | Tag | Workflow |
1672
1744
  | --- | --- | --- | --- |
1673
- | Python `aiwaf` | `pyproject.toml` | `python-v1.2.4` | `python-publish.yml` |
1674
- | npm `aiwaf` | `js/package.json` | `js-v1.2.3` | `npm-publish.yml` |
1675
- | PyPI `aiwaf-rust` | `rust/pyproject.toml` + `rust/Cargo.toml` | `rust-v0.2.12` | `rust-publish.yml` |
1676
- | npm `aiwaf-wasm` | `rust/crates/aiwaf_wasm/Cargo.toml` | `wasm-v0.2.9` | `wasm-publish.yml` |
1677
- | Maven `aiwaf-java` | `java/pom.xml` | `java-v1.3.7` | `java-publish.yml` |
1745
+ | Python `aiwaf` | `pyproject.toml` | `python-v1.2.6` | `python-publish.yml` |
1746
+ | npm `aiwaf` | `js/package.json` | `js-v1.2.5` | `npm-publish.yml` |
1747
+ | PyPI `aiwaf-rust` | `rust/pyproject.toml` + `rust/Cargo.toml` | `rust-v0.2.13` | `rust-publish.yml` |
1748
+ | npm `aiwaf-wasm` | `rust/crates/aiwaf_wasm/Cargo.toml` | `wasm-v0.2.10` | `wasm-publish.yml` |
1749
+ | Maven `aiwaf-java` | `java/pom.xml` | `java-v1.3.9` | `java-publish.yml` |
1678
1750
 
1679
1751
  Python and Rust publish to PyPI with trusted publishing. The npm workflows use npm trusted publishing and stage packages for approval. Configure the trusted publisher with organization `aiwaf-project`, repository `aiwaf`, the exact workflow filename, and the environment used by that workflow.
1680
1752
 
@@ -1682,11 +1754,12 @@ Java publishing uses the protected `maven-publish` environment plus `GPG_PRIVATE
1682
1754
 
1683
1755
  Registry releases are immutable. Increment the relevant manifest version before publishing another release.
1684
1756
 
1685
- This release is Python `aiwaf 1.2.4` with `aiwaf-rust 0.2.12`, and npm `aiwaf 1.2.3` with
1686
- `aiwaf-wasm 0.2.9`. Python 1.2.3, `aiwaf-rust 0.2.11` and `aiwaf-wasm 0.2.8` are already
1687
- published. Python 1.2.4 still requires only `aiwaf-rust>=0.2.11`, and npm `aiwaf` only
1688
- `aiwaf-wasm ^0.2.8`; publish the new engines first so the features that need them are
1689
- available. Java 1.3.7 has no changes in this release.
1757
+ This release is Python `aiwaf 1.2.6`, npm `aiwaf 1.2.5`, Java `aiwaf-java 1.3.9`,
1758
+ `aiwaf-rust 0.2.13` and `aiwaf-wasm 0.2.10`: `AIWAF_PROFILE` and the route checks for the new
1759
+ operations. Python 1.2.5, npm 1.2.4, Java 1.3.8, `aiwaf-rust 0.2.12` and `aiwaf-wasm 0.2.9` are
1760
+ already published. Publish the two engines first: they carry the new route rules, and Python
1761
+ requires `aiwaf-rust>=0.2.13`. npm `aiwaf` keeps `aiwaf-wasm ^0.2.9`, which picks up 0.2.10
1762
+ once it's published.
1690
1763
 
1691
1764
  ## Security and limitations
1692
1765
 
@@ -155,6 +155,7 @@ module.exports = {
155
155
  async block(ip, reason = 'WAF blocked', options = {}) {
156
156
  const normalizedIp = String(ip || '').trim();
157
157
  if (!normalizedIp) return false;
158
+ if (require('./profiles').skipBlocklist(normalizedIp, reason)) return false;
158
159
  if (options.checkExemptions !== false) {
159
160
  try {
160
161
  const exemptionStore = require('./exemptionStore');