chore: secure fix
This commit is contained in:
@@ -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, "'", "'\\''") + "'"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user