Skip to content

Commit fc4b0f4

Browse files
committed
Merge branch 'main' of github.com:AikidoSec/node-RASP into poc-required-pkg
* 'main' of github.com:AikidoSec/node-RASP: (440 commits) Fix test coverage Report SQL dialect in event metadata Move to separate test with skip reason Skip express bench on v24.x Skip hono-pg bench on Node.js v24 Remove --experimental-sqlite Run tests & benchmarks on Node.js v24 Add comment to extractStringsFromUserInput Add new safeDecodeURIComponent function Update library/helpers/extractStringsFromUserInput.ts Fix tests Support Koa v3 Extract safeDecodeURIComponent Add unit test Try decode possible uri encoded strings Add failing tests Prevent ReDoS Fix multiple control chars Remove unused code Check blocked users every time but log once ...
2 parents e07e982 + e0f0a68 commit fc4b0f4

File tree

433 files changed

+78027
-21311
lines changed

Some content is hidden

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

433 files changed

+78027
-21311
lines changed

.devcontainer/devcontainer.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
{
3+
"name": "Zen Node.js",
4+
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
5+
"image": "mcr.microsoft.com/devcontainers/typescript-node:22",
6+
7+
// Features to add to the dev container. More info: https://containers.dev/features.
8+
"features": {
9+
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
10+
"ghcr.io/devcontainers/features/rust:1": {}
11+
},
12+
13+
// Configure tool-specific properties.
14+
"customizations": {
15+
// Configure properties specific to VS Code.
16+
"vscode": {
17+
"settings": {},
18+
"extensions": [
19+
"ms-azuretools.vscode-docker",
20+
"dbaeumer.vscode-eslint",
21+
"esbenp.prettier-vscode",
22+
"YoavBls.pretty-ts-errors",
23+
"rust-lang.rust-analyzer"
24+
]
25+
}
26+
},
27+
28+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
29+
"forwardPorts": [3000, 4000],
30+
31+
// Use 'portsAttributes' to set default properties for specific forwarded ports.
32+
// More info: https://containers.dev/implementors/json_reference/#port-attributes
33+
"portsAttributes": {},
34+
35+
// Use 'postCreateCommand' to run commands after the container is created.
36+
"postCreateCommand": "./.devcontainer/postCreateCommand.sh"
37+
38+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
39+
// "remoteUser": "root"
40+
}

.devcontainer/postCreateCommand.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
# Update
4+
sudo apt update -y && sudo apt upgrade -y
5+
rustup update
6+
source /usr/local/share/nvm/nvm.sh
7+
nvm install --lts
8+
nvm use --lts
9+
npm update -g
10+
11+
# Install WASM pack
12+
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
13+
14+
# Install k6
15+
## k6 installation -- arm machines
16+
if [ "$(uname -m)" = "aarch64" ]; then
17+
K6_TAR_LINK=https://github.com/grafana/k6/releases/download/v0.58.0/k6-v0.58.0-linux-arm64.tar.gz
18+
curl -OL $K6_TAR_LINK
19+
tar -xzf k6-v0.58.0-linux-arm64.tar.gz
20+
sudo mv k6-v0.58.0-linux-arm64/k6 /usr/local/bin/k6
21+
rm -rf k6-v0.58.0-linux-arm64*
22+
else ## k6 installation -- other architectures
23+
sudo gpg -k
24+
sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69
25+
echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list
26+
sudo apt-get update -y
27+
sudo apt-get install k6 -y
28+
fi
29+
30+
# Install wrk, sqlite3
31+
sudo apt install wrk sqlite3 -y
32+
33+
# Install npm packages, build and run containers
34+
npm i
35+
npm run build
36+
npm run containers

