Skip to content

Commit e912769

Browse files
TestThomasK33
authored andcommitted
fix: validate script names to prevent path traversal attacks
Change-Id: Ie765802a9d713726bdc7401c88e550b8093aac5f Signed-off-by: Test <test@example.com>
1 parent fdcebbd commit e912769

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/node/services/ipcMain.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,8 +1244,25 @@ export class IpcMain {
12441244
}
12451245

12461246
try {
1247+
// Validate scriptName doesn't contain path separators (prevent path traversal)
1248+
if (scriptName.includes("/") || scriptName.includes("\\") || scriptName.includes("..")) {
1249+
return Err(
1250+
`Invalid script name: ${scriptName}. Script names must not contain path separators.`
1251+
);
1252+
}
1253+
12471254
const scriptPath = getScriptPath(workspacePath, scriptName);
12481255

1256+
// Double-check the resolved path stays within scripts directory
1257+
const scriptsDir = path.join(workspacePath, ".cmux", "scripts");
1258+
const normalizedScriptPath = path.normalize(scriptPath);
1259+
const normalizedScriptsDir = path.normalize(scriptsDir);
1260+
if (!normalizedScriptPath.startsWith(normalizedScriptsDir + path.sep)) {
1261+
return Err(
1262+
`Invalid script name: ${scriptName}. Script path escapes scripts directory.`
1263+
);
1264+
}
1265+
12491266
let scriptExists = false;
12501267
try {
12511268
const stat = await runtimeInstance.stat(scriptPath);

0 commit comments

Comments
 (0)