Documentation
¶
Overview ¶
Package input provides input detection and processing.
Index ¶
Constants ¶
const ( DefaultMaxFileSize = 10 * 1024 * 1024 // 10MB DefaultMaxFileCount = 100 DefaultMaxTotalBytes = 50 * 1024 * 1024 // 50MB DefaultMaxURLBytes = 10 * 1024 * 1024 // 10MB )
Default limits for file operations.
Variables ¶
var ( ErrPathTraversal = pathutil.ErrPathTraversal ErrPathOutsideBase = pathutil.ErrPathOutsideBase ErrBlockedURL = errors.New("URL is blocked") ErrPrivateIP = errors.New("private IP addresses are not allowed") ErrInvalidScheme = errors.New("only http and https schemes are allowed") ErrBlockedContentType = errors.New("content type is not allowed") ErrFileTooLarge = errors.New("file exceeds maximum size limit") ErrTooManyFiles = errors.New("glob pattern matched too many files") ErrTotalSizeExceeded = errors.New("total file size exceeds limit") )
Security-related errors.
Functions ¶
This section is empty.
Types ¶
type Content ¶
type Content struct {
// Type is the detected type of the input.
Type Type
// Raw is the original input value.
Raw string
// Data is the processed data (file contents, URL response, etc).
Data []byte
// Metadata contains additional information about the content.
Metadata map[string]any
}
Content represents processed input content.
func NewContent ¶
NewContent creates a new Content with the given type and raw value.
type FileProcessor ¶
type FileProcessor struct {
// contains filtered or unexported fields
}
FileProcessor processes file inputs with path traversal protection.
func NewFileProcessor ¶
func NewFileProcessor(opts ...FileProcessorOption) *FileProcessor
NewFileProcessor creates a new file processor with path validation.
func (*FileProcessor) CanProcess ¶
func (p *FileProcessor) CanProcess(typ Type) bool
CanProcess returns true for file types.
type FileProcessorOption ¶
type FileProcessorOption func(*FileProcessor)
FileProcessorOption configures FileProcessor.
func WithBaseDir ¶
func WithBaseDir(dir string) FileProcessorOption
WithBaseDir restricts file access to the specified directory.
func WithMaxFileSize ¶
func WithMaxFileSize(maxBytes int64) FileProcessorOption
WithMaxFileSize sets the maximum file size to read.
type GlobProcessor ¶
type GlobProcessor struct {
// contains filtered or unexported fields
}
GlobProcessor processes glob pattern inputs with resource limits.
func NewGlobProcessor ¶
func NewGlobProcessor(opts ...GlobProcessorOption) *GlobProcessor
NewGlobProcessor creates a new glob processor with resource limits.
func (*GlobProcessor) CanProcess ¶
func (p *GlobProcessor) CanProcess(typ Type) bool
CanProcess returns true for glob types.
type GlobProcessorOption ¶
type GlobProcessorOption func(*GlobProcessor)
GlobProcessorOption configures GlobProcessor.
func WithGlobBaseDir ¶
func WithGlobBaseDir(dir string) GlobProcessorOption
WithGlobBaseDir restricts glob to files within the specified directory.
func WithGlobMaxFileCount ¶
func WithGlobMaxFileCount(count int) GlobProcessorOption
WithGlobMaxFileCount sets the maximum number of files to process (deprecated: use WithMaxMatches).
func WithGlobMaxFileSize ¶
func WithGlobMaxFileSize(bytes int64) GlobProcessorOption
WithGlobMaxFileSize sets the maximum size per file.
func WithGlobMaxTotalBytes ¶
func WithGlobMaxTotalBytes(bytes int64) GlobProcessorOption
WithGlobMaxTotalBytes sets the maximum total bytes to read across all files.
func WithMaxMatches ¶
func WithMaxMatches(count int) GlobProcessorOption
WithMaxMatches sets the maximum number of files to process (default 100).
type Processor ¶
type Processor interface {
// Process processes the input value and returns Content.
Process(ctx context.Context, value string) (*Content, error)
// CanProcess returns true if this processor can handle the given type.
CanProcess(typ Type) bool
}
Processor processes input and returns Content.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages processors for different input types.
func NewRegistry ¶
func NewRegistry() *Registry
NewRegistry creates a new processor registry with default processors.
type TextProcessor ¶
type TextProcessor struct{}
TextProcessor processes plain text inputs.
func NewTextProcessor ¶
func NewTextProcessor() *TextProcessor
NewTextProcessor creates a new text processor.
func (*TextProcessor) CanProcess ¶
func (p *TextProcessor) CanProcess(typ Type) bool
CanProcess returns true for text types.
type Type ¶
type Type int
Type represents the type of input detected.
const ( // TypeUnknown indicates the input type could not be determined. TypeUnknown Type = iota // TypeURL indicates the input is a URL. TypeURL // TypeFile indicates the input is a file path. TypeFile // TypeGlob indicates the input is a glob pattern. TypeGlob // TypeText indicates the input is plain text. TypeText // TypeStdin indicates the input comes from stdin. TypeStdin )
type URLProcessor ¶
type URLProcessor struct {
// contains filtered or unexported fields
}
URLProcessor processes URL inputs with SSRF protection.
func NewURLProcessor ¶
func NewURLProcessor(opts ...URLProcessorOption) *URLProcessor
NewURLProcessor creates a new URL processor with SSRF protection.
func (*URLProcessor) CanProcess ¶
func (p *URLProcessor) CanProcess(typ Type) bool
CanProcess returns true for URL types.
type URLProcessorOption ¶
type URLProcessorOption func(*URLProcessor)
URLProcessorOption configures URLProcessor.
func WithAllowPrivateIPs ¶
func WithAllowPrivateIPs(allow bool) URLProcessorOption
WithAllowPrivateIPs allows fetching from private IP addresses (use only for testing).
func WithMaxContentSize ¶
func WithMaxContentSize(maxBytes int64) URLProcessorOption
WithMaxContentSize sets the maximum response body size (default 10MB).
func WithMaxURLBytes ¶
func WithMaxURLBytes(maxBytes int64) URLProcessorOption
WithMaxURLBytes sets the maximum response body size (deprecated: use WithMaxContentSize).
func WithTimeout ¶
func WithTimeout(timeout time.Duration) URLProcessorOption
WithTimeout sets the HTTP client timeout (default 30s).