sanitize

package module
v0.0.0-...-4e0b77b Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2018 License: MIT Imports: 3 Imported by: 0

README

sanitize

Build Status Windows build status Go Report Card Coverage Status

This is just a simple golang library for checking user-supplied paths for attempts to perform directory traversal. See the godoc for details.

You probably should read the code before using this for anything actually security-sensitive. It has tests, but I'm fairly unexperienced at this programming thing. Caveat emptor.

Documentation

Overview

Package sanitize provides functions which check whether a path expands to be outside the allowed root directory.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorIfNotSane

func ErrorIfNotSane(rootPath, path string) error

ErrorIfNotSane is like IsSane, except that it returns a PathNotSaneError if the path is outside the root path. It will also return any errors encountered by IsSane. This function is useful if you wish to pass the error along in your own program, as you don't have to come up with a custom error type, message etc.

func IsSane

func IsSane(rootPath string, path string) (bool, error)

IsSane checks whether a user-supplied path expands to be outside the provided absolute rootPath. The provided root path has to be an absolute path in order to avoid surprises during expansion. The function will return a PathNotAbsoluteError otherwise.

Types

type PathNotAbsoluteError

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

PathNotAbsoluteError is returned if a path isn't absolute.

func (PathNotAbsoluteError) Error

func (p PathNotAbsoluteError) Error() string

Err serializes the PathNotAbsoluteError.

type PathNotSaneError

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

PathNotSaneError is returned by ErrorIfNotSane() if a path isn't absolute.

func (PathNotSaneError) Error

func (p PathNotSaneError) Error() string

Err serializes the PathNotSaneError.

Jump to

Keyboard shortcuts

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