mask

package
v1.35.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 12 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 mask hides secret values in everything Probe prints or writes.

Index

Constants

View Source
const MinLength = 4

MinLength is the fewest characters a value must have to be masked inside other text. A shorter value, such as 1, ok or dev, is as likely to stand inside an unrelated word as for itself: replacing it wherever it appears mangles the whole output, and the letters missing from the words give it away anyway. Such a value is masked only where it is a whole value of a request or a response, which neither mangles nor gives away anything. A credential header or parameter shown by Map, and the password in a URL under dsn or url, are still replaced outright, whatever their length, since that depends on their names, not their values.

Variables

View Source
var Placeholder = regexp.MustCompile(`<(?:redacted|secret:[^<>\n]+)>`)

Placeholder matches what a Masker writes in place of a value it hides: <secret:NAME> for a secret of the workflow, NAME as the workflow lists it, and <redacted> for a credential it learned. A Masker writes NAME as it is, so the placeholder of a name with <, > or a line break in it, which an environment variable can hardly be given, is not matched, or matched in part.

Functions

func HoldsCredential

func HoldsCredential(key string) bool

HoldsCredential reports whether the parameter or header named key holds a credential, whole or, as a database URL does, in part. A message about such a value, such as why its template could not be evaluated, must not show what was written there.

func HoldsURL

func HoldsURL(key string) bool

HoldsURL reports whether the parameter named key holds a URL whose password is a credential, as dsn and url do.

func Userinfo

func Userinfo(rawURL string) string

Userinfo returns the user info of a URL, what stands between its scheme and the last @ of its authority, as user:password, or nothing when it has none. It does not rely on url.Parse, which rejects the tcp(host:port) address a MySQL DSN may carry.

Types

type Masker

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

Masker hides secret values in everything Probe prints or writes. It starts with the secrets the workflow declares and learns the values of credential headers as actions are about to send them, so that a token obtained at run time is hidden too. A nil Masker hides only credential headers in the maps passed to Map, and learns nothing.

func New

func New(secrets []string, env map[string]string) *Masker

New builds a Masker for the environment variables named in secrets. Each value is replaced by <secret:NAME>. A name that is not set, or set to an empty string, has nothing to hide and is skipped. A value shorter than MinLength is masked only where it is a whole value; TooShort names those secrets so that the caller can warn about them.

func (*Masker) Generation added in v1.32.0

func (m *Masker) Generation() uint64

Generation is a number that changes whenever the masker learns a value that String or Value hides, so that what was masked with it can be kept until it does. A nil Masker learns nothing, and its generation is always 0.

func (*Masker) Learn

func (m *Masker) Learn(data map[string]any)

Learn registers the values of credential headers and parameters found anywhere in data, and the password in a database URL, so that they are hidden from then on. It is called with an action's parameters before the action runs, which is what keeps them out of the action's own log records.

func (*Masker) Map

func (m *Masker) Map(data map[string]any) map[string]any

Map returns a copy of a request or response with secret values hidden in every string, and the values of credential headers replaced outright. The original is left untouched, since tests and outputs still need the real values. A nil map stays nil.

func (*Masker) String

func (m *Masker) String(s string) string

String hides every secret value in s, and the credentials of every URL in it. The values go first, so that a secret is replaced whole with its label and its name is kept, also when it stands in a URL: a scan of the URL could otherwise cut it at a quote it holds and leave the rest visible.

func (*Masker) TooShort added in v1.30.0

func (m *Masker) TooShort() []string

TooShort returns the names of the declared secrets whose values are set but shorter than MinLength, and so are masked only where they are a whole value, once each in the order they were declared. It never returns the values.

func (*Masker) Value

func (m *Masker) Value(v any) any

Value returns v, a value read out of a request or a response, with secret values hidden in every string at any depth, as Map hides them in a whole one. The original is left untouched.

func (*Masker) Writer

func (m *Masker) Writer(w io.Writer) io.Writer

Writer wraps w so that secret values are hidden in what is written to it. Every caller writes whole messages or lines, so a value is never split across two writes. The wrapper consults the masker on each write, so values learned later are hidden too.

Directories

Path Synopsis
Package markdown writes the placeholders a mask.Masker puts in place of hidden values so that Markdown shows them, for an action that posts text with them, such as the notes of a run, where <secret:NAME> and <redacted> would be taken for something else: an HTML tag on GitHub, which leaves it out, or a link or a mention on Slack.
Package markdown writes the placeholders a mask.Masker puts in place of hidden values so that Markdown shows them, for an action that posts text with them, such as the notes of a run, where <secret:NAME> and <redacted> would be taken for something else: an HTML tag on GitHub, which leaves it out, or a link or a mention on Slack.

Jump to

Keyboard shortcuts

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