security

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package security provides content scanning and PII redaction for TokMan.

The security package detects sensitive information in command output such as API keys, tokens, credentials, and personally identifiable information (PII).

Scanner

Use the Scanner to detect sensitive content:

scanner := security.NewScanner()
findings := scanner.Scan(output)
for _, f := range findings {
    fmt.Printf("Found %s: %s\n", f.Rule, f.Match)
}

Redaction

RedactPII removes detected sensitive information:

safe := security.RedactPII(output)

Validation

The Validator type provides input validation for API requests:

v := security.NewValidator()
if err := v.ValidateBudget(budget); err != nil { ... }

Package security provides content scanning and PII redaction capabilities for detecting sensitive information in command output.

Index

Constants

View Source
const (
	SeverityCritical = "critical"
	SeverityHigh     = "high"
	SeverityMedium   = "medium"
	SeverityLow      = "low"
)

Severity levels for findings

Variables

This section is empty.

Functions

func HasHiddenUnicode added in v0.28.0

func HasHiddenUnicode(s string) bool

HasHiddenUnicode checks for hidden/invisible Unicode characters

func IsPrintableASCII added in v0.28.0

func IsPrintableASCII(s string) bool

IsPrintableASCII checks if a string contains only printable ASCII characters

func IsSuspiciousContent added in v0.28.0

func IsSuspiciousContent(content string) bool

IsSuspiciousContent checks for potentially malicious content patterns

func RedactPII

func RedactPII(content string) string

RedactPII removes personally identifiable information from content

func RedactWithMask added in v0.28.0

func RedactWithMask(content string, mask rune) string

RedactWithMask redacts sensitive data but keeps structure with mask character

func SanitizeForLogging added in v0.28.0

func SanitizeForLogging(content string) string

SanitizeForLogging prepares content for logging by redacting PII and truncating if needed

func ValidateUTF8 added in v0.28.0

func ValidateUTF8(content string) bool

ValidateUTF8 checks if content is valid UTF-8

Types

type Finding

type Finding struct {
	Rule     string
	Severity string
	Message  string
	Match    string
	Position int
}

Finding represents a security finding from content scanning

func ValidateContent added in v0.28.0

func ValidateContent(content string) (bool, []Finding)

ValidateContent checks if content is safe and returns findings Returns true if safe (no critical findings), false otherwise

type ScanRule added in v0.28.0

type ScanRule struct {
	Name        string
	Pattern     *regexp.Regexp
	Severity    string
	Description string
}

ScanRule defines a single scanning rule

type Scanner

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

Scanner provides security scanning capabilities

func NewScanner

func NewScanner() *Scanner

NewScanner creates a new security scanner with all rules configured

func (*Scanner) HasCriticalFindings added in v0.28.0

func (s *Scanner) HasCriticalFindings(content string) bool

HasCriticalFindings checks if content contains any critical severity findings

func (*Scanner) Scan

func (s *Scanner) Scan(content string) []Finding

Scan analyzes content for sensitive information and returns findings

func (*Scanner) ScanWithRedaction added in v0.28.0

func (s *Scanner) ScanWithRedaction(content string) (string, []Finding)

ScanWithRedaction scans content and returns redacted version along with findings

type Validator added in v0.28.0

type Validator struct{}

Validator provides input validation for API requests

func NewValidator added in v0.28.0

func NewValidator() *Validator

NewValidator creates a new input validator

func (*Validator) ValidateBudget added in v0.28.0

func (v *Validator) ValidateBudget(budget int) error

ValidateBudget validates a token budget value

func (*Validator) ValidateMode added in v0.28.0

func (v *Validator) ValidateMode(mode string) error

ValidateMode validates a compression mode value

func (*Validator) ValidatePath added in v0.28.0

func (v *Validator) ValidatePath(path string) error

ValidatePath validates a file path for security

func (*Validator) ValidatePreset added in v0.28.0

func (v *Validator) ValidatePreset(preset string) error

ValidatePreset validates a compression preset value

Jump to

Keyboard shortcuts

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