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
3 changes: 2 additions & 1 deletion bin/lib/onboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

const fs = require("fs");
const path = require("path");
const { ROOT, SCRIPTS, run, runCapture } = require("./runner");
const { ROOT, SCRIPTS, run, runCapture, validateName } = require("./runner");
const { prompt, ensureApiKey, getCredential } = require("./credentials");
const registry = require("./registry");
const nim = require("./nim");
Expand Down Expand Up @@ -125,6 +125,7 @@ async function createSandbox(gpu) {

const nameAnswer = await prompt(" Sandbox name [my-assistant]: ");
const sandboxName = nameAnswer || "my-assistant";
validateName(sandboxName);

// Check if sandbox already exists in registry
const existing = registry.getSandbox(sandboxName);
Expand Down
15 changes: 14 additions & 1 deletion bin/lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,17 @@ function runCapture(cmd, opts = {}) {
}
}

module.exports = { ROOT, SCRIPTS, run, runCapture };
/**
* Validate a sandbox or instance name to prevent shell injection.
* Names must be 1–63 chars, alphanumeric with 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, 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 } = require("./lib/runner");
const { ROOT, SCRIPTS, run, runCapture, validateName } = require("./lib/runner");
const {
ensureApiKey,
ensureGithubToken,
Expand Down Expand Up @@ -57,6 +57,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 @@ -329,6 +330,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