Skip to main content

Scan and redact hardcoded credentials in source code

Project description

PyPI CI License

Credactor

TL;DR: Detect and redact hardcoded credentials before they hit version control. Regex + entropy + context-aware analysis, SARIF output, pre-commit hooks, parallel scanning, automated redaction.

Credactor scans source code for hardcoded secrets — API keys, tokens, passwords, private keys, connection strings — and replaces them with language-aware environment variable references before they reach version control. It runs as a CLI tool, a pre-commit hook, or in CI pipelines. SARIF output plugs straight into GitHub Code Scanning.

credactor

Why Credactor?

Most secret scanners stop at detection. Credactor redacts in place and replaces credentials with the right env var syntax for each language — os.environ in Python, process.env in JS, System.getenv in Java, and so on. It assigns severity levels so you can triage critical findings first instead of wading through noise.

Install

pip install credactor

From source:

git clone https://github.com/rxb06/Credactor.git
cd Credactor
pip install -e .

After either method, credactor works from any directory.

Quick Start

Always run --dry-run first and review findings before redacting. False positives are possible — use # credactor:ignore or .credactorignore to suppress them.

# Scan current directory (dry run)
credactor --dry-run .

# Scan and interactively redact
credactor .

# Redact everything without prompting
credactor --fix-all .

# CI mode — exit 1 on findings
credactor --ci .

Pre-commit Hook

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/rxb06/Credactor
    rev: v2.3.3
    hooks:
      - id: credactor

Or run as a module:

python -m credactor .

Detection

Category Examples Severity
Cloud provider keys AWS (AKIA...), GCP (AIza...), Stripe (sk_live_...), Slack (xoxb-...) Critical
Platform tokens GitHub (ghp_, github_pat_), GitLab (glpat-), npm (npm_), PyPI (pypi-) Critical
Private keys PEM blocks (-----BEGIN RSA PRIVATE KEY-----) Critical
JWT tokens eyJ... three-segment tokens High
Connection strings postgresql://user:pass@host, mongodb+srv://..., redis://... High
Variable assignments password = "...", api_key = "...", db_password = "..." High/Medium
XML attributes <add key="Password" value="..." /> High
High-entropy strings Hex (32-64 chars), Base64 (60+ chars) Medium/Low

Features

  • Entropy-based detection with per-pattern thresholds to cut false positives
  • Interactive or batch redaction — review one-by-one, or --fix-all
  • Language-aware replacements (os.environ, process.env, System.getenv, etc.)
  • Git history scanning via --scan-history
  • .bak backups before any file modification
  • Inline # credactor:ignore suppression and .credactorignore allowlists
  • Per-repo config via .credactor.toml
  • Parallel scanning (8 workers) for large repos
  • SARIF 2.1.0 output with column-level annotations for GitHub Code Scanning
  • --fail-on-error to catch files that couldn't be scanned

Scanned File Types

.py .js .ts .jsx .tsx .sh .bash .env .env.* .cfg .ini .toml .yaml .yml .rb .go .java .php .cs .kt .tf .hcl .conf .properties .xml

JSON files are excluded by default (high false-positive rate from API responses). Use --scan-json to include them.

Exit Codes

Code Meaning
0 No findings, or all resolved
1 Unresolved findings
2 Error, or files skipped with --fail-on-error

Docs

Document Description
Setup Guide Installation, configuration, CI/CD integration
User Guide CLI reference, replacement modes, backup safety
Examples Common workflows with output
Integration Pre-commit hooks, CI pipelines
Security Threat model, hardening measures, known limitations
Changelog Version history
Contributing Development setup, code style, PR process
Disclaimer Limitations, safe usage, warranty

Licence

Apache 2.0. See LICENSE.

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

credactor-2.3.3.tar.gz (52.5 kB view details)

Uploaded Source

Built Distribution

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

credactor-2.3.3-py3-none-any.whl (43.1 kB view details)

Uploaded Python 3

File details

Details for the file credactor-2.3.3.tar.gz.

File metadata

  • Download URL: credactor-2.3.3.tar.gz
  • Upload date:
  • Size: 52.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for credactor-2.3.3.tar.gz
Algorithm Hash digest
SHA256 7e70636b02575923e2549753b8d0218b3b9cad12d95d826692f0650efe60bf87
MD5 278d21a733a94c2d52a02a78f442d1e3
BLAKE2b-256 83b160c6f09f61893f1a0faec026570b709f91cbb52a210a6194bbb447c4ef72

See more details on using hashes here.

Provenance

The following attestation bundles were made for credactor-2.3.3.tar.gz:

Publisher: publish.yml on rxb06/Credactor

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

File details

Details for the file credactor-2.3.3-py3-none-any.whl.

File metadata

  • Download URL: credactor-2.3.3-py3-none-any.whl
  • Upload date:
  • Size: 43.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for credactor-2.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4a167290b9d5f9332b7d56012dbb8db0ba0f907bf94f656723c5234dfe5d8fd6
MD5 4b7f51861acfd5fbd1599cb19622712c
BLAKE2b-256 0fa8b7ef8f405553bb933bb5ca203d8c42d152c0e21991f7215f63add5a8bac4

See more details on using hashes here.

Provenance

The following attestation bundles were made for credactor-2.3.3-py3-none-any.whl:

Publisher: publish.yml on rxb06/Credactor

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