loader

package
v0.1.15 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package loader provides secure filesystem access control for template engines.

Security considerations: - Always validate custom fs.FS implementations before use - Ensure path traversal attacks are prevented at the fs.FS level - Consider implementing audit logging for all filesystem access - Use io/fs.Sub to create restricted filesystem views

Index

Constants

This section is empty.

Variables

View Source
var ErrFilesystemAccessDisabled = errors.New("template loading from filesystem disabled for security reasons")

ErrFilesystemAccessDisabled is the error returned when filesystem access is disabled for security.

Functions

This section is empty.

Types

type FSLoader

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

FSLoader wraps an fs.FS to provide controlled filesystem access. This is used internally when explicit filesystem access is needed.

Security note: The provided fs.FS should be pre-validated to ensure: - It doesn't allow access outside intended boundaries - Path traversal attempts are blocked - Symbolic links don't escape the filesystem root - Consider using fs.Sub() to create restricted views

func NewFSLoader

func NewFSLoader(filesystem fs.FS) *FSLoader

NewFSLoader creates a new FSLoader with the provided filesystem.

func (*FSLoader) Get

func (fl *FSLoader) Get(path string) (io.Reader, error)

Get opens a file from the controlled filesystem. The path is passed directly to the underlying fs.FS, which should handle its own path validation and normalization.

func (*FSLoader) Path

func (fl *FSLoader) Path(path string) (string, error)

Path validates that a path exists in the controlled filesystem.

type NilFSLoader

type NilFSLoader struct{}

NilFSLoader is a template loader that provides no filesystem access. This prevents template injection attacks like {% include "/etc/passwd" %}.

func (*NilFSLoader) Get

func (nl *NilFSLoader) Get(path string) (io.Reader, error)

Get always returns an error to prevent filesystem access.

func (*NilFSLoader) Path

func (nl *NilFSLoader) Path(path string) (string, error)

Path always returns an error to prevent filesystem access.

Jump to

Keyboard shortcuts

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