Scan and redact hardcoded credentials in source code
Project description
Credactor
The secret scanner that fixes what it finds.
Most scanners stop at detection, they hand you a list and leave the cleanup to you. Credactor finds the hardcoded secret and rewrites it in place, so remediation is one command instead of a manual chore.
# Credactor finds this…
db_password = "h8Tq2vKp9mRz4Wd"
# …and rewrites it — by default, a loud sentinel that fails closed at runtime:
db_password = "REDACTED_BY_CREDACTOR"
# …or, with --replace-with env, real code that reads from the environment:
db_password = os.environ["DB_PASSWORD"]
Redaction rewrites your working tree. If a secret has already been committed, rotate the key and scrub history too (e.g.
git filter-repo) — a rewrite isn't a substitute for revoking a leaked credential.
What makes it different
- It redacts, not just reports. In-place replacement — a loud
REDACTED_BY_CREDACTORsentinel by default, or language-aware environment-variable references (Python, JS/TS, Go, Java/Kotlin, Ruby, PHP, shell), e.g.os.environ["KEY"]. The reference parses as valid code; add the matching import (e.g.import os) if the file doesn't already have one. - Zero runtime dependencies. Pure Python 3.11+ standard library — nothing to vet, no supply chain. (An optional extra adds detection for non-UTF-8 encodings.)
- Fail-closed by design. Atomic writes, automatic
.bakbackups, symlink-boundary and file-permission guards, and full-secret masking in every output. If a safe backup can't be written, the file is skipped — never silently rewritten. - Plugs into your workflow. SARIF for GitHub Code Scanning, a read-only
--cigate with clear exit codes, a pre-commit hook (beta), and ingestion of Gitleaks / TruffleHog reports (BETA) — detect with anything, remediate with Credactor.
Install
pip install credactor
Requires Python 3.11+. No other dependencies.
From source:
git clone https://github.com/rxb06/Credactor.git
cd Credactor
pip install -e .
credactor then works from any directory.
Quick start
Run
--dry-runfirst and review the findings before redacting — false positives are possible, and under--fix-alla false positive gets rewritten. Suppress known-safe values with# credactor:ignoreor a.credactorignoreentry.
credactor --dry-run . # scan, change nothing
credactor . # scan, then redact interactively (y/n per finding)
credactor --fix-all . # redact everything after one confirmation
credactor --fix-all --yes . # redact non-interactively (CI / scripts)
credactor --ci . # read-only gate: exit 1 on findings
credactor --replace-with env . # redact to env-var references instead of the sentinel
Pre-commit hook (beta)
Hook integration is in beta — run
credactor --dry-run .manually before relying on it alone.
# .pre-commit-config.yaml
repos:
- repo: https://github.com/rxb06/Credactor
rev: v2.4.0 # pin to the latest release tag
hooks:
- id: 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 … PRIVATE KEY-----) |
Critical |
| JWTs | eyJ… three-segment tokens |
High |
| Connection strings | URLs with inline credentials (scheme://user:pass@host) |
High |
| Credential variables | password = "…", api_key = "…", secret_key = "…" |
High/Medium/Low |
| XML attributes | <add key="Password" value="…" /> |
High/Medium/Low |
| High-entropy strings | quoted hex (32–64 chars) / Base64 (60+ chars) | Medium/Low |
Deterministic provider tokens (the prefixes above) are flagged regardless of entropy; heuristic detectors (JWTs, connection strings, hex, Base64) must clear an entropy floor. Standalone hex/Base64 is flagged only when quoted — an unquoted high-entropy value is caught only on a credential-named variable, which spares git SHAs and checksums. Full detection and severity rules: see the Manual.
Credactor's edge is remediation, not out-detecting every scanner. Pair it with a dedicated detector for the broadest coverage — or run it standalone.
Detect with another scanner, redact with Credactor (BETA)
Already run Gitleaks or TruffleHog? Feed their report in and Credactor redacts the combined set, deduplicated against its own findings (higher severity wins on overlap):
gitleaks dir . -f json -r gitleaks.json
credactor --from-gitleaks gitleaks.json --fix-all --yes .
--from-gitleaks / --from-trufflehog (or an [ingest] table in .credactor.toml) require a directory target. See the CI Integration guide.
More features
- Interactive or batch redaction; a custom replacement string via
--replacement;--scan-historyto scan git commit history - Secure backups:
--secure-delete(overwrite and remove the.bak; raises the bar against casual recovery, not a forensic guarantee) or--secure-backup-dirto store backups outside the repo - Inline
# credactor:ignoreand.credactorignoreallowlists (globs,file:line, value literals) - Per-repo config via
.credactor.toml; concurrent (I/O-bound) file scanning, up to 8 workers - 28 source/config file types out of the box;
--scan-jsonto include JSON;--fail-on-errorto fail when a file can't be read
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.config.properties.xml.pem.key.crt
Plus SSH / private-key files matched by name (id_rsa, id_dsa, id_ecdsa, id_ed25519). JSON is excluded by default (high false-positive rate from API responses) — add --scan-json to include it. A file named directly on the command line is scanned even if its extension isn't in this list.
Exit codes
| Code | Meaning |
|---|---|
0 |
No findings, or all resolved |
1 |
Unresolved findings |
2 |
Error — e.g. bad path, dangerous --replacement, --ci --fix-all, or --fail-on-error with unreadable files |
Docs
| Document | Description |
|---|---|
| Setup Guide | Installation, configuration, CI/CD integration |
| Manual | Complete reference: every flag, mode, combination, replacement & backup behaviour, detection/severity, exit codes, and limitations (behaviour test-verified) |
| Examples | Common workflows with output |
| CI 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file credactor-2.4.0.tar.gz.
File metadata
- Download URL: credactor-2.4.0.tar.gz
- Upload date:
- Size: 112.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d20ec9828bfd39735acd1fdfba4161f71a4c14f9fde4c984e0ef2852dc2bcc8
|
|
| MD5 |
a2dfde16578466fb8047f6a85ca34c28
|
|
| BLAKE2b-256 |
9adc7d19cd058acc81647b755c41d33e92e984afa072eed1c9a0dafb3f89feca
|
Provenance
The following attestation bundles were made for credactor-2.4.0.tar.gz:
Publisher:
publish.yml on rxb06/Credactor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
credactor-2.4.0.tar.gz -
Subject digest:
0d20ec9828bfd39735acd1fdfba4161f71a4c14f9fde4c984e0ef2852dc2bcc8 - Sigstore transparency entry: 1747248589
- Sigstore integration time:
-
Permalink:
rxb06/Credactor@7725e987aa6f0d9d57481ccf1ea5656ad6fd9146 -
Branch / Tag:
refs/tags/v2.4.0 - Owner: https://github.com/rxb06
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7725e987aa6f0d9d57481ccf1ea5656ad6fd9146 -
Trigger Event:
release
-
Statement type:
File details
Details for the file credactor-2.4.0-py3-none-any.whl.
File metadata
- Download URL: credactor-2.4.0-py3-none-any.whl
- Upload date:
- Size: 66.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67a65dffb383df27f2c48e79ed7f39e6df2d4dec497dd05584f59ea3949ab919
|
|
| MD5 |
14d934bbaa5d4cfb4971414b52714970
|
|
| BLAKE2b-256 |
cd9f853e92ea68f1a606930605cd59e4e890a4ccb012a91c07a45bc86c692a62
|
Provenance
The following attestation bundles were made for credactor-2.4.0-py3-none-any.whl:
Publisher:
publish.yml on rxb06/Credactor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
credactor-2.4.0-py3-none-any.whl -
Subject digest:
67a65dffb383df27f2c48e79ed7f39e6df2d4dec497dd05584f59ea3949ab919 - Sigstore transparency entry: 1747248675
- Sigstore integration time:
-
Permalink:
rxb06/Credactor@7725e987aa6f0d9d57481ccf1ea5656ad6fd9146 -
Branch / Tag:
refs/tags/v2.4.0 - Owner: https://github.com/rxb06
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7725e987aa6f0d9d57481ccf1ea5656ad6fd9146 -
Trigger Event:
release
-
Statement type: