leakpulse 0.4.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 (39) hide show
  1. leakpulse-0.4.0/.github/workflows/ci.yml +74 -0
  2. leakpulse-0.4.0/.github/workflows/publish.yml +80 -0
  3. leakpulse-0.4.0/.pre-commit-hooks.yaml +17 -0
  4. leakpulse-0.4.0/CHANGELOG.md +90 -0
  5. leakpulse-0.4.0/CONTRIBUTING.md +52 -0
  6. leakpulse-0.4.0/LICENSE +21 -0
  7. leakpulse-0.4.0/MANIFEST.in +6 -0
  8. leakpulse-0.4.0/PKG-INFO +315 -0
  9. leakpulse-0.4.0/README.md +284 -0
  10. leakpulse-0.4.0/SECURITY.md +34 -0
  11. leakpulse-0.4.0/action.yml +75 -0
  12. leakpulse-0.4.0/docs/distribution.md +100 -0
  13. leakpulse-0.4.0/docs/sarif.md +99 -0
  14. leakpulse-0.4.0/pyproject.toml +50 -0
  15. leakpulse-0.4.0/run_tests.py +27 -0
  16. leakpulse-0.4.0/setup.cfg +4 -0
  17. leakpulse-0.4.0/src/leakpulse/__init__.py +4 -0
  18. leakpulse-0.4.0/src/leakpulse/__main__.py +9 -0
  19. leakpulse-0.4.0/src/leakpulse/cli.py +295 -0
  20. leakpulse-0.4.0/src/leakpulse/entropy.py +66 -0
  21. leakpulse-0.4.0/src/leakpulse/exporters.py +235 -0
  22. leakpulse-0.4.0/src/leakpulse/gitutil.py +75 -0
  23. leakpulse-0.4.0/src/leakpulse/report.py +59 -0
  24. leakpulse-0.4.0/src/leakpulse/rules.py +295 -0
  25. leakpulse-0.4.0/src/leakpulse/scanner.py +357 -0
  26. leakpulse-0.4.0/src/leakpulse.egg-info/PKG-INFO +315 -0
  27. leakpulse-0.4.0/src/leakpulse.egg-info/SOURCES.txt +37 -0
  28. leakpulse-0.4.0/src/leakpulse.egg-info/dependency_links.txt +1 -0
  29. leakpulse-0.4.0/src/leakpulse.egg-info/entry_points.txt +2 -0
  30. leakpulse-0.4.0/src/leakpulse.egg-info/top_level.txt +1 -0
  31. leakpulse-0.4.0/tests/support.py +30 -0
  32. leakpulse-0.4.0/tests/test_cli.py +105 -0
  33. leakpulse-0.4.0/tests/test_cn_rules.py +162 -0
  34. leakpulse-0.4.0/tests/test_distribution.py +139 -0
  35. leakpulse-0.4.0/tests/test_entropy.py +40 -0
  36. leakpulse-0.4.0/tests/test_git.py +128 -0
  37. leakpulse-0.4.0/tests/test_reports.py +199 -0
  38. leakpulse-0.4.0/tests/test_rules.py +119 -0
  39. leakpulse-0.4.0/tests/test_scanner.py +197 -0
