Socket
Socket
Sign inDemoInstall

rjweb-server

Package Overview
Dependencies
76
Maintainers
1
Versions
369
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 9.5.1 to 9.5.2

6

CHANGELOG.md
# Changelog
## 9.5.2
- Add back `<WsMessageContext>.getRateLimit`
- Add back `<WsMessageContext>.clearRateLimit`
- Add back `<WsMessageContext>.skipRateLimit`
## 9.5.1

@@ -4,0 +10,0 @@

@@ -45,3 +45,58 @@ "use strict";

}
/**
* Skips counting the request to the Client IPs Rate limit (if there is one)
*
* When a specific IP makes sends a message to an endpoint under a ratelimit, the maxhits will be
* increased instantly to prevent bypassing the rate limit by spamming messages faster than the host can
* handle. When this function is called, the server removes the set hit again.
* @since 8.6.0
*/ skipRateLimit() {
if (!this.context.route || !this.context.route.ratelimit || this.context.route.ratelimit.maxHits === Infinity)
return this;
const data = this.context.global.rateLimits.get(`ws+${this.client.ip.usual()}-${this.context.route.ratelimit.sortTo}`, {
hits: 1,
end: Date.now() + this.context.route.ratelimit.timeWindow
});
this.context.global.rateLimits.set(`ws+${this.client.ip.usual()}-${this.context.route.ratelimit.sortTo}`, {
...data,
hits: data.hits - 1
});
return this;
}
/**
* Clear the active Ratelimit of the Client
*
* This Clears the currently active Ratelimit (on this socket) of the Client, remember:
* you cant call this in a normal message callback if the max hits are already reached since well...
* they are already reached.
* @since 8.6.0
*/ clearRateLimit() {
if (!this.context.route || !this.context.route.ratelimit || this.context.route.ratelimit.maxHits === Infinity)
return this;
this.context.global.rateLimits.delete(`ws+${this.client.ip.usual()}-${this.context.route.ratelimit.sortTo}`);
return this;
}
/**
* Get Infos about the current Ratelimit
*
* This will get all information about the currently applied ratelimit
* to the socket. If none is active, will return `null`.
*/ getRateLimit() {
if (!this.context.route || !this.context.route.ratelimit || this.context.route.ratelimit.maxHits === Infinity)
return null;
const data = this.context.global.rateLimits.get(`ws+${this.client.ip}-${this.context.route.ratelimit.sortTo}`, {
hits: 0,
end: Date.now() + this.context.route.ratelimit.timeWindow
});
return {
hits: data.hits,
maxHits: this.context.route.ratelimit.maxHits,
hasPenalty: data.hits > this.context.route.ratelimit.maxHits,
penalty: this.context.route.ratelimit.penalty,
timeWindow: this.context.route.ratelimit.timeWindow,
get endsAt() { return new Date(data.end); },
endsIn: data.end - Date.now()
};
}
}
exports.default = WsMessageContext;

8

