validation

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package validation provides input validation functions for public APIs. This package implements Tier 1 security validation for OSS distribution.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SanitizeFilename

func SanitizeFilename(filename string) string

SanitizeFilename removes or replaces potentially dangerous characters in a filename. Returns a safe filename that can be used across different operating systems.

func SetConfig

func SetConfig(config *Config)

SetConfig sets the global validation configuration. This should only be used for testing purposes.

func ValidateChunkSize

func ValidateChunkSize(chunkSize int64) error

ValidateChunkSize validates that a download chunk size is reasonable. Returns an error if the chunk size is too small, too large, or invalid.

func ValidateContentLength

func ValidateContentLength(contentLength string) (int64, error)

ValidateContentLength validates HTTP Content-Length header value. Returns an error if the value is invalid or poses security risks.

func ValidateDestination

func ValidateDestination(dest string) error

ValidateDestination validates a file destination path for security and usability. Returns an error if the path is unsafe, invalid, or poses security risks.

func ValidateFileSize

func ValidateFileSize(size int64) error

ValidateFileSize validates that a file size is within reasonable bounds. Returns an error if the size is negative or exceeds system limits.

func ValidateTimeout

func ValidateTimeout(timeoutSeconds int) error

ValidateTimeout validates that a timeout duration is reasonable. Returns an error if the timeout is negative or excessively long.

func ValidateURL

func ValidateURL(rawURL string) error

ValidateURL validates a download URL for security and correctness. Returns an error if the URL is malformed, uses unsupported scheme, or poses security risks.

Types

type Config

type Config struct {
	AllowLocalhost bool // Allow localhost URLs (for testing)
}

Config holds validation configuration

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default validation configuration for production use

func GetConfig

func GetConfig() *Config

GetConfig returns the current validation configuration.

func TestConfig

func TestConfig() *Config

TestConfig returns a validation configuration suitable for testing

Jump to

Keyboard shortcuts

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