leakcheck

package
v0.2.0 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: 8 Imported by: ? 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 leakcheck is the one AD-3 leak checker of the test suites: it looks for more of a generated key than its redacted form in a captured output, raw and in its JSON-escaped, URL-encoded and base64-encoded views, and reports each hit by format, file, byte offset, encoding and finding id, never by the matched text.

Index

Constants

View Source
const (
	EncodingRaw    = "raw"
	EncodingJSON   = "json"
	EncodingURL    = "url"
	EncodingBase64 = "base64"
)

Encodings a hit can be found in.

View Source
const UnknownID = "unknown"

UnknownID is the finding id of a key that matches no finding of the Report.

Variables

This section is empty.

Functions

func PNGChunks

func PNGChunks(b []byte) [][]byte

PNGChunks returns the payload of every chunk of b when b is a PNG, else nil.

func Redacted

func Redacted(key string) string

Redacted returns the redacted form TokenHound shows for key (secret.Split).

func Window

func Window(n int) int

Window is the number of visible key characters an output may show for a key of n characters: 10 (6 leading and 4 trailing) for keys of 20 or more, else 6. A run of Window(n)+1 contiguous key characters is a leak.

Types

type Hit

type Hit struct {
	Format    string
	File      string
	Offset    int
	Encoding  string
	FindingID string
}

Hit is one place where an output holds more of a key than its redacted form. It never holds key material: its String and Error name the place, not the text.

func Check

func Check(format, file string, data []byte, keys []Key) []Hit

Check returns every hit of keys in data: a run of Window(len(key))+1 contiguous key characters found raw, after JSON-string unescaping, after URL percent-decoding or inside a decoded base64 run (standard or URL alphabet, padded or not, nested up to three times). Offsets are byte offsets into data; for a decoded view, the start of the escape region or of the base64 run. For a key shorter than its window plus one the run is the whole key: such a key is a hit only when it appears in full.

func CheckOutput

func CheckOutput(format, file string, data []byte, keys []Key) []Hit

CheckOutput is Check of data plus, when data is a PNG, of every chunk payload as file "<file> chunk <n>".

func (Hit) Error

func (h Hit) Error() string

Error is String, so a Hit can be returned as an error.

func (Hit) String

func (h Hit) String() string

String describes the hit without the matched substring.

type Key

type Key struct {
	Value     string
	FindingID string
}

Key is one generated key and the id of the finding it belongs to.

func IDsFromReport

func IDsFromReport(jsonReport []byte, keys []string) []Key

IDsFromReport resolves the finding id of each key by matching its redacted form (prefix, suffix and length) against the findings and credential parts of a JSON Report. A key that matches no finding gets UnknownID; one whose redacted form several findings share gets their ids joined by "|".

func Keys

func Keys(values ...string) []Key

Keys wraps values as Keys with an unknown finding id.

Jump to

Keyboard shortcuts

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