workdir

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package workdir provides generic, confinement-policy-free filesystem helpers for resolving user-supplied paths safely: canonicalizing directories, walking up to the nearest existing ancestor before resolving symlinks (so a symlinked parent can't be combined with a nonexistent leaf path to land somewhere unexpected), checking subpath containment, and rejecting symlinked leaf files. This package has no opinion on which root a caller should confine paths to — callers that need to enforce a specific confinement policy (an approved-root env var, for example) build it on top of these primitives.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanonicalizeDir

func CanonicalizeDir(path string) (string, error)

CanonicalizeDir resolves path to an absolute, symlink-resolved directory path. It returns an error if path does not exist or is not a directory.

func IsSubpath

func IsSubpath(root, target string) bool

IsSubpath reports whether target is root itself or lies inside it. A name that merely starts with ".." (e.g. "..secrets") is not treated as parent traversal; only an actual ".." path segment counts as escaping root.

func RequireNonSymlinkLeaf

func RequireNonSymlinkLeaf(root, leafPath string) error

RequireNonSymlinkLeaf rejects a leafPath that is itself a symlink, or whose resolved location escapes root. A leafPath that does not exist yet is allowed, since callers typically create it as a regular file on first use.

func ResolveViaExistingAncestor

func ResolveViaExistingAncestor(path string) (string, error)

ResolveViaExistingAncestor finds the nearest existing ancestor of path, resolves symlinks there with EvalSymlinks, then rejoins any missing trailing path components. This blocks a symlinked/junction parent from being combined with a nonexistent leaf path to resolve somewhere other than where the symlink target actually points.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL