redact

package
v0.30.2 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 11 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 removes secrets before anything reaches the log (SP2 §4, T8). It uses gitleaks' default rules; the test pins the four the design names.

Index

Constants

This section is empty.

Variables

View Source
var ErrKeyCollision = errors.New("redact: two object keys are the same once redacted")

ErrKeyCollision reports two object keys that are one once NULs and secrets are removed. Keeping either would drop the other's value, and which one depends on map order, so the payload is refused. The error never quotes a key.

Functions

This section is empty.

Types

type Redactor

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

Redactor applies gitleaks' default rules to text and JSON payloads.

func New

func New() (*Redactor, error)

New parses gitleaks' default configuration once. It also silences gitleaks' own global logger, which logs each finding's secret at Trace to stderr, outside slog: call it at startup, before any scan runs.

func (*Redactor) Payload

func (r *Redactor) Payload(ctx context.Context, raw json.RawMessage) (json.RawMessage, []string, error)

Payload redacts every string of a JSON document, object keys included, and keeps its shape. Each string is scanned alone: a secret split across sibling fields is not detected, so callers must not split tokens.

It honours ctx between strings, and an ended ctx fails the whole payload: it is never returned partly scanned. One string's scan is not interruptible: gitleaks' ctx-aware entry point takes its deprecated Fragment type, and the caller's body limit bounds a string anyway.

func (*Redactor) String

func (r *Redactor) String(s string) (string, []string)

String replaces each finding's secret with [REDACTED:<rule>]. A fresh Detector per call: a Detector accumulates every finding it ever made, which would grow forever in a long-lived broker.

Jump to

Keyboard shortcuts

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