aiwaf-js 0.0.8 → 0.0.9
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/package.json +16 -1
- package/.dockerignore +0 -6
- package/.github/workflows/node.js.yml +0 -31
- package/.github/workflows/npm-publish.yml +0 -27
- package/aiwaf.sqlite +0 -0
- package/examples/sandbox/README.md +0 -95
- package/examples/sandbox/aiwaf-adonis-proxy/Dockerfile +0 -16
- package/examples/sandbox/aiwaf-adonis-proxy/package.json +0 -13
- package/examples/sandbox/aiwaf-adonis-proxy/server.js +0 -71
- package/examples/sandbox/aiwaf-fastify-proxy/Dockerfile +0 -21
- package/examples/sandbox/aiwaf-fastify-proxy/package.json +0 -16
- package/examples/sandbox/aiwaf-fastify-proxy/server.js +0 -42
- package/examples/sandbox/aiwaf-hapi-proxy/Dockerfile +0 -16
- package/examples/sandbox/aiwaf-hapi-proxy/package.json +0 -15
- package/examples/sandbox/aiwaf-hapi-proxy/server.js +0 -55
- package/examples/sandbox/aiwaf-koa-proxy/Dockerfile +0 -16
- package/examples/sandbox/aiwaf-koa-proxy/package.json +0 -16
- package/examples/sandbox/aiwaf-koa-proxy/server.js +0 -41
- package/examples/sandbox/aiwaf-nest-proxy/Dockerfile +0 -17
- package/examples/sandbox/aiwaf-nest-proxy/main.js +0 -55
- package/examples/sandbox/aiwaf-nest-proxy/package.json +0 -20
- package/examples/sandbox/aiwaf-next-proxy/Dockerfile +0 -16
- package/examples/sandbox/aiwaf-next-proxy/package.json +0 -16
- package/examples/sandbox/aiwaf-next-proxy/pages/index.js +0 -3
- package/examples/sandbox/aiwaf-next-proxy/server.js +0 -65
- package/examples/sandbox/aiwaf-proxy/Dockerfile +0 -21
- package/examples/sandbox/aiwaf-proxy/package.json +0 -15
- package/examples/sandbox/aiwaf-proxy/server.js +0 -44
- package/examples/sandbox/attack-suite.js +0 -572
- package/examples/sandbox/compare-results-modes.js +0 -141
- package/examples/sandbox/compare-results.js +0 -324
- package/examples/sandbox/docker-compose.yml +0 -142
- package/examples/sandbox/run-and-compare.js +0 -32
- package/geolock/ipinfo_lite.mmdb +0 -0
- package/knexfile.js +0 -9
- package/migrations/001_create_blocked_ips.js +0 -11
- package/migrations/002_create_dynamic_keywords.js +0 -11
- package/test/adonis-middleware.test.js +0 -129
- package/test/anomaly-detector.test.js +0 -36
- package/test/cli.test.js +0 -125
- package/test/csv-fallback.test.js +0 -165
- package/test/dynamic-keyword-integration.test.js +0 -24
- package/test/dynamic-keyword-store.test.js +0 -78
- package/test/exemptions-db.test.js +0 -38
- package/test/fastify-plugin.test.js +0 -106
- package/test/geo-mmdb.test.js +0 -77
- package/test/hapi-plugin.test.js +0 -115
- package/test/header-validation.test.js +0 -66
- package/test/honeypot-detector.test.js +0 -42
- package/test/isolation-forest.test.js +0 -38
- package/test/jest.teardown.js +0 -33
- package/test/koa-middleware.test.js +0 -104
- package/test/middleware-behavior.test.js +0 -75
- package/test/model-store-db.test.js +0 -22
- package/test/model-store.test.js +0 -31
- package/test/nest-integration.test.js +0 -92
- package/test/nest-middleware.test.js +0 -88
- package/test/next-handler.test.js +0 -174
- package/test/perf-wasm.js +0 -64
- package/test/redis-client.test.js +0 -35
- package/test/settingsCompat.test.js +0 -95
- package/test/train.test.js +0 -137
- package/test/uuid-detector.test.js +0 -20
- package/test/waf.test.js +0 -357
- package/test/wasm-adapter.test.js +0 -59
- package/test/wasm-retrain-behavior.test.js +0 -87
- package/test/wasm-waf-integration.test.js +0 -65
- package/test-anomaly.js +0 -77
- package/test-complete-waf.js +0 -147
- package/test-simple.js +0 -79
package/package.json
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aiwaf-js",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "Adaptive Web Application Firewall middleware for Node.js (Express, Fastify, Hapi, Next.js)",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"index.js",
|
|
8
|
+
"bin/",
|
|
9
|
+
"lib/",
|
|
10
|
+
"resources/",
|
|
11
|
+
"utils/",
|
|
12
|
+
"train.js",
|
|
13
|
+
"README.md",
|
|
14
|
+
"INSTALLATION.md",
|
|
15
|
+
"LICENSE"
|
|
16
|
+
],
|
|
6
17
|
"bin": {
|
|
7
18
|
"aiwaf": "bin/aiwaf.js"
|
|
8
19
|
},
|
|
@@ -64,6 +75,10 @@
|
|
|
64
75
|
"middleware",
|
|
65
76
|
"ml"
|
|
66
77
|
],
|
|
78
|
+
"repository": {
|
|
79
|
+
"type": "git",
|
|
80
|
+
"url": "https://github.com/aiwaf/aiwaf-js"
|
|
81
|
+
},
|
|
67
82
|
"author": "Aayush Gauba",
|
|
68
83
|
"license": "MIT"
|
|
69
84
|
}
|
package/.dockerignore
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
|
|
2
|
-
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
|
|
3
|
-
|
|
4
|
-
name: Node.js CI
|
|
5
|
-
|
|
6
|
-
on:
|
|
7
|
-
push:
|
|
8
|
-
branches: [ "main" ]
|
|
9
|
-
pull_request:
|
|
10
|
-
branches: [ "main" ]
|
|
11
|
-
|
|
12
|
-
jobs:
|
|
13
|
-
build:
|
|
14
|
-
|
|
15
|
-
runs-on: ubuntu-latest
|
|
16
|
-
|
|
17
|
-
strategy:
|
|
18
|
-
matrix:
|
|
19
|
-
node-version: [18.x, 20.x, 22.x]
|
|
20
|
-
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
|
21
|
-
|
|
22
|
-
steps:
|
|
23
|
-
- uses: actions/checkout@v4
|
|
24
|
-
- name: Use Node.js ${{ matrix.node-version }}
|
|
25
|
-
uses: actions/setup-node@v4
|
|
26
|
-
with:
|
|
27
|
-
node-version: ${{ matrix.node-version }}
|
|
28
|
-
cache: 'npm'
|
|
29
|
-
- run: npm install
|
|
30
|
-
- run: npm run build --if-present
|
|
31
|
-
- run: npm test
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
name: Publish to npm
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
release:
|
|
5
|
-
types: [created]
|
|
6
|
-
workflow_dispatch:
|
|
7
|
-
|
|
8
|
-
jobs:
|
|
9
|
-
build-and-publish:
|
|
10
|
-
runs-on: ubuntu-latest
|
|
11
|
-
environment: npm-publish
|
|
12
|
-
|
|
13
|
-
steps:
|
|
14
|
-
- uses: actions/checkout@v4
|
|
15
|
-
with:
|
|
16
|
-
fetch-depth: 0
|
|
17
|
-
|
|
18
|
-
- uses: actions/setup-node@v4
|
|
19
|
-
with:
|
|
20
|
-
node-version: 20
|
|
21
|
-
registry-url: https://registry.npmjs.org/
|
|
22
|
-
|
|
23
|
-
- run: npm install
|
|
24
|
-
- run: npm test
|
|
25
|
-
- run: npm publish --access public
|
|
26
|
-
env:
|
|
27
|
-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/aiwaf.sqlite
DELETED
|
Binary file
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
# AIWAF-JS + OWASP Juice Shop Sandbox
|
|
2
|
-
|
|
3
|
-
This sandbox runs AIWAF-JS as a proxy in front of OWASP Juice Shop.
|
|
4
|
-
|
|
5
|
-
## Run
|
|
6
|
-
|
|
7
|
-
From `examples/sandbox/`:
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
docker compose up --build
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
Then open:
|
|
14
|
-
|
|
15
|
-
- AIWAF-protected: `http://localhost:3000`
|
|
16
|
-
- AIWAF-protected (Fastify): `http://localhost:3002`
|
|
17
|
-
- AIWAF-protected (Hapi): `http://localhost:3003`
|
|
18
|
-
- AIWAF-protected (Koa): `http://localhost:3004`
|
|
19
|
-
- AIWAF-protected (NestJS): `http://localhost:3005`
|
|
20
|
-
- AIWAF-protected (Next.js): `http://localhost:3006`
|
|
21
|
-
- AIWAF-protected (AdonisJS): `http://localhost:3007`
|
|
22
|
-
- Direct Juice Shop: `http://localhost:3001`
|
|
23
|
-
|
|
24
|
-
## Test
|
|
25
|
-
|
|
26
|
-
```bash
|
|
27
|
-
curl http://localhost:3000
|
|
28
|
-
curl http://localhost:3000/admin.php
|
|
29
|
-
curl http://localhost:3000/../../etc/passwd
|
|
30
|
-
curl -A "sqlmap/1.0" http://localhost:3000
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
Check logs in the `aiwaf_logs` volume (JSONL).
|
|
34
|
-
|
|
35
|
-
## Attack Suite
|
|
36
|
-
|
|
37
|
-
Run against direct Juice Shop:
|
|
38
|
-
|
|
39
|
-
```bash
|
|
40
|
-
node attack-suite.js http://localhost:3001 direct
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
Run against AIWAF-protected Juice Shop:
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
node attack-suite.js http://localhost:3000 protected
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
Run against AIWAF-protected Juice Shop (Fastify):
|
|
50
|
-
|
|
51
|
-
```bash
|
|
52
|
-
node attack-suite.js http://localhost:3002 protected_fastify
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
Run against AIWAF-protected Juice Shop (Hapi):
|
|
56
|
-
|
|
57
|
-
```bash
|
|
58
|
-
node attack-suite.js http://localhost:3003 protected_hapi
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
Run against AIWAF-protected Juice Shop (Koa):
|
|
62
|
-
|
|
63
|
-
```bash
|
|
64
|
-
node attack-suite.js http://localhost:3004 protected_koa
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
Run against AIWAF-protected Juice Shop (NestJS):
|
|
68
|
-
|
|
69
|
-
```bash
|
|
70
|
-
node attack-suite.js http://localhost:3005 protected_nest
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
Run against AIWAF-protected Juice Shop (Next.js):
|
|
74
|
-
|
|
75
|
-
```bash
|
|
76
|
-
node attack-suite.js http://localhost:3006 protected_next
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
Run against AIWAF-protected Juice Shop (AdonisJS):
|
|
80
|
-
|
|
81
|
-
```bash
|
|
82
|
-
node attack-suite.js http://localhost:3007 protected_adonis
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
Compare results:
|
|
86
|
-
|
|
87
|
-
```bash
|
|
88
|
-
node compare-results.js results_direct_*.json results_protected_*.json results_protected_fastify_*.json results_protected_hapi_*.json results_protected_koa_*.json results_protected_nest_*.json results_protected_next_*.json results_protected_adonis_*.json
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
Or run the full suite + comparison in one command:
|
|
92
|
-
|
|
93
|
-
```bash
|
|
94
|
-
node run-and-compare.js
|
|
95
|
-
```
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
FROM node:20-bullseye
|
|
2
|
-
|
|
3
|
-
WORKDIR /workspace
|
|
4
|
-
COPY . /workspace
|
|
5
|
-
|
|
6
|
-
RUN apt-get update && apt-get install -y python3 make g++ \
|
|
7
|
-
&& rm -rf /var/lib/apt/lists/*
|
|
8
|
-
|
|
9
|
-
RUN npm_config_build_from_source=true npm install
|
|
10
|
-
|
|
11
|
-
WORKDIR /workspace/examples/sandbox/aiwaf-adonis-proxy
|
|
12
|
-
|
|
13
|
-
RUN npm_config_build_from_source=true npm install
|
|
14
|
-
|
|
15
|
-
EXPOSE 3007
|
|
16
|
-
CMD ["npm", "start"]
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
const { createProxyMiddleware } = require('http-proxy-middleware');
|
|
2
|
-
const aiwaf = require('aiwaf-js');
|
|
3
|
-
|
|
4
|
-
const PORT = process.env.PORT || 3007;
|
|
5
|
-
const TARGET_BASE_URL = process.env.TARGET_BASE_URL || 'http://localhost:3001';
|
|
6
|
-
|
|
7
|
-
const proxy = createProxyMiddleware({
|
|
8
|
-
target: TARGET_BASE_URL,
|
|
9
|
-
changeOrigin: true,
|
|
10
|
-
ws: true,
|
|
11
|
-
logLevel: 'warn'
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
function createCtx(req, res) {
|
|
15
|
-
const response = {
|
|
16
|
-
response: res,
|
|
17
|
-
statusCode: res.statusCode || 200,
|
|
18
|
-
status(code) {
|
|
19
|
-
response.statusCode = code;
|
|
20
|
-
res.statusCode = code;
|
|
21
|
-
return response;
|
|
22
|
-
},
|
|
23
|
-
send(payload) {
|
|
24
|
-
res.end(payload);
|
|
25
|
-
return response;
|
|
26
|
-
},
|
|
27
|
-
json(payload) {
|
|
28
|
-
res.setHeader('content-type', 'application/json');
|
|
29
|
-
res.end(JSON.stringify(payload));
|
|
30
|
-
return response;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const request = {
|
|
35
|
-
request: req,
|
|
36
|
-
url: () => req.url,
|
|
37
|
-
headers: () => req.headers || {},
|
|
38
|
-
ip: () => (req.headers?.['x-forwarded-for'] || req.socket?.remoteAddress),
|
|
39
|
-
method: () => req.method
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
return { request, response };
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const middleware = aiwaf.adonis({
|
|
46
|
-
staticKeywords: ['.php', '.env', '.git', '../'],
|
|
47
|
-
dynamicTopN: 5,
|
|
48
|
-
WINDOW_SEC: 10,
|
|
49
|
-
MAX_REQ: 25,
|
|
50
|
-
FLOOD_REQ: 50,
|
|
51
|
-
HONEYPOT_FIELD: 'hp_field',
|
|
52
|
-
AIWAF_METHOD_POLICY_ENABLED: true,
|
|
53
|
-
AIWAF_ALLOWED_METHODS: ['GET', 'POST', 'HEAD', 'OPTIONS'],
|
|
54
|
-
AIWAF_HEADER_VALIDATION: true,
|
|
55
|
-
AIWAF_REQUIRED_HEADERS: [],
|
|
56
|
-
AIWAF_MIDDLEWARE_LOGGING: true,
|
|
57
|
-
AIWAF_MIDDLEWARE_LOG_PATH: process.env.AIWAF_MIDDLEWARE_LOG_PATH || 'logs/aiwaf-requests.jsonl'
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
require('http')
|
|
61
|
-
.createServer(async (req, res) => {
|
|
62
|
-
console.log(`[sandbox-adonis] ${req.method} ${req.url}`);
|
|
63
|
-
const ctx = createCtx(req, res);
|
|
64
|
-
await middleware(ctx, () => new Promise(resolve => {
|
|
65
|
-
proxy(req, res, resolve);
|
|
66
|
-
}));
|
|
67
|
-
})
|
|
68
|
-
.listen(PORT, '0.0.0.0', () => {
|
|
69
|
-
console.log(`AIWAF Adonis sandbox proxy running on port ${PORT}`);
|
|
70
|
-
console.log(`Forwarding traffic to ${TARGET_BASE_URL}`);
|
|
71
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
FROM node:20-bullseye
|
|
2
|
-
|
|
3
|
-
WORKDIR /workspace
|
|
4
|
-
|
|
5
|
-
COPY . /workspace
|
|
6
|
-
|
|
7
|
-
WORKDIR /workspace
|
|
8
|
-
|
|
9
|
-
RUN apt-get update && apt-get install -y python3 make g++ && rm -rf /var/lib/apt/lists/*
|
|
10
|
-
|
|
11
|
-
ENV npm_config_build_from_source=sqlite3
|
|
12
|
-
|
|
13
|
-
RUN npm install
|
|
14
|
-
|
|
15
|
-
WORKDIR /workspace/examples/sandbox/aiwaf-fastify-proxy
|
|
16
|
-
|
|
17
|
-
RUN npm install
|
|
18
|
-
|
|
19
|
-
EXPOSE 3002
|
|
20
|
-
|
|
21
|
-
CMD ["npm", "start"]
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "aiwaf-fastify-proxy-sandbox",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"private": true,
|
|
5
|
-
"main": "server.js",
|
|
6
|
-
"type": "commonjs",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"start": "node server.js"
|
|
9
|
-
},
|
|
10
|
-
"dependencies": {
|
|
11
|
-
"aiwaf-js": "file:../../..",
|
|
12
|
-
"fastify": "^4.29.1",
|
|
13
|
-
"@fastify/middie": "^8.0.0",
|
|
14
|
-
"http-proxy-middleware": "^3.0.0"
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
const fastify = require('fastify')({ logger: true });
|
|
2
|
-
const aiwaf = require('aiwaf-js');
|
|
3
|
-
const { createProxyMiddleware } = require('http-proxy-middleware');
|
|
4
|
-
|
|
5
|
-
const PORT = process.env.PORT || 3002;
|
|
6
|
-
const TARGET_BASE_URL = process.env.TARGET_BASE_URL || 'http://localhost:3001';
|
|
7
|
-
|
|
8
|
-
fastify.register(aiwaf.fastify, {
|
|
9
|
-
staticKeywords: ['.php', '.env', '.git', '../'],
|
|
10
|
-
dynamicTopN: 5,
|
|
11
|
-
WINDOW_SEC: 10,
|
|
12
|
-
MAX_REQ: 25,
|
|
13
|
-
FLOOD_REQ: 50,
|
|
14
|
-
HONEYPOT_FIELD: 'hp_field',
|
|
15
|
-
AIWAF_METHOD_POLICY_ENABLED: true,
|
|
16
|
-
AIWAF_ALLOWED_METHODS: ['GET', 'POST', 'HEAD', 'OPTIONS'],
|
|
17
|
-
AIWAF_HEADER_VALIDATION: true,
|
|
18
|
-
AIWAF_REQUIRED_HEADERS: [],
|
|
19
|
-
AIWAF_MIDDLEWARE_LOGGING: true,
|
|
20
|
-
AIWAF_MIDDLEWARE_LOG_PATH: process.env.AIWAF_MIDDLEWARE_LOG_PATH || 'logs/aiwaf-requests.jsonl'
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
fastify.addHook('onRequest', async (request, reply) => {
|
|
24
|
-
fastify.log.info(`[sandbox-fastify] ${request.method} ${request.url}`);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
fastify.register(require('@fastify/middie')).then(() => {
|
|
28
|
-
fastify.use(
|
|
29
|
-
'/',
|
|
30
|
-
createProxyMiddleware({
|
|
31
|
-
target: TARGET_BASE_URL,
|
|
32
|
-
changeOrigin: true,
|
|
33
|
-
ws: true,
|
|
34
|
-
logLevel: 'warn'
|
|
35
|
-
})
|
|
36
|
-
);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
fastify.listen({ port: PORT, host: '0.0.0.0' }).then(() => {
|
|
40
|
-
fastify.log.info(`AIWAF Fastify sandbox proxy running on port ${PORT}`);
|
|
41
|
-
fastify.log.info(`Forwarding traffic to ${TARGET_BASE_URL}`);
|
|
42
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
FROM node:20-bullseye
|
|
2
|
-
|
|
3
|
-
WORKDIR /workspace
|
|
4
|
-
COPY . /workspace
|
|
5
|
-
|
|
6
|
-
RUN apt-get update && apt-get install -y python3 make g++ \
|
|
7
|
-
&& rm -rf /var/lib/apt/lists/*
|
|
8
|
-
|
|
9
|
-
RUN npm_config_build_from_source=true npm install
|
|
10
|
-
|
|
11
|
-
WORKDIR /workspace/examples/sandbox/aiwaf-hapi-proxy
|
|
12
|
-
|
|
13
|
-
RUN npm_config_build_from_source=true npm install
|
|
14
|
-
|
|
15
|
-
EXPOSE 3003
|
|
16
|
-
CMD ["npm", "start"]
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "aiwaf-hapi-proxy-sandbox",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"private": true,
|
|
5
|
-
"main": "server.js",
|
|
6
|
-
"type": "commonjs",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"start": "node server.js"
|
|
9
|
-
},
|
|
10
|
-
"dependencies": {
|
|
11
|
-
"aiwaf-js": "file:../../..",
|
|
12
|
-
"@hapi/hapi": "^21.3.12",
|
|
13
|
-
"@hapi/h2o2": "^10.0.4"
|
|
14
|
-
}
|
|
15
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
const Hapi = require('@hapi/hapi');
|
|
2
|
-
const H2o2 = require('@hapi/h2o2');
|
|
3
|
-
const aiwaf = require('aiwaf-js');
|
|
4
|
-
|
|
5
|
-
const PORT = process.env.PORT || 3003;
|
|
6
|
-
const TARGET_BASE_URL = process.env.TARGET_BASE_URL || 'http://localhost:3001';
|
|
7
|
-
|
|
8
|
-
async function start() {
|
|
9
|
-
const server = Hapi.server({ port: PORT, host: '0.0.0.0' });
|
|
10
|
-
|
|
11
|
-
await server.register(H2o2);
|
|
12
|
-
await server.register({
|
|
13
|
-
plugin: aiwaf.hapi,
|
|
14
|
-
options: {
|
|
15
|
-
staticKeywords: ['.php', '.env', '.git', '../'],
|
|
16
|
-
dynamicTopN: 5,
|
|
17
|
-
WINDOW_SEC: 10,
|
|
18
|
-
MAX_REQ: 25,
|
|
19
|
-
FLOOD_REQ: 50,
|
|
20
|
-
HONEYPOT_FIELD: 'hp_field',
|
|
21
|
-
AIWAF_METHOD_POLICY_ENABLED: true,
|
|
22
|
-
AIWAF_ALLOWED_METHODS: ['GET', 'POST', 'HEAD', 'OPTIONS'],
|
|
23
|
-
AIWAF_HEADER_VALIDATION: true,
|
|
24
|
-
AIWAF_REQUIRED_HEADERS: [],
|
|
25
|
-
AIWAF_MIDDLEWARE_LOGGING: true,
|
|
26
|
-
AIWAF_MIDDLEWARE_LOG_PATH: process.env.AIWAF_MIDDLEWARE_LOG_PATH || 'logs/aiwaf-requests.jsonl'
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
server.ext('onRequest', (request, h) => {
|
|
31
|
-
console.log(`[sandbox-hapi] ${request.method.toUpperCase()} ${request.url.pathname}`);
|
|
32
|
-
return h.continue;
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
server.route({
|
|
36
|
-
method: '*',
|
|
37
|
-
path: '/{path*}',
|
|
38
|
-
handler: {
|
|
39
|
-
proxy: {
|
|
40
|
-
uri: TARGET_BASE_URL,
|
|
41
|
-
passThrough: true,
|
|
42
|
-
xforward: true
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
await server.start();
|
|
48
|
-
console.log(`AIWAF Hapi sandbox proxy running on port ${PORT}`);
|
|
49
|
-
console.log(`Forwarding traffic to ${TARGET_BASE_URL}`);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
start().catch(err => {
|
|
53
|
-
console.error(err);
|
|
54
|
-
process.exit(1);
|
|
55
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
FROM node:20-bullseye
|
|
2
|
-
|
|
3
|
-
WORKDIR /workspace
|
|
4
|
-
COPY . /workspace
|
|
5
|
-
|
|
6
|
-
RUN apt-get update && apt-get install -y python3 make g++ \
|
|
7
|
-
&& rm -rf /var/lib/apt/lists/*
|
|
8
|
-
|
|
9
|
-
RUN npm_config_build_from_source=true npm install
|
|
10
|
-
|
|
11
|
-
WORKDIR /workspace/examples/sandbox/aiwaf-koa-proxy
|
|
12
|
-
|
|
13
|
-
RUN npm_config_build_from_source=true npm install
|
|
14
|
-
|
|
15
|
-
EXPOSE 3004
|
|
16
|
-
CMD ["npm", "start"]
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "aiwaf-koa-proxy-sandbox",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"private": true,
|
|
5
|
-
"main": "server.js",
|
|
6
|
-
"type": "commonjs",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"start": "node server.js"
|
|
9
|
-
},
|
|
10
|
-
"dependencies": {
|
|
11
|
-
"aiwaf-js": "file:../../..",
|
|
12
|
-
"koa": "^2.15.4",
|
|
13
|
-
"koa-bodyparser": "^4.4.1",
|
|
14
|
-
"koa-proxies": "^0.12.4"
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
const Koa = require('koa');
|
|
2
|
-
const bodyParser = require('koa-bodyparser');
|
|
3
|
-
const proxy = require('koa-proxies');
|
|
4
|
-
const aiwaf = require('aiwaf-js');
|
|
5
|
-
|
|
6
|
-
const PORT = process.env.PORT || 3004;
|
|
7
|
-
const TARGET_BASE_URL = process.env.TARGET_BASE_URL || 'http://localhost:3001';
|
|
8
|
-
|
|
9
|
-
const app = new Koa();
|
|
10
|
-
|
|
11
|
-
app.use(bodyParser());
|
|
12
|
-
app.use((ctx, next) => {
|
|
13
|
-
console.log(`[sandbox-koa] ${ctx.method} ${ctx.url}`);
|
|
14
|
-
return next();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
app.use(aiwaf.koa({
|
|
18
|
-
staticKeywords: ['.php', '.env', '.git', '../'],
|
|
19
|
-
dynamicTopN: 5,
|
|
20
|
-
WINDOW_SEC: 10,
|
|
21
|
-
MAX_REQ: 25,
|
|
22
|
-
FLOOD_REQ: 50,
|
|
23
|
-
HONEYPOT_FIELD: 'hp_field',
|
|
24
|
-
AIWAF_METHOD_POLICY_ENABLED: true,
|
|
25
|
-
AIWAF_ALLOWED_METHODS: ['GET', 'POST', 'HEAD', 'OPTIONS'],
|
|
26
|
-
AIWAF_HEADER_VALIDATION: true,
|
|
27
|
-
AIWAF_REQUIRED_HEADERS: [],
|
|
28
|
-
AIWAF_MIDDLEWARE_LOGGING: true,
|
|
29
|
-
AIWAF_MIDDLEWARE_LOG_PATH: process.env.AIWAF_MIDDLEWARE_LOG_PATH || 'logs/aiwaf-requests.jsonl'
|
|
30
|
-
}));
|
|
31
|
-
|
|
32
|
-
app.use(proxy('/', {
|
|
33
|
-
target: TARGET_BASE_URL,
|
|
34
|
-
changeOrigin: true,
|
|
35
|
-
logs: true
|
|
36
|
-
}));
|
|
37
|
-
|
|
38
|
-
app.listen(PORT, () => {
|
|
39
|
-
console.log(`AIWAF Koa sandbox proxy running on port ${PORT}`);
|
|
40
|
-
console.log(`Forwarding traffic to ${TARGET_BASE_URL}`);
|
|
41
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
FROM node:20-bullseye
|
|
2
|
-
|
|
3
|
-
WORKDIR /workspace
|
|
4
|
-
COPY . /workspace
|
|
5
|
-
|
|
6
|
-
RUN apt-get update && apt-get install -y python3 make g++ \
|
|
7
|
-
&& rm -rf /var/lib/apt/lists/*
|
|
8
|
-
|
|
9
|
-
RUN npm_config_build_from_source=true npm install
|
|
10
|
-
|
|
11
|
-
WORKDIR /workspace/examples/sandbox/aiwaf-nest-proxy
|
|
12
|
-
|
|
13
|
-
RUN npm_config_build_from_source=true npm install
|
|
14
|
-
RUN npm_config_build_from_source=true npm install http-proxy-middleware
|
|
15
|
-
|
|
16
|
-
EXPOSE 3005
|
|
17
|
-
CMD ["npm", "start"]
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
require('reflect-metadata');
|
|
2
|
-
const { NestFactory } = require('@nestjs/core');
|
|
3
|
-
const { Module } = require('@nestjs/common');
|
|
4
|
-
const { createProxyMiddleware } = require('http-proxy-middleware');
|
|
5
|
-
const aiwaf = require('aiwaf-js');
|
|
6
|
-
|
|
7
|
-
const PORT = process.env.PORT || 3005;
|
|
8
|
-
const TARGET_BASE_URL = process.env.TARGET_BASE_URL || 'http://localhost:3001';
|
|
9
|
-
|
|
10
|
-
class AppModule {}
|
|
11
|
-
|
|
12
|
-
Module({})(AppModule);
|
|
13
|
-
|
|
14
|
-
async function bootstrap() {
|
|
15
|
-
const app = await NestFactory.create(AppModule);
|
|
16
|
-
|
|
17
|
-
app.use(aiwaf({
|
|
18
|
-
staticKeywords: ['.php', '.env', '.git', '../'],
|
|
19
|
-
dynamicTopN: 5,
|
|
20
|
-
WINDOW_SEC: 10,
|
|
21
|
-
MAX_REQ: 25,
|
|
22
|
-
FLOOD_REQ: 50,
|
|
23
|
-
HONEYPOT_FIELD: 'hp_field',
|
|
24
|
-
AIWAF_METHOD_POLICY_ENABLED: true,
|
|
25
|
-
AIWAF_ALLOWED_METHODS: ['GET', 'POST', 'HEAD', 'OPTIONS'],
|
|
26
|
-
AIWAF_HEADER_VALIDATION: true,
|
|
27
|
-
AIWAF_REQUIRED_HEADERS: [],
|
|
28
|
-
AIWAF_MIDDLEWARE_LOGGING: true,
|
|
29
|
-
AIWAF_MIDDLEWARE_LOG_PATH: process.env.AIWAF_MIDDLEWARE_LOG_PATH || 'logs/aiwaf-requests.jsonl'
|
|
30
|
-
}));
|
|
31
|
-
|
|
32
|
-
app.use((req, res, next) => {
|
|
33
|
-
console.log(`[sandbox-nest] ${req.method} ${req.originalUrl}`);
|
|
34
|
-
next();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
app.use(
|
|
38
|
-
'/',
|
|
39
|
-
createProxyMiddleware({
|
|
40
|
-
target: TARGET_BASE_URL,
|
|
41
|
-
changeOrigin: true,
|
|
42
|
-
ws: true,
|
|
43
|
-
logLevel: 'warn'
|
|
44
|
-
})
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
await app.listen(PORT, '0.0.0.0');
|
|
48
|
-
console.log(`AIWAF NestJS sandbox proxy running on port ${PORT}`);
|
|
49
|
-
console.log(`Forwarding traffic to ${TARGET_BASE_URL}`);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
bootstrap().catch(err => {
|
|
53
|
-
console.error(err);
|
|
54
|
-
process.exit(1);
|
|
55
|
-
});
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "aiwaf-nest-proxy-sandbox",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"private": true,
|
|
5
|
-
"main": "main.js",
|
|
6
|
-
"type": "commonjs",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"start": "node main.js"
|
|
9
|
-
},
|
|
10
|
-
"dependencies": {
|
|
11
|
-
"aiwaf-js": "file:../../..",
|
|
12
|
-
"@nestjs/core": "^10.4.2",
|
|
13
|
-
"@nestjs/common": "^10.4.2",
|
|
14
|
-
"@nestjs/platform-express": "^10.4.2",
|
|
15
|
-
"http-proxy-middleware": "^3.0.0",
|
|
16
|
-
"reflect-metadata": "^0.1.14",
|
|
17
|
-
"rxjs": "^7.8.1",
|
|
18
|
-
"express": "^4.21.2"
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
FROM node:20-bullseye
|
|
2
|
-
|
|
3
|
-
WORKDIR /workspace
|
|
4
|
-
COPY . /workspace
|
|
5
|
-
|
|
6
|
-
RUN apt-get update && apt-get install -y python3 make g++ \
|
|
7
|
-
&& rm -rf /var/lib/apt/lists/*
|
|
8
|
-
|
|
9
|
-
RUN npm_config_build_from_source=true npm install
|
|
10
|
-
|
|
11
|
-
WORKDIR /workspace/examples/sandbox/aiwaf-next-proxy
|
|
12
|
-
|
|
13
|
-
RUN npm_config_build_from_source=true npm install
|
|
14
|
-
|
|
15
|
-
EXPOSE 3006
|
|
16
|
-
CMD ["npm", "start"]
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "aiwaf-next-proxy-sandbox",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"private": true,
|
|
5
|
-
"type": "commonjs",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"start": "node server.js"
|
|
8
|
-
},
|
|
9
|
-
"dependencies": {
|
|
10
|
-
"aiwaf-js": "file:../../..",
|
|
11
|
-
"http-proxy-middleware": "^3.0.0",
|
|
12
|
-
"next": "^14.2.13",
|
|
13
|
-
"react": "^18.3.1",
|
|
14
|
-
"react-dom": "^18.3.1"
|
|
15
|
-
}
|
|
16
|
-
}
|