NAME

Text::Redact::Secrets - find secrets in text by gitleaks' rules, and redact them

SYNOPSIS

use Text::Redact::Secrets qw(find redact);

# The text with each secret in it replaced by *REDACTED*.
print {$log} redact($text);

# Each secret in the text, with the rule that found it.
for my $found (find($text)) {
    say "$found->{rule} at $found->{offset}";
}

DESCRIPTION

Text that might hold a secret, such as a dump written to a log, should be safe to write. Text::Redact::Secrets finds the secrets in a string by gitleaks' rules: a maintained set of regexes, keywords, entropies and allowlists, carried over from gitleaks unchanged. redact puts *REDACTED* in place of each, and find reports each, with the rule that found it.

gitleaks' rules are in Text::Redact::Secrets::Rules::Gitleaks, which names the gitleaks tag and commit they came from. gitleaks is https://github.com/gitleaks/gitleaks, copyright (c) 2019 Zachary Rice, under the MIT licence.

Beside gitleaks' rules are some of the module's own, for secrets gitleaks has no rule for, such as a password in a URL, in Text::Redact::Secrets::Rules::Dist, which says what each finds.

Nothing is exported unless asked for.

FUNCTIONS

redact

my $safe = redact($text);

Returns a copy of $text with each secret found in it replaced by *REDACTED*. $text itself is left as it was. Where two rules find secrets that overlap, the text they cover between them is replaced once.

find

my @found = find($text);

Returns each secret found in $text, in the order it appears, as a hash reference:

rule

The id of the gitleaks rule that found it, such as aws-access-token.

secret

The secret, as the rule picks it out of what it matched.

offset

Where the secret starts in $text, counting from 0.

Returns an empty list if there are none.

DIAGNOSTICS

Expected a string to redact

redact was given undef or a reference.

find was given undef or a reference.

SEE ALSO

gitleaks, whose rules these are, and Text::Redact::Secrets::Rules::Dist, the module's own.

AUTHOR

Iain Campbell <cpanic@cpan.org>

LICENSE

Copyright (c) 2026 by Iain Campbell.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself, except for gitleaks' rules, in Text::Redact::Secrets::Rules::Gitleaks, which are under gitleaks' MIT licence, in LICENSE-gitleaks.