Skip to main content

secretmask

Lianes8 Certified

Typed, zero-dependency secret masker: redact API keys, tokens, passwords, emails and card numbers in strings, logs, JSON and nested data before they are stored.

pip install secretmask

Python 3.10 or later. No runtime dependencies. Full guide: GUIDE.md · changes: CHANGELOG.md.

The problem

A log line, an error report or a debug dump is the easiest place for a credential to leak: logging writes whatever it is given, and a request payload or an exception message often carries an Authorization header, a database URL with its password, or a cloud key. secretmask cleans the text or the data before it leaves your process.

Quick start

from secretmask import mask, mask_text

print(mask_text("Authorization: Bearer abc123def456ghi"))
# Authorization: Bearer ***

print(mask_text("db=postgres://app:s3cr3t@db:5432/main card 4242 4242 4242 4242"))
# db=postgres://app:***@db:5432/main card ***

payload = {"user": "ada", "db_password": "hunter2", "note": "mail ada@example.com"}
print(mask(payload))
# {'user': 'ada', 'db_password': '***', 'note': 'mail ***'}

mask walks dicts, lists and tuples: the value of a sensitive key (password, apiKey, X-Api-Key, client_secret, ...) is hidden whole, every other string is scanned. The input is never changed.

Choose how secrets are shown, add your own detectors, keep known values:

from secretmask import MaskConfig, SecretMask

masker = SecretMask(
    MaskConfig(
        strategy="label",  # or "full", "partial", "hash"
        extra_patterns=(("ticket", r"TCK-\d{4}"),),
        allowlist=("support@example.com",),
    )
)
print(masker.mask_text("TCK-1234 from ada@example.com, cc support@example.com"))
# <redacted:ticket> from <redacted:email>, cc support@example.com

From the shell, on a file, standard input or JSON:

$ secretmask "token=abc123"
token=***
$ secretmask --strategy hash < app.log > app.masked.log
$ echo '{"password": "p", "user": "ada"}' | secretmask --json
{"password": "***", "user": "ada"}

What it finds

Vendor formats as each vendor documents them: AWS access key ids (AKIA, ASIA, ABIA, ACCA), GitHub tokens (ghp_, gho_, ghu_, ghs_, ghr_, github_pat_), Stripe secret, restricted and webhook keys, Slack tokens and webhook URLs, Google API keys, OpenAI-style sk- keys, JWTs, and PEM, OpenSSH and OpenPGP private keys. Generic shapes: passwords in URLs and connection strings, Basic and Bearer credentials, key = value assignments whose key names a secret, email addresses, and card numbers that pass the Luhn checksum. The guide lists every detector with its source.

The detectors are checked against the vendors' own documentation and RFC examples, and against the rule sets of gitleaks, trufflehog and detect-secrets: whatever those tools call a secret in the test corpus is hidden.

Why another one

  • scrubadub finds personal data with natural-language tooling and depends on textblob, scikit-learn and six other packages; it is not aimed at credentials.
  • loggingredactor and misprint are logging filters: they redact records as they pass through logging, not a string or a payload you hold.
  • detect-secrets, gitleaks and trufflehog scan repositories and files and report findings; they do not hand back a cleaned copy of a string.

secretmask is a plain function you can call anywhere (a log formatter, an error handler, an API response, a CLI pipe) that already knows the common credential formats, masks nested data by key, and depends on nothing.

License

MIT. See LICENSE.

Metadata

Release files for secretmask 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for secretmask 1.0.0
File Size Uploaded Provenance Actions
secretmask-1.0.0.tar.gz 144.0 kB Without provenance Details for secretmask-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for secretmask 1.0.0
File Interpreter ABI Platform Actions
secretmask-1.0.0-py3-none-any.whl Python 3 none any Details for secretmask-1.0.0-py3-none-any.whl

Total release size: 168.7 kB

Release files / secretmask-1.0.0.tar.gz

Download URL secretmask-1.0.0.tar.gz
Size 144.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a1fab9a05a10995ea5c32cf957b6a5d9a909f6ecddc8a574888bad1953e92c35
BLAKE2b-256 checksum
How to use checksums
a4d73b7f2bac0bb93eab8e475721e8c7d9baf48f672cc7a6e26f19f36599a836
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Release files / secretmask-1.0.0-py3-none-any.whl

Download URL secretmask-1.0.0-py3-none-any.whl
Size 24.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ef703215d3a005ea24bc0cb874150aa16e648abb96968a62f92c9e98699d8457
BLAKE2b-256 checksum
How to use checksums
caa379b71eec0f9058f40ca07d74153c9fbf65d5dd6402da4843bdff471c4565
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Security for secretmask 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page