secretscreen 0.3.0__tar.gz → 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. {secretscreen-0.3.0 → secretscreen-0.5.0}/.github/workflows/ci.yml +4 -1
  2. secretscreen-0.5.0/.github/workflows/codeql.yml +32 -0
  3. {secretscreen-0.3.0 → secretscreen-0.5.0}/.github/workflows/publish.yml +1 -1
  4. {secretscreen-0.3.0 → secretscreen-0.5.0}/.github/workflows/scorecard.yml +1 -1
  5. secretscreen-0.5.0/PKG-INFO +240 -0
  6. secretscreen-0.5.0/README.md +208 -0
  7. {secretscreen-0.3.0 → secretscreen-0.5.0}/pyproject.toml +1 -1
  8. {secretscreen-0.3.0 → secretscreen-0.5.0}/src/secretscreen/__init__.py +1 -1
  9. secretscreen-0.5.0/src/secretscreen/_cli.py +818 -0
  10. secretscreen-0.5.0/src/secretscreen/_config.py +381 -0
  11. {secretscreen-0.3.0 → secretscreen-0.5.0}/src/secretscreen/_core.py +245 -15
  12. {secretscreen-0.3.0 → secretscreen-0.5.0}/src/secretscreen/_urls.py +14 -0
  13. {secretscreen-0.3.0 → secretscreen-0.5.0}/tests/test_cli.py +27 -0
  14. secretscreen-0.5.0/tests/test_config.py +642 -0
  15. {secretscreen-0.3.0 → secretscreen-0.5.0}/tests/test_core.py +104 -2
  16. secretscreen-0.5.0/tests/test_explain.py +255 -0
  17. {secretscreen-0.3.0 → secretscreen-0.5.0}/tests/test_urls.py +34 -0
  18. secretscreen-0.5.0/tests/test_yaml_and_prefixes.py +248 -0
  19. secretscreen-0.3.0/.github/workflows/codeql.yml +0 -29
  20. secretscreen-0.3.0/PKG-INFO +0 -138
  21. secretscreen-0.3.0/README.md +0 -106
  22. secretscreen-0.3.0/src/secretscreen/_cli.py +0 -265
  23. {secretscreen-0.3.0 → secretscreen-0.5.0}/.github/FUNDING.yml +0 -0
  24. {secretscreen-0.3.0 → secretscreen-0.5.0}/.github/ISSUE_TEMPLATE/bug_report.yml +0 -0
  25. {secretscreen-0.3.0 → secretscreen-0.5.0}/.github/dependabot.yml +0 -0
  26. {secretscreen-0.3.0 → secretscreen-0.5.0}/.github/pull_request_template.md +0 -0
  27. {secretscreen-0.3.0 → secretscreen-0.5.0}/.github/workflows/dependabot-automerge.yml +0 -0
  28. {secretscreen-0.3.0 → secretscreen-0.5.0}/.gitignore +0 -0
  29. {secretscreen-0.3.0 → secretscreen-0.5.0}/CODE_OF_CONDUCT.md +0 -0
  30. {secretscreen-0.3.0 → secretscreen-0.5.0}/CONTRIBUTING.md +0 -0
  31. {secretscreen-0.3.0 → secretscreen-0.5.0}/LICENSE +0 -0
  32. {secretscreen-0.3.0 → secretscreen-0.5.0}/NOTICE +0 -0
  33. {secretscreen-0.3.0 → secretscreen-0.5.0}/SECURITY.md +0 -0
  34. {secretscreen-0.3.0 → secretscreen-0.5.0}/docs/audits/security-audit-2026-04-05.md +0 -0
  35. {secretscreen-0.3.0 → secretscreen-0.5.0}/src/secretscreen/_entropy.py +0 -0
  36. {secretscreen-0.3.0 → secretscreen-0.5.0}/src/secretscreen/_formats.py +0 -0
  37. {secretscreen-0.3.0 → secretscreen-0.5.0}/src/secretscreen/_keys.py +0 -0
  38. {secretscreen-0.3.0 → secretscreen-0.5.0}/src/secretscreen/_parsers.py +0 -0
  39. {secretscreen-0.3.0 → secretscreen-0.5.0}/src/secretscreen/gitleaks.toml +0 -0
  40. {secretscreen-0.3.0 → secretscreen-0.5.0}/src/secretscreen/py.typed +0 -0
  41. {secretscreen-0.3.0 → secretscreen-0.5.0}/tests/__init__.py +0 -0
  42. {secretscreen-0.3.0 → secretscreen-0.5.0}/tests/test_architecture.py +0 -0
  43. {secretscreen-0.3.0 → secretscreen-0.5.0}/tests/test_entropy.py +0 -0
  44. {secretscreen-0.3.0 → secretscreen-0.5.0}/tests/test_formats.py +0 -0
  45. {secretscreen-0.3.0 → secretscreen-0.5.0}/tests/test_keys.py +0 -0
  46. {secretscreen-0.3.0 → secretscreen-0.5.0}/tests/test_parsers.py +0 -0
