Skip to main content

mask your secrets from your logs

Project description

Tests Lint Quality codecov PyPI version Python Platform License PRs Welcome

MaskerLoggerTitle

Masker Logger

Keep Your logs safe! This formatter ensures the security of your logs and prevents sensitive data leaks. For example - Using this Formatter will print this line: logger.info(f'Dont Give Your {secrets} away') like this: Dont Give Your ****** away

Getting started

This formatter utilizes the standard logging.Formatter module. Before printing each record to any destination (file, stdout, etc.), it ensures sensitive data is masked with asterisks to prevent leaks.

Requirements

MaskerLogger Version Python Version
1.0.0+ 3.10 - 3.13
< 1.0.0 3.9 - 3.13

Install the library

pip install maskerlogger

Basic Usage

Like any formatter - just init your logger handler with the MaskerLogger formatter.

from maskerlogger import MaskerFormatter
logger = logging.getLogger('logger')
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler()
handler.setFormatter(
    MaskerFormatter("%(asctime)s %(name)s %(levelname)s %(message)s"))
logger.addHandler(handler)

skip masking

If, for some reason, you want to disable masking on a specific log line, use the SKIP_MASK mechanism.

from maskerlogger import MaskerFormatter, SKIP_MASK
...
...
logger.info('Line you want to skip', extra=SKIP_MASK)

redact

Here’s a rewritten version suitable for inclusion in a README.md file:


Partial Masking of Secrets

If you prefer to mask only a portion of a secret (rather than its entire length), you can set the redact parameter in the formatter. The redact parameter specifies the percentage of the secret to be masked.

Here’s an example of how to use it:

handler.setFormatter(
    MaskerFormatter("%(asctime)s %(name)s %(levelname)s %(message)s",
                    redact=30))

In this example, 30% of the secret will be masked. Adjust the redact value as needed to suit your requirements.

The Config File

Here's where the magic happens! Our tool is built upon the powerful Gitleaks tool, leveraging its default configuration to scan for sensitive data leaks in repositories. You can find the default configuration here

Use custom config file

To create and use your own config file, set the path when initializing the formatter:

handler.setFormatter(
    MaskerFormatter("%(asctime)s %(name)s %(levelname)s %(message)s",
                    regex_config_path="your/config/gitleaks.toml"))

Good luck!

Brought to you by OX Security

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

maskerlogger-1.0.0b3.tar.gz (24.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

maskerlogger-1.0.0b3-py3-none-any.whl (23.6 kB view details)

Uploaded Python 3

File details

Details for the file maskerlogger-1.0.0b3.tar.gz.

File metadata

  • Download URL: maskerlogger-1.0.0b3.tar.gz
  • Upload date:
  • Size: 24.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for maskerlogger-1.0.0b3.tar.gz
Algorithm Hash digest
SHA256 f1948b419a921dafb227eace63ef58aa155543b2ffcf1cf1ddc9a8f5378163a8
MD5 afe284a5dde1d2aa31e76ce98b2d6a85
BLAKE2b-256 a3179c517590be4c9cf596247dc8c1743f0d7a210ed5e192b087020e6d743ac8

See more details on using hashes here.

Provenance

The following attestation bundles were made for maskerlogger-1.0.0b3.tar.gz:

Publisher: publish.yml on oxsecurity/MaskerLogger

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file maskerlogger-1.0.0b3-py3-none-any.whl.

File metadata

  • Download URL: maskerlogger-1.0.0b3-py3-none-any.whl
  • Upload date:
  • Size: 23.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for maskerlogger-1.0.0b3-py3-none-any.whl
Algorithm Hash digest
SHA256 656e9716ca4293fd34334ed4f8c21170c4a7e672355439d8828f0d0baac54756
MD5 aadca2f38a99e0f997e5bf9131ff58d7
BLAKE2b-256 7305856af6e7a65eef72f6cccaeae9ec99d819f3c372b4d63a2da7c0954ef66b

See more details on using hashes here.

Provenance

The following attestation bundles were made for maskerlogger-1.0.0b3-py3-none-any.whl:

Publisher: publish.yml on oxsecurity/MaskerLogger

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page