lib/cjs/package.json
{
"name": "rjweb-server",
"version": "9.5.1",
"version": "9.5.2",
"description": "Easy and Robust Way to create a Web Server with Many Easy-to-use Features in NodeJS",

@@ -50,3 +50,3 @@ "main": "./lib/cjs/index.js",

"@types/inquirer": "^9.0.7",
"@types/node": "^20.12.11",
"@types/node": "^20.12.12",
"@types/yargs": "^17.0.32",

@@ -62,5 +62,5 @@ "rjweb-server": "link:",

"dependencies": {
"@rjweb/utils": "^1.12.13",
"@rjweb/utils": "^1.12.14",
"content-disposition": "^0.5.4",
"inquirer": "^9.2.20",
"inquirer": "^9.2.21",
"openapi3-ts": "^4.3.1",

@@ -67,0 +67,0 @@ "yargs": "^17.7.2",

@@ -40,2 +40,57 @@ import WsOpenContext from "./WsOpenContext";

}
/**
* Skips counting the request to the Client IPs Rate limit (if there is one)
*
* When a specific IP makes sends a message to an endpoint under a ratelimit, the maxhits will be
* increased instantly to prevent bypassing the rate limit by spamming messages faster than the host can
* handle. When this function is called, the server removes the set hit again.
* @since 8.6.0
*/ skipRateLimit() {
if (!this.context.route || !this.context.route.ratelimit || this.context.route.ratelimit.maxHits === Infinity)
return this;
const data = this.context.global.rateLimits.get(`ws+${this.client.ip.usual()}-${this.context.route.ratelimit.sortTo}`, {
hits: 1,
end: Date.now() + this.context.route.ratelimit.timeWindow
});
this.context.global.rateLimits.set(`ws+${this.client.ip.usual()}-${this.context.route.ratelimit.sortTo}`, {
...data,
hits: data.hits - 1
});
return this;
}
/**
* Clear the active Ratelimit of the Client
*
* This Clears the currently active Ratelimit (on this socket) of the Client, remember:
* you cant call this in a normal message callback if the max hits are already reached since well...
* they are already reached.
* @since 8.6.0
*/ clearRateLimit() {
if (!this.context.route || !this.context.route.ratelimit || this.context.route.ratelimit.maxHits === Infinity)
return this;
this.context.global.rateLimits.delete(`ws+${this.client.ip.usual()}-${this.context.route.ratelimit.sortTo}`);
return this;
}
/**
* Get Infos about the current Ratelimit
*
* This will get all information about the currently applied ratelimit
* to the socket. If none is active, will return `null`.
*/ getRateLimit() {
if (!this.context.route || !this.context.route.ratelimit || this.context.route.ratelimit.maxHits === Infinity)
return null;
const data = this.context.global.rateLimits.get(`ws+${this.client.ip}-${this.context.route.ratelimit.sortTo}`, {
hits: 0,
end: Date.now() + this.context.route.ratelimit.timeWindow
});
return {
hits: data.hits,
maxHits: this.context.route.ratelimit.maxHits,
hasPenalty: data.hits > this.context.route.ratelimit.maxHits,
penalty: this.context.route.ratelimit.penalty,
timeWindow: this.context.route.ratelimit.timeWindow,
get endsAt() { return new Date(data.end); },
endsIn: data.end - Date.now()
};
}
}
{
"name": "rjweb-server",
"version": "9.5.1",
"version": "9.5.2",
"description": "Easy and Robust Way to create a Web Server with Many Easy-to-use Features in NodeJS",

@@ -50,3 +50,3 @@ "main": "./lib/cjs/index.js",

"@types/inquirer": "^9.0.7",
"@types/node": "^20.12.11",
"@types/node": "^20.12.12",
"@types/yargs": "^17.0.32",

@@ -62,5 +62,5 @@ "rjweb-server": "link:",

"dependencies": {
"@rjweb/utils": "^1.12.13",
"@rjweb/utils": "^1.12.14",
"content-disposition": "^0.5.4",
"inquirer": "^9.2.20",
"inquirer": "^9.2.21",
"openapi3-ts": "^4.3.1",

@@ -67,0 +67,0 @@ "yargs": "^17.7.2",

@@ -6,3 +6,3 @@ /// <reference types="node" />

import WsOpenContext from "./WsOpenContext";
import { ParsedBody } from "../../types/global";
import { ParsedBody, RatelimitInfos } from "../../types/global";
export default class WsMessageContext<Context extends Record<any, any> = {}> extends WsOpenContext<'message', Context> {

@@ -26,2 +26,24 @@ constructor(context: InternalRequestContext, rawContext: WsContext, abort: AbortSignal);

*/ rawMessageBytes(): Buffer;
/**
* Skips counting the request to the Client IPs Rate limit (if there is one)
*
* When a specific IP makes sends a message to an endpoint under a ratelimit, the maxhits will be
* increased instantly to prevent bypassing the rate limit by spamming messages faster than the host can
* handle. When this function is called, the server removes the set hit again.
* @since 8.6.0
*/ skipRateLimit(): this;
/**
* Clear the active Ratelimit of the Client
*
* This Clears the currently active Ratelimit (on this socket) of the Client, remember:
* you cant call this in a normal message callback if the max hits are already reached since well...
* they are already reached.
* @since 8.6.0
*/ clearRateLimit(): this;
/**
* Get Infos about the current Ratelimit
*
* This will get all information about the currently applied ratelimit
* to the socket. If none is active, will return `null`.
*/ getRateLimit(): RatelimitInfos | null;
}
{
"name": "rjweb-server",
"version": "9.5.1",
"version": "9.5.2",
"description": "Easy and Robust Way to create a Web Server with Many Easy-to-use Features in NodeJS",

@@ -41,3 +41,3 @@ "main": "./lib/cjs/index.js",

"@types/inquirer": "^9.0.7",
"@types/node": "^20.12.11",
"@types/node": "^20.12.12",
"@types/yargs": "^17.0.32",

@@ -53,5 +53,5 @@ "rjweb-server": "link:",

"dependencies": {
"@rjweb/utils": "^1.12.13",
"@rjweb/utils": "^1.12.14",
"content-disposition": "^0.5.4",
"inquirer": "^9.2.20",
"inquirer": "^9.2.21",
"openapi3-ts": "^4.3.1",

@@ -58,0 +58,0 @@ "yargs": "^17.7.2",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc