confine

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package confine maps the file names a user types to paths on disk, keeping them inside one directory when 012 serves sessions over SSH.

A Root's zero value confines nothing: names are used as typed, relative to the working directory, as the local app always has. A Root made with New resolves names inside its directory and rejects absolute paths, names that climb out with "..", hidden files and directories, and symbolic links that lead outside or nowhere.

Index

Constants

This section is empty.

Variables

View Source
var ErrOutside = errors.New("outside the served directory")

ErrOutside is wrapped by every name a confined Root refuses.

Functions

This section is empty.

Types

type Root

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

Root is a directory names are confined to; the zero value confines nothing.

func New

func New(dir string) (Root, error)

New confines names to dir, which must exist.

func (Root) Confined

func (r Root) Confined() bool

Confined reports whether r keeps names inside a directory.

func (Root) Dir

func (r Root) Dir() string

Dir is the directory names are confined to, "" when unconfined.

func (Root) Resolve

func (r Root) Resolve(name string) (string, error)

Resolve returns the path to use on disk for name, as the user typed it. Unconfined, that's name itself. Confined, it's a path inside the root with every existing symbolic link along it followed, or an error wrapping ErrOutside.

func (Root) Scrub

func (r Root) Scrub(msg string) string

Scrub removes the root's location from msg, such as an error naming a resolved path, so it names files relative to the root.

Jump to

Keyboard shortcuts

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