Documentation
¶
Overview ¶
Package securityutils provides utility functions for security operations and data sanitization.
Index ¶
- func EscapeSQL(input string) string
- func GenerateSecureToken(length int) (string, error)
- func IsCommonPassword(password string) bool
- func MaskCreditCard(cardNumber string) string
- func MaskEmail(email string) string
- func MaskString(input string, start, end int, maskChar rune) string
- func SanitizeFilename(filename string) string
- func SanitizeHTML(input string) string
- func SanitizeURL(rawURL string) (string, error)
- func StripHTMLTags(input string) string
- func UnescapeHTML(input string) string
- func ValidateCSRFToken(token, expectedToken string) error
- func ValidatePassword(password string, minLength int, ...) []string
- type CSRFToken
- type RateLimiter
- type SecureHeaders
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EscapeSQL ¶
EscapeSQL escapes SQL input to prevent SQL injection (basic escaping). Note: This is a basic implementation. Use parameterized queries in production.
func GenerateSecureToken ¶
GenerateSecureToken generates a cryptographically secure random token.
func IsCommonPassword ¶
IsCommonPassword checks if a password is in a list of common passwords.
func MaskCreditCard ¶
MaskCreditCard masks a credit card number while preserving the last 4 digits.
func MaskString ¶
MaskString masks a string by replacing characters with a mask character.
func SanitizeFilename ¶
SanitizeFilename sanitizes a filename by removing dangerous characters.
func SanitizeHTML ¶
SanitizeHTML sanitizes HTML input by escaping dangerous characters.
func SanitizeURL ¶
SanitizeURL sanitizes a URL by escaping dangerous characters.
func StripHTMLTags ¶
StripHTMLTags removes HTML tags from input string.
func ValidateCSRFToken ¶
ValidateCSRFToken validates a CSRF token.
Types ¶
type CSRFToken ¶
CSRFToken represents a CSRF token with metadata.
func GenerateCSRFToken ¶
GenerateCSRFToken generates a cryptographically secure CSRF token.
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter represents a simple rate limiter.
func NewRateLimiter ¶
func NewRateLimiter(limit int, window time.Duration) *RateLimiter
NewRateLimiter creates a new rate limiter.
func (*RateLimiter) Allow ¶
func (rl *RateLimiter) Allow(identifier string) bool
Allow checks if a request from the given identifier is allowed.
func (*RateLimiter) CleanupExpired ¶
func (rl *RateLimiter) CleanupExpired()
CleanupExpired removes expired entries from the rate limiter.
type SecureHeaders ¶
type SecureHeaders struct {
ContentTypeOptions string
FrameOptions string
XSSProtection string
ReferrerPolicy string
ContentSecurityPolicy string
StrictTransportSecurity string
}
SecureHeaders represents common security headers.
func DefaultSecureHeaders ¶
func DefaultSecureHeaders() SecureHeaders
DefaultSecureHeaders returns default secure headers.
func (*SecureHeaders) ToMap ¶
func (h *SecureHeaders) ToMap() map[string]string
ToMap converts SecureHeaders to a map for easy HTTP header setting.