跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

private.go

37 行 · 1016 B历史下载
1package host
2
3import (
4 "errors"
5 "os"
6)
7
8// EnsurePrivateDir creates host-only storage and removes inherited access.
9// Windows uses an explicit DACL; POSIX mode bits do not protect Windows files.
10func EnsurePrivateDir(path string) error {
11 if err := os.MkdirAll(path, 0700); err != nil {
12 return err
13 }
14 info, err := os.Lstat(path)
15 if err != nil {
16 return err
17 }
18 if !info.IsDir() || info.Mode()&(os.ModeSymlink|os.ModeIrregular) != 0 {
19 return errors.New("private storage must be a real directory")
20 }
21 return protectPrivate(path, true)
22}
23
24// ProtectFile restricts an existing file or local socket to the current user.
25func ProtectFile(path string) error { return protectPrivate(path, false) }
26
27// CheckPrivateFile rejects non-regular files and access by other local users.
28func CheckPrivateFile(path string) error {
29 info, err := os.Lstat(path)
30 if err != nil {
31 return err
32 }
33 if !info.Mode().IsRegular() {
34 return errors.New("private record must be a regular file")
35 }
36 return checkPrivate(path, info)
37}