Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion bin/lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,17 @@ function runCapture(cmd, opts = {}) {
}
}

module.exports = { ROOT, SCRIPTS, run, runCapture, runInteractive };
/**
* Validate a sandbox or instance name to prevent shell injection.
* Names must be 1–63 chars, alphanumeric with dots, hyphens, and underscores,
* and must start with a letter or digit.
*/
function validateName(name) {
if (!name || !/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,62}$/.test(name)) {
console.error(` Invalid name: '${String(name).slice(0, 40)}'`);
console.error(" Names must be 1–63 characters: letters, digits, hyphens, underscores, dots.");
process.exit(1);
}
}

module.exports = { ROOT, SCRIPTS, run, runCapture, runInteractive, validateName };
4 changes: 3 additions & 1 deletion bin/nemoclaw.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const path = require("path");
const fs = require("fs");
const os = require("os");

const { ROOT, SCRIPTS, run, runCapture, runInteractive } = require("./lib/runner");
const { ROOT, SCRIPTS, run, runCapture, runInteractive, validateName } = require("./lib/runner");
const {
ensureApiKey,
ensureGithubToken,
Expand Down Expand Up @@ -101,6 +101,7 @@ async function deploy(instanceName) {
console.error(" nemoclaw deploy nemoclaw-test");
process.exit(1);
}
validateName(instanceName);
await ensureApiKey();
if (isRepoPrivate("NVIDIA/OpenShell")) {
await ensureGithubToken();
Expand Down Expand Up @@ -427,6 +428,7 @@ const [cmd, ...args] = process.argv.slice(2);
}

// Sandbox-scoped commands: nemoclaw <name> <action>
validateName(cmd);
const sandbox = registry.getSandbox(cmd);
if (sandbox) {
const action = args[0] || "connect";
Expand Down