guardrails

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CredentialRules = []SensitiveRule{
		{Name: "openai_proj", Regex: regexp.MustCompile(`sk-proj-[A-Za-z0-9_-]{20,}`), Replacement: "[REDACTED:openai]", Severity: "high"},
		{Name: "openai", Regex: regexp.MustCompile(`\bsk-[A-Za-z0-9]{48}\b`), Replacement: "[REDACTED:openai]", Severity: "high"},
		{Name: "anthropic", Regex: regexp.MustCompile(`sk-ant-api[0-9]*-[A-Za-z0-9_-]{20,}`), Replacement: "[REDACTED:anthropic]", Severity: "high"},
		{Name: "anthropic_alt", Regex: regexp.MustCompile(`sk-ant-[A-Za-z0-9_-]{20,}`), Replacement: "[REDACTED:anthropic]", Severity: "high"},
		{Name: "groq", Regex: regexp.MustCompile(`\bgsk_[A-Za-z0-9]{20,}`), Replacement: "[REDACTED:groq]", Severity: "high"},
		{Name: "xai", Regex: regexp.MustCompile(`\bxai-[A-Za-z0-9]{20,}`), Replacement: "[REDACTED:xai]", Severity: "high"},
		{Name: "google", Regex: regexp.MustCompile(`AIza[0-9A-Za-z_-]{20,}`), Replacement: "[REDACTED:google]", Severity: "high"},
		{Name: "github", Regex: regexp.MustCompile(`gh[pousr]_[A-Za-z0-9]{36,}`), Replacement: "[REDACTED:github]", Severity: "high"},
		{Name: "slack", Regex: regexp.MustCompile(`xox[bpoa]-[A-Za-z0-9-]{10,}`), Replacement: "[REDACTED:slack]", Severity: "high"},
		{Name: "huggingface", Regex: regexp.MustCompile(`hf_[A-Za-z0-9]{34}`), Replacement: "[REDACTED:hf]", Severity: "high"},
		{Name: "aws_access_key", Regex: regexp.MustCompile(`AKIA[0-9A-Z]{16}`), Replacement: "[REDACTED:aws]", Severity: "high"},
		{Name: "generic_api_key", Regex: regexp.MustCompile(`(?i)(?:sk|pk|api|key|token)[_-][a-zA-Z0-9]{20,}`), Replacement: "[REDACTED:api_key]", Severity: "high"},
	}

	PIIRules = []SensitiveRule{
		{Name: "email", Regex: regexp.MustCompile(`[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}`), Replacement: "[EMAIL_REDACTED]", Severity: "medium"},
		{Name: "ssn", Regex: regexp.MustCompile(`\b\d{3}-\d{2}-\d{4}\b`), Replacement: "[SSN_REDACTED]", Severity: "high"},
		{Name: "credit_card", Regex: regexp.MustCompile(`\b(?:\d{4}[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}|\d{4}[-\s]?\d{6}[-\s]?\d{4,5})\b`), Replacement: "[CC_REDACTED]", Severity: "high"},
		{Name: "phone_us", Regex: regexp.MustCompile(`(?:\+?1[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}`), Replacement: "[PHONE_REDACTED]", Severity: "medium"},
	}
)

Built-in credential & secret patterns (OmniRoute parity: credentialPatterns.ts + piiMasker.ts)

Functions

func RedactHeaders

func RedactHeaders(headers map[string][]string) map[string][]string

RedactHeaders scrubs authorization and API key tokens from request headers.

Types

type RedactionResult

type RedactionResult struct {
	CleanedText string
	Detections  map[string]int
	Modified    bool
}

func RedactAll

func RedactAll(content string) RedactionResult

RedactAll strips both credentials and PII.

func RedactCredentials

func RedactCredentials(content string) RedactionResult

RedactCredentials removes API keys and tokens from content.

func RedactPII

func RedactPII(content string) RedactionResult

RedactPII removes personally identifiable information (emails, SSNs, credit cards).

type SensitiveRule

type SensitiveRule struct {
	Name        string
	Regex       *regexp.Regexp
	Replacement string
	Severity    string
}

SensitiveRule defines a pattern to detect and redact sensitive data.

Jump to

Keyboard shortcuts

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