jail

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEscapeAttempt = errors.New("path escape attempt: operation would access path outside jail")
)

Functions

func EnsureInJail

func EnsureInJail(jailPath, p string) string

EnsureInJail returns a path that resides inside jail when possible.

If the path is already inside jail, the cleaned absolute form is returned. Otherwise a path under jail is returned by appending the base name of the path.

func EnsureInJailFor

func EnsureInJailFor(jailPath, p string) string

EnsureInJailFor is a test-friendly helper that mirrors EnsureInJail but accepts paths written with forward slashes.

It converts both jail and p using filepath.FromSlash before applying the EnsureInJail logic. Use this from tests when expected values are easier to express using POSIX-style literals.

func IsInJail

func IsInJail(jailPath, rel string) bool

IsInJail reports whether the provided path resides within the jail boundary.

If jail is empty, the function returns true (no boundary). Relative paths always are in the jail.

func IsJailed

func IsJailed(j Jailed) bool

IsJailed reports whether j has a non-empty jail configured.

func RemoveJailPrefix

func RemoveJailPrefix(jailPath, path string) string

RemoveJailPrefix removes the jail prefix from a path and returns an absolute path.

Types

type Jailed

type Jailed interface {
	// GetJail returns the current jail root.
	GetJail() string
	// SetJail updates the current jail root.
	SetJail(jail string) error
}

Jailed describes components that can report and update a jail root.

Implementations should treat an empty jail as "not jailed".

Jump to

Keyboard shortcuts

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