sandbox

package
v1.3.0 Latest Latest
Warning

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

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

Documentation

Overview

Package sandbox confines the files a request file may read or write to a file root. Every path that comes from a request file (bodies, multipart files, `output`, certificates, keys, netrc and cookie files, unix sockets) goes through a Root; paths given on the command line do not.

Index

Constants

This section is empty.

Variables

View Source
var ErrDenied = errors.New("access denied outside file root")

ErrDenied reports a path outside the file root (after resolving `..` and symbolic links).

Functions

This section is empty.

Types

type Root

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

Root is a directory that confines file access.

func Open

func Open(dir string) (*Root, error)

Open opens dir (relative to the working directory or absolute) as a file root.

func (*Root) Close

func (r *Root) Close() error

Close releases the root.

func (*Root) Dir

func (r *Root) Dir() string

Dir returns the absolute path of the file root.

func (*Root) Path

func (r *Root) Path(name string) (string, error)

Path returns the absolute path of name after checking that it stays in the root, for the APIs that need a path (unix sockets).

func (*Root) ReadFile

func (r *Root) ReadFile(name string) ([]byte, error)

ReadFile reads a file. name is relative to the root, or absolute and inside it; any other name returns an error wrapping ErrDenied.

func (*Root) WriteFile

func (r *Root) WriteFile(name string, data []byte) error

WriteFile writes a file; its parent directory must exist.

Jump to

Keyboard shortcuts

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