chore: secure fix

This commit is contained in:
engigu
2026-03-27 16:47:12 +08:00
parent 2a7677e9f8
commit 2c8a0b8967
6 changed files with 33 additions and 9 deletions
+10
View File
@@ -69,3 +69,13 @@ func NewShellCommandCmd(command string) *exec.Cmd {
shell, args := GetShellCommand(command)
return exec.Command(shell, args...)
}
// QuotePath 转义并包裹路径,防止 Shell 注入
func QuotePath(path string) string {
if path == "" {
return "''"
}
// 在 Unix-like 系统中,单引号包裹是最安全的
// 需要将路径中的 ' 替换为 '\'' (结束当前引号,转义一个单引号,重新开启引号)
return "'" + strings.ReplaceAll(path, "'", "'\\''") + "'"
}