Documentation
¶
Index ¶
- func AtomicWriteFileInWorkspace(workDir, relPath string, data []byte, perm os.FileMode) error
- func AtomicWriteFilePreservingModeInWorkspace(workDir, relPath string, data []byte, perm os.FileMode) error
- func CreateExclusiveFileInWorkspace(workDir, relPath string, data []byte, perm os.FileMode) error
- func MkdirAllInWorkspace(workDir, relPath string, perm os.FileMode) error
- func OpenFileNoFollow(path string, flag int, perm os.FileMode) (*os.File, error)
- func OpenInWorkspace(workDir, relPath string, flag int, perm os.FileMode) (*os.File, error)
- func ReadFileNoFollow(path string) ([]byte, os.FileInfo, error)
- func ReadFileNoFollowLimit(path string, maxBytes int64) ([]byte, os.FileInfo, error)
- func RequireSingleLink(info os.FileInfo) error
- func Resolve(workDir, inputPath string) string
- func ResolveWorkspace(workDir, inputPath string) (string, error)
- func SuggestRelative(inputPath string) string
- func WriteFileNoFollow(path string, data []byte, perm os.FileMode) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AtomicWriteFileInWorkspace ¶ added in v0.0.67
AtomicWriteFileInWorkspace writes a new same-directory inode and atomically replaces relPath, leaving any hardlink aliases to the old inode unchanged.
func AtomicWriteFilePreservingModeInWorkspace ¶ added in v0.0.67
func AtomicWriteFilePreservingModeInWorkspace(workDir, relPath string, data []byte, perm os.FileMode) error
AtomicWriteFilePreservingModeInWorkspace atomically replaces relPath while preserving the permission bits of an existing regular destination. New files use perm.
func CreateExclusiveFileInWorkspace ¶ added in v0.0.67
CreateExclusiveFileInWorkspace creates relPath beneath workDir and refuses to overwrite any existing directory entry.
func MkdirAllInWorkspace ¶ added in v0.0.67
MkdirAllInWorkspace recursively creates a directory beneath workDir without traversing symlinks.
func OpenFileNoFollow ¶
OpenFileNoFollow opens a file after refusing a symlink in the final path component. Platforms with O_NOFOLLOW use the kernel flag; other platforms use an Lstat preflight so the package still compiles and fails closed for ordinary symlink attacks.
func OpenInWorkspace ¶
OpenInWorkspace opens a file located beneath workDir without exposing a canonicalize-then-open TOCTOU window.
On Linux the implementation uses openat2(2) with RESOLVE_BENEATH and RESOLVE_NO_SYMLINKS so the kernel atomically refuses any symlink (final or intermediate) and any path that escapes the workspace, eliminating the race between resolution and open.
Non-Linux platforms fail closed because this package does not provide an equivalent descriptor-relative containment primitive there.
func ReadFileNoFollow ¶
ReadFileNoFollow reads a file after refusing a symlink in the final path component. Callers should first resolve and validate workspace membership.
func ReadFileNoFollowLimit ¶
ReadFileNoFollowLimit behaves like ReadFileNoFollow but rejects regular files whose size exceeds maxBytes before reading their contents into memory. A maxBytes of zero or less disables the size check.
func RequireSingleLink ¶ added in v0.0.67
RequireSingleLink rejects regular files with more than one directory entry. A path can be lexically inside the workspace while its inode is also linked outside it; refusing multiply-linked inputs prevents that alias from crossing the workspace read boundary.
func Resolve ¶
Resolve resolves tool input paths relative to the agent work directory. Absolute paths are returned as-is.
func ResolveWorkspace ¶
ResolveWorkspace resolves a path and rejects paths outside the workspace.
func SuggestRelative ¶
SuggestRelative extracts the likely relative portion from a wrong absolute path for use in error messages.
Types ¶
This section is empty.