@@ -0,0 +1,74 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ test:
13
+ name: test (python ${{ matrix.python }})
14
+ runs-on: ${{ matrix.os }}
15
+ strategy:
16
+ fail-fast: false
17
+ matrix:
18
+ include:
19
+ # Python 3.9 is no longer preinstalled on the newest Ubuntu image.
20
+ - python: "3.9"
21
+ os: ubuntu-22.04
22
+ - python: "3.10"
23
+ os: ubuntu-latest
24
+ - python: "3.11"
25
+ os: ubuntu-latest
26
+ - python: "3.12"
27
+ os: ubuntu-latest
28
+ - python: "3.13"
29
+ os: ubuntu-latest
30
+ steps:
31
+ - uses: actions/checkout@v4
32
+ - uses: actions/setup-python@v5
33
+ with:
34
+ python-version: ${{ matrix.python }}
35
+ - name: Unit tests
36
+ run: python run_tests.py
37
+ - name: Self scan
38
+ run: PYTHONPATH=src python -m leakpulse scan . --history 0 --fail-on high --no-color
39
+
40
+ metadata:
41
+ name: validate action and workflow metadata
42
+ runs-on: ubuntu-latest
43
+ steps:
44
+ - uses: actions/checkout@v4
45
+ - uses: actions/setup-python@v5
46
+ with:
47
+ python-version: "3.12"
48
+ - name: Parse YAML files
49
+ run: |
50
+ python -m pip install --disable-pip-version-check pyyaml
51
+ python - <<'PY'
52
+ import glob, yaml
53
+ for path in ["action.yml", ".pre-commit-hooks.yaml"] + sorted(glob.glob(".github/workflows/*.yml")):
54
+ with open(path, encoding="utf-8") as fh:
55
+ yaml.safe_load(fh)
56
+ print("ok", path)
57
+ PY
58
+
59
+ build:
60
+ name: build sdist + wheel
61
+ runs-on: ubuntu-latest
62
+ steps:
63
+ - uses: actions/checkout@v4
64
+ - uses: actions/setup-python@v5
65
+ with:
66
+ python-version: "3.12"
67
+ - run: python -m pip install --upgrade build
68
+ - run: python -m build
69
+ - run: python -m pip install dist/*.whl
70
+ - run: leakpulse version
71
+ - uses: actions/upload-artifact@v4
72
+ with:
73
+ name: dist
74
+ path: dist/
@@ -0,0 +1,80 @@
1
+ name: Publish to PyPI
2
+
3
+ # Trusted Publishing (OIDC): no API token or password is stored in this repository.
4
+ # One-time setup: PyPI → Account → Publishing → add a "pending publisher" with
5
+ # project: leakpulse
6
+ # owner: stackpulse-lab
7
+ # repository: leakpulse
8
+ # workflow: publish.yml
9
+ # environment: pypi
10
+ # After the first successful upload the pending publisher becomes a normal publisher.
11
+
12
+ on:
13
+ push:
14
+ tags:
15
+ - "v*"
16
+ workflow_dispatch:
17
+
18
+ permissions:
19
+ contents: read
20
+
21
+ jobs:
22
+ test:
23
+ name: test before publish
24
+ runs-on: ubuntu-latest
25
+ steps:
26
+ - uses: actions/checkout@v4
27
+ - uses: actions/setup-python@v5
28
+ with:
29
+ python-version: "3.12"
30
+ - name: Unit tests
31
+ run: python run_tests.py
32
+
33
+ build:
34
+ name: build sdist + wheel
35
+ needs: test
36
+ runs-on: ubuntu-latest
37
+ steps:
38
+ - uses: actions/checkout@v4
39
+ - uses: actions/setup-python@v5
40
+ with:
41
+ python-version: "3.12"
42
+ - name: Verify tag matches package version
43
+ if: startsWith(github.ref, 'refs/tags/')
44
+ env:
45
+ TAG: ${{ github.ref_name }}
46
+ run: |
47
+ python - <<'PY'
48
+ import os, pathlib, re, sys
49
+ init = pathlib.Path("src/leakpulse/__init__.py").read_text(encoding="utf-8")
50
+ version = re.search(r'__version__\s*=\s*"([^"]+)"', init).group(1)
51
+ tag = os.environ["TAG"].lstrip("v")
52
+ if tag != version:
53
+ sys.exit(f"tag {os.environ['TAG']} does not match package version {version}")
54
+ print(f"tag and version agree: {version}")
55
+ PY
56
+ - run: python -m pip install --upgrade build
57
+ - run: python -m build
58
+ - run: python -m pip install dist/*.whl
59
+ - run: leakpulse version
60
+ - uses: actions/upload-artifact@v4
61
+ with:
62
+ name: dist
63
+ path: dist/
64
+
65
+ publish:
66
+ name: upload to PyPI (OIDC)
67
+ needs: build
68
+ if: startsWith(github.ref, 'refs/tags/')
69
+ runs-on: ubuntu-latest
70
+ environment:
71
+ name: pypi
72
+ url: https://pypi.org/p/leakpulse
73
+ permissions:
74
+ id-token: write # required for Trusted Publishing
75
+ steps:
76
+ - uses: actions/download-artifact@v4
77
+ with:
78
+ name: dist
79
+ path: dist/
80
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,17 @@
1
+ - id: leakpulse
2
+ name: leakpulse (staged changes)
3
+ description: Block commits that stage likely credentials; redacted output only.
4
+ entry: leakpulse scan --staged --fail-on high --no-color
5
+ language: python
6
+ types: [text]
7
+ pass_filenames: false
8
+ always_run: true
9
+
10
+ - id: leakpulse-worktree
11
+ name: leakpulse (worktree, no history)
12
+ description: Scan the working tree without walking git history.
13
+ entry: leakpulse scan . --history 0 --fail-on high --no-color
14
+ language: python
15
+ types: [text]
16
+ pass_filenames: false
17
+ always_run: true
@@ -0,0 +1,90 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here.
4
+ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and
5
+ the project adheres to [Semantic Versioning](https://semver.org/).
6
+
7
+ ## [0.4.0] - 2026-11-26
8
+
9
+ ### Added
10
+
11
+ - `scan --format {text,json,sarif,html}` and `--output FILE` for shareable reports.
12
+ `--json` stays as an alias for `--format json`; `--quiet` still suppresses clean
13
+ text output, and an explicit `--output` is always written.
14
+ - SARIF 2.1.0 export (`leakpulse/exporters.py`): all 28 regex rules plus
15
+ `high-entropy-string` in `tool.driver.rules`, severity mapped to
16
+ `error`/`warning`/`note`, percent-encoded repo-relative artifact URIs,
17
+ `partialFingerprints.leakpulse/v1`, and masked match text only.
18
+ - Self-contained HTML audit report: inline CSS, no scripts or remote assets, escaped
19
+ paths/descriptions, masked matches.
20
+ - `docs/sarif.md`: GitHub code scanning workflow (`upload-sarif`), SARIF shape,
21
+ HTML usage and a GitLab CI artifact example.
22
+ - `action.yml`: new `format` and `output` inputs; existing inputs and `exit-code`
23
+ output are unchanged.
24
+ - `tests/test_reports.py`: 15 tests covering SARIF structure/levels/URI encoding/
25
+ redaction/fingerprints, HTML escaping/no-remote-assets, and CLI format/output
26
+ behavior including the `--json` conflict.
27
+
28
+ ### Changed
29
+
30
+ - README documents the new report formats in both languages, and pins Action /
31
+ pre-commit examples to `v0.4.0`.
32
+
33
+ ## [0.3.0] - 2026-11-26
34
+
35
+ ### Added
36
+
37
+ - Zero-config composite GitHub Action (`action.yml`): installs the scanner from the
38
+ pinned tag checkout and scans with `path`, `history`, `fail-on` and `extra-args`
39
+ inputs; exposes the scanner `exit-code` and fails the step on findings.
40
+ - Expanded `.pre-commit-hooks.yaml`: visible (uncolored) output, text-only file types,
41
+ explicit `pass_filenames: false`/`always_run: true`, and a second
42
+ `leakpulse-worktree` hook for whole-tree scans without history.
43
+ - `publish.yml` using PyPI Trusted Publishing (OIDC): tag-only trigger, tests before
44
+ build, tag/`__version__` consistency check, `id-token: write`, no stored API token.
45
+ - `docs/distribution.md`: GitHub Action, pre-commit and PyPI setup, plus a comparison
46
+ of the three paths.
47
+ - `tests/test_distribution.py`: cross-checks every CLI flag used by the action/hooks
48
+ against the argparse definitions and asserts the publish workflow stays OIDC-only.
49
+
50
+ ### Changed
51
+
52
+ - README CI section now leads with the Action and documents both pre-commit hook ids.
53
+
54
+ ## [0.2.0] - 2026-11-26
55
+
56
+ ### Added
57
+
58
+ - Ten localized rules for Chinese cloud providers and domestic SaaS:
59
+ - `deepseek-key` (DeepSeek `sk-…`, reported separately from OpenAI keys),
60
+ - `aliyun-access-key-id` (`LTAI…`) and `aliyun-access-key-secret`,
61
+ - `tencent-secret-id` (`AKID…`) and `tencent-secret-key`,
62
+ - `volcengine-access-key-id` (`AKLT…`),
63
+ - `feishu-webhook`, `wecom-webhook`, `dingtalk-webhook` (only the token is captured),
64
+ - `afdian-token` (爱发电).
65
+ - Redaction regression tests for every localized rule: masked text, JSON `match` and
66
+ text reports never contain the captured credential; webhook findings never print
67
+ the full URL.
68
+ - False-positive guards: documentation URLs, env references and placeholder
69
+ values (`your_…`, `${VAR}`, repeated characters) stay quiet.
70
+ - Rule count is now 28; 77 stdlib tests (18 new).
71
+
72
+ ## [0.1.0] - 2026-11-24
73
+
74
+ ### Added
75
+
76
+ - `leakpulse scan` for worktrees, directories and individual files.
77
+ - `--staged` mode that scans the git index (pre-commit friendly).
78
+ - `--history N` mode that scans added lines of recent commits, with commit attribution.
79
+ - 18 detection rules covering major cloud, VCS, mail, payment and package-registry tokens,
80
+ private keys, URLs with embedded credentials, bearer tokens and JWTs.
81
+ - Shannon-entropy heuristic for unknown secrets (`--no-entropy`, `--entropy-threshold`).
82
+ - Redacted output, JSON reports and deterministic exit codes (`--fail-on`).
83
+ - `.leakpulseignore` (gitignore-style, with negation), inline `leakpulse:allow` and `--exclude`.
84
+ - `leakpulse install-hook` for a fail-closed native pre-commit hook.
85
+ - Stdlib-only test suite (rules, entropy, scanner, git integration, CLI) and GitHub Actions CI
86
+ on Python 3.9–3.13.
87
+
88
+ [0.3.0]: https://github.com/stackpulse-lab/leakpulse/releases/tag/v0.3.0
89
+ [0.2.0]: https://github.com/stackpulse-lab/leakpulse/releases/tag/v0.2.0
90
+ [0.1.0]: https://github.com/stackpulse-lab/leakpulse/releases/tag/v0.1.0
@@ -0,0 +1,52 @@
1
+ # Contributing to LeakPulse
2
+
3
+ Thanks for helping. This project is intentionally small: Python standard
4
+ library only, no runtime dependencies, no network access.
5
+
6
+ ## Ground rules
7
+
8
+ 1. **No new runtime dependencies.** If the standard library can do it, use it.
9
+ 2. **No network calls, telemetry or uploads.** Scanning must stay local.
10
+ 3. **Never commit real credentials.** Test fixtures must be generated at
11
+ runtime (see `tests/support.py`) and never look like live keys.
12
+ 4. **Tests first.** New rules and CLI behavior need unit tests; git features
13
+ need integration tests guarded by `skipUnless(shutil.which("git"))`.
14
+ 5. **Redact output.** Any new finding path must mask the secret in text and
15
+ JSON output. Raw values stay in memory only.
16
+
17
+ ## Development workflow
18
+
19
+ ```bash
20
+ git clone https://github.com/stackpulse-lab/leakpulse
21
+ cd leakpulse
22
+ python3 run_tests.py
23
+ PYTHONPATH=src python3 -m leakpulse scan . --history 0 --fail-on high
24
+ ```
25
+
26
+ There is no virtualenv requirement; Python 3.9+ is enough. If you use one,
27
+ `.venv/` is already ignored.
28
+
29
+ ## Adding a rule
30
+
31
+ 1. Add a `Rule(...)` entry to `RULES` in `src/leakpulse/rules.py`. Keep the
32
+ regex anchored enough to avoid matching documentation placeholders.
33
+ 2. Prefer a specific prefix over a broad keyword. Ordered rules win overlaps,
34
+ so put specific patterns first.
35
+ 3. Add a positive case and a placeholder/negative case to
36
+ `tests/test_rules.py`.
37
+ 4. Update the rules table in `README.md` if you add a new category.
38
+
39
+ ## Commit style
40
+
41
+ Conventional Commits (`feat:`, `fix:`, `docs:`, `test:`, `chore:`) with a short
42
+ imperative subject. Keep commits focused.
43
+
44
+ ## Code style
45
+
46
+ - 4-space indentation, type hints on public functions, `from __future__ import annotations`.
47
+ - Prefer small pure functions; keep the scanner testable without shelling out.
48
+ - Line length around 110 characters; no formatter is enforced.
49
+
50
+ ## License
51
+
52
+ By contributing you agree that your changes are released under the MIT license.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 StackPulse Lab
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,6 @@
1
+ include action.yml .pre-commit-hooks.yaml
2
+ include CHANGELOG.md SECURITY.md CONTRIBUTING.md
3
+ recursive-include docs *.md
4
+ recursive-include .github *.yml
5
+ include run_tests.py
6
+ recursive-include tests *.py
@@ -0,0 +1,315 @@
1
+ Metadata-Version: 2.4
2
+ Name: leakpulse
3
+ Version: 0.4.0
4
+ Summary: Zero-dependency secret scanner for worktrees, staged changes and git history
5
+ Author-email: StackPulse Lab <360556499+stackpulse-lab@users.noreply.github.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/stackpulse-lab/leakpulse
8
+ Project-URL: Issues, https://github.com/stackpulse-lab/leakpulse/issues
9
+ Project-URL: Changelog, https://github.com/stackpulse-lab/leakpulse/blob/main/CHANGELOG.md
10
+ Project-URL: Source, https://github.com/stackpulse-lab/leakpulse
11
+ Keywords: security,secrets,secret-scanning,devsecops,git,pre-commit,cli
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: System Administrators
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Topic :: Security
25
+ Classifier: Topic :: Software Development :: Quality Assurance
26
+ Classifier: Typing :: Typed
27
+ Requires-Python: >=3.9
28
+ Description-Content-Type: text/markdown
29
+ License-File: LICENSE
30
+ Dynamic: license-file
31
+
32
+ # LeakPulse
33
+
34
+ **A zero-dependency secret scanner for worktrees, staged changes and git history.**
35
+ Catch `ghp_…`, `sk-…`, private keys and high-entropy tokens before they leave your laptop.
36
+
37
+ [![CI](https://github.com/stackpulse-lab/leakpulse/actions/workflows/ci.yml/badge.svg)](https://github.com/stackpulse-lab/leakpulse/actions/workflows/ci.yml)
38
+ [![PyPI](https://img.shields.io/badge/python-3.9%2B-blue?logo=python&logoColor=white)](https://www.python.org/)
39
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green)](LICENSE)
40
+ [![Dependencies: none](https://img.shields.io/badge/dependencies-0-brightgreen)](pyproject.toml)
41
+
42
+ ```
43
+ $ leakpulse scan .
44
+ HIGH github-token src/config.py:12 ghp_****q7R8 GitHub token (classic app/OAuth/refresh)
45
+ MEDIUM generic-secret-assignment deploy/prod.env:5 Tr0u****9xyz Secret-like value assigned to a sensitive name
46
+
47
+ 2 potential secrets found (1 high, 1 medium) Scanned 84 files and 50 commits in 0.09s.
48
+ ```
49
+
50
+ ---
51
+
52
+ ## 中文速览
53
+
54
+ **LeakPulse** 是一个**零依赖**的密钥泄露扫描器,一条命令同时检查:
55
+
56
+ 1. **工作区**文件(自动跳过 `.git`、虚拟环境、二进制与压缩产物);
57
+ 2. **暂存区**(`--staged`,适合 pre-commit 钩子);
58
+ 3. **提交历史**(`--history N`,发现「已经提交过一次」的密钥)。
59
+
60
+ 它只做本地静态检查:**不联网、不上传、无遥测**,命中结果默认脱敏输出,避免二次泄露。
61
+
62
+ ```bash
63
+ pipx install git+https://github.com/stackpulse-lab/leakpulse
64
+ leakpulse scan . # 工作区 + 最近 50 个提交
65
+ leakpulse scan --staged # 只看暂存区(pre-commit)
66
+ leakpulse scan . --history 200 --json # 输出 JSON 给 CI
67
+ leakpulse install-hook # 安装 pre-commit 钩子
68
+ ```
69
+
70
+ 支持以下忽略方式:仓库根目录 `.leakpulseignore`(gitignore 风格,支持 `!` 反选)、行内注释 `leakpulse:allow`、命令行 `--exclude 'vendor/**'`。
71
+
72
+ **v0.2.0 起内置国内生态规则**(共 28 条):DeepSeek `sk-…`、阿里云 `LTAI…` AccessKey ID / Secret、腾讯云 `AKID…` SecretId / SecretKey、火山引擎 `AKLT…`、飞书/企微/钉钉群机器人 Webhook、爱发电 API Token。Webhook 只截取并脱敏 token 部分,报告里不会出现完整回调 URL。
73
+
74
+ **开箱即用分发**:GitHub Action 一行 `uses: stackpulse-lab/leakpulse@v0.4.0`(无需 `setup-python`);`pre-commit` 钩子 `id: leakpulse`;以及基于 OIDC 的 PyPI Trusted Publishing workflow(不存任何 API Token)。三种接入方式见 [`docs/distribution.md`](docs/distribution.md)。
75
+
76
+ **审计与 CI 报告**:`--format sarif` 输出 SARIF 2.1.0(可直接交给 GitHub Code Scanning),`--format html` 输出单文件、无脚本、无远程资源的审计报告,交给不做命令行评审的人看;用法与可直接复制的 workflow 见 [`docs/sarif.md`](docs/sarif.md)。
77
+
78
+ 适用场景:个人项目推送前自检、CI 门禁、给团队补一层低成本的「防手滑」保险。它不是 SAST 的替代品,也不能判断密钥是否仍然有效——**发现即轮换**。
79
+
80
+ ---
81
+
82
+ ## Why another secret scanner?
83
+
84
+ Because the good ones are either heavy (Go binaries, container images, cloud accounts) or noisy enough that people disable them. LeakPulse is deliberately small:
85
+
86
+ - **Zero third-party dependencies** — Python standard library only, so the audit surface is a handful of files.
87
+ - **Three scopes in one binary** — worktree, index and history share the same rule engine.
88
+ - **Redacted output** — findings never print the full secret; safe to paste into an issue or CI log.
89
+ - **Fail-closed hook** — `install-hook` writes a pre-commit gate that refuses to commit when the scanner is unavailable.
90
+ - **Deterministic exit codes** — `0` clean, `1` findings at/above `--fail-on`, `2` usage or git error.
91
+
92
+ ## Install
93
+
94
+ Requires Python 3.9+ and (for history/staged modes) git.
95
+
96
+ ```bash
97
+ # Isolated install from the repository
98
+ pipx install git+https://github.com/stackpulse-lab/leakpulse
99
+
100
+ # or into a virtualenv
101
+ python -m venv .venv && . .venv/bin/activate
102
+ pip install git+https://github.com/stackpulse-lab/leakpulse
103
+
104
+ # development
105
+ git clone https://github.com/stackpulse-lab/leakpulse
106
+ cd leakpulse
107
+ python run_tests.py
108
+ PYTHONPATH=src python -m leakpulse scan .
109
+ ```
110
+
111
+ No PyPI release yet — `v0.4.0` is distributed from GitHub Releases. PyPI publishing is
112
+ wired through Trusted Publishing (OIDC) and activates after the one-time project setup
113
+ in [`docs/distribution.md`](docs/distribution.md); no API token is stored in the repo.
114
+
115
+ ## Usage
116
+
117
+ ```bash
118
+ leakpulse scan [PATH ...] [options] # scan files/directories
119
+ leakpulse scan --staged # scan staged content only
120
+ leakpulse scan . --history 0 # skip git history
121
+ leakpulse rules # list detection rules
122
+ leakpulse install-hook [--repo PATH] [--force]
123
+ leakpulse version
124
+ ```
125
+
126
+ ### Common options
127
+
128
+ | Option | Default | Description |
129
+ | --- | --- | --- |
130
+ | `--history N` | `50` | Scan the last N commits (`0` disables) |
131
+ | `--staged` | off | Scan the git index only; history defaults to `0` |
132
+ | `--json` | off | Machine-readable report with redacted matches |
133
+ | `--format {text,json,sarif,html}` | `text` | Report format; `sarif` for code scanning, `html` for audits |
134
+ | `--output FILE` | stdout | Write the report to a file (parent dirs created) |
135
+ | `--fail-on {low,medium,high,never}` | `high` | Severity threshold for exit code `1` |
136
+ | `--no-entropy` | off | Disable the high-entropy heuristic |
137
+ | `--entropy-threshold` | `3.6` | Shannon entropy threshold (bits/char) |
138
+ | `--exclude GLOB` | — | Extra ignore glob (repeatable) |
139
+ | `--all` | off | Also scan lockfiles and minified assets |
140
+ | `--max-file-bytes` | `1000000` | Skip larger files |
141
+ | `--quiet` | off | Print nothing when clean (hook-friendly) |
142
+
143
+ `--json` output:
144
+
145
+ ```json
146
+ {
147
+ "tool": "leakpulse",
148
+ "version": "0.4.0",
149
+ "scanned": { "files": 84, "commits": 50 },
150
+ "summary": { "total": 1, "high": 1, "medium": 0, "low": 0 },
151
+ "findings": [
152
+ {
153
+ "rule": "github-token",
154
+ "severity": "high",
155
+ "path": "src/config.py",
156
+ "line": 12,
157
+ "commit": null,
158
+ "match": "ghp_****q7R8",
159
+ "description": "GitHub token (classic app/OAuth/refresh)"
160
+ }
161
+ ],
162
+ "elapsed_seconds": 0.091,
163
+ "exit_code": 1
164
+ }
165
+ ```
166
+
167
+ ### SARIF and HTML reports
168
+
169
+ ```bash
170
+ leakpulse scan . --history 0 --format sarif --output leakpulse.sarif
171
+ leakpulse scan . --format html --output audit-report.html
172
+ ```
173
+
174
+ SARIF 2.1.0 output plugs into GitHub code scanning (rule metadata, masked matches,
175
+ stable fingerprints, repo-relative URIs). HTML output is a single self-contained file
176
+ for tickets or reviewers — inline CSS, no scripts, no remote assets. Copy-paste
177
+ workflow and notes: [`docs/sarif.md`](docs/sarif.md).
178
+
179
+ ## Detection rules
180
+
181
+ 28 high-signal rules plus an entropy heuristic. Full list: `leakpulse rules`.
182
+
183
+ | Rule | Severity | Catches |
184
+ | --- | --- | --- |
185
+ | `private-key-block` | high | PEM/PGP private key headers |
186
+ | `aws-access-key-id` | high | `AKIA…` / `ASIA…` access key IDs |
187
+ | `github-pat` / `github-token` | high | `github_pat_…`, `ghp_…`, `gho_…`, `ghs_…` |
188
+ | `deepseek-key` | high | `sk-…` used with a `deepseek` config name |
189
+ | `anthropic-key` / `openai-key` | high | `sk-ant-…`, `sk-…`, `sk-proj-…` |
190
+ | `resend-key` / `sendgrid-key` | high | transactional-mail API keys |
191
+ | `slack-token` / `stripe-key` | high | `xox…`, `sk_live_…`, `rk_live_…` |
192
+ | `google-api-key` / `npm-token` / `pypi-token` | high | cloud and package-registry credentials |
193
+ | `aliyun-access-key-id` / `aliyun-access-key-secret` | high | `LTAI…` and `ALIBABA_CLOUD_ACCESS_KEY_SECRET=…` |
194
+ | `tencent-secret-id` / `tencent-secret-key` | high | `AKID…` and `TENCENTCLOUD_SECRET_KEY=…` |
195
+ | `volcengine-access-key-id` | high | `AKLT…` |
196
+ | `feishu-webhook` / `wecom-webhook` / `dingtalk-webhook` | high | bot webhook tokens (Feishu/Lark, WeCom, DingTalk) |
197
+ | `afdian-token` | high | Afdian `AFDIAN_TOKEN=…` |
198
+ | `discord-webhook` | high | webhook URLs with embedded token |
199
+ | `url-basic-auth` | high | `scheme://user:pass@host` |
200
+ | `bearer-token` | high | `Authorization: Bearer …` |
201
+ | `jwt` | medium | three-part JSON Web Tokens |
202
+ | `generic-secret-assignment` | medium | `password = "…"`, `api_key: "…"` |
203
+ | `high-entropy-string` | medium | unknown random-looking 24+ char strings |
204
+
205
+ For webhook rules only the token is captured, so text and JSON reports never expose the
206
+ full callback URL. Placeholders (`example`, `your_…`, `${VAR}`, `changeme`, repeated characters) and code references (`os.environ.get`, `process.env`) are suppressed to keep noise low.
207
+
208
+ ## Ignoring findings
209
+
210
+ `.leakpulseignore` in the repository root, gitignore-style:
211
+
212
+ ```gitignore
213
+ tests/fixtures/**
214
+ vendor/**
215
+ !vendor/keep-this.txt
216
+ ```
217
+
218
+ Inline, per line (use sparingly, always with a reason):
219
+
220
+ ```python
221
+ DEMO_TOKEN = "..." # leakpulse:allow: documented sample, revoked
222
+ ```
223
+
224
+ Command line: `--exclude 'docs/**' --exclude '*.snap'`.
225
+
226
+ Lockfiles and minified assets are skipped by default because integrity hashes look random; pass `--all` to include them.
227
+
228
+ ## CI and pre-commit
229
+
230
+ Zero-config GitHub Action (recommended — installs the scanner from the pinned tag,
231
+ no `setup-python` step needed):
232
+
233
+ ```yaml
234
+ name: secrets
235
+ on: [push, pull_request]
236
+ permissions:
237
+ contents: read
238
+ jobs:
239
+ leakpulse:
240
+ runs-on: ubuntu-latest
241
+ steps:
242
+ - uses: actions/checkout@v4
243
+ with:
244
+ fetch-depth: 0 # only needed when history > 0
245
+ - uses: stackpulse-lab/leakpulse@v0.4.0
246
+ with:
247
+ history: "0" # set to 100+ to scan recent commits
248
+ fail-on: high
249
+ ```
250
+
251
+ Inputs: `path`, `history`, `fail-on`, `extra-args`, `format`, `output`; output `exit-code`.
252
+ For code scanning, set `format: sarif` and `output: leakpulse.sarif`, then upload with
253
+ `github/codeql-action/upload-sarif` — see [`docs/sarif.md`](docs/sarif.md).
254
+ A plain CLI step works too if you prefer explicit control:
255
+
256
+ ```bash
257
+ pipx install git+https://github.com/stackpulse-lab/leakpulse
258
+ leakpulse scan . --history 100 --fail-on high --no-color
259
+ ```
260
+
261
+ `pre-commit` framework (`.pre-commit-config.yaml`):
262
+
263
+ ```yaml
264
+ repos:
265
+ - repo: https://github.com/stackpulse-lab/leakpulse
266
+ rev: v0.4.0
267
+ hooks:
268
+ - id: leakpulse # staged changes only
269
+ # - id: leakpulse-worktree # whole worktree, no history
270
+ ```
271
+
272
+ Maintainer-side PyPI publishing (tag → OIDC → PyPI, tests re-run, tag/version checked)
273
+ lives in `.github/workflows/publish.yml`. Full setup for all three paths:
274
+ [`docs/distribution.md`](docs/distribution.md).
275
+
276
+ Native hook (no framework):
277
+
278
+ ```bash
279
+ leakpulse install-hook # writes .git/hooks/pre-commit
280
+ ```
281
+
282
+ The hook fails closed: if `leakpulse` is not on `PATH`, the commit is blocked with an install hint. In a source checkout, export `LEAKPULSE_SRC=/absolute/path/to/leakpulse/src` so the hook can run `python3 -m leakpulse`.
283
+
284
+ ## How it works
285
+
286
+ 1. **Collect** — walk the requested paths (or `git diff --cached`, or `git rev-list` + `git show`).
287
+ 2. **Scan** — run ordered regex rules per line; the first matching rule owns the span. Then apply Shannon entropy to remaining long strings.
288
+ 3. **Filter** — drop placeholders, env references and ignored paths.
289
+ 4. **Deduplicate** — one finding per `(rule, path, secret)`; history duplicates collapse to the newest commit.
290
+ 5. **Report** — mask the secret, sort by severity, set the exit code.
291
+
292
+ There is no network access anywhere in the codebase. Scan results stay on your machine unless you paste them somewhere.
293
+
294
+ ## Limitations
295
+
296
+ - Regex + entropy is a heuristic, not formal verification. False negatives are possible (encoded or split secrets); false positives are possible (random identifiers).
297
+ - History mode inspects **added lines** of the last N commits; it does not rewrite history or revoke anything.
298
+ - Binary files, archives and files over `--max-file-bytes` are skipped; `.git` internals are never walked.
299
+ - Finding a secret does not prove it is live, and *not* finding one does not prove the repo is clean.
300
+
301
+ When you do find one: **rotate/revoke first**, then remove it from history if the repository is public.
302
+
303
+ ## Development
304
+
305
+ ```bash
306
+ python run_tests.py # stdlib unittest, no deps
307
+ PYTHONPATH=src python -m leakpulse scan . --history 0
308
+ make test lint # optional convenience targets
309
+ ```
310
+
311
+ The test suite covers rule matching, placeholder suppression, masking, ignore lists, staged scanning, history parsing and CLI exit codes. CI runs it on Python 3.9–3.13.
312
+
313
+ ## License
314
+
315
+ MIT © 2026 StackPulse Lab. See [LICENSE](LICENSE).