mirror of
https://github.com/Twigpine/zero.git
synced 2026-11-10 13:11:31 -10:00
* Add cross-session messaging * Harden cross-session messaging Authenticate sender metadata against live registry records, bound peer lifecycle state, preserve records across transient discovery failures, and make receipt delivery direct and bounded. Also serialize TUI peer approvals, harden platform runtime paths and transport deadlines, widen session references, and add regression coverage for identity spoofing, queue limits, path boundaries, and tool failures. * Support canonical macOS socket paths Resolve Unix transport directories to their physical path before applying strict no-symlink traversal, allowing the standard /var to /private/var macOS alias without weakening runtime-directory validation. * Fix macOS socket path regression test Create the canonicalization fixture beneath a guaranteed short Unix path so it exercises the primary endpoint on macOS, and report temporary-directory cleanup failures. * Harden peer messaging lifecycle * Fix Windows peer directory traversal * Handle Windows token-owned peer directories * Accept equivalent Windows ACL masks * Build Windows peer ACL explicitly * Pin Windows ACL trustee SIDs * Validate Windows peer ACL semantics * Propagate Windows peer handle cleanup errors * Use null handle for Windows close failure test * Test held-message eviction callback
63 lines
1.6 KiB
Go
63 lines
1.6 KiB
Go
//go:build unix
|
|
|
|
package peermsg
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
func ensurePrivateDir(path string) error {
|
|
abs, err := filepath.Abs(path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
components := strings.Split(strings.TrimPrefix(filepath.Clean(abs), string(filepath.Separator)), string(filepath.Separator))
|
|
parentFD, err := unix.Open(string(filepath.Separator), unix.O_RDONLY|unix.O_DIRECTORY|unix.O_CLOEXEC, 0)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer unix.Close(parentFD)
|
|
for index, component := range components {
|
|
if component == "" {
|
|
continue
|
|
}
|
|
var stat unix.Stat_t
|
|
err = unix.Fstatat(parentFD, component, &stat, unix.AT_SYMLINK_NOFOLLOW)
|
|
if errors.Is(err, unix.ENOENT) {
|
|
if err = unix.Mkdirat(parentFD, component, 0o700); err != nil && !errors.Is(err, unix.EEXIST) {
|
|
return err
|
|
}
|
|
err = unix.Fstatat(parentFD, component, &stat, unix.AT_SYMLINK_NOFOLLOW)
|
|
}
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if stat.Mode&unix.S_IFMT != unix.S_IFDIR {
|
|
return fmt.Errorf("refusing non-directory or symlink runtime path component %q", component)
|
|
}
|
|
nextFD, openErr := unix.Openat(parentFD, component, unix.O_RDONLY|unix.O_DIRECTORY|unix.O_CLOEXEC|unix.O_NOFOLLOW, 0)
|
|
if openErr != nil {
|
|
return openErr
|
|
}
|
|
if index == len(components)-1 {
|
|
if int(stat.Uid) != os.Getuid() {
|
|
unix.Close(nextFD)
|
|
return fmt.Errorf("refusing runtime directory not owned by the current user: %q", path)
|
|
}
|
|
if err = unix.Fchmod(nextFD, 0o700); err != nil {
|
|
unix.Close(nextFD)
|
|
return err
|
|
}
|
|
}
|
|
unix.Close(parentFD)
|
|
parentFD = nextFD
|
|
}
|
|
return nil
|
|
}
|