Redact secrets from files
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-09-08 07:34:13 -04:00
cmd/redact fix: variables shadowed in defer 2026-09-08 07:34:13 -04:00
examples example: ignore redacted secrets, example file 2026-08-31 09:10:58 -04:00
internal/pkg/fdpair refactor: fdpair: use interface 2025-11-05 07:15:34 -05:00
pkg/redact redact: handle overlapping matches 2026-08-03 09:27:36 -04:00
.gitignore 0.4.0 2025-11-07 09:41:29 -05:00
go.mod build: use vanity URL 2025-11-06 09:10:44 -05:00
go.sum deps: update 2024-09-22 07:59:21 -04:00
LICENSE doc: update copyright date 2025-03-26 07:22:33 -04:00
README.md build: use vanity URL 2025-11-06 09:10:44 -05:00

Go Reference

SYNOPSIS

redact [options] <file|directory|-> <...>

DESCRIPTION

Redact secrets from files using gitleaks rules.

BUILDING

go install go.iscode.ca/redact/cmd/redact@latest

Source

CGO_ENABLED=0 go build -trimpath -ldflags "-w" ./cmd/redact

EXAMPLES

# redact files in-place
redact -i file.txt file.json file.yml

# redact files in-place found in current directory and subdirectories
# (exclude files using -S/--skip)
redact -i .

# from stdin
cat file | redact -

$ echo 'root:$6$d468dc01f1cd655d$1c0a188389f4db6399265080815ac488ea65c3295a18d2d7da3ce5e8ef082362adeedec9b69.9704d4d188:18515:0:99999:7:::' | \
 ./redact --rules examples/gitleaks.toml -
root:$6$**REDACTED**:18515:0:99999:7:::

ENVIRONMENT VARIABLES

REDACT_LOG_LEVEL
Sets default value for --log-level
REDACT_REMOVE
Sets default value for --remove
REDACT_RULES
Sets default value for --rules
REDACT_SKIP
Sets default value for -S/--skip
REDACT_SUBSTITUTE
Sets default value for -s/--substitute

OPTIONS

-i/--inplace
Redact the file in-place
--log-level string
Set log level (default "error")
--remove string
Redaction method: redact, mask, mask:percentage (default "redact")
--rules string
Path to file containing gitleaks rules
-s string/--substitute string
Text used to overwrite secrets (default **REDACTED**)
-S/--skip
Skip glob matches in directories (default .git .gitleaks.toml)

REDACTION METHODS

redact

Replace the matched secret with the string provided by --substitute.

mask

Overwrite the matched secret with the first character of the string provided by --substitute.

mask can optionally leave a percentage of the match unmasked:

$ echo 'root:$6$d468dc01f1cd655d$1c0a188389f4db6399265080815ac488ea65c3295a18d2d7da3ce5e8ef082362adeedec9b69.9704d4d188:18515:0:99999:7:::' | \
 ./redact --remove=mask:10 --rules examples/gitleaks.toml -
root:$6$d468d*********************************************************************************************4d188:18515:0:99999:7:::

ISSUES/TODO

Note: While efficient for small files, redact may not be ideal for large files like logs because the entire file is read into memory.