Skip to content

Commit a09ed77

Browse files
committed
Merge branch 'main' into cache-forceProtectionOff
2 parents 0fd65db + 62d750c commit a09ed77

File tree

160 files changed

+35580
-21976
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+35580
-21976
lines changed

.github/workflows/benchmark.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ jobs:
2323
- "27016:5432"
2424
timeout-minutes: 10
2525
strategy:
26+
fail-fast: false
2627
matrix:
27-
node-version: [18.x]
28+
node-version: [20.x, 24.x]
2829
steps:
2930
- uses: actions/checkout@v4
3031
- name: Use Node.js ${{ matrix.node-version }}
@@ -34,7 +35,7 @@ jobs:
3435
cache: "npm"
3536
cache-dependency-path: "**/package-lock.json"
3637
- name: Install K6
37-
uses: grafana/setup-k6-action@v1
38+
uses: grafana/setup-k6-action@ffe7d7290dfa715e48c2ccc924d068444c94bde2 # v1
3839
- name: Install wrk
3940
run: |
4041
sudo apt-get update
@@ -48,10 +49,15 @@ jobs:
4849
- name: Run shell injection Benchmark
4950
run: cd benchmarks/shell-injection && node benchmark.js
5051
- name: Run Hono with Postgres Benchmark
52+
# Skip on Node 24.x due to a bug: https://github.com/honojs/node-server/issues/240
53+
if: matrix.node-version != '24.x'
5154
run: cd benchmarks/hono-pg && node benchmark.js
5255
- name: Run API Discovery Benchmark
5356
run: cd benchmarks/api-discovery && node benchmark.js
5457
- name: Run Express Benchmark
58+
# Skip on Node 24.x because benchmark currently fails.
59+
# Big performance improve in comparison to older Node.js versions, but higher difference between usage with and without Zen
60+
if: matrix.node-version != '24.x'
5561
run: cd benchmarks/express && node benchmark.js
5662
- name: Check Rate Limiter memory usage
5763
run: cd benchmarks/rate-limiting && node --expose-gc memory.js

.github/workflows/unit-test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
strategy:
6565
fail-fast: false
6666
matrix:
67-
node-version: [16.x, 18.x, 20.x, 22.x, 23.x]
67+
node-version: [16.x, 18.x, 20.x, 22.x, 24.x]
6868
timeout-minutes: 10
6969
steps:
7070
- uses: actions/checkout@v4
@@ -81,9 +81,9 @@ jobs:
8181
- run: npm run build
8282
- run: npm run test:ci
8383
- name: "Upload coverage"
84-
uses: codecov/codecov-action@v4.0.1
84+
uses: codecov/codecov-action@0565863a31f2c772f9f0395002a31e3f06189574 # v5
8585
with:
86-
file: ./library/.tap/report/lcov.info
86+
files: ./library/.tap/report/lcov.info
8787
env:
8888
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
8989
slug: AikidoSec/firewall-node

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Zen for Node.js 16+ is compatible with:
4545
*[micro](docs/micro.md) 10.x
4646
*[Next.js](docs/next.md) 12.x, 13.x and 14.x
4747
*[Fastify](docs/fastify.md) 4.x and 5.x
48-
*[Koa](docs/koa.md) 2.x
48+
*[Koa](docs/koa.md) 3.x and 2.x
4949
*[NestJS](docs/nestjs.md) 10.x and 11.x
5050

5151
### Database drivers
@@ -87,12 +87,12 @@ See list above for supported database drivers.
8787
### Data serialization tools
8888

