// Package security provides security utilities for the KnowFoolery application.
package security
import (
"html"
"regexp"
"strings"
"unicode"
)
const (
// PlayerNameMaxLength defines the maximum length for player names.
PlayerNameMaxLength = 50
// AnswerMaxLength defines the maximum length for answer submissions.
AnswerMaxLength = 500
// QuestionTextMaxLength defines the maximum length for admin-authored question text.
QuestionTextMaxLength = 1000
// ThemeMaxLength defines the maximum length for theme names.
ThemeMaxLength = 100
)
var (
// Sanitization order is trim -> collapse spaces -> HTML escape -> clamp -> allowed pattern.
spaceRegex = regexp.MustCompile(`\s+`)
// Player names allow letters, numbers, spaces, '-', '_' and '.'.
playerNameAllowedPattern = regexp.MustCompile(`^[a-zA-Z0-9\s\-_.]+$`)
// Themes allow letters, numbers, spaces, '-' and '_'.
themeAllowedPattern = regexp.MustCompile(`^[a-zA-Z0-9\s\-_]+$`)
tagRegex = regexp.MustCompile(`<[^>]*>`)
scriptRegex = regexp.MustCompile(`(?i)`)
dangerousPatterns = []string{
"javascript:",
"data:",
"vbscript:",
"