Documentation
¶
Overview ¶
Package sanitization provides utilities for cleaning and validating user input to prevent XSS attacks, injection attacks, and other security vulnerabilities.
Package sanitization provides utilities for cleaning and validating user input to prevent XSS attacks, injection attacks, and other security vulnerabilities.
Package sanitization provides utilities for cleaning and validating user input to prevent XSS attacks, injection attacks, and other security vulnerabilities.
Index ¶
- func IsValidEmail(s ServiceInterface, input string) bool
- func IsValidURL(s ServiceInterface, input string) bool
- type SanitizeOptions
- type Service
- func (s *Service) Alpha(input string, spaces bool) string
- func (s *Service) AlphaNumeric(input string, spaces bool) string
- func (s *Service) Domain(input string) (string, error)
- func (s *Service) Email(input string) string
- func (s *Service) HTML(input string) string
- func (s *Service) IPAddress(input string) string
- func (s *Service) Numeric(input string) string
- func (s *Service) Path(input string) string
- func (s *Service) SanitizeForLogging(input string) string
- func (s *Service) SanitizeFormData(data, fieldTypes map[string]string) map[string]string
- func (s *Service) SanitizeJSON(data any) any
- func (s *Service) SanitizeMap(data map[string]any)
- func (s *Service) SanitizeSlice(data []any)
- func (s *Service) SanitizeStruct(obj any)
- func (s *Service) SanitizeWithOptions(input string, opts SanitizeOptions) string
- func (s *Service) Scripts(input string) string
- func (s *Service) SingleLine(input string) string
- func (s *Service) String(input string) string
- func (s *Service) TrimAndSanitize(input string) string
- func (s *Service) TrimAndSanitizeEmail(input string) string
- func (s *Service) URI(input string) string
- func (s *Service) URL(input string) string
- func (s *Service) XML(input string) string
- type ServiceInterface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsValidEmail ¶
func IsValidEmail(s ServiceInterface, input string) bool
IsValidEmail checks if an email is valid after sanitization
func IsValidURL ¶
func IsValidURL(s ServiceInterface, input string) bool
IsValidURL checks if a URL is valid after sanitization
Types ¶
type SanitizeOptions ¶
type SanitizeOptions struct {
TrimWhitespace bool
RemoveHTML bool
MaxLength int
AllowedTags []string
}
SanitizeOptions provides advanced sanitization with options
type Service ¶
type Service struct{}
Service provides sanitization functionality for various input types
func (*Service) AlphaNumeric ¶
AlphaNumeric sanitizes to alphanumeric characters only
func (*Service) SanitizeForLogging ¶
SanitizeForLogging sanitizes a string specifically for safe logging This method prevents log injection attacks by removing newlines, null bytes, HTML tags, and HTML escaping the content
func (*Service) SanitizeFormData ¶
SanitizeFormData sanitizes form data based on field types
func (*Service) SanitizeJSON ¶
SanitizeJSON sanitizes JSON data recursively
func (*Service) SanitizeMap ¶
SanitizeMap sanitizes a map of string keys to any values
func (*Service) SanitizeSlice ¶
SanitizeSlice sanitizes a slice of any values
func (*Service) SanitizeStruct ¶
SanitizeStruct sanitizes all string fields in a struct
func (*Service) SanitizeWithOptions ¶
func (s *Service) SanitizeWithOptions(input string, opts SanitizeOptions) string
SanitizeWithOptions sanitizes a string with custom options
func (*Service) SingleLine ¶
SingleLine removes newlines and extra whitespace
func (*Service) TrimAndSanitize ¶
TrimAndSanitize trims whitespace and sanitizes a string
func (*Service) TrimAndSanitizeEmail ¶
TrimAndSanitizeEmail trims whitespace and sanitizes an email
type ServiceInterface ¶
type ServiceInterface interface {
// Basic string sanitization methods
String(input string) string
Email(input string) string
URL(input string) string
HTML(input string) string
Path(input string) string
IPAddress(input string) string
Domain(input string) (string, error)
URI(input string) string
Alpha(input string, spaces bool) string
AlphaNumeric(input string, spaces bool) string
Numeric(input string) string
SingleLine(input string) string
Scripts(input string) string
XML(input string) string
TrimAndSanitize(input string) string
TrimAndSanitizeEmail(input string) string
// Log-specific sanitization
SanitizeForLogging(input string) string
// Complex data structure sanitization
SanitizeMap(data map[string]any)
SanitizeSlice(data []any)
SanitizeStruct(obj any)
SanitizeFormData(data map[string]string, fieldTypes map[string]string) map[string]string
SanitizeJSON(data any) any
SanitizeWithOptions(input string, opts SanitizeOptions) string
}
ServiceInterface defines the interface for sanitization operations