security

package
v1.22.61 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package security provides security validation and protection utilities

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConstantTimeCompare

func ConstantTimeCompare(a, b string) bool

ConstantTimeCompare performs constant-time comparison of two strings Returns true if strings are equal, false otherwise

func SafeIntConversion

func SafeIntConversion(value int64, bitSize int) (int64, error)

SafeIntConversion safely converts between integer types checking for overflow

func SafeUintConversion

func SafeUintConversion(value int64, bitSize int) (uint64, error)

SafeUintConversion safely converts to unsigned integer checking for overflow

func SanitizeSQL

func SanitizeSQL(input string) string

SanitizeSQL performs basic SQL injection prevention This is a basic implementation - use prepared statements for production

func ValidateAlphanumeric

func ValidateAlphanumeric(s string) error

ValidateAlphanumeric checks if a string contains only alphanumeric characters

func ValidateEmail

func ValidateEmail(email string) error

ValidateEmail performs basic email validation

func ValidateURL

func ValidateURL(url string) error

ValidateURL performs basic URL validation

Types

type InputValidator

type InputValidator struct {
	// MaxStringLength is the maximum allowed string length
	MaxStringLength int
	// AllowedPathPrefixes are the allowed path prefixes for file operations
	AllowedPathPrefixes []string
}

InputValidator provides methods for validating and sanitizing user input

func NewInputValidator

func NewInputValidator() *InputValidator

NewInputValidator creates a new input validator with default settings

func (*InputValidator) ValidateFilePath

func (v *InputValidator) ValidateFilePath(path string) error

ValidateFilePath validates a file path for security issues

func (*InputValidator) ValidateIPAddress

func (v *InputValidator) ValidateIPAddress(addr string) error

ValidateIPAddress validates an IP address or hostname

func (*InputValidator) ValidatePort

func (v *InputValidator) ValidatePort(port int) error

ValidatePort validates a network port number

func (*InputValidator) ValidateStringLength

func (v *InputValidator) ValidateStringLength(s string) error

ValidateStringLength checks if a string length is within acceptable bounds

type RateLimiter

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

RateLimiter provides basic rate limiting functionality

func NewRateLimiter

func NewRateLimiter(limit int, windowSeconds int64) *RateLimiter

NewRateLimiter creates a new rate limiter

func (*RateLimiter) Allow

func (r *RateLimiter) Allow(clientID string, now int64) bool

Allow checks if a request should be allowed based on rate limits

Jump to

Keyboard shortcuts

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