mirror of
https://github.com/PR0M3TH3AN/TORCH.git
synced 2026-11-06 21:01:54 +00:00
Merge pull request #275 from PR0M3TH3AN/fix-install-dir-command-injection-4005485668731201594
🔒 Fix command injection via install directory name
This commit is contained in:
2 files changed
+128
-4
No files matched your search
+19
-4
@@ -147,11 +147,26 @@ async function interactiveInit(cwd) {
|
||||
}
|
||||
}
|
||||
|
||||
async function resolveConfiguration(cwd, mockAnswers) {
|
||||
if (mockAnswers) {
|
||||
return mockAnswers;
|
||||
function validateInstallDir(dir) {
|
||||
if (dir === '.') return;
|
||||
|
||||
// Strict validation to prevent command injection
|
||||
// Only allow alphanumeric, hyphens, underscores, slashes, and periods.
|
||||
if (!/^[a-zA-Z0-9_\-\/\.]+$/.test(dir)) {
|
||||
throw new Error(`Invalid directory name: "${dir}". Only alphanumeric characters, hyphens, underscores, slashes, and periods are allowed.`);
|
||||
}
|
||||
return await interactiveInit(cwd);
|
||||
}
|
||||
|
||||
async function resolveConfiguration(cwd, mockAnswers) {
|
||||
let config;
|
||||
if (mockAnswers) {
|
||||
config = mockAnswers;
|
||||
} else {
|
||||
config = await interactiveInit(cwd);
|
||||
}
|
||||
|
||||
validateInstallDir(config.installDir);
|
||||
return config;
|
||||
}
|
||||
|
||||
function ensureInstallDirectory(paths, force, installDir) {
|
||||
|
||||
Reference in new issue
Block a user