commitwarden 0.1.1__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.
@@ -0,0 +1,26 @@
1
+ # Changelog
2
+
3
+ ## 0.1.1 (2026-12-04)
4
+
5
+ - Published on PyPI: `pipx install commitwarden`. Releases are uploaded by CI with
6
+ trusted publishing.
7
+ - The source distribution now includes the full test suite and the changelog.
8
+ - Fixed: the `generic-assignment` and `db-url-with-password` rules backtracked quadratically
9
+ on long runs of identifier characters (a 20,000-character line took up to 0.8 s). Every
10
+ rule now scans in linear time, with a regression test.
11
+ - Docs: animated demo, `SECURITY.md`, `CONTRIBUTING.md`, issue and pull request templates.
12
+
13
+ ## 0.1.0 (2026-12-03)
14
+
15
+ First release.
16
+
17
+ - Three scan modes: `--staged` (default, for pre-commit), `--all` (worktree) and
18
+ `--history` (every added line on every ref, with its commit).
19
+ - 17 provider rules (AWS, GitHub, GitLab, Slack, Stripe, Google, SendGrid, Twilio, npm,
20
+ PyPI, OpenAI, Anthropic, JWT, private keys) and 3 heuristic rules (passwords in URLs,
21
+ bearer tokens, generic secret assignments) with entropy and placeholder filtering.
22
+ - Secrets are never printed in full; findings carry a stable SHA-256 fingerprint.
23
+ - Suppression by inline `commitwarden:allow`, `.commitwardenignore` (gitignore syntax,
24
+ including `!` negation) and fingerprint baselines.
25
+ - Text and `--json` output, exit codes 0 / 1 / 2, deterministic ordering.
26
+ - pre-commit hook. No runtime dependencies, no network access.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rrezart Prebreza
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ include LICENSE README.md CHANGELOG.md
2
+ recursive-include tests *.py
@@ -0,0 +1,394 @@
1
+ Metadata-Version: 2.4
2
+ Name: commitwarden
3
+ Version: 0.1.1
4
+ Summary: Catch secrets before they're committed. Local, zero-config, no network, no telemetry.
5
+ Author: Rrezart Prebreza
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/rrezartprebreza/commitwarden
8
+ Project-URL: Issues, https://github.com/rrezartprebreza/commitwarden/issues
9
+ Project-URL: Changelog, https://github.com/rrezartprebreza/commitwarden/blob/main/CHANGELOG.md
10
+ Keywords: secrets,secret-scanning,security,git,pre-commit,credentials,devsecops
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: MacOS
16
+ Classifier: Operating System :: POSIX :: Linux
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3 :: Only
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Security
24
+ Classifier: Topic :: Software Development :: Version Control :: Git
25
+ Requires-Python: >=3.10
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest>=8; extra == "dev"
30
+ Dynamic: license-file
31
+
32
+ # commitwarden
33
+
34
+ [![CI](https://github.com/rrezartprebreza/commitwarden/actions/workflows/ci.yml/badge.svg)](https://github.com/rrezartprebreza/commitwarden/actions/workflows/ci.yml)
35
+ [![PyPI](https://img.shields.io/pypi/v/commitwarden)](https://pypi.org/project/commitwarden/)
36
+ [![Python](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13-blue)](https://github.com/rrezartprebreza/commitwarden/blob/main/pyproject.toml)
37
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green)](https://github.com/rrezartprebreza/commitwarden/blob/main/LICENSE)
38
+ [![Dependencies: none](https://img.shields.io/badge/dependencies-none-brightgreen)](https://github.com/rrezartprebreza/commitwarden/blob/main/pyproject.toml)
39
+
40
+ **Catch secrets before they're committed.** A small, local secret scanner for git
41
+ repositories: no config to write, no network calls, no telemetry, pure Python with no
42
+ runtime dependencies.
43
+
44
+ <p align="center">
45
+ <img src="https://raw.githubusercontent.com/rrezartprebreza/commitwarden/main/docs/demo.svg"
46
+ alt="Terminal: git commit is blocked because settings.py contains a GitHub token, an AWS key and a database password; after moving them to environment variables the commit goes through."
47
+ width="820">
48
+ </p>
49
+
50
+ <sub>A real session, generated by <a href="https://github.com/rrezartprebreza/commitwarden/blob/main/scripts/demo_svg.py"><code>scripts/demo_svg.py</code></a>. The keys are fakes.</sub>
51
+
52
+ ## Why
53
+
54
+ Credentials end up in git history all the time, and once pushed they have to be treated as
55
+ leaked: rotating them is the only real fix. Many scanners are large binaries, need
56
+ configuration, or send data to a service, so developers turn them off. commitwarden aims to be
57
+ the one you leave on: it works with zero setup, has no dependencies beyond Python and git,
58
+ and never touches the network.
59
+
60
+ It is a first line of defence on your machine. It does not replace server-side scanning
61
+ (such as GitHub secret scanning) or a secrets manager, and it does not rewrite history.
62
+
63
+ ## Contents
64
+
65
+ - [Install](#install)
66
+ - [Usage](#usage)
67
+ - [Output](#output)
68
+ - [What it detects](#what-it-detects)
69
+ - [What it skips](#what-it-skips)
70
+ - [Suppressing false positives](#suppressing-false-positives)
71
+ - [Use as a pre-commit hook](#use-as-a-pre-commit-hook)
72
+ - [Use in CI](#use-in-ci)
73
+ - [How it works](#how-it-works)
74
+ - [Limitations](#limitations)
75
+ - [Development](#development)
76
+
77
+ ## Install
78
+
79
+ Requires Python 3.10+ and git.
80
+
81
+ ```bash
82
+ pipx install commitwarden
83
+ ```
84
+
85
+ Or into the current environment:
86
+
87
+ ```bash
88
+ pip install commitwarden
89
+ ```
90
+
91
+ ## Usage
92
+
93
+ Run it anywhere inside a git repository. It always scans from the repository root.
94
+
95
+ | Command | Scans |
96
+ |---|---|
97
+ | `commitwarden` or `commitwarden --staged` | The staged version of every added, copied, modified or renamed file: exactly what the next commit will contain. Unstaged edits are ignored. |
98
+ | `commitwarden --all` | Every tracked file plus untracked files that are not `.gitignore`d, as they are on disk. |
99
+ | `commitwarden --history` | Every line ever added in every commit on every branch and tag, including secrets that were later deleted. Each finding names its commit. |
100
+
101
+ ### Options
102
+
103
+ | Option | Effect |
104
+ |---|---|
105
+ | `--json` | Print findings as JSON (see [Output](#output)). |
106
+ | `--baseline PATH` | Ignore findings whose fingerprint is in this file (see [Baseline](#by-fingerprint-baseline)). |
107
+ | `--no-entropy` | Turn off the rules that guess from randomness (generic assignments, bearer tokens); keep the exact provider formats. |
108
+ | `--max-commits N` | With `--history`, only look at the newest `N` commits. |
109
+ | `-q`, `--quiet` | Print nothing; rely on the exit code. |
110
+
111
+ ### Exit codes
112
+
113
+ | Code | Meaning |
114
+ |---|---|
115
+ | `0` | No secrets found. |
116
+ | `1` | At least one secret found. |
117
+ | `2` | Could not scan: not a git repository, git not installed, unreadable or malformed baseline, invalid option. |
118
+
119
+ Because errors exit `2` rather than `0`, a broken setup never looks like a clean scan.
120
+
121
+ ## Output
122
+
123
+ One line per finding on stdout, then a summary on stderr:
124
+
125
+ ```text
126
+ path:line rule redacted-secret [fingerprint] (commit …, with --history only)
127
+ ```
128
+
129
+ ```console
130
+ $ commitwarden --history
131
+ .env:1 generic-assignment x9K…4w [43b6bd32f7d6] (commit 9c513ab67a)
132
+ deploy.py:1 github-pat ghp_x7…R8tY [c3577d3c4374] (commit 7d3e2bc448)
133
+ settings.py:3 db-url-with-password Hun…s9 [1718457635e3] (commit 9c513ab67a)
134
+ settings.py:4 aws-access-key-id AKIAI…PLE [1a5d44a2dca1] (commit 9c513ab67a)
135
+
136
+ 4 secret(s) found.
137
+ ```
138
+
139
+ Here `deploy.py` was deleted in a later commit, so `--all` no longer sees it, but the token
140
+ is still in history and still needs rotating.
141
+
142
+ **Secrets are never printed in full.** Values under 12 characters show only their first 2;
143
+ longer ones show a short prefix and suffix, never more than half the value. The fingerprint
144
+ is the first 12 hex characters of the secret's SHA-256, so the same secret has the same
145
+ fingerprint in every file, commit and machine.
146
+
147
+ With `--json`:
148
+
149
+ ```json
150
+ [
151
+ {
152
+ "path": "settings.py",
153
+ "line": 4,
154
+ "rule": "aws-access-key-id",
155
+ "secret": "AKIAI…PLE",
156
+ "fingerprint": "1a5d44a2dca1"
157
+ }
158
+ ]
159
+ ```
160
+
161
+ `--history` adds a `"commit"` field with the full SHA. Findings are sorted by path, line and
162
+ rule, so the same repository always gives the same output.
163
+
164
+ ## What it detects
165
+
166
+ Exact provider formats:
167
+
168
+ | Rule | Matches |
169
+ |---|---|
170
+ | `aws-access-key-id` | AWS access key IDs (`AKIA…`, `ASIA…`, `ABIA…`, `ACCA…`, `A3T…`) |
171
+ | `aws-secret-access-key` | 40-character values assigned to `aws_secret_access_key` |
172
+ | `github-pat` | GitHub tokens: `ghp_`, `gho_`, `ghu_`, `ghs_`, `ghr_` |
173
+ | `github-fine-grained-pat` | `github_pat_…` |
174
+ | `gitlab-pat` | `glpat-…` |
175
+ | `slack-token` | `xoxa-`, `xoxb-`, `xoxe-`, `xoxo-`, `xoxp-`, `xoxr-`, `xoxs-` |
176
+ | `slack-webhook` | `https://hooks.slack.com/services/T…/B…/…` |
177
+ | `stripe-key` | Secret and restricted keys: `sk_live_`, `sk_test_`, `rk_live_`, `rk_test_` |
178
+ | `google-api-key` | `AIza…` |
179
+ | `sendgrid-key` | `SG.….…` |
180
+ | `twilio-key` | `SK` followed by 32 hex characters |
181
+ | `npm-token` | `npm_…` |
182
+ | `pypi-token` | `pypi-…` |
183
+ | `openai-key` | `sk-…`, `sk-proj-…`, `sk-svcacct-…`, `sk-admin-…` |
184
+ | `anthropic-key` | `sk-ant-…` |
185
+ | `jwt` | Three base64url segments starting with `eyJ` |
186
+ | `private-key-block` | `-----BEGIN … PRIVATE KEY-----` (RSA, EC, DSA, OpenSSH, PGP, encrypted, PKCS#8) |
187
+
188
+ Heuristic rules, which also check that the value looks real (see [How it works](#how-it-works)):
189
+
190
+ | Rule | Matches |
191
+ |---|---|
192
+ | `db-url-with-password` | The password in any `scheme://user:password@host` URL |
193
+ | `bearer-token` | `Bearer <token>`, for random-looking tokens of 20+ characters |
194
+ | `generic-assignment` | Random-looking values of 12+ characters assigned to a name containing `api_key`, `apikey`, `secret`, `token`, `password`, `passwd`, `pwd`, `auth`, `credential` or `private_key` |
195
+
196
+ The generic rule understands the common assignment styles:
197
+
198
+ ```text
199
+ STRIPE_SECRET_KEY=… .env and shell; any prefix or suffix on the name
200
+ "api_key": "…" JSON
201
+ db_password: … YAML
202
+ apiKey := "…" Go
203
+ 'clientSecret' => '…' PHP
204
+ AUTH_TOKEN=`…` backticks
205
+ ```
206
+
207
+ ## What it skips
208
+
209
+ **Values that are clearly not secrets** (heuristic rules only):
210
+
211
+ - Placeholders: anything containing `example`, `changeme`, `placeholder`, `your_`, `dummy`,
212
+ `sample`, `redacted`, `xxxxxx`, `******`, `<…>`, `${…}`, `{{…}}`, `$(…)` or `%(…)`, and
213
+ bare words like `pass`, `password` or `secret` (as in `postgres://user:pass@host`).
214
+ - References to other values: `process.env.API_KEY`, `settings.SECRET_KEY`,
215
+ `self.config.token`, `MY_OTHER_CONSTANT`.
216
+ - Stripe `pk_` keys, which are public by design.
217
+
218
+ **Files that rarely hold real secrets and are slow or noisy to scan:**
219
+
220
+ - Directories: `.git`, `node_modules`, `vendor`, `dist`, `build`, `target`, `.venv`, `venv`,
221
+ `__pycache__`, `.mypy_cache`, `.pytest_cache`, `.next`, `.terraform`, `Pods`.
222
+ - Lockfiles: `package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`, `poetry.lock`, `Cargo.lock`,
223
+ `composer.lock`, `Gemfile.lock`, `go.sum`, and any `*.lock`.
224
+ - Minified and binary assets: `.min.js`, `.min.css`, `.map`, images, fonts, archives, video,
225
+ `.wasm`.
226
+ - Any file with a NUL byte in its first 8 KB (treated as binary).
227
+ - Symlinks, which could point outside the repository.
228
+
229
+ Any of these paths can be brought back with a `!` pattern in `.commitwardenignore`.
230
+
231
+ ## Suppressing false positives
232
+
233
+ ### Inline
234
+
235
+ Put `commitwarden:allow` anywhere on the line, usually in a comment:
236
+
237
+ ```python
238
+ TEST_KEY = "sk_test_…" # commitwarden:allow
239
+ ```
240
+
241
+ ### By path: `.commitwardenignore`
242
+
243
+ A file at the repository root, in `.gitignore` syntax. Comments go on their own lines.
244
+
245
+ ```gitignore
246
+ # No slash: matches the file name at any depth
247
+ *.example
248
+ # Contains a slash: relative to the repository root
249
+ fixtures/*
250
+ # Leading slash: root only
251
+ /local-only.env
252
+ # Trailing slash: a directory, at any depth
253
+ testdata/
254
+ # ** matches any number of directories
255
+ **/snapshots/*
256
+ # ! scans a path again
257
+ !fixtures/prod.yml
258
+ ```
259
+
260
+ When several patterns match a path, the last one wins, as in `.gitignore`. A pattern that
261
+ matches a directory covers everything inside it.
262
+
263
+ ### By fingerprint: baseline
264
+
265
+ When adopting commitwarden in an existing repository, record what it finds today and fail
266
+ only on new secrets:
267
+
268
+ ```bash
269
+ commitwarden --all --json > .commitwarden-baseline.json
270
+ git add .commitwarden-baseline.json
271
+ commitwarden --all --baseline .commitwarden-baseline.json # exit 0 until something new appears
272
+ ```
273
+
274
+ The baseline can be the `--json` output as is, or just the fingerprints:
275
+
276
+ ```json
277
+ { "fingerprints": ["1a5d44a2dca1", "43b6bd32f7d6"] }
278
+ ```
279
+
280
+ A baseline holds fingerprints and redacted values only, never the secrets. A missing or
281
+ malformed baseline is an error (exit `2`), never a silent pass. It hides findings; it does not
282
+ make a leaked secret safe, so rotate anything real.
283
+
284
+ ## Use as a pre-commit hook
285
+
286
+ ### With the pre-commit framework
287
+
288
+ Add to `.pre-commit-config.yaml` in your project:
289
+
290
+ ```yaml
291
+ repos:
292
+ - repo: https://github.com/rrezartprebreza/commitwarden
293
+ rev: v0.1.1
294
+ hooks:
295
+ - id: commitwarden
296
+ ```
297
+
298
+ Then:
299
+
300
+ ```bash
301
+ pipx install pre-commit
302
+ pre-commit install
303
+ ```
304
+
305
+ The hook runs `commitwarden --staged`, so it checks exactly what is being committed.
306
+
307
+ ### As a plain git hook
308
+
309
+ ```bash
310
+ printf '#!/bin/sh\nexec commitwarden --staged\n' > .git/hooks/pre-commit
311
+ chmod +x .git/hooks/pre-commit
312
+ ```
313
+
314
+ To commit anyway in an emergency: `git commit --no-verify`.
315
+
316
+ ## Use in CI
317
+
318
+ A GitHub Actions job that fails the build when a secret is pushed:
319
+
320
+ ```yaml
321
+ name: commitwarden
322
+ on: [push, pull_request]
323
+ jobs:
324
+ scan:
325
+ runs-on: ubuntu-latest
326
+ steps:
327
+ - uses: actions/checkout@v4
328
+ with:
329
+ fetch-depth: 0 # full history, for --history
330
+ - uses: actions/setup-python@v5
331
+ with:
332
+ python-version: "3.12"
333
+ - run: pip install commitwarden
334
+ - run: commitwarden --all
335
+ - run: commitwarden --history
336
+ ```
337
+
338
+ ## How it works
339
+
340
+ 1. **List the content** with git (`git diff --cached`, `git ls-files` or `git log -p`), using
341
+ NUL-separated output and fixed options, so unusual file names and personal git settings
342
+ (`diff.noprefix`, `core.quotePath`, colours, external diff tools) don't change the result.
343
+ 2. **Skip** ignored paths and binary content.
344
+ 3. **Scan line by line.** Lines are split on `\n` only, so line numbers match your editor and
345
+ `git blame`. Lines longer than 20,000 characters are scanned up to that point.
346
+ 4. **Match each rule.** For the heuristic rules a candidate must also:
347
+ - have a [Shannon entropy](https://en.wikipedia.org/wiki/Entropy_(information_theory)) of at
348
+ least 3.5 bits per character (generic assignments and bearer tokens), which separates
349
+ random keys like `x9Kq2mZ7pL4w` from repetitive values like `aaaaaaaaaaaa`, and
350
+ - not look like a placeholder or a reference to another value.
351
+
352
+ A value already found by a provider rule is not reported again by a generic rule.
353
+ 5. **Deduplicate:** one finding per secret per file and rule, at its first line (and, in
354
+ history, its earliest commit by sort order).
355
+ 6. **Apply the baseline**, sort, print, and exit `0`, `1` or `2`.
356
+
357
+ ## Limitations
358
+
359
+ - **Line-based.** A secret split across lines is not reassembled. For private keys only the
360
+ `BEGIN` line is matched, which is enough to flag the block.
361
+ - **Heuristics miss things.** The generic rules need a secret-sounding name and a random value
362
+ of 12+ characters, so a short or dictionary-word password, or a key under an unrelated name,
363
+ can slip through. Provider rules are much more reliable.
364
+ - **Text only.** Files are read as UTF-8; secrets inside binary files, archives or images are
365
+ not found.
366
+ - **History covers added lines.** `--history` reports where a secret entered, not every commit
367
+ that still contains it. Merge commits are not diffed separately.
368
+ - **It can't tell whether a key is live.** By design it never calls a provider to check.
369
+
370
+ ## Development
371
+
372
+ ```bash
373
+ git clone https://github.com/rrezartprebreza/commitwarden
374
+ cd commitwarden
375
+ python3 -m venv .venv
376
+ .venv/bin/pip install -e ".[dev]"
377
+ .venv/bin/pytest # 190 tests
378
+ .venv/bin/commitwarden --all # the repository scans itself clean
379
+ ```
380
+
381
+ Tests live in `tests/`:
382
+
383
+ - `test_detectors.py`: every rule, assignment styles, false positives, and redaction for every
384
+ length.
385
+ - `test_allow.py`: default skips and `.commitwardenignore` patterns.
386
+ - `test_cli.py`: all three modes against real temporary git repositories, exit codes,
387
+ baselines, odd file names and personal git config.
388
+
389
+ Fake secrets in the tests are assembled from pieces (`tests/fakes.py`), so no complete token
390
+ appears in the source and the repository passes its own scan.
391
+
392
+ ## License
393
+
394
+ [MIT](https://github.com/rrezartprebreza/commitwarden/blob/main/LICENSE) © 2026 Rrezart Prebreza. See the [changelog](https://github.com/rrezartprebreza/commitwarden/blob/main/CHANGELOG.md) for release notes.