8989
*[`xml2js`](https://www.npmjs.com/package/xml2js) 0.6.x, 0.5.x, ^0.4.18
90-
*[`fast-xml-parser`](https://www.npmjs.com/package/fast-xml-parser) 4.x
90+
*[`fast-xml-parser`](https://www.npmjs.com/package/fast-xml-parser) 5.x, 4.x
9191
*[`xml-js`](https://www.npmjs.com/package/xml-js) 1.x
9292

9393
### Shell tools
9494

95-
*[`ShellJS`](https://www.npmjs.com/package/shelljs) 0.8.x, 0.7.x
95+
*[`ShellJS`](https://www.npmjs.com/package/shelljs) 0.9.x, 0.8.x, 0.7.x
9696

9797
### Routers
9898

benchmarks/express/package-lock.json

Lines changed: 452 additions & 406 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

benchmarks/hono-pg/package-lock.json

Lines changed: 22 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

benchmarks/operations/benchmark.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ const modules = [
1414
module: "nosqli",
1515
name: "NoSQL query",
1616
},
17+
/*
18+
Disabled because functionName.constructor === Function is false after patching global
1719
{
1820
module: "jsinjection",
1921
name: "`new Function(...)`",
20-
},
22+
},*/
2123
{
2224
module: "shelli",
2325
name: "Shell command",

docs/express.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ Zen.addExpressMiddleware(app);
5959
app.get(...);
6060
```
6161

62+
You can also pass a `Router` instance to `Zen.addExpressMiddleware`:
63+
64+
```js
65+
const router = express.Router();
66+
67+
// Note: The middleware should be executed once per request
68+
Zen.addExpressMiddleware(router);
69+
70+
router.get(...);
71+
72+
app.use(router);
73+
```
74+
6275
## Debug mode
6376

6477
If you need to debug the firewall, you can run your express app with the environment variable `AIKIDO_DEBUG` set to `true`:

end2end/server/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:22
1+
FROM node:22-slim
22

33
WORKDIR /app
44

end2end/server/src/handlers/lists.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ const {
22
getBlockedIPAddresses,
33
getBlockedUserAgents,
44
getAllowedIPAddresses,
5+
getMonitoredUserAgents,
6+
getMonitoredIPAddresses,
7+
getUserAgentDetails,
58
} = require("../zen/config");
69

710
module.exports = function lists(req, res) {
@@ -12,6 +15,9 @@ module.exports = function lists(req, res) {
1215
const blockedIps = getBlockedIPAddresses(req.app);
1316
const blockedUserAgents = getBlockedUserAgents(req.app);
1417
const allowedIps = getAllowedIPAddresses(req.app);
18+
const monitoredUserAgents = getMonitoredUserAgents(req.app);
19+
const monitoredIps = getMonitoredIPAddresses(req.app);
20+
const userAgentDetails = getUserAgentDetails(req.app);
1521

1622
res.json({
1723
success: true,
@@ -20,22 +26,37 @@ module.exports = function lists(req, res) {
2026
blockedIps.length > 0
2127
? [
2228
{
29+
key: "geoip/Belgium;BE",
2330
source: "geoip",
2431
description: "geo restrictions",
2532
ips: blockedIps,
2633
},
2734
]
2835
: [],
2936
blockedUserAgents: blockedUserAgents,
37+
monitoredUserAgents: monitoredUserAgents,
38+
userAgentDetails: userAgentDetails,
3039
allowedIPAddresses:
3140
allowedIps.length > 0
3241
? [
3342
{
43+
key: "geoip/Belgium;BE",
3444
source: "geoip",
3545
description: "geo restrictions",
3646
ips: allowedIps,
3747
},
3848
]
3949
: [],
50+
monitoredIPAddresses:
51+
monitoredIps.length > 0
52+
? monitoredIps
53+
: [
54+
{
55+
key: "geoip/Belgium;BE",
56+
source: "geoip",
57+
description: "geo restrictions",
58+
ips: monitoredIps,
59+
},
60+
],
4061
});
4162
};

end2end/server/src/handlers/updateLists.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ const {
22
updateBlockedIPAddresses,
33
updateBlockedUserAgents,
44
updateAllowedIPAddresses,
5+
updateMonitoredUserAgents,
6+
updateMonitoredIPAddresses,
7+
updateUserAgentDetails,
58
} = require("../zen/config");
69

710
module.exports = function updateIPLists(req, res) {
@@ -46,5 +49,26 @@ module.exports = function updateIPLists(req, res) {
4649
updateAllowedIPAddresses(req.app, req.body.allowedIPAddresses);
4750
}
4851

52+
if (
53+
req.body.monitoredUserAgents &&
54+
typeof req.body.monitoredUserAgents === "string"
55+
) {
56+
updateMonitoredUserAgents(req.app, req.body.monitoredUserAgents);
57+
}
58+
59+
if (
60+
req.body.monitoredIPAddresses &&
61+
Array.isArray(req.body.monitoredIPAddresses)
62+
) {
63+
updateMonitoredIPAddresses(req.app, req.body.monitoredIPAddresses);
64+
}
65+
66+
if (
67+
req.body.userAgentDetails &&
68+
Array.isArray(req.body.userAgentDetails)
69+
) {
70+
updateUserAgentDetails(req.app, req.body.userAgentDetails);
71+
}
72+
4973
res.json({ success: true });
5074
};

0 commit comments

Comments
 (0)