Help us shape the future of Go! Take the 2026 Go Developer Survey

jail

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package jail resolves every client-supplied path against the configured roots. There is exactly one resolution function; every handler uses it, so path traversal, symlink escape, and denylist bypass have a single choke point to audit.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OpenRoot

func OpenRoot(root string) (*os.Root, error)

OpenRoot opens the resolved project root for contained reads, so symlinks inside the project cannot escape it even between check and open.

Types

type Jail

type Jail struct {
	// contains filtered or unexported fields
}

Jail is a resolved filesystem jail. The startup roots never change; the only mutable part is the small set of extra roots the server itself registers for directories it created (temporary clones).

func New

func New(roots []string, extraDeny []string) (*Jail, error)

New builds a jail from the configured roots (each resolved with EvalSymlinks at startup) plus extra denylist entries. Roots must exist and be directories.

func (*Jail) AddRoot

func (j *Jail) AddRoot(dir string) (string, error)

AddRoot admits one more directory (resolved through symlinks, so a /tmp that is itself a link still matches). It is for directories the server created, never for client input; the denylist still applies beneath it. It returns the resolved path, which is also what RemoveRoot expects.

func (*Jail) RemoveRoot

func (j *Jail) RemoveRoot(real string)

RemoveRoot withdraws a root added with AddRoot. Unknown roots are ignored.

func (*Jail) Resolve

func (j *Jail) Resolve(clientPath string) (string, error)

Resolve maps a client path to an absolute filesystem path inside the jail. It requires an absolute path, rejects NUL bytes and overlong input, resolves symlinks, verifies containment on a separator boundary, and applies the denylist. Failures are generic: callers must answer 403 without revealing whether the path exists.

func (*Jail) Roots

func (j *Jail) Roots() []string

Roots returns the resolved allowed roots for banners and /api/meta.

Jump to

Keyboard shortcuts

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