Skip to content

Commit ce3cada

Browse files
pjt222claude
andcommitted
fix(telegram): require alphanumeric-start sandbox names and exclusive file creation
Address CodeRabbit review feedback: - Regex now requires first character to be alphanumeric, preventing option injection via names like "-v" or "--help" into execFileSync - Add flag: "wx" to writeFileSync for exclusive creation, preventing TOCTOU/symlink attacks on the SSH config temp file Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent 8b6dbab commit ce3cada

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎scripts/telegram-bridge.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const ALLOWED_CHATS = process.env.ALLOWED_CHAT_IDS
2929

3030
if (!TOKEN) { console.error("TELEGRAM_BOT_TOKEN required"); process.exit(1); }
3131
if (!API_KEY) { console.error("NVIDIA_API_KEY required"); process.exit(1); }
32-
if (!/^[a-zA-Z0-9_-]+$/.test(SANDBOX)) {
32+
if (!/^[A-Za-z0-9][A-Za-z0-9_-]*$/.test(SANDBOX)) {
3333
console.error(`Invalid SANDBOX_NAME: must be alphanumeric, hyphens, or underscores. Got: ${SANDBOX}`);
3434
process.exit(1);
3535
}
@@ -94,7 +94,7 @@ function runAgentInSandbox(message, sessionId) {
9494

9595
// Write temp ssh config with unpredictable filename to prevent symlink races
9696
const confPath = `/tmp/nemoclaw-tg-ssh-${crypto.randomBytes(8).toString("hex")}.conf`;
97-
require("fs").writeFileSync(confPath, sshConfig, { mode: 0o600 });
97+
require("fs").writeFileSync(confPath, sshConfig, { mode: 0o600, flag: "wx" });
9898

9999
const escaped = message.replace(/'/g, "'\\''");
100100
const cmd = `export NVIDIA_API_KEY='${API_KEY}' && nemoclaw-start openclaw agent --agent main --local -m '${escaped}' --session-id 'tg-${sessionId}'`;

0 commit comments

Comments
 (0)