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 ¶
IsSecretName reports whether a variable name must be masked.
func Mask ¶
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 ¶
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" )