redact

package
v0.2.1 Latest Latest
Warning

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

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

Overview

Package redact masks secrets before anything derived from a request or response reaches logs, the TUI or an error result.

It works two ways (SPEC §5.3, T11):

  • by name: auth headers, cookies, and header or query names that look secret (or are configured as secret) have their values replaced;
  • by value: every resolved secret is replaced wherever it appears, in its raw, percent-encoded, base64 and JSON-escaped forms. This catches upstream error bodies that echo a key back.

Well-known token formats (GitHub, Stripe, Slack, AWS, JWT, PEM keys, ...) are masked as a backstop even when they were never configured.

Index

Constants

View Source
const Mask = "***"

Mask replaces every redacted value.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	SecretHeaders     []string
	SecretQueryParams []string
	Secrets           []string
}

Options configures a Redactor.

type Redactor

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

Redactor masks secrets. It is immutable after New and safe for concurrent use.

func New

func New(opts Options) *Redactor

New builds a Redactor from opts.

func (*Redactor) Args

func (r *Redactor) Args(args map[string]any) map[string]any

Args returns a copy of call arguments for the call log: values under secret-looking names (at any depth) become Mask, and every string has secrets and known token formats masked. args is not changed.

func (*Redactor) Bytes

func (r *Redactor) Bytes(b []byte) []byte

Bytes is String for byte slices. It always returns a new slice.

func (*Redactor) Header

func (r *Redactor) Header(h http.Header) http.Header

Header returns a redacted copy of h. Secret-named headers become Mask, Cookie keeps cookie names but masks their values, and every other value is masked by value and token pattern. h is not modified.

func (*Redactor) IsSecretHeader

func (r *Redactor) IsSecretHeader(name string) bool

IsSecretHeader reports whether values of the header called name must be masked.

func (*Redactor) String

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

String returns s with every secret value and known token format masked.

func (*Redactor) URL

func (r *Redactor) URL(u *url.URL) string

URL returns a redacted string form of u. Userinfo passwords and the values of secret-named query parameters are masked; parameter order and encoding are kept. The result is then masked by value and token pattern.

func (*Redactor) Values

func (r *Redactor) Values(args map[string]any) map[string]any

Values is Args without masking by name (log.args: full). Resolved secrets and token formats are still masked.

func (*Redactor) With

func (r *Redactor) With(extra ...string) *Redactor

With returns a Redactor that also masks extra secrets, for values only known later (an OAuth access token fetched while serving). Empty values are ignored; with none left, it returns r itself.

Jump to

Keyboard shortcuts

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