@@ -3,8 +3,11 @@ name: CI
3
3
  on:
4
4
  push:
5
5
  branches: [main]
6
+ # No `branches:` filter. Gating on the base branch means a stacked pull
7
+ # request — one opened against another feature branch — runs nothing, and
8
+ # reports only the skipped automerge job, which reads like a pass. Push is
9
+ # still limited to main so feature-branch pushes do not double-run.
6
10
  pull_request:
7
- branches: [main]
8
11
 
9
12
  concurrency:
10
13
  group: ${{ github.workflow }}-${{ github.ref }}
@@ -0,0 +1,32 @@
1
+ name: CodeQL
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ # No `branches:` filter. Gating on the base branch means a stacked pull
7
+ # request — one opened against another feature branch — runs nothing, and
8
+ # reports only the skipped automerge job, which reads like a pass. Push is
9
+ # still limited to main so feature-branch pushes do not double-run.
10
+ pull_request:
11
+ schedule:
12
+ - cron: "0 6 * * 3"
13
+
14
+ permissions:
15
+ security-events: write
16
+
17
+ jobs:
18
+ analyze:
19
+ runs-on: ubuntu-latest
20
+ steps:
21
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
22
+
23
+ - name: Initialize CodeQL
24
+ uses: github/codeql-action/init@f205ea1c3313d32999d8d6a48b4f6530d4437b38 # v4.37.4
25
+ with:
26
+ languages: python
27
+
28
+ - name: Autobuild
29
+ uses: github/codeql-action/autobuild@f205ea1c3313d32999d8d6a48b4f6530d4437b38 # v4.37.4
30
+
31
+ - name: Perform CodeQL Analysis
32
+ uses: github/codeql-action/analyze@f205ea1c3313d32999d8d6a48b4f6530d4437b38 # v4.37.4
@@ -25,4 +25,4 @@ jobs:
25
25
  python -m build
26
26
 
27
27
  - name: Publish to PyPI
28
- uses: pypa/gh-action-pypi-publish@ba38be9e461d3875417946c167d0b5f3d385a247 # v1.14.1
28
+ uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2
@@ -30,6 +30,6 @@ jobs:
30
30
  publish_results: true
31
31
 
32
32
  - name: Upload to code-scanning
33
- uses: github/codeql-action/upload-sarif@e4fba868fa4b1b91e1fdab776edc8cfbe6e9fb81 # v4.37.3
33
+ uses: github/codeql-action/upload-sarif@f205ea1c3313d32999d8d6a48b4f6530d4437b38 # v4.37.4
34
34
  with:
35
35
  sarif_file: results.sarif