.github/CONTRIBUTING.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ First off, thanks for taking the time to contribute! ❤️
55
All types of contributions are encouraged and valued. See the [Table of Contents](#table-of-contents) for different ways to help and details about how this project handles them. Please make sure to read the relevant section before making your contribution. It will make it a lot easier for us maintainers and smooth out the experience for all involved. The community looks forward to your contributions. 🎉
66

77
> And if you like the project, but just don't have time to contribute, that's fine. There are other easy ways to support the project and show your appreciation, which we would also be very happy about:
8+
>
89
> - Star the project
910
> - Tweet about it
1011
> - Refer this project in your project's readme
@@ -64,7 +65,7 @@ We use GitHub issues to track bugs and errors. If you run into an issue with the
6465

6566
- Open an [Issue](https://github.com/AikidoSec/firewall-node/issues/new). (Since we can't be sure at this point whether it is a bug or not, we ask you not to talk about a bug yet and not to label the issue.)
6667
- Explain the behavior you would expect and the actual behavior.
67-
- Please provide as much context as possible and describe the *reproduction steps* that someone else can follow to recreate the issue on their own. This usually includes your code. For good bug reports you should isolate the problem and create a reduced test case.
68+
- Please provide as much context as possible and describe the _reproduction steps_ that someone else can follow to recreate the issue on their own. This usually includes your code. For good bug reports you should isolate the problem and create a reduced test case.
6869
- Provide the information you collected in the previous section.
6970

7071
Once it's filed:
@@ -96,12 +97,12 @@ Enhancement suggestions are tracked as [GitHub issues](https://github.com/Aikido
9697
### Your First Code Contribution
9798

9899
- clone the repository to your local machine
99-
- run `$ make install` to install dependencies
100-
- run `$ make build` to build the library
101-
- run `$ make watch` to watch for changes and rebuild the library
102-
- run `$ make test` to run tests using tap
103-
- run `$ make end2end` to run end-to-end tests using tap
104-
- run `$ make lint` to run ESLint
100+
- run `$ npm install` to install dependencies
101+
- run `$ npm run build` to build the library
102+
- run `$ npm run watch` to watch for changes and rebuild the library
103+
- run `$ npm t` to run tests using tap
104+
- run `$ npm run end2end` to run end-to-end tests using tap
105+
- run `$ npm run lint` to run ESLint
105106

106107
## Styleguides
107108

.github/workflows/benchmark.yml

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on:
33
push: {}
44
workflow_call: {}
55
jobs:
6-
build:
6+
benchmark:
77
runs-on: ubuntu-latest
88
services:
99
mongodb:
@@ -24,30 +24,39 @@ jobs:
2424
timeout-minutes: 10
2525
strategy:
2626
matrix:
27-
node-version: [18.x]
27+
node-version: [20.x, 24.x]
2828
steps:
2929
- uses: actions/checkout@v4
3030
- name: Use Node.js ${{ matrix.node-version }}
31-
uses: actions/setup-node@v2
31+
uses: actions/setup-node@v4
3232
with:
3333
node-version: ${{ matrix.node-version }}
34+
cache: "npm"
35+
cache-dependency-path: "**/package-lock.json"
3436
- name: Install K6
35-
uses: grafana/setup-k6-action@v1
37+
uses: grafana/setup-k6-action@ffe7d7290dfa715e48c2ccc924d068444c94bde2 # v1
3638
- name: Install wrk
3739
run: |
3840
sudo apt-get update
3941
sudo apt-get install -y wrk
40-
- run: make install
41-
- run: make build
42+
- run: npm install
43+
- run: npm run build
4244
- name: Run NoSQL Injection Benchmark
43-
run: cd benchmarks/nosql-injection && AIKIDO_CI=true node --preserve-symlinks benchmark.js
45+
run: cd benchmarks/nosql-injection && AIKIDO_CI=true node benchmark.js
4446
- name: Run SQL Injection Benchmark
45-
run: cd benchmarks/sql-injection && node --preserve-symlinks benchmark.js
47+
run: cd benchmarks/sql-injection && node benchmark.js
4648
- name: Run shell injection Benchmark
47-
run: cd benchmarks/shell-injection && node --preserve-symlinks benchmark.js
49+
run: cd benchmarks/shell-injection && node benchmark.js
4850
- name: Run Hono with Postgres Benchmark
49-
run: cd benchmarks/hono-pg && node --preserve-symlinks benchmark.js
51+
# Skip on Node 24.x due to a bug: https://github.com/honojs/node-server/issues/240
52+
if: matrix.node-version != '24.x'
53+
run: cd benchmarks/hono-pg && node benchmark.js
5054
- name: Run API Discovery Benchmark
51-
run: cd benchmarks/api-discovery && node --preserve-symlinks benchmark.js
55+
run: cd benchmarks/api-discovery && node benchmark.js
5256
- name: Run Express Benchmark
53-
run: cd benchmarks/express && node --preserve-symlinks benchmark.js
57+
# Skip on Node 24.x because benchmark currently fails.
58+
# Big performance improve in comparison to older Node.js versions, but higher difference between usage with and without Zen
59+
if: matrix.node-version != '24.x'
60+
run: cd benchmarks/express && node benchmark.js
61+
- name: Check Rate Limiter memory usage
62+
run: cd benchmarks/rate-limiting && node --expose-gc memory.js

.github/workflows/build-and-release.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@ jobs:
2121
timeout-minutes: 15
2222
steps:
2323
- uses: actions/checkout@v4
24-
- uses: actions/setup-node@v3
24+
- uses: actions/setup-node@v4
2525
with:
2626
node-version: "18.x"
2727
registry-url: "https://registry.npmjs.org"
2828
scope: "@aikidosec"
2929
- name: Install dependencies
30-
run: make install
30+
run: npm run install-lib-only
3131
- name: Get the version
3232
id: get_version
3333
run: echo "tag=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT
3434
- name: Set the version
3535
run: cd library && npm --no-git-tag-version version ${{ steps.get_version.outputs.tag }}
3636
- name: Build the library
37-
run: make build
37+
run: npm run build
3838
- name: Linting
39-
run: make lint
39+
run: npm run lint
4040
- name: Publish to NPM
4141
run: |
4242
if [ "${{ github.event.release.prerelease }}" = "true" ]; then

.github/workflows/end-to-end-tests.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on:
33
push: {}
44
workflow_call: {}
55
jobs:
6-
build:
6+
test:
77
runs-on: ubuntu-latest
88
services:
99
mongodb:
@@ -52,15 +52,17 @@ jobs:
5252
steps:
5353
- uses: actions/checkout@v4
5454
- name: Use Node.js ${{ matrix.node-version }}
55-
uses: actions/setup-node@v2
55+
uses: actions/setup-node@v4
5656
with:
5757
node-version: ${{ matrix.node-version }}
58+
cache: "npm"
59+
cache-dependency-path: "**/package-lock.json"
5860
- name: Add local.aikido.io to /etc/hosts
5961
run: |
6062
sudo echo "127.0.0.1 local.aikido.io" | sudo tee -a /etc/hosts
6163
- name: Build and run server
6264
run: |
6365
cd end2end/server && docker build -t server . && docker run -d -p 5874:3000 server
64-
- run: make install
65-
- run: make build
66-
- run: make end2end
66+
- run: npm install
67+
- run: npm run build
68+
- run: npm run end2end

.github/workflows/lint-code.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
name: Lint code
22
on: push
33
jobs:
4-
build:
4+
lint:
55
runs-on: ubuntu-latest
6+
timeout-minutes: 10
67
strategy:
78
matrix:
89
node-version: [18.x]
910
steps:
1011
- uses: actions/checkout@v4
1112
- name: Use Node.js ${{ matrix.node-version }}
12-
uses: actions/setup-node@v2
13+
uses: actions/setup-node@v4
1314
with:
1415
node-version: ${{ matrix.node-version }}
15-
- run: make install
16-
- run: make build
17-
- run: make lint
16+
cache: "npm"
17+
cache-dependency-path: "**/package-lock.json"
18+
- run: npm run install-lib-only
19+
- run: npm run build
20+
- run: npm run lint

.github/workflows/unit-test.yml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on:
33
push: {}
44
workflow_call: {}
55
jobs:
6-
build:
6+
test:
77
runs-on: ubuntu-latest
88
services:
99
s3:
@@ -51,26 +51,39 @@ jobs:
5151
"CLICKHOUSE_DEFAULT_ACCESS": "MANAGEMENT=1"
5252
ports:
5353
- "27019:8123"
54+
mongodb-replica:
55+
image: bitnami/mongodb:8.0
56+
env:
57+
MONGODB_ADVERTISED_HOSTNAME: 127.0.0.1
58+
MONGODB_REPLICA_SET_MODE: primary
59+
MONGODB_ROOT_USER: root
60+
MONGODB_ROOT_PASSWORD: password
61+
MONGODB_REPLICA_SET_KEY: replicasetkey123
62+
ports:
63+
- "27020:27017"
5464
strategy:
5565
fail-fast: false
5666
matrix:
57-
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]
68+
timeout-minutes: 10
5869
steps:
5970
- uses: actions/checkout@v4
6071
- name: Use Node.js ${{ matrix.node-version }}
61-
uses: actions/setup-node@v2
72+
uses: actions/setup-node@v4
6273
with:
6374
node-version: ${{ matrix.node-version }}
75+
cache: "npm"
76+
cache-dependency-path: "**/package-lock.json"
6477
- name: Add local.aikido.io to /etc/hosts
6578
run: |
6679
sudo echo "127.0.0.1 local.aikido.io" | sudo tee -a /etc/hosts
67-
- run: make install
68-
- run: make build
69-
- run: make test-ci
80+
- run: npm run install-lib-only
81+
- run: npm run build
82+
- run: npm run test:ci
7083
- name: "Upload coverage"
71-
uses: codecov/codecov-action@v4.0.1
84+
uses: codecov/codecov-action@0565863a31f2c772f9f0395002a31e3f06189574 # v5
7285
with:
73-
file: ./library/.tap/report/lcov.info
86+
files: ./library/.tap/report/lcov.info
7487
env:
7588
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
7689
slug: AikidoSec/firewall-node

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20.11
1+
22.12

0 commit comments

Comments
 (0)