Skip to content

Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.

fix(bots): separator-agnostic traversal guard + close doctor's queue

Salman Qureshi1c52b3b8e6c7
diff --git a/src/bots/doctor.test.ts b/src/bots/doctor.test.ts
index e8b47a5d..6d988f06 100644
--- a/src/bots/doctor.test.ts
+++ b/src/bots/doctor.test.ts
@@ -23,6 +23,9 @@ describe('runBotDoctor', () => {
});
afterEach(() => {
+ // The queue owns the SQLite handle — close it or Windows locks queue.db
+ // (EBUSY) and the tmpdir teardown fails.
+ queue.close();
rmSync(root, { recursive: true, force: true });
});
diff --git a/src/bots/skill-synthesis.ts b/src/bots/skill-synthesis.ts
index 450a6047..d39b6f31 100644
--- a/src/bots/skill-synthesis.ts
+++ b/src/bots/skill-synthesis.ts
@@ -1,5 +1,5 @@
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
-import { join, resolve } from 'node:path';
+import { isAbsolute, join, relative, resolve } from 'node:path';
import { getMercuryHome } from '../utils/config.js';
import { logger } from '../utils/logger.js';
import type { BaseProvider } from '../providers/base.js';
@@ -64,7 +64,10 @@ Write the skill that captures the REUSABLE procedure (not this one instance). Ru
const name = (nameMatch?.[1] ?? `${input.botId}-skill`).trim().slice(0, 60);
const slug = slugify(`${input.botId}-${name}`);
const dir = join(skillsRoot, 'bots', slug);
- if (!dir.startsWith(resolve(skillsRoot) + '/')) return null; // traversal guard
+ // Traversal guard (separator-agnostic — a hardcoded '/' made this fail
+ // on EVERY Windows run): the resolved dir must stay inside the skills root.
+ const rel = relative(resolve(skillsRoot), resolve(dir));
+ if (rel === '' || rel.startsWith('..') || isAbsolute(rel)) return null;
mkdirSync(dir, { recursive: true });
const path = join(dir, 'SKILL.md');
if (!existsSync(path)) {