homebridge-xbox-tv 4.2.0 → 4.2.1

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/CHANGELOG.md CHANGED
@@ -18,6 +18,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
18
18
  - For plugin < v4.1.0 use Homebridge UI <= v5.5.0
19
19
  - For plugin >= v4.1.0 use Homebridge UI >= v5.13.0
20
20
 
21
+ ## [4.2.1] - (24.09.2026)
22
+
23
+ ### Changes
24
+
25
+ - added: RESTFul request rate limit, 600 requests per minute per client and at most 1000 clients per minute, answered with `429` and `Retry-After`, one log warning per client and minute.
26
+
21
27
  ## [4.2.0] - (23.09.2026)
22
28
 
23
29
  ### Changes
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Xbox TV",
3
3
  "name": "homebridge-xbox-tv",
4
- "version": "4.2.0",
4
+ "version": "4.2.1",
5
5
  "description": "Homebridge plugin to control Xbox game consoles.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
package/src/restful.js CHANGED
@@ -28,6 +28,49 @@ class RestFul extends EventEmitter {
28
28
  try {
29
29
  const app = express();
30
30
  app.set('json spaces', 2);
31
+
32
+ // Request rate limit per client, protects Homebridge from request floods (CWE-770)
33
+ const rateLimitWindow = 60 * 1000;
34
+ const rateLimitMax = 600;
35
+ const rateLimitClients = 1000;
36
+ const clients = new Map();
37
+ let clientsLimitWarned = 0;
38
+ app.use((req, res, next) => {
39
+ const now = Date.now();
40
+
41
+ // Drop expired windows so the map cannot grow without limit
42
+ if (clients.size > 100) {
43
+ for (const [ip, client] of clients) {
44
+ if (now - client.start >= rateLimitWindow) clients.delete(ip);
45
+ }
46
+ }
47
+
48
+ let client = clients.get(req.ip);
49
+ if (!client || now - client.start >= rateLimitWindow) {
50
+ // Hard limit of tracked addresses, new addresses wait until older windows expire
51
+ if (!client && clients.size >= rateLimitClients) {
52
+ if (now - clientsLimitWarned >= rateLimitWindow) {
53
+ clientsLimitWarned = now;
54
+ if (this.logWarn) this.emit('warn', `RESTFul too many clients (${rateLimitClients}) in one minute, new clients are rejected until the window ends`);
55
+ }
56
+ res.set('Retry-After', String(Math.ceil(rateLimitWindow / 1000)));
57
+ return res.status(429).json({ error: 'RESTFul Too Many Requests' });
58
+ }
59
+ client = { count: 0, start: now, warned: false };
60
+ clients.set(req.ip, client);
61
+ }
62
+
63
+ if (++client.count > rateLimitMax) {
64
+ // Warn once per client and window, a flood must not flood the log too
65
+ if (!client.warned && this.logWarn) this.emit('warn', `RESTFul rate limit ${rateLimitMax} requests per minute exceeded by: ${req.ip}, further requests are rejected until the window ends`);
66
+ client.warned = true;
67
+ res.set('Retry-After', String(Math.ceil((client.start + rateLimitWindow - now) / 1000)));
68
+ return res.status(429).json({ error: 'RESTFul Too Many Requests' });
69
+ }
70
+
71
+ next();
72
+ });
73
+
31
74
  app.use(json());
32
75
 
33
76
  // Optional token auth, when a token is configured every route requires "Authorization: Bearer <token>"