Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:lock: Prevent elevated command injection in Windows Defender exclusion flow https://github.com/siyuan-note/siyuan/security/advisories/GHSA-vmp7-pm7g-ghcc

Daniel39ed33479e82
diff --git a/app/elevator/elevator-amd64.exe b/app/elevator/elevator-amd64.exe
index 53668dd3a1..aa6c0ba0b0 100644
Binary files a/app/elevator/elevator-amd64.exe and b/app/elevator/elevator-amd64.exe differ
diff --git a/app/elevator/elevator-arm64.exe b/app/elevator/elevator-arm64.exe
index 0e68afacb3..aa6c0ba0b0 100644
Binary files a/app/elevator/elevator-arm64.exe and b/app/elevator/elevator-arm64.exe differ
diff --git a/kernel/model/elevator_windows.go b/kernel/model/elevator_windows.go
index 6ed63dd16f..59ff45479c 100644
--- a/kernel/model/elevator_windows.go
+++ b/kernel/model/elevator_windows.go
@@ -66,8 +66,17 @@ func AddMicrosoftDefenderExclusion() (err error) {
return
}
- ps := []string{"powershell"}
- ps = append(ps, []string{"-Command", "Add-MpPreference", "-ExclusionPath", installPath, ",", util.WorkspaceDir}...)
+ // 工作空间路径由用户自由指定,这里校验并转义,避免路径中的 cmd.exe 元字符导致提权后命令注入
+ if err = validateExclusionPath(installPath); nil != err {
+ logging.LogWarnf("invalid Windows Defender exclusion path [%s]: %s", installPath, err)
+ return
+ }
+ if err = validateExclusionPath(util.WorkspaceDir); nil != err {
+ logging.LogWarnf("invalid Windows Defender exclusion path [%s]: %s", util.WorkspaceDir, err)
+ return
+ }
+
+ ps := []string{"add-defender-exclusion", syscall.EscapeArg(installPath), syscall.EscapeArg(util.WorkspaceDir)}
verbPtr, _ := syscall.UTF16PtrFromString("runas")
exePtr, _ := syscall.UTF16PtrFromString(elevator)
cwdPtr, _ := syscall.UTF16PtrFromString(util.WorkingDir)
@@ -119,6 +128,17 @@ func isUsingMicrosoftDefender() bool {
return cmd.Run() == nil
}
+// validateExclusionPath 校验用于添加到 Windows Defender 排除项的路径,
+// 拒绝包含 cmd.exe 或 PowerShell 元字符的路径,防止通过未转义的路径字符串实现命令注入
+func validateExclusionPath(path string) error {
+ for _, c := range path {
+ if strings.ContainsRune("&|<>^%!\"'$`", c) {
+ return fmt.Errorf("path contains invalid character [%s]", string(c))
+ }
+ }
+ return nil
+}
+
func getElevatorBin() string {
elevator := filepath.Join(util.WorkingDir, "kernel", "elevator.exe")
if "dev" == util.Mode || !gulu.File.IsExist(elevator) {