security

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// StrictSanitizer allows only basic text formatting tags
	StrictSanitizer = bluemonday.StrictPolicy()

	// ArticleSanitizer allows common article formatting but removes dangerous elements
	ArticleSanitizer = createArticlePolicy()

	// UGCSanitizer for user-generated content with moderate restrictions
	UGCSanitizer = bluemonday.UGCPolicy()
)

Functions

func IsSSRFError

func IsSSRFError(err error) bool

IsSSRFError checks if the error is related to SSRF protection

func IsValidWebURL

func IsValidWebURL(u *url.URL) bool

IsValidWebURL performs basic validation for web URLs (less strict than ValidateURL)

func SanitizeHTML

func SanitizeHTML(html string) string

SanitizeHTML sanitizes HTML content for safe display

func SanitizeHTMLStrict

func SanitizeHTMLStrict(html string) string

SanitizeHTMLStrict uses strict sanitization (text only)

func SanitizeUserContent

func SanitizeUserContent(html string) string

SanitizeUserContent sanitizes user-generated content

func ValidateURL

func ValidateURL(rawURL string) error

ValidateURL performs comprehensive URL validation for security DEPRECATED: This method uses context.Background() which prevents proper timeout control. Use ValidateURLWithContext instead.

func ValidateURLWithContext

func ValidateURLWithContext(ctx context.Context, rawURL string) error

ValidateURLWithContext performs comprehensive URL validation for security with context support

func ValidateURLWithOptions

func ValidateURLWithOptions(ctx context.Context, rawURL string, allowPrivateNetworks bool) error

ValidateURLWithOptions performs URL validation with configurable options

Types

type URLValidationError

type URLValidationError struct {
	Type    string
	Message string
}

URLValidationError represents URL validation errors

func (*URLValidationError) Error

func (e *URLValidationError) Error() string

Jump to

Keyboard shortcuts

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