Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WebSocket support (ws) #270

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c7d2ccc
WIP: Start wrapping ws
timokoessler Jul 5, 2024
0e29774
Fix ws event context, parse message event
timokoessler Jul 5, 2024
bfded04
Decode binary web socket messages
timokoessler Jul 5, 2024
d5c119c
Check data of ping and pong events
timokoessler Jul 11, 2024
7f85dd1
Wrap other ws listener methods
timokoessler Jul 11, 2024
afff1f2
Wrap ws.onevent functions
timokoessler Jul 11, 2024
972901f
fix: Node.js v16 does not support Blob
timokoessler Jul 11, 2024
5fd0431
Parse ws close reason
timokoessler Jul 11, 2024
8a43de0
Add sample ws chat app
timokoessler Jul 12, 2024
5fb7fce
Add ws to source, use AsyncResource
timokoessler Jul 12, 2024
141033a
Add ws e2e tests
timokoessler Jul 12, 2024
3d09625
Add supported package version
timokoessler Jul 12, 2024
2993202
Add AIKIDO_MAX_WS_MSG_SIZE_MB
timokoessler Jul 12, 2024
20cd235
Implement rate limiting and user blocking (ws)
timokoessler Jul 12, 2024
46e0bc2
Merge branch 'main' into ws
timokoessler Jul 12, 2024
37790ad
Remove console.log
timokoessler Jul 12, 2024
9def302
Fix AIKIDO_MAX_WS_MSG_SIZE_MB test
timokoessler Jul 12, 2024
f349c20
Improve test coverage, update readme
timokoessler Jul 15, 2024
6a92c2b
Wrap handleUpgrade instead of events
timokoessler Jul 15, 2024
07ef845
Refactor and comment code
timokoessler Jul 15, 2024
905e6e9
Apply requested changes
timokoessler Jul 15, 2024
d88dcf4
Refactor websocket data parsing
timokoessler Jul 16, 2024
2a2e252
Fix linting
timokoessler Jul 16, 2024
a533e10
Add test for ws data parsing
timokoessler Jul 16, 2024
43aea41
Rename checkWsDataSize to isMessageDataTooLarge
timokoessler Jul 16, 2024
7816dd8
Merge branch 'beta' into ws
timokoessler Nov 25, 2024
0236881
Fix branch after merging beta
timokoessler Nov 25, 2024
344742b
Merge branch 'main' into ws
timokoessler Dec 20, 2024
e014589
Merge branch 'main' into ws
timokoessler Jan 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ hono-sqlite3:
hapi-postgres:
cd sample-apps/hapi-postgres && AIKIDO_DEBUG=true AIKIDO_BLOCKING=true node app.js


.PHONY: ws-postgres
ws-postgres:
cd sample-apps/ws-postgres && AIKIDO_DEBUG=true AIKIDO_BLOCKING=true node app.js

.PHONY: install
install:
mkdir -p build && cp library/package.json build/package.json
Expand Down
2 changes: 2 additions & 0 deletions library/agent/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type Context = {
graphql?: string[];
xml?: unknown;
subdomains?: string[]; // https://expressjs.com/en/5x/api.html#req.subdomains
ws?: unknown; // Additional data related to WebSocket connections, like the last message received
};

/**
Expand Down Expand Up @@ -56,6 +57,7 @@ export function runWithContext<T>(context: Context, fn: () => T) {
current.graphql = context.graphql;
current.xml = context.xml;
current.subdomains = context.subdomains;
current.ws = context.ws;

return fn();
}
Expand Down
1 change: 1 addition & 0 deletions library/agent/Source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const SOURCES = [
"graphql",
"xml",
"subdomains",
"ws",
] as const;

export type Source = (typeof SOURCES)[number];
2 changes: 2 additions & 0 deletions library/agent/protect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { FastXmlParser } from "../sources/FastXmlParser";
import { SQLite3 } from "../sinks/SQLite3";
import { Hapi } from "../sources/Hapi";
import { Shelljs } from "../sinks/Shelljs";
import { Ws } from "../sources/Ws";

function isDebugging() {
return (
Expand Down Expand Up @@ -133,6 +134,7 @@ function getWrappers() {
new SQLite3(),
new Shelljs(),
new Hapi(),
new Ws(),
];
}

Expand Down
2 changes: 2 additions & 0 deletions library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"@types/shell-quote": "^1.7.5",
"@types/sinonjs__fake-timers": "^8.1.5",
"@types/supertest": "^6.0.2",
"@types/ws": "^8.5.10",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
"aws-sdk": "^2.1595.0",
Expand All @@ -72,6 +73,7 @@
"tap": "^18.6.1",
"typescript": "^5.3.3",
"undici": "^6.12.0",
"ws": "^8.18.0",
"xml2js": "^0.6.2"
},
"scripts": {
Expand Down
Loading
Loading