redact

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 7 Imported by: 1 module, 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

Overview

Package redact masks secrets in text before it is written to disk.

Index

Constants

This section is empty.

Variables

View Source
var Formats = []Format{
	{"private key", regexp.MustCompile(`-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z ]*PRIVATE KEY-----`)},
	{"AWS access key", regexp.MustCompile(`\b(?:AKIA|ASIA)[0-9A-Z]{16}\b`)},
	{"Anthropic API key", regexp.MustCompile(`\bsk-ant-[A-Za-z0-9_\-]{20,}`)},
	{"OpenAI API key", regexp.MustCompile(`\bsk-(?:proj-|svcacct-)?[A-Za-z0-9_\-]{20,}`)},
	{"Google API key", regexp.MustCompile(`\bAIza[0-9A-Za-z_\-]{35}\b`)},
	{"GitHub token", regexp.MustCompile(`\b(?:ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9]{36,}\b`)},
	{"GitHub token", regexp.MustCompile(`\bgithub_pat_[A-Za-z0-9_]{60,}\b`)},
	{"GitLab token", regexp.MustCompile(`\bglpat-[A-Za-z0-9_\-]{20,}\b`)},
	{"Slack token", regexp.MustCompile(`\bxox[abprs]-[A-Za-z0-9\-]{10,}`)},
	{"Stripe key", regexp.MustCompile(`\b(?:sk|rk)_live_[A-Za-z0-9]{20,}\b`)},
	{"Hugging Face token", regexp.MustCompile(`\bhf_[A-Za-z0-9]{30,}\b`)},
	{"JWT", regexp.MustCompile(`\beyJ[A-Za-z0-9_\-]{8,}\.[A-Za-z0-9_\-]{8,}\.[A-Za-z0-9_\-]{8,}`)},
}

Formats are the credential formats Blitz knows, the one table the redactor, the secrets guardrail's description and the secret scan (pkg/secretscan, its hook's pattern too) read.

Functions

func Mask added in v0.7.1

func Mask(s string) string

Mask masks only the remembered values in s (not the patterns): for text shown as it is, such as a model's answer.

func PII added in v0.7.1

func PII(s string) (string, bool)

PII masks the personal data in s and reports whether it found any.

func Remember added in v0.7.1

func Remember(values ...string)

Remember adds values for every Redactor to mask from now on (ignoring ones shorter than 8 characters, as New does).

Types

type Format added in v0.9.1

type Format struct {
	Kind    string
	Pattern *regexp.Regexp
}

Format is a credential format: what it is, and a pattern that matches one whole.

type Redactor

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

Redactor masks known secret formats plus specific secret values.

func FromEnv

func FromEnv(namePatterns []string, extra ...string) *Redactor

FromEnv returns a redactor for the values of environment variables whose names match any of the glob patterns (case-insensitive), e.g. "*_API_KEY".

func New

func New(values ...string) *Redactor

New returns a redactor that also masks the given literal values (ignoring ones shorter than 8 characters, which would cause false positives).

func (*Redactor) Longest added in v0.9.1

func (r *Redactor) Longest() int

Longest is the length of the longest value r masks, its own or remembered (0 for none): text streamed in pieces is held at least this long so a value is whole when it's checked. A nil Redactor has the remembered ones.

func (*Redactor) String

func (r *Redactor) String(s string) string

String masks secrets in s. A nil Redactor still applies the built-in patterns and the remembered values.

func (*Redactor) Value

func (r *Redactor) Value(v any) any

Value masks secrets inside strings nested in maps and slices (e.g. tool arguments), returning a copy.

Jump to

Keyboard shortcuts

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