@tiledesk/tiledesk-server 2.13.18 → 2.13.20
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 +5 -1
- package/package.json +2 -2
- package/pubmodules/canned/cannedResponseRoute.js +23 -21
- package/routes/faq_kb.js +160 -155
- package/routes/llm.js +1 -1
- package/routes/message.js +204 -226
- package/services/chatbotService.js +5 -5
- package/services/requestService.js +17 -0
- package/test/faqkbRoute.js +66 -0
- package/websocket/webSocketServer.js +25 -1
@@ -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
|
-
|
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
|