let-them-talk 3.2.3 → 3.3.0

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/README.md CHANGED
@@ -154,6 +154,22 @@ npx let-them-talk plugin disable <name> # Disable a plugin
154
154
  npx let-them-talk help # Show help
155
155
  ```
156
156
 
157
+ ## Updating
158
+
159
+ ```bash
160
+ # If using npx (recommended) — clear cache to get latest version
161
+ npx clear-npx-cache
162
+ npx let-them-talk init # Re-run to update MCP config paths
163
+
164
+ # If installed globally
165
+ npm update -g let-them-talk
166
+
167
+ # Check your version
168
+ npx let-them-talk help # Shows version in header
169
+ ```
170
+
171
+ After updating, restart your CLI terminals to pick up the new MCP server.
172
+
157
173
  ## Plugins
158
174
 
159
175
  Extend Let Them Talk with custom tools. Plugins are `.js` files in the `.agent-bridge/plugins/` directory.
package/cli.js CHANGED
@@ -331,24 +331,33 @@ function pluginCmd() {
331
331
  const absPath = path.resolve(filePath);
332
332
  if (!fs.existsSync(absPath)) { console.error(' File not found: ' + absPath); process.exit(1); }
333
333
 
334
- // Validate plugin exports
334
+ // Validate plugin structure without executing it (no require — prevents RCE on install)
335
335
  try {
336
- const plugin = require(absPath);
337
- if (!plugin.name || !plugin.handler) { console.error(' Plugin must export name, description, and handler'); process.exit(1); }
336
+ const src = fs.readFileSync(absPath, 'utf8');
337
+ if (!src.includes('module.exports') || !src.includes('name') || !src.includes('handler')) {
338
+ console.error(' Plugin must export name, description, and handler (module.exports = { name, handler })');
339
+ process.exit(1);
340
+ }
341
+
342
+ // Extract plugin name from source using regex (no eval)
343
+ const nameMatch = src.match(/name\s*:\s*['"]([^'"]+)['"]/);
344
+ const descMatch = src.match(/description\s*:\s*['"]([^'"]+)['"]/);
345
+ const pluginName = nameMatch ? nameMatch[1] : path.basename(absPath, '.js');
346
+ const pluginDesc = descMatch ? descMatch[1] : '';
338
347
 
339
348
  if (!fs.existsSync(pluginsDir)) fs.mkdirSync(pluginsDir, { recursive: true });
340
349
  const destFile = path.join(pluginsDir, path.basename(absPath));
341
350
  fs.copyFileSync(absPath, destFile);
342
351
 
343
352
  const reg = getRegistry();
344
- if (!reg.find(p => p.name === plugin.name)) {
345
- reg.push({ name: plugin.name, description: plugin.description || '', file: path.basename(absPath), enabled: true, added_at: new Date().toISOString() });
353
+ if (!reg.find(p => p.name === pluginName)) {
354
+ reg.push({ name: pluginName, description: pluginDesc, file: path.basename(absPath), enabled: true, added_at: new Date().toISOString() });
346
355
  saveRegistry(reg);
347
356
  }
348
- console.log(' Plugin "' + plugin.name + '" installed successfully.');
349
- console.log(' Restart CLI to load the new tool.');
357
+ console.log(' Plugin "' + pluginName + '" installed successfully.');
358
+ console.log(' Restart CLI to load the new tool (runs sandboxed).');
350
359
  } catch (e) {
351
- console.error(' Failed to load plugin: ' + e.message);
360
+ console.error(' Failed to install plugin: ' + e.message);
352
361
  process.exit(1);
353
362
  }
354
363
  break;
@@ -362,8 +371,11 @@ function pluginCmd() {
362
371
  const newReg = reg.filter(p => p.name !== name);
363
372
  saveRegistry(newReg);
364
373
  if (plugin.file) {
365
- const pluginFile = path.join(pluginsDir, plugin.file);
366
- if (fs.existsSync(pluginFile)) fs.unlinkSync(pluginFile);
374
+ const pluginFile = path.resolve(pluginsDir, plugin.file);
375
+ // Prevent path traversal — only delete files inside pluginsDir
376
+ if (pluginFile.startsWith(path.resolve(pluginsDir) + path.sep) && fs.existsSync(pluginFile)) {
377
+ fs.unlinkSync(pluginFile);
378
+ }
367
379
  }
368
380
  console.log(' Plugin "' + name + '" removed.');
369
381
  break;
package/dashboard.js CHANGED
@@ -690,8 +690,18 @@ const server = http.createServer(async (req, res) => {
690
690
  return;
691
691
  }
692
692
 
693
- // CSRF protection: validate origin on mutating requests
693
+ // CSRF + DNS rebinding protection: validate Host and Origin on mutating requests
694
694
  if (req.method === 'POST' || req.method === 'DELETE') {
695
+ // Check Host header to block DNS rebinding attacks
696
+ const host = (req.headers.host || '').replace(/:\d+$/, '');
697
+ const validHosts = ['localhost', '127.0.0.1'];
698
+ if (LAN_MODE && getLanIP()) validHosts.push(getLanIP());
699
+ if (!validHosts.includes(host)) {
700
+ res.writeHead(403, { 'Content-Type': 'application/json' });
701
+ res.end(JSON.stringify({ error: 'Forbidden: invalid host' }));
702
+ return;
703
+ }
704
+ // Check Origin header to block cross-site requests
695
705
  const origin = req.headers.origin || '';
696
706
  const referer = req.headers.referer || '';
697
707
  const source = origin || referer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "let-them-talk",
3
- "version": "3.2.3",
3
+ "version": "3.3.0",
4
4
  "description": "MCP message broker + web dashboard for inter-agent communication. Let AI CLI agents talk to each other.",
5
5
  "main": "server.js",
6
6
  "bin": {
package/server.js CHANGED
@@ -23,11 +23,27 @@ const PLUGINS_DIR = path.join(DATA_DIR, 'plugins');
23
23
 
24
24
  // In-memory state for this process
25
25
  let registeredName = null;
26
+ let registeredToken = null; // auth token for re-registration
26
27
  let lastReadOffset = 0; // byte offset into messages.jsonl for efficient polling
27
28
  let heartbeatInterval = null; // heartbeat timer reference
28
29
  let messageSeq = 0; // monotonic sequence counter for message ordering
29
30
  let currentBranch = 'main'; // which branch this agent is on
30
31
 
32
+ // Rate limiting — prevent broadcast storms and message flooding
33
+ const rateLimitWindow = 60000; // 1 minute window
34
+ const rateLimitMax = 30; // max 30 messages per minute per agent
35
+ let rateLimitMessages = []; // timestamps of recent messages
36
+
37
+ function checkRateLimit() {
38
+ const now = Date.now();
39
+ rateLimitMessages = rateLimitMessages.filter(t => now - t < rateLimitWindow);
40
+ if (rateLimitMessages.length >= rateLimitMax) {
41
+ return { error: `Rate limit exceeded: max ${rateLimitMax} messages per minute. Wait before sending more.` };
42
+ }
43
+ rateLimitMessages.push(now);
44
+ return null;
45
+ }
46
+
31
47
  // --- Helpers ---
32
48
 
33
49
  function ensureDataDir() {
@@ -112,7 +128,13 @@ function validateContentSize(content) {
112
128
  }
113
129
 
114
130
  function generateId() {
115
- return Date.now().toString(36) + Math.random().toString(36).slice(2, 8);
131
+ try { return Date.now().toString(36) + require('crypto').randomBytes(6).toString('hex'); }
132
+ catch { return Date.now().toString(36) + Math.random().toString(36).slice(2, 8); }
133
+ }
134
+
135
+ function generateToken() {
136
+ try { return require('crypto').randomBytes(16).toString('hex'); }
137
+ catch { return Math.random().toString(36).slice(2) + Math.random().toString(36).slice(2); }
116
138
  }
117
139
 
118
140
  function sleep(ms) {
@@ -230,9 +252,11 @@ function autoCompact() {
230
252
  return false;
231
253
  });
232
254
 
233
- // Rewrite messages.jsonl with only active messages
255
+ // Rewrite messages.jsonl atomically write to temp file then rename
234
256
  const newContent = active.map(m => JSON.stringify(m)).join('\n') + (active.length ? '\n' : '');
235
- fs.writeFileSync(msgFile, newContent);
257
+ const tmpFile = msgFile + '.tmp';
258
+ fs.writeFileSync(tmpFile, newContent);
259
+ fs.renameSync(tmpFile, msgFile);
236
260
  lastReadOffset = Buffer.byteLength(newContent, 'utf8');
237
261
 
238
262
  // Trim consumed ID files — keep only IDs still in active messages
@@ -366,7 +390,15 @@ function toolRegister(name, provider = null) {
366
390
 
367
391
  const agents = getAgents();
368
392
  if (agents[name] && agents[name].pid !== process.pid && isPidAlive(agents[name].pid)) {
369
- return { error: `Agent "${name}" is already registered by a live process (PID ${agents[name].pid})` };
393
+ return { error: `Agent "${name}" is already registered by a live process. Choose a different name.` };
394
+ }
395
+
396
+ // If name was previously registered by a dead process, verify token to prevent impersonation
397
+ if (agents[name] && agents[name].token && !isPidAlive(agents[name].pid)) {
398
+ // Dead agent — only allow re-registration from the same process (same token)
399
+ if (registeredToken && registeredToken !== agents[name].token) {
400
+ return { error: `Agent "${name}" was previously registered by another process. Choose a different name.` };
401
+ }
370
402
  }
371
403
 
372
404
  // Clean up old registration if re-registering with a different name
@@ -375,9 +407,11 @@ function toolRegister(name, provider = null) {
375
407
  }
376
408
 
377
409
  const now = new Date().toISOString();
378
- agents[name] = { pid: process.pid, timestamp: now, last_activity: now, provider: provider || 'unknown', branch: currentBranch };
410
+ const token = (agents[name] && agents[name].token) || generateToken();
411
+ agents[name] = { pid: process.pid, timestamp: now, last_activity: now, provider: provider || 'unknown', branch: currentBranch, token };
379
412
  saveAgents(agents);
380
413
  registeredName = name;
414
+ registeredToken = token;
381
415
 
382
416
  // Auto-create profile if not exists
383
417
  const profiles = getProfiles();
@@ -459,6 +493,9 @@ function toolSendMessage(content, to = null, reply_to = null) {
459
493
  return { error: 'You must call register() first' };
460
494
  }
461
495
 
496
+ const rateErr = checkRateLimit();
497
+ if (rateErr) return rateErr;
498
+
462
499
  const agents = getAgents();
463
500
  const otherAgents = Object.keys(agents).filter(n => n !== registeredName);
464
501
 
@@ -531,6 +568,9 @@ function toolBroadcast(content) {
531
568
  return { error: 'You must call register() first' };
532
569
  }
533
570
 
571
+ const rateErr = checkRateLimit();
572
+ if (rateErr) return rateErr;
573
+
534
574
  const sizeErr = validateContentSize(content);
535
575
  if (sizeErr) return sizeErr;
536
576
 
@@ -1909,13 +1949,16 @@ function loadPlugins() {
1909
1949
  const enabledNames = new Set(registry.filter(p => p.enabled !== false).map(p => p.name));
1910
1950
 
1911
1951
  try {
1952
+ const vm = require('vm');
1912
1953
  const files = fs.readdirSync(PLUGINS_DIR).filter(f => f.endsWith('.js'));
1913
1954
  for (const file of files) {
1914
1955
  try {
1915
1956
  const pluginPath = path.join(PLUGINS_DIR, file);
1916
- // Clear require cache so plugins can be reloaded
1917
- delete require.cache[require.resolve(pluginPath)];
1918
- const plugin = require(pluginPath);
1957
+ const code = fs.readFileSync(pluginPath, 'utf8');
1958
+ // Run plugin in a sandboxed VM context — no require, no process, no child_process
1959
+ const sandbox = { module: { exports: {} }, exports: {}, console: { log: () => {}, error: () => {}, warn: () => {} } };
1960
+ vm.runInNewContext(code, sandbox, { filename: file, timeout: 5000 });
1961
+ const plugin = sandbox.module.exports;
1919
1962
  if (!plugin.name || !plugin.description || !plugin.handler) {
1920
1963
  console.error(`Plugin ${file}: missing name, description, or handler`);
1921
1964
  continue;
@@ -1927,7 +1970,7 @@ function loadPlugins() {
1927
1970
  inputSchema: plugin.inputSchema || { type: 'object', properties: {} },
1928
1971
  handler: plugin.handler,
1929
1972
  });
1930
- console.error(`Plugin loaded: ${plugin.name}`);
1973
+ console.error(`Plugin loaded: ${plugin.name} (sandboxed)`);
1931
1974
  } catch (e) {
1932
1975
  console.error(`Plugin ${file} failed to load: ${e.message}`);
1933
1976
  }
@@ -1941,17 +1984,18 @@ function executePlugin(pluginName, args) {
1941
1984
 
1942
1985
  const context = {
1943
1986
  registeredName,
1944
- dataDir: DATA_DIR,
1945
1987
  sendMessage: (to, content) => toolSendMessage(content, to),
1946
1988
  getAgents: () => toolListAgents().agents,
1947
1989
  getHistory: (limit) => toolGetHistory(limit),
1948
1990
  readFile: (filePath) => {
1949
1991
  const resolved = path.resolve(filePath);
1950
1992
  const allowedRoot = path.resolve(process.cwd());
1951
- if (!resolved.startsWith(allowedRoot + path.sep) && resolved !== allowedRoot) {
1993
+ let realPath;
1994
+ try { realPath = fs.realpathSync(resolved); } catch { throw new Error('File not found'); }
1995
+ if (!realPath.startsWith(allowedRoot + path.sep) && realPath !== allowedRoot) {
1952
1996
  throw new Error('File path must be within the project directory');
1953
1997
  }
1954
- return fs.readFileSync(resolved, 'utf8');
1998
+ return fs.readFileSync(realPath, 'utf8');
1955
1999
  },
1956
2000
  };
1957
2001