secretscan

package
v1.3.6 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 15 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 secretscan finds API keys and other secrets in files about to be committed, for the pre-commit hook a harness gets (spec_051_secret_hooks): known key formats anywhere, and long random values assigned to key-like names in .env and config files. A line with "blitz:allow-secret" is skipped (a false alarm, a test fixture).

Index

Constants

View Source
const (
	// Installed: the hook was written and core.hooksPath set.
	Installed = "installed"
	// Present: the repository already has it.
	Present = "present"
	// OtherHooks: the repository uses other hooks (core.hooksPath set
	// elsewhere, husky, the pre-commit framework, a .git/hooks/pre-commit);
	// nothing was changed. Detail says which.
	OtherHooks = "other_hooks"
)

Install results.

View Source
const AllowMarker = "blitz:allow-secret"

AllowMarker on a line skips it.

View Source
const HookScript = `` /* 1364-byte string literal not displayed */

HookScript is .githooks/pre-commit: Blitz's scan when blitz is on PATH, else a portable search of the lines being added for the same key formats.

View Source
const HooksDir = ".githooks"

HooksDir is where the hook goes, relative to the repository's top: versioned, so everyone who clones it gets it (core.hooksPath).

Variables

View Source
var ErrNotARepository = errors.New("not a git repository")

ErrNotARepository is Install outside a git repository.

Functions

func Staged

func Staged(ctx context.Context, dir string) (map[string][]byte, error)

Staged is what the commit being made adds: each added, copied, changed or renamed file's content as staged, by its path from the repository's top.

Types

type Finding

type Finding struct {
	Path string
	Line int
	// Kind names what it looks like ("AWS access key").
	Kind string
	// Masked is the value with all but its first four characters hidden.
	Masked string
}

A Finding is a secret on a line of a file.

func History added in v0.9.0

func History(ctx context.Context, dir, ref string, maxFiles int) (found []Finding, complete bool, err error)

History finds the secrets in every file of the history ref has in the repository at dir (each version of each file once, those under 1 MB), for a repository about to be shared: its past commits go with it. At most maxFiles files are read (folders don't count); complete says whether that was all of them. A version seen at several paths is read as a settings file when one of them is one (.env, a .json…), where a long random value assigned to a key-like name is a secret.

func Scan

func Scan(name string, data []byte) []Finding

Scan finds the secrets in a file's content (binary and very large files are skipped).

type Result

type Result struct {
	Status string
	// Path is the hook, absolute.
	Path   string
	Detail string
}

Result is what Install did.

func Install

func Install(ctx context.Context, dir string) (Result, error)

Install puts the hook in the repository dir is in: .githooks/pre-commit at its top and core.hooksPath in its own config. A repository with other hooks is left as it is (OtherHooks).

Jump to

Keyboard shortcuts

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