redact

package
v0.44.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT, MIT Imports: 4 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 is redaction for anything a human is shown.

The UI wants to display a deployment's configuration, and a spec's `env:` block is where connection strings and tokens legitimately live. So values are masked by DEFAULT and revealed only when the name looks unambiguously harmless — deny-by-default, because the cost of the two mistakes is wildly asymmetric: wrongly masking `PREVIEW_DOMAIN` is a mild annoyance, wrongly revealing `DATABASE_URL` in a browser tab (or a screenshot, or a support ticket) is a breach.

This is defence in depth, NOT the primary control. The primary control is that responses are built field-by-field and `Stack.Env` is never serialised — see the api package. If you find yourself relying on this package to keep a secret out of a response, the response is wrong.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsSecretName

func IsSecretName(key string) bool

IsSecretName reports whether a variable name must be masked.

func Mask

func Mask(value string) string

Mask masks preserving only shape. Not a prefix/suffix reveal: a 4-character prefix of a 20-character token is a meaningful head start for an attacker and buys the operator almost nothing.

func RedactText

func RedactText(text string, extraSecrets ...string) string

RedactText strips anything that looks like a secret out of free text — command output, a log line, an error. Values are matched by content, since a log line has no key to inspect.

Deliberately conservative: it catches the shapes that actually leak (a URL with a password, a long opaque token assigned to a secret-looking name) and does not attempt to be exhaustive. Text shown to a human is a weaker channel than a JSON field, but hook output is written by the spec author and can echo anything.

`\s` here is RE2's ASCII class where JS's also covered Unicode spaces (U+00A0, U+FEFF, …): a password containing a non-breaking space is redacted one character shorter than Bun would. A documented divergence, not worth a hand-rolled class.

Types

type DisplayVar

type DisplayVar struct {
	Key string `json:"key"`
	// Value is the value, or a mask. Never the real value when Visibility is Masked.
	Value      string     `json:"value"`
	Visibility Visibility `json:"visibility"`
	// Length is the character count (UTF-16 units, as `.length` counted it) of the real value —
	// useful for "did it get set at all?" without revealing it.
	Length int `json:"length"`
}

DisplayVar is one variable, ready to render.

func Display

func Display(key, value string) DisplayVar

Display is the TS displayVar: one variable, ready to render.

func DisplayDeclared

func DisplayDeclared(declaredEnv []string, env map[string]string) []DisplayVar

DisplayDeclared renders a spec's DECLARED variables only.

`Stack.Env` also contains the entire ambient environment (see its doc comment), so iterating it would dump every secret the process holds. declaredEnv is the authored key list. Never nil.

type Visibility

type Visibility string

Visibility is whether a DisplayVar carries the real value or a mask.

const (
	Shown  Visibility = "shown"
	Masked Visibility = "masked"
)

Jump to

Keyboard shortcuts

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