@tiledesk/tiledesk-server 2.13.19 → 2.13.21

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.
@@ -34,6 +34,29 @@ if (pKey) {
34
34
  configSecretOrPubicKay = pKey.replace(/\\n/g, '\n');
35
35
  }
36
36
 
37
+ // Cache for tracking invalid token logs to prevent spam
38
+ const invalidTokenCache = new Map();
39
+
40
+ function logInvalidToken(req, err) {
41
+ const ip = req.socket.remoteAddress;
42
+ const ua = req.headers['user-agent'] || 'unknown';
43
+ const now = Date.now();
44
+
45
+ const cacheKey = `${ip}_${req.url}`;
46
+ const lastLog = invalidTokenCache.get(cacheKey);
47
+
48
+ if (!lastLog || now - lastLog > 60000) {
49
+ invalidTokenCache.set(cacheKey, now);
50
+ console.warn('[⚠️ INVALID WS TOKEN]', {
51
+ ip,
52
+ ua,
53
+ url: req.url,
54
+ time: new Date().toISOString(),
55
+ message: err.message,
56
+ });
57
+ }
58
+ }
59
+
37
60
  var cacheEnabler = require("../services/cacheEnabler");
38
61
 
39
62
 
@@ -93,7 +116,8 @@ class WebSocketServer {
93
116
  token = token.replace('JWT ', '');
94
117
  jwt.verify(token, configSecretOrPubicKay, function (err, decoded) { //pub_jwt pp_jwt
95
118
  if (err) {
96
- winston.error('WebSocket error verifing websocket jwt token: ' + token, err);
119
+ // Log invalid token with rate limiting
120
+ logInvalidToken(info.req, err);
97
121
  return cb(false, 401, 'Unauthorized');
98
122
  } else {
99
123
  // uncomment it