aiwaf 1.1.5 → 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 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.1.8, Rust/Python 0.2.7, Node.js 1.1.5, WASM 0.2.5, and Java 1.3.5 are local source targets. See the package table below and [CHANGELOG](CHANGELOG.md) for release changes.
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.
43
43
 
44
44
  | Runtime | Package | Repository version | Primary use |
45
45
  | --- | --- | ---: | --- |
46
- | Python | [`aiwaf`](https://pypi.org/project/aiwaf/) | `1.1.8` | Django, Flask, and FastAPI protection |
47
- | Node.js | [`aiwaf`](https://www.npmjs.com/package/aiwaf) | `1.1.5` | Express and Node framework middleware |
48
- | Rust/Python | [`aiwaf-rust`](https://pypi.org/project/aiwaf-rust/) | `0.2.7` | Native Python acceleration and JSON model inference |
49
- | WebAssembly | [`aiwaf-wasm`](https://www.npmjs.com/package/aiwaf-wasm) | `0.2.5` | Rust detection and model primitives for JavaScript |
50
- | Java | `io.github.aiwaf-project:aiwaf-java` | `1.3.5` | Spring MVC and Jakarta Servlet protection |
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 |
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.1.8 already installs aiwaf-rust
259
+ # Backward-compatible alias; Python 1.1.9 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.5, after it is published to Maven Central:
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.5</version>
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.1.8 requires `aiwaf-rust>=0.2.7`; the `rust` extra remains an installation
283
+ Python 1.1.9 requires `aiwaf-rust>=0.2.8`; 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
@@ -553,12 +714,10 @@ Check the installed extension without touching application data:
553
714
  python scripts/check_native_csv_runtime.py
554
715
  ```
555
716
 
556
- Development request batching adds `policy_sql_signatures` and
557
- `csv_geo_policy` capabilities. Shared SQL inspection checks the first
558
- eight ASCII strings immediately for prompt denial, then checks subsequent strings
559
- in batches of at most 128. Unicode boundaries and inspection-limit exits flush
560
- pending checks first, preserving first-finding order. Django, Flask, and FastAPI
561
- 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.
562
721
 
563
722
  Flask with CSV geo state and an explicit allow/block list can read dynamic countries
564
723
  and evaluate the geo policy in one native call. Django CSV and FastAPI CSV use
@@ -784,7 +943,7 @@ npm run aiwaf -- manifest --framework express --routes routes.json --output .aiw
784
943
  | Logging | `AIWAF_MIDDLEWARE_LOGGING`, `AIWAF_MIDDLEWARE_LOG_PATH`, DB/CSV options |
785
944
  | WASM | `AIWAF_WASM_VALIDATION`, `AIWAF_WASM_VALIDATE_RECENT` |
786
945
 
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.
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.
788
947
 
789
948
  The Python filesystem CSV transactions and retained training bindings remain
790
949
  PyO3-specific. Node now also has an **explicit stateful WASM request pipeline**;
@@ -1027,7 +1186,7 @@ cp -R ../licenses crates/aiwaf_wasm/pkg/
1027
1186
 
1028
1187
  ## Java package
1029
1188
 
1030
- AIWAF Java 1.3.5 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.
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.
1031
1190
 
1032
1191
  ### Core engine
1033
1192
 
@@ -1096,7 +1255,7 @@ aiwaf.storage.redis-pool-min-idle=0
1096
1255
  aiwaf.storage.redis-pool-max-wait-millis=250
1097
1256
  ```
1098
1257
 
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.
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.
1100
1259
 
1101
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:
1102
1261
 
@@ -1116,7 +1275,7 @@ UUID protection uses Python-compatible weighted signals: malformed input, valid
1116
1275
  Generate a route manifest from the live Spring application rather than supplying controller methods manually:
1117
1276
 
1118
1277
  ```bash
1119
- java -cp "your-app.jar:aiwaf-java-1.3.5.jar" \
1278
+ java -cp "your-app.jar:aiwaf-java-1.3.6.jar" \
1120
1279
  com.aiwaf.cli.AiwafConsole init \
1121
1280
  --app com.example.Application \
1122
1281
  --output .aiwaf/paths.json
@@ -1287,7 +1446,7 @@ Do not train directly on unreviewed sensitive request bodies or authentication h
1287
1446
  - Configure the outermost proxy to overwrite client-supplied forwarding headers.
1288
1447
  - Use Redis, a database, or another shared backend when multiple workers must share rate-limit, blocklist, or exemption state.
1289
1448
  - Keep health checks, static assets, and trusted webhook routes explicitly scoped instead of disabling protection globally.
1290
- - Start anomaly detection in observe-only or conservative mode and tune it with representative normal traffic.
1449
+ - Tune anomaly detection with representative normal traffic before relying on it in production.
1291
1450
  - Rotate logs and exclude secrets, authorization headers, cookies, and personal data.
1292
1451
  - Sign model/configuration artifacts where the runtime supports HMAC verification.
1293
1452
  - Run AIWAF alongside normal secure-development controls and an edge/reverse-proxy layer.
@@ -1347,11 +1506,11 @@ Release versions and tags must match the relevant manifest.
1347
1506
 
1348
1507
  | Package | Manifest | Tag | Workflow |
1349
1508
  | --- | --- | --- | --- |
1350
- | Python `aiwaf` | `pyproject.toml` | `python-v1.1.8` | `python-publish.yml` |
1351
- | npm `aiwaf` | `js/package.json` | `js-v1.1.5` | `npm-publish.yml` |
1352
- | PyPI `aiwaf-rust` | `rust/pyproject.toml` + `rust/Cargo.toml` | `rust-v0.2.7` | `rust-publish.yml` |
1353
- | npm `aiwaf-wasm` | `rust/crates/aiwaf_wasm/Cargo.toml` | `wasm-v0.2.5` | `wasm-publish.yml` |
1354
- | Maven `aiwaf-java` | `java/pom.xml` | `java-v1.3.5` | `java-publish.yml` |
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` |
1355
1514
 
1356
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.
1357
1516
 
@@ -1359,11 +1518,12 @@ Java publishing uses the protected `maven-publish` environment plus `GPG_PRIVATE
1359
1518
 
1360
1519
  Registry releases are immutable. Increment the relevant manifest version before publishing another release.
1361
1520
 
1362
- For this release, publish `aiwaf-rust 0.2.7` before Python `aiwaf 1.1.8`, and
1363
- `aiwaf-wasm 0.2.5` before npm `aiwaf 1.1.5`. After WASM publication, refresh the
1364
- npm lockfile against the registry to record the actual companion checksum, then
1365
- run `npm ci` and the release checks. The prepared future WASM lock entry has no
1366
- integrity checksum; it cannot be installed until that package is published.
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`.
1367
1527
 
1368
1528
  ## Security and limitations
1369
1529
 
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
- return print({ ok: true, output: options.output, framework: options.framework, routes: Object.keys(manifest.routes || {}).length });
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') {
package/lib/geoBlocker.js CHANGED
@@ -2,6 +2,7 @@ const fs = require('fs');
2
2
  const path = require('path');
3
3
  const geoStore = require('./geoStore');
4
4
  const { evaluateGeoPolicy } = require('./geoPolicy');
5
+ const { getRequestIp } = require('./runtimeUtils');
5
6
 
6
7
  let config = {
7
8
  enabled: false,
@@ -19,13 +20,6 @@ function normalizeCountry(value) {
19
20
  return String(value || '').trim().toUpperCase();
20
21
  }
21
22
 
22
- function getRequestIp(req) {
23
- const rawIp = req.headers?.['x-forwarded-for']
24
- ? String(req.headers['x-forwarded-for']).split(',')[0].trim()
25
- : (req.ip || req.connection?.remoteAddress || req.socket?.remoteAddress || '');
26
- return String(rawIp).replace(/^::ffff:/, '');
27
- }
28
-
29
23
  function getCachedCountry(ip) {
30
24
  if (!ip || config.cacheSeconds <= 0) return '';
31
25
  const key = `${config.cachePrefix}${ip}`;