-
Notifications
You must be signed in to change notification settings - Fork 6
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is 📢 Thoughts on this report? Let us know! |
library/helpers/getMaxWsMsgSize.ts
Outdated
|
||
export function getMaxWsMsgSize() { | ||
if (process.env.AIKIDO_MAX_WS_MSG_SIZE_MB) { | ||
const parsed = parseInt(process.env.AIKIDO_MAX_WS_MSG_SIZE_MB, 10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's reuse
export function getMaxBodySize() { |
return; | ||
} | ||
} catch (e) { | ||
// Ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is dangerous, lets log at least
} // Handle ArrayBuffer or Buffer | ||
else if (Buffer.isBuffer(data) || data instanceof ArrayBuffer) { | ||
const decoder = new TextDecoder("utf-8", { | ||
fatal: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you comment what this means?
|
||
const result = shouldRateLimitRequest(context, agent); | ||
if (result.block) { | ||
let message = "You are rate limited by Aikido firewall."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's remove this for now
"WebSocket message size exceeded the maximum allowed size. Use AIKIDO_MAX_BODY_SIZE_MB to increase the limit." | ||
); | ||
// Closing does not prevent the regular onMessage event from firing | ||
socket.terminate(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we close it?
library/sources/ws/parseWSData.ts
Outdated
return Array.isArray(data) && data.every((d) => Buffer.isBuffer(d)); | ||
} | ||
|
||
function checkWsDataSize(data: WsData) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
naming suggestion-: isMessageDataTooLarge
ws
: https://github.com/websockets/ws/blob/master/doc/ws.md