@@ -0,0 +1,240 @@
1
+ Metadata-Version: 2.4
2
+ Name: secretscreen
3
+ Version: 0.5.0
4
+ Summary: Detect and redact secrets in key-value pairs, dicts, and environment variables. Library and CLI.
5
+ Project-URL: Homepage, https://github.com/featurecreep-cron/secretscreen
6
+ Project-URL: Repository, https://github.com/featurecreep-cron/secretscreen
7
+ Project-URL: Issues, https://github.com/featurecreep-cron/secretscreen/issues
8
+ Author-email: Cron <cron@featurecreep.dev>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ License-File: NOTICE
12
+ Keywords: cli,command-line,docker,environment,redaction,secrets,security
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Environment :: Console
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Security
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Classifier: Topic :: Utilities
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.11
26
+ Provides-Extra: dev
27
+ Requires-Dist: mypy<3,>=2.3.0; extra == 'dev'
28
+ Requires-Dist: pytest-cov>=7.1.0; extra == 'dev'
29
+ Requires-Dist: pytest>=9.1.1; extra == 'dev'
30
+ Requires-Dist: ruff<0.17,>=0.16.0; extra == 'dev'
31
+ Description-Content-Type: text/markdown
32
+
33
+ # secretscreen
34
+
35
+ [![CI](https://github.com/featurecreep-cron/secretscreen/actions/workflows/ci.yml/badge.svg)](https://github.com/featurecreep-cron/secretscreen/actions/workflows/ci.yml)
36
+ [![Codecov](https://codecov.io/gh/featurecreep-cron/secretscreen/graph/badge.svg)](https://codecov.io/gh/featurecreep-cron/secretscreen)
37
+ [![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/featurecreep-cron/secretscreen/badge)](https://scorecard.dev/viewer/?uri=github.com/featurecreep-cron/secretscreen)
38
+ [![License: MIT](https://img.shields.io/github/license/featurecreep-cron/secretscreen)](https://github.com/featurecreep-cron/secretscreen/blob/main/LICENSE)
39
+ [![Python](https://img.shields.io/python/required-version-toml?tomlFilePath=https%3A%2F%2Fraw.githubusercontent.com%2Ffeaturecreep-cron%2Fsecretscreen%2Fmain%2Fpyproject.toml)](https://www.python.org/downloads/)
40
+ [![PyPI](https://img.shields.io/pypi/v/secretscreen)](https://pypi.org/project/secretscreen/)
41
+ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
42
+
43
+ Detect and redact secrets in key-value pairs, dicts, and environment variables.
44
+
45
+ Best-effort defense-in-depth. Not a security boundary.
46
+
47
+ ## Install
48
+
49
+ As a library:
50
+
51
+ ```
52
+ pip install secretscreen
53
+ ```
54
+
55
+ As a command-line tool — `pipx` or `uv` keep it in its own environment and put `secretscreen` on your PATH everywhere, rather than only in whichever venv is active:
56
+
57
+ ```
58
+ pipx install secretscreen
59
+ uv tool install secretscreen
60
+ ```
61
+
62
+ Zero dependencies, Python 3.11+.
63
+
64
+ ## Quick start
65
+
66
+ ```python
67
+ from secretscreen import redact_pair, redact_dict, audit_dict, Mode
68
+
69
+ # Single pair
70
+ redact_pair("DB_PASSWORD", "hunter2") # → "[REDACTED]"
71
+ redact_pair("APP_NAME", "myapp") # → "myapp"
72
+
73
+ # Dict with recursion
74
+ redact_dict({"db": {"password": "x", "host": "localhost"}})
75
+ # → {"db": {"password": "[REDACTED]", "host": "localhost"}}
76
+
77
+ # Aggressive mode (adds entropy detection)
78
+ redact_dict(env, mode=Mode.AGGRESSIVE)
79
+
80
+ # Audit mode (structured findings, no mutation)
81
+ findings = audit_dict(env)
82
+ # → [Finding(key="DB_PASSWORD", reason="key_pattern:password", ...)]
83
+
84
+ # Custom safe suffixes (keys ending with these are never redacted)
85
+ redact_dict(env, safe_suffixes=("_config", "_enabled"))
86
+ ```
87
+
88
+ ## Command line
89
+
90
+ The library only helps Python callers. The CLI covers the shell side — `docker exec`, Makefiles, CI logs, anything you are about to paste somewhere.
91
+
92
+ ```
93
+ secretscreen tandoor.env # redact and print, cat-like
94
+ docker exec app env | secretscreen # scrub a stream before it hits your terminal
95
+ secretscreen --audit config.json # findings only, no values, exit 1 if any
96
+ ```
97
+
98
+ ```
99
+ secretscreen [FILE...] reads stdin when FILE is omitted or '-'
100
+ --audit report findings without values; exit 1 if any
101
+ --format env|json|ini|yaml|dsn|auto default: auto-detect from extension, then content
102
+ --aggressive add entropy detection; more false positives
103
+ --explain account on stderr for every value, including the untouched ones
104
+ --replacement TEXT default: [REDACTED]
105
+ ```
106
+
107
+ Redaction is structural, not line-based: it parses the format, so it catches `DB_PASSWORD=hunter2` on the key name and rewrites `postgres://admin:s3cr3t@host/db` to `postgres://admin:REDACTED@host/db` without destroying the rest of the line. Comments, blank lines, quoting, `export` prefixes, INI sections and `:` separators all survive the round trip.
108
+
109
+ Inside a URL the replacement drops its brackets, because `[` in that position makes the result unparseable — screening already-screened output would otherwise destroy it.
110
+
111
+ ### Compose files and grep output
112
+
113
+ ```
114
+ $ secretscreen compose.yaml
115
+ # Watchtower stack
116
+ services:
117
+ watchtower:
118
+ image: containrrr/watchtower
119
+ environment:
120
+ WATCHTOWER_NOTIFICATION_URL: discord://REDACTED@1234567890
121
+ WATCHTOWER_CLEANUP: "true"
122
+ # keep an eye on this one
123
+ restart: unless-stopped
124
+ ```
125
+
126
+ Indentation, comments, and block openers (`services:`) survive; only values are touched. List entries are screened whether they carry a key (`- DB_PASSWORD=hunter2`) or not (`- discord://token@id`).
127
+
128
+ This is **line-oriented, not a real YAML parse** — a parser would mean a third-party dependency, and this package is stdlib-only on purpose. Block scalars (`|`, `>`) are the visible consequence: their bodies are not `key: value`, so they are redacted and reported rather than quietly passed through.
129
+
130
+ grep's `file:NN:` and `file-NN-` markers are recognised and stripped before parsing, then put back on output, so `grep -rn SECRET ~/stacks | secretscreen` keeps its file-and-line context:
131
+
132
+ ```
133
+ $ grep -n 'NOTIFICATION' compose.yaml | secretscreen
134
+ secretscreen: detected grep-style line prefixes; stripped before parsing, restored on output
135
+ 6: WATCHTOWER_NOTIFICATION_URL: discord://REDACTED@1234567890
136
+ ```
137
+
138
+ That stripping is what makes colon-separated detection safe to attempt at all. Without it the first colon on the line belongs to grep's line number, the key becomes `6`, and the whole remainder — secret included — becomes one value that matches nothing. So when the input is only partly prefixed and the shape is ambiguous, the sniffer refuses the colon format and falls back to `env`, which redacts what it cannot parse. Useless output beats quiet output.
139
+
140
+ One case stays deliberately blunt: a single stream mixing formats, such as `grep -rn` across both `.env` and `.yaml` files, picks the majority format and redacts the rest wholesale. Loud and safe rather than half-parsed.
141
+
142
+ ### Config
143
+
144
+ Once you have found a false positive, `--explain` tells you which key it was. A config file stops you diagnosing it again next run.
145
+
146
+ ```toml
147
+ # ~/.config/secretscreen.toml or .secretscreen.toml beside a stack
148
+
149
+ # Never redact these. Exact key names — no wildcards.
150
+ show = ["DEPLOY_PUBLIC_KEY"]
151
+
152
+ # Always redact these. Globs are fine.
153
+ hide = ["*_NOTIFICATION_URL", "*_WEBHOOK_URL"]
154
+
155
+ [detection]
156
+ mode = "normal" # normal | aggressive
157
+ entropy_threshold = 4.5
158
+
159
+ # Applies only while this filename is being processed.
160
+ [files."demo.env"]
161
+ show = ["API_TOKEN"]
162
+ ```
163
+
164
+ Order: user config, then `.secretscreen.toml` files discovered upward from **each input file**, nearest last, then flags. Lists union rather than replace, so a closer file extends the broader one instead of silently discarding it. Discovery runs per input, so `secretscreen a/compose.yaml b/compose.yaml` can pick up a different config beside each. Add `root = true` to stop the upward walk.
165
+
166
+ **`hide` takes globs. `show` does not.** `show = ["*_KEY"]` would print `AWS_SECRET_ACCESS_KEY`, and it would go on matching keys nobody has written yet. Every show entry is a credential you are choosing to print, so every entry gets named in full. `hide` always wins over `show`, at every scope.
167
+
168
+ The same asymmetry decides what a rule can cover in JSON. `hide` names a key and takes whatever that key holds — a string, a port number, a whole object — and replaces all of it, because the shape and key names of a hidden subtree are usually the half worth hiding. `show` is honoured for a string and refused for anything else, with a note on stderr: vouching for one named key is a decision about one value, and vouching for an object is a decision about values nobody has added yet. In a `--format dsn` stream the whole line is the value, and rules match the key `dsn`.
169
+
170
+ **A discovered project config may tighten redaction but not relax it.** A `.secretscreen.toml` can arrive with a repository you cloned five minutes ago, or be dropped in a shared directory by anyone who can write there, so every setting one carries is read as a request to tighten:
171
+
172
+ | setting | from a discovered config |
173
+ |---|---|
174
+ | `hide` | applied |
175
+ | `show` | ignored |
176
+ | `[detection] mode` | only `normal` → `aggressive` |
177
+ | `[detection] entropy_threshold` | only downward |
178
+ | `root` | ignored |
179
+
180
+ `--trust-config` honours all five. Each ignored setting is named on stderr, so a rule that did not fire says so rather than looking like one that did.
181
+
182
+ The three settings below `show` matter as much as `show` does. `show` prints a credential and is the obvious one; `entropy_threshold = 99` and `mode = "normal"` stop a credential being *found*, and `root = true` needs no rules of its own — it ends the upward walk before your own config one directory up is ever read. All four end with a secret on stdout and `--audit` exiting 0.
183
+
184
+ Only your own `~/.config` file, or a file you name yourself with `--config`, can loosen anything.
185
+
186
+ Every loaded config is named on stderr, and a malformed one — bad TOML, an unknown setting, a wildcard where none is allowed — is fatal rather than skipped. A typo that silently disabled a `hide` rule would leave you believing you had configured something you had not.
187
+
188
+ Equivalent flags exist for one-off use: `--show KEY`, `--hide GLOB`, `--entropy-threshold N`, `--no-config`, and `--config FILE` — which uses that file *only*, skipping both discovery and your own `~/.config`, and trusts it because you named it.
189
+
190
+ ### Knowing what was left alone
191
+
192
+ A missed secret is invisible: the output looks screened and nothing says otherwise. `--explain` writes an account of every value to **stderr**, so stdout stays a usable redacted stream and `secretscreen app.env --explain > clean.env` still works.
193
+
194
+ ```
195
+ $ secretscreen watchtower.env --explain > screened.env
196
+ secretscreen: explain — key names and reasons only, no values
197
+ redacted WATCHTOWER_NOTIFICATION_URL url_credentials credential in userinfo position
198
+ vetoed GF_OAUTH_TOKEN_URL key_pattern matched 'token', suppressed by safe suffix '_url'
199
+ clean IMAGE_DIGEST - entropy 4.14 (aggressive would not flag; threshold 4.50)
200
+ clean DEPLOY_PUBLIC_KEY - entropy 4.67 (aggressive WOULD flag; threshold 4.50)
201
+ unscanned BACKUP_BLOB - 2202009 bytes exceeds the 65536-byte scan cap
202
+ ```
203
+
204
+ Four states. `redacted` and `clean` are self-explanatory; the two in between are the ones worth reading. **`vetoed`** means a rule fired and something suppressed it — that is where the tool decided to stay quiet. **`unscanned`** means the size cap skipped the value-scanning layers.
205
+
206
+ Clean lines carry the nearest miss rather than silence. The entropy figure is computed even in normal mode, where that layer never runs, so you can see what `--aggressive` would change before turning it on.
207
+
208
+ Like `--audit`, this never prints a value — paste it into a bug report as-is.
209
+
210
+ **What the exit code means:**
211
+
212
+ | Code | Meaning |
213
+ |------|---------|
214
+ | 0 | Everything was parsed and screened |
215
+ | 1 | `--audit` found secrets |
216
+ | 2 | Something could not be parsed or read — see stderr |
217
+
218
+ That third case is the one that matters. This is best-effort defense-in-depth, and a cat-replacement is exactly the tool people stop thinking about, so the CLI never prints unparsed content verbatim: a line it cannot structure is replaced with the redaction token, named on stderr, and turns the exit code non-zero. The same applies to values above the 64 KB detection cap — they are reported as unscanned rather than passed off as clean.
219
+
220
+ If you are scanning a git repository rather than config-shaped data, use [gitleaks](https://github.com/gitleaks/gitleaks) instead. That is a different job.
221
+
222
+ ## Detection layers
223
+
224
+ 1. **Key-name denylist** — substring match against ~30 known secret key patterns
225
+ 2. **Structured value parsing** — JSON, Python literals, DSN, INI, URL query params
226
+ 3. **Value-format detection** — 222 known formats via vendored [gitleaks](https://github.com/gitleaks/gitleaks) patterns (MIT)
227
+ 4. **URL credential detection** — partial redaction of `user:pass@host` URLs
228
+ 5. **Entropy detection** — Shannon entropy for machine-generated strings (aggressive mode only)
229
+
230
+ ## Contributing
231
+
232
+ Bug reports and pull requests welcome. See [CONTRIBUTING.md](CONTRIBUTING.md).
233
+
234
+ ## Support
235
+
236
+ If you find secretscreen useful, consider [buying us a coffee](https://buymeacoffee.com/featurecreep).
237
+
238
+ ## License
239
+
240
+ MIT. Gitleaks patterns are also MIT-licensed.
@@ -0,0 +1,208 @@
1
+ # secretscreen
2
+
3
+ [![CI](https://github.com/featurecreep-cron/secretscreen/actions/workflows/ci.yml/badge.svg)](https://github.com/featurecreep-cron/secretscreen/actions/workflows/ci.yml)
4
+ [![Codecov](https://codecov.io/gh/featurecreep-cron/secretscreen/graph/badge.svg)](https://codecov.io/gh/featurecreep-cron/secretscreen)
5
+ [![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/featurecreep-cron/secretscreen/badge)](https://scorecard.dev/viewer/?uri=github.com/featurecreep-cron/secretscreen)
6
+ [![License: MIT](https://img.shields.io/github/license/featurecreep-cron/secretscreen)](https://github.com/featurecreep-cron/secretscreen/blob/main/LICENSE)
7
+ [![Python](https://img.shields.io/python/required-version-toml?tomlFilePath=https%3A%2F%2Fraw.githubusercontent.com%2Ffeaturecreep-cron%2Fsecretscreen%2Fmain%2Fpyproject.toml)](https://www.python.org/downloads/)
8
+ [![PyPI](https://img.shields.io/pypi/v/secretscreen)](https://pypi.org/project/secretscreen/)
9
+ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
10
+
11
+ Detect and redact secrets in key-value pairs, dicts, and environment variables.
12
+
13
+ Best-effort defense-in-depth. Not a security boundary.
14
+
15
+ ## Install
16
+
17
+ As a library:
18
+
19
+ ```
20
+ pip install secretscreen
21
+ ```
22
+
23
+ As a command-line tool — `pipx` or `uv` keep it in its own environment and put `secretscreen` on your PATH everywhere, rather than only in whichever venv is active:
24
+
25
+ ```
26
+ pipx install secretscreen
27
+ uv tool install secretscreen
28
+ ```
29
+
30
+ Zero dependencies, Python 3.11+.
31
+
32
+ ## Quick start
33
+
34
+ ```python
35
+ from secretscreen import redact_pair, redact_dict, audit_dict, Mode
36
+
37
+ # Single pair
38
+ redact_pair("DB_PASSWORD", "hunter2") # → "[REDACTED]"
39
+ redact_pair("APP_NAME", "myapp") # → "myapp"
40
+
41
+ # Dict with recursion
42
+ redact_dict({"db": {"password": "x", "host": "localhost"}})
43
+ # → {"db": {"password": "[REDACTED]", "host": "localhost"}}
44
+
45
+ # Aggressive mode (adds entropy detection)
46
+ redact_dict(env, mode=Mode.AGGRESSIVE)
47
+
48
+ # Audit mode (structured findings, no mutation)
49
+ findings = audit_dict(env)
50
+ # → [Finding(key="DB_PASSWORD", reason="key_pattern:password", ...)]
51
+
52
+ # Custom safe suffixes (keys ending with these are never redacted)
53
+ redact_dict(env, safe_suffixes=("_config", "_enabled"))
54
+ ```
55
+
56
+ ## Command line
57
+
58
+ The library only helps Python callers. The CLI covers the shell side — `docker exec`, Makefiles, CI logs, anything you are about to paste somewhere.
59
+
60
+ ```
61
+ secretscreen tandoor.env # redact and print, cat-like
62
+ docker exec app env | secretscreen # scrub a stream before it hits your terminal
63
+ secretscreen --audit config.json # findings only, no values, exit 1 if any
64
+ ```
65
+
66
+ ```
67
+ secretscreen [FILE...] reads stdin when FILE is omitted or '-'
68
+ --audit report findings without values; exit 1 if any
69
+ --format env|json|ini|yaml|dsn|auto default: auto-detect from extension, then content
70
+ --aggressive add entropy detection; more false positives
71
+ --explain account on stderr for every value, including the untouched ones
72
+ --replacement TEXT default: [REDACTED]
73
+ ```
74
+
75
+ Redaction is structural, not line-based: it parses the format, so it catches `DB_PASSWORD=hunter2` on the key name and rewrites `postgres://admin:s3cr3t@host/db` to `postgres://admin:REDACTED@host/db` without destroying the rest of the line. Comments, blank lines, quoting, `export` prefixes, INI sections and `:` separators all survive the round trip.
76
+
77
+ Inside a URL the replacement drops its brackets, because `[` in that position makes the result unparseable — screening already-screened output would otherwise destroy it.
78
+
79
+ ### Compose files and grep output
80
+
81
+ ```
82
+ $ secretscreen compose.yaml
83
+ # Watchtower stack
84
+ services:
85
+ watchtower:
86
+ image: containrrr/watchtower
87
+ environment:
88
+ WATCHTOWER_NOTIFICATION_URL: discord://REDACTED@1234567890
89
+ WATCHTOWER_CLEANUP: "true"
90
+ # keep an eye on this one
91
+ restart: unless-stopped
92
+ ```
93
+
94
+ Indentation, comments, and block openers (`services:`) survive; only values are touched. List entries are screened whether they carry a key (`- DB_PASSWORD=hunter2`) or not (`- discord://token@id`).
95
+
96
+ This is **line-oriented, not a real YAML parse** — a parser would mean a third-party dependency, and this package is stdlib-only on purpose. Block scalars (`|`, `>`) are the visible consequence: their bodies are not `key: value`, so they are redacted and reported rather than quietly passed through.
97
+
98
+ grep's `file:NN:` and `file-NN-` markers are recognised and stripped before parsing, then put back on output, so `grep -rn SECRET ~/stacks | secretscreen` keeps its file-and-line context:
99
+
100
+ ```
101
+ $ grep -n 'NOTIFICATION' compose.yaml | secretscreen
102
+ secretscreen: detected grep-style line prefixes; stripped before parsing, restored on output
103
+ 6: WATCHTOWER_NOTIFICATION_URL: discord://REDACTED@1234567890
104
+ ```
105
+
106
+ That stripping is what makes colon-separated detection safe to attempt at all. Without it the first colon on the line belongs to grep's line number, the key becomes `6`, and the whole remainder — secret included — becomes one value that matches nothing. So when the input is only partly prefixed and the shape is ambiguous, the sniffer refuses the colon format and falls back to `env`, which redacts what it cannot parse. Useless output beats quiet output.
107
+
108
+ One case stays deliberately blunt: a single stream mixing formats, such as `grep -rn` across both `.env` and `.yaml` files, picks the majority format and redacts the rest wholesale. Loud and safe rather than half-parsed.
109
+
110
+ ### Config
111
+
112
+ Once you have found a false positive, `--explain` tells you which key it was. A config file stops you diagnosing it again next run.
113
+
114
+ ```toml
115
+ # ~/.config/secretscreen.toml or .secretscreen.toml beside a stack
116
+
117
+ # Never redact these. Exact key names — no wildcards.
118
+ show = ["DEPLOY_PUBLIC_KEY"]
119
+
120
+ # Always redact these. Globs are fine.
121
+ hide = ["*_NOTIFICATION_URL", "*_WEBHOOK_URL"]
122
+
123
+ [detection]
124
+ mode = "normal" # normal | aggressive
125
+ entropy_threshold = 4.5
126
+
127
+ # Applies only while this filename is being processed.
128
+ [files."demo.env"]
129
+ show = ["API_TOKEN"]
130
+ ```
131
+
132
+ Order: user config, then `.secretscreen.toml` files discovered upward from **each input file**, nearest last, then flags. Lists union rather than replace, so a closer file extends the broader one instead of silently discarding it. Discovery runs per input, so `secretscreen a/compose.yaml b/compose.yaml` can pick up a different config beside each. Add `root = true` to stop the upward walk.
133
+
134
+ **`hide` takes globs. `show` does not.** `show = ["*_KEY"]` would print `AWS_SECRET_ACCESS_KEY`, and it would go on matching keys nobody has written yet. Every show entry is a credential you are choosing to print, so every entry gets named in full. `hide` always wins over `show`, at every scope.
135
+
136
+ The same asymmetry decides what a rule can cover in JSON. `hide` names a key and takes whatever that key holds — a string, a port number, a whole object — and replaces all of it, because the shape and key names of a hidden subtree are usually the half worth hiding. `show` is honoured for a string and refused for anything else, with a note on stderr: vouching for one named key is a decision about one value, and vouching for an object is a decision about values nobody has added yet. In a `--format dsn` stream the whole line is the value, and rules match the key `dsn`.
137
+
138
+ **A discovered project config may tighten redaction but not relax it.** A `.secretscreen.toml` can arrive with a repository you cloned five minutes ago, or be dropped in a shared directory by anyone who can write there, so every setting one carries is read as a request to tighten:
139
+
140
+ | setting | from a discovered config |
141
+ |---|---|
142
+ | `hide` | applied |
143
+ | `show` | ignored |
144
+ | `[detection] mode` | only `normal` → `aggressive` |
145
+ | `[detection] entropy_threshold` | only downward |
146
+ | `root` | ignored |
147
+
148
+ `--trust-config` honours all five. Each ignored setting is named on stderr, so a rule that did not fire says so rather than looking like one that did.
149
+
150
+ The three settings below `show` matter as much as `show` does. `show` prints a credential and is the obvious one; `entropy_threshold = 99` and `mode = "normal"` stop a credential being *found*, and `root = true` needs no rules of its own — it ends the upward walk before your own config one directory up is ever read. All four end with a secret on stdout and `--audit` exiting 0.
151
+
152
+ Only your own `~/.config` file, or a file you name yourself with `--config`, can loosen anything.
153
+
154
+ Every loaded config is named on stderr, and a malformed one — bad TOML, an unknown setting, a wildcard where none is allowed — is fatal rather than skipped. A typo that silently disabled a `hide` rule would leave you believing you had configured something you had not.
155
+
156
+ Equivalent flags exist for one-off use: `--show KEY`, `--hide GLOB`, `--entropy-threshold N`, `--no-config`, and `--config FILE` — which uses that file *only*, skipping both discovery and your own `~/.config`, and trusts it because you named it.
157
+
158
+ ### Knowing what was left alone
159
+
160
+ A missed secret is invisible: the output looks screened and nothing says otherwise. `--explain` writes an account of every value to **stderr**, so stdout stays a usable redacted stream and `secretscreen app.env --explain > clean.env` still works.
161
+
162
+ ```
163
+ $ secretscreen watchtower.env --explain > screened.env
164
+ secretscreen: explain — key names and reasons only, no values
165
+ redacted WATCHTOWER_NOTIFICATION_URL url_credentials credential in userinfo position
166
+ vetoed GF_OAUTH_TOKEN_URL key_pattern matched 'token', suppressed by safe suffix '_url'
167
+ clean IMAGE_DIGEST - entropy 4.14 (aggressive would not flag; threshold 4.50)
168
+ clean DEPLOY_PUBLIC_KEY - entropy 4.67 (aggressive WOULD flag; threshold 4.50)
169
+ unscanned BACKUP_BLOB - 2202009 bytes exceeds the 65536-byte scan cap
170
+ ```
171
+
172
+ Four states. `redacted` and `clean` are self-explanatory; the two in between are the ones worth reading. **`vetoed`** means a rule fired and something suppressed it — that is where the tool decided to stay quiet. **`unscanned`** means the size cap skipped the value-scanning layers.
173
+
174
+ Clean lines carry the nearest miss rather than silence. The entropy figure is computed even in normal mode, where that layer never runs, so you can see what `--aggressive` would change before turning it on.
175
+
176
+ Like `--audit`, this never prints a value — paste it into a bug report as-is.
177
+
178
+ **What the exit code means:**
179
+
180
+ | Code | Meaning |
181
+ |------|---------|
182
+ | 0 | Everything was parsed and screened |
183
+ | 1 | `--audit` found secrets |
184
+ | 2 | Something could not be parsed or read — see stderr |
185
+
186
+ That third case is the one that matters. This is best-effort defense-in-depth, and a cat-replacement is exactly the tool people stop thinking about, so the CLI never prints unparsed content verbatim: a line it cannot structure is replaced with the redaction token, named on stderr, and turns the exit code non-zero. The same applies to values above the 64 KB detection cap — they are reported as unscanned rather than passed off as clean.
187
+
188
+ If you are scanning a git repository rather than config-shaped data, use [gitleaks](https://github.com/gitleaks/gitleaks) instead. That is a different job.
189
+
190
+ ## Detection layers
191
+
192
+ 1. **Key-name denylist** — substring match against ~30 known secret key patterns
193
+ 2. **Structured value parsing** — JSON, Python literals, DSN, INI, URL query params
194
+ 3. **Value-format detection** — 222 known formats via vendored [gitleaks](https://github.com/gitleaks/gitleaks) patterns (MIT)
195
+ 4. **URL credential detection** — partial redaction of `user:pass@host` URLs
196
+ 5. **Entropy detection** — Shannon entropy for machine-generated strings (aggressive mode only)
197
+
198
+ ## Contributing
199
+
200
+ Bug reports and pull requests welcome. See [CONTRIBUTING.md](CONTRIBUTING.md).
201
+
202
+ ## Support
203
+
204
+ If you find secretscreen useful, consider [buying us a coffee](https://buymeacoffee.com/featurecreep).
205
+
206
+ ## License
207
+
208
+ MIT. Gitleaks patterns are also MIT-licensed.
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "secretscreen"
7
- version = "0.3.0"
7
+ version = "0.5.0"
8
8
  description = "Detect and redact secrets in key-value pairs, dicts, and environment variables. Library and CLI."
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -37,4 +37,4 @@ __all__ = [
37
37
  "redact_pair",
38
38
  ]
39
39
 
40
- __version__ = "0.3.0"
40
+ __version__ = "0.5.0"