margin-secret-leaks 0.1.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.
- margin_secret_leaks-0.1.0/.gitignore +86 -0
- margin_secret_leaks-0.1.0/CHANGELOG.md +22 -0
- margin_secret_leaks-0.1.0/LICENSE +21 -0
- margin_secret_leaks-0.1.0/PKG-INFO +138 -0
- margin_secret_leaks-0.1.0/README.md +114 -0
- margin_secret_leaks-0.1.0/pyproject.toml +44 -0
- margin_secret_leaks-0.1.0/src/secret_leaks/__init__.py +14 -0
- margin_secret_leaks-0.1.0/src/secret_leaks/agent.py +45 -0
- margin_secret_leaks-0.1.0/src/secret_leaks/exports.py +272 -0
- margin_secret_leaks-0.1.0/src/secret_leaks/models.py +99 -0
- margin_secret_leaks-0.1.0/src/secret_leaks/py.typed +0 -0
- margin_secret_leaks-0.1.0/src/secret_leaks/rules.py +552 -0
- margin_secret_leaks-0.1.0/src/secret_leaks/scanner.py +864 -0
- margin_secret_leaks-0.1.0/tests/test_exports.py +73 -0
- margin_secret_leaks-0.1.0/tests/test_secret_leaks.py +735 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
.Python
|
|
7
|
+
build/
|
|
8
|
+
develop-eggs/
|
|
9
|
+
dist/
|
|
10
|
+
downloads/
|
|
11
|
+
eggs/
|
|
12
|
+
.eggs/
|
|
13
|
+
/lib/
|
|
14
|
+
/lib64/
|
|
15
|
+
parts/
|
|
16
|
+
sdist/
|
|
17
|
+
var/
|
|
18
|
+
wheels/
|
|
19
|
+
share/python-wheels/
|
|
20
|
+
*.egg-info/
|
|
21
|
+
.installed.cfg
|
|
22
|
+
*.egg
|
|
23
|
+
|
|
24
|
+
# Virtual environments
|
|
25
|
+
.venv/
|
|
26
|
+
venv/
|
|
27
|
+
ENV/
|
|
28
|
+
env/
|
|
29
|
+
|
|
30
|
+
# uv
|
|
31
|
+
.uv/
|
|
32
|
+
|
|
33
|
+
# Environment variables & secrets
|
|
34
|
+
.env
|
|
35
|
+
.env.local
|
|
36
|
+
.env.*.local
|
|
37
|
+
*.key
|
|
38
|
+
*.pem
|
|
39
|
+
|
|
40
|
+
# Testing & Coverage
|
|
41
|
+
.pytest_cache/
|
|
42
|
+
.coverage
|
|
43
|
+
.coverage.*
|
|
44
|
+
htmlcov/
|
|
45
|
+
.tox/
|
|
46
|
+
.nox/
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py,cover
|
|
50
|
+
|
|
51
|
+
# Type checking & linting
|
|
52
|
+
.mypy_cache/
|
|
53
|
+
.ruff_cache/
|
|
54
|
+
.dmypy.json
|
|
55
|
+
dmypy.json
|
|
56
|
+
|
|
57
|
+
# IDEs & Editors
|
|
58
|
+
.vscode/
|
|
59
|
+
.idea/
|
|
60
|
+
*.swp
|
|
61
|
+
*.swo
|
|
62
|
+
*~
|
|
63
|
+
|
|
64
|
+
# Operating System
|
|
65
|
+
.DS_Store
|
|
66
|
+
Thumbs.db
|
|
67
|
+
ehthumbs.db
|
|
68
|
+
desktop.ini
|
|
69
|
+
|
|
70
|
+
# Output / Reports
|
|
71
|
+
report.json
|
|
72
|
+
report.md
|
|
73
|
+
temp/
|
|
74
|
+
tmp/
|
|
75
|
+
|
|
76
|
+
# Private planning notes (kept locally, not published)
|
|
77
|
+
PLAN.md
|
|
78
|
+
# notes for Claude Code and Antigravity sessions; marker files stay out of the public repo
|
|
79
|
+
CLAUDE.md
|
|
80
|
+
GEMINI.md
|
|
81
|
+
|
|
82
|
+
# the web UI bundled into margin-api at release time (scripts/build_release.py)
|
|
83
|
+
packages/api/src/margin_api/ui/
|
|
84
|
+
|
|
85
|
+
# local agent plugins and state
|
|
86
|
+
.agents/
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this agent are documented here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and versions follow
|
|
5
|
+
[Semantic Versioning](https://semver.org/).
|
|
6
|
+
|
|
7
|
+
## [0.1.0] - 2026-12-03
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- Initial experimental release of the Secret Leaks agent (`secret-leaks`), wired for PyPI.
|
|
11
|
+
- High-precision detection rules for AWS, GitHub, GitLab, Slack tokens and webhooks, Stripe live
|
|
12
|
+
API keys and webhook secrets, Google, OpenAI, Anthropic, PyPI, npm, Hugging Face, and SendGrid
|
|
13
|
+
tokens, PEM private key headers, credentialed database URLs, and generic quoted secret
|
|
14
|
+
assignments.
|
|
15
|
+
- Shannon entropy and placeholder filtering, inline suppression (`# margin:ignore` and
|
|
16
|
+
`pragma: allowlist secret`), and custom `allowlist_patterns` regex filtering across file paths,
|
|
17
|
+
lines, and values.
|
|
18
|
+
- Always-on masking so raw secret values never appear in findings, output data, exports, or
|
|
19
|
+
summaries.
|
|
20
|
+
- Workspace and bounded git commit-patch scanning (including historical secrets later deleted
|
|
21
|
+
from `HEAD`, with clean partial-clone detection); local folders scan without system `git`.
|
|
22
|
+
- Exportable SARIF 2.1.0, formula-safe CSV, and printable HTML reports (`output_dir`).
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 margin contributors
|
|
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,138 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: margin-secret-leaks
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Scans workspace files and git history for hardcoded secrets, API keys, private keys, and credentials.
|
|
5
|
+
Project-URL: Homepage, https://github.com/Waddah0-0/margin
|
|
6
|
+
Project-URL: Source, https://github.com/Waddah0-0/margin/tree/main/agents/secret_leaks
|
|
7
|
+
Project-URL: Issues, https://github.com/Waddah0-0/margin/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/Waddah0-0/margin/blob/main/agents/secret_leaks/CHANGELOG.md
|
|
9
|
+
Author: Waddah Ali
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: agents,credentials,git-history,secrets,security
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Security
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Python: >=3.11
|
|
22
|
+
Requires-Dist: margin-core<0.2,>=0.1.3
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# Secret Leaks
|
|
26
|
+
|
|
27
|
+
Scans workspace files and git history for hardcoded secrets, API keys, private keys, and
|
|
28
|
+
database credentials, reporting only redacted previews.
|
|
29
|
+
|
|
30
|
+
> **Status: experimental.** Runs locally with regular expressions and entropy checks; no files
|
|
31
|
+
> or matched values are sent to a model.
|
|
32
|
+
|
|
33
|
+
## What it does
|
|
34
|
+
|
|
35
|
+
Point it at a local folder or a public GitHub repository and it checks current files and recent
|
|
36
|
+
git commits for accidentally committed credentials, including secrets added in an earlier commit
|
|
37
|
+
and removed before `HEAD`. Local folders scan without system `git`; history scanning runs when
|
|
38
|
+
git history is available.
|
|
39
|
+
|
|
40
|
+
## How it works
|
|
41
|
+
|
|
42
|
+
1. Loads the target through `margin_core` (`ctx.load_workspace`), skipping binaries, lockfiles,
|
|
43
|
+
minified files, files over 1 MB, and tool or build folders (`node_modules`, `.vscode`,
|
|
44
|
+
`dist`, ...). Vendored and generated files are scanned, since secrets end up there too.
|
|
45
|
+
The run warns with what was not scanned.
|
|
46
|
+
2. Scans each text file line by line (very long lines in overlapping windows) for provider tokens
|
|
47
|
+
(AWS, GitHub, GitLab, Slack tokens & webhooks, Stripe API & webhook keys, Google, OpenAI,
|
|
48
|
+
Anthropic, PyPI, npm, Hugging Face, SendGrid), PEM private key headers, database URLs with
|
|
49
|
+
passwords, and generic quoted secret assignments (`api_key`, `secret`, `token`, `password`).
|
|
50
|
+
3. Drops common false positives using Shannon entropy thresholds, explicit placeholder checks
|
|
51
|
+
(`example`, `changeme`, `placeholder`, `your_`, `dummy`, `xxxx`, `0000`, `<...>`, `${...}`),
|
|
52
|
+
inline ignore comments (`# margin:ignore`, `pragma: allowlist secret`), and any
|
|
53
|
+
`allowlist_patterns` (matching file paths, lines, or values).
|
|
54
|
+
4. When `scan_git_history` is true and the repository has local history, streams added lines
|
|
55
|
+
from up to `history_depth` recent commits using read-only `git log` patches (excluding
|
|
56
|
+
deleted files, lockfiles, binaries, and ignored folders, and capping patch size at 16 MiB).
|
|
57
|
+
Each match records its commit SHA and whether it is still in `HEAD`. PEM keys are matched
|
|
58
|
+
by their whole block, so a key that moved within a file is still found in `HEAD`.
|
|
59
|
+
5. Replaces every matched secret with a masked preview (or header label for PEM keys) before
|
|
60
|
+
building findings, output data, exports, or the summary.
|
|
61
|
+
|
|
62
|
+
## Input
|
|
63
|
+
|
|
64
|
+
| Field | Default | Meaning |
|
|
65
|
+
|---|---|---|
|
|
66
|
+
| `target` | required | Local path or GitHub URL (`https://github.com/<owner>/<repo>`). The primary input. |
|
|
67
|
+
| `scan_git_history` | `true` | Scan recent git commit patches for introduced or deleted secrets. |
|
|
68
|
+
| `history_depth` | `50` | Maximum number of commits to inspect (`1` to `5000`). |
|
|
69
|
+
| `paths` | all files | Only scan these relative files or folders. |
|
|
70
|
+
| `branch` | default branch | Branch to scan (GitHub URL targets only). |
|
|
71
|
+
| `min_severity` | `"low"` | Minimum severity to report: `"low"`, `"medium"`, or `"high"`. |
|
|
72
|
+
| `allowlist_patterns` | `[]` | Regular expressions for file paths, lines, or values to ignore. |
|
|
73
|
+
| `output_dir` | empty | Folder for exported reports (`secrets.sarif.json`, `secrets.csv`, `secrets.report.html`). Filled automatically in the web UI. |
|
|
74
|
+
|
|
75
|
+
## Output
|
|
76
|
+
|
|
77
|
+
`data` holds a `SecretLeaksOutput` with:
|
|
78
|
+
|
|
79
|
+
- `total_matches`, `workspace_matches`, and `git_history_matches`
|
|
80
|
+
- `counts_by_severity` (`high`, `medium`, `low`)
|
|
81
|
+
- `files_scanned`, `commits_scanned`, and `rules_triggered`
|
|
82
|
+
- `matches`: up to 200 `SecretMatchSummary` entries with rule details, severity, source
|
|
83
|
+
(`workspace` or `git_history`), `file_path`, `line`, `commit_sha`, `in_head`, `entropy`, and
|
|
84
|
+
a masked `redacted_preview` (such as `AKIA...12`, `BEGIN RSA PRIVATE KEY`, or `***`).
|
|
85
|
+
- `files`: exported report paths when `output_dir` is set (SARIF 2.1.0, formula-safe CSV, and
|
|
86
|
+
printable HTML).
|
|
87
|
+
|
|
88
|
+
`findings` lists the same capped entries with file and commit evidence. Raw secret values are
|
|
89
|
+
never stored in the result or written to exported reports.
|
|
90
|
+
|
|
91
|
+
## Limits
|
|
92
|
+
|
|
93
|
+
- Relies on regular expressions and entropy heuristics; custom token formats, split values, or
|
|
94
|
+
obfuscated secrets can be missed.
|
|
95
|
+
- Placeholder and entropy filters suppress obvious documentation values and may miss weak or
|
|
96
|
+
synthetic credentials that look like placeholders.
|
|
97
|
+
- GitHub URL targets are cloned without historical blobs (`--filter=blob:none`), so git history
|
|
98
|
+
patch scanning is skipped with a warning and `partial` status. Clone the repository locally
|
|
99
|
+
to scan full git history.
|
|
100
|
+
- Git history patch scanning stops after 16 MiB of patch output or 120 seconds and marks the
|
|
101
|
+
run `partial`.
|
|
102
|
+
- `matches` and `findings` are capped at 200 entries; `total_matches` and `counts_by_severity`
|
|
103
|
+
always reflect all matches found.
|
|
104
|
+
- Previews show at most four characters of a secret: a provider's public prefix (`ghp_`,
|
|
105
|
+
`AKIA`) and the last two characters, or for other secrets of 16 characters or more the first
|
|
106
|
+
and last two. Treat any flagged credential as exposed until it is rotated and removed from
|
|
107
|
+
git history.
|
|
108
|
+
|
|
109
|
+
## Usage
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
pip install margin-cli margin-secret-leaks
|
|
113
|
+
margin run secret-leaks ./path/to/repo --format markdown
|
|
114
|
+
margin run secret-leaks ./path/to/repo --set scan_git_history=false --set min_severity=high
|
|
115
|
+
margin run secret-leaks ./path/to/repo --set output_dir=out
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
import asyncio
|
|
120
|
+
|
|
121
|
+
from secret_leaks import SecretLeaksAgent
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
async def main() -> None:
|
|
125
|
+
result = await SecretLeaksAgent().execute({"target": "."})
|
|
126
|
+
print(result.summary)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
asyncio.run(main())
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Development
|
|
133
|
+
|
|
134
|
+
This agent lives in the [margin](https://github.com/Waddah0-0/margin) monorepo, in
|
|
135
|
+
[`agents/secret_leaks`](https://github.com/Waddah0-0/margin/tree/main/agents/secret_leaks). If you are reading this in its mirror
|
|
136
|
+
repository, that copy is read-only: open issues and pull requests in the main repository.
|
|
137
|
+
|
|
138
|
+
Run its tests with `uv run python -m pytest agents/secret_leaks`.
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# Secret Leaks
|
|
2
|
+
|
|
3
|
+
Scans workspace files and git history for hardcoded secrets, API keys, private keys, and
|
|
4
|
+
database credentials, reporting only redacted previews.
|
|
5
|
+
|
|
6
|
+
> **Status: experimental.** Runs locally with regular expressions and entropy checks; no files
|
|
7
|
+
> or matched values are sent to a model.
|
|
8
|
+
|
|
9
|
+
## What it does
|
|
10
|
+
|
|
11
|
+
Point it at a local folder or a public GitHub repository and it checks current files and recent
|
|
12
|
+
git commits for accidentally committed credentials, including secrets added in an earlier commit
|
|
13
|
+
and removed before `HEAD`. Local folders scan without system `git`; history scanning runs when
|
|
14
|
+
git history is available.
|
|
15
|
+
|
|
16
|
+
## How it works
|
|
17
|
+
|
|
18
|
+
1. Loads the target through `margin_core` (`ctx.load_workspace`), skipping binaries, lockfiles,
|
|
19
|
+
minified files, files over 1 MB, and tool or build folders (`node_modules`, `.vscode`,
|
|
20
|
+
`dist`, ...). Vendored and generated files are scanned, since secrets end up there too.
|
|
21
|
+
The run warns with what was not scanned.
|
|
22
|
+
2. Scans each text file line by line (very long lines in overlapping windows) for provider tokens
|
|
23
|
+
(AWS, GitHub, GitLab, Slack tokens & webhooks, Stripe API & webhook keys, Google, OpenAI,
|
|
24
|
+
Anthropic, PyPI, npm, Hugging Face, SendGrid), PEM private key headers, database URLs with
|
|
25
|
+
passwords, and generic quoted secret assignments (`api_key`, `secret`, `token`, `password`).
|
|
26
|
+
3. Drops common false positives using Shannon entropy thresholds, explicit placeholder checks
|
|
27
|
+
(`example`, `changeme`, `placeholder`, `your_`, `dummy`, `xxxx`, `0000`, `<...>`, `${...}`),
|
|
28
|
+
inline ignore comments (`# margin:ignore`, `pragma: allowlist secret`), and any
|
|
29
|
+
`allowlist_patterns` (matching file paths, lines, or values).
|
|
30
|
+
4. When `scan_git_history` is true and the repository has local history, streams added lines
|
|
31
|
+
from up to `history_depth` recent commits using read-only `git log` patches (excluding
|
|
32
|
+
deleted files, lockfiles, binaries, and ignored folders, and capping patch size at 16 MiB).
|
|
33
|
+
Each match records its commit SHA and whether it is still in `HEAD`. PEM keys are matched
|
|
34
|
+
by their whole block, so a key that moved within a file is still found in `HEAD`.
|
|
35
|
+
5. Replaces every matched secret with a masked preview (or header label for PEM keys) before
|
|
36
|
+
building findings, output data, exports, or the summary.
|
|
37
|
+
|
|
38
|
+
## Input
|
|
39
|
+
|
|
40
|
+
| Field | Default | Meaning |
|
|
41
|
+
|---|---|---|
|
|
42
|
+
| `target` | required | Local path or GitHub URL (`https://github.com/<owner>/<repo>`). The primary input. |
|
|
43
|
+
| `scan_git_history` | `true` | Scan recent git commit patches for introduced or deleted secrets. |
|
|
44
|
+
| `history_depth` | `50` | Maximum number of commits to inspect (`1` to `5000`). |
|
|
45
|
+
| `paths` | all files | Only scan these relative files or folders. |
|
|
46
|
+
| `branch` | default branch | Branch to scan (GitHub URL targets only). |
|
|
47
|
+
| `min_severity` | `"low"` | Minimum severity to report: `"low"`, `"medium"`, or `"high"`. |
|
|
48
|
+
| `allowlist_patterns` | `[]` | Regular expressions for file paths, lines, or values to ignore. |
|
|
49
|
+
| `output_dir` | empty | Folder for exported reports (`secrets.sarif.json`, `secrets.csv`, `secrets.report.html`). Filled automatically in the web UI. |
|
|
50
|
+
|
|
51
|
+
## Output
|
|
52
|
+
|
|
53
|
+
`data` holds a `SecretLeaksOutput` with:
|
|
54
|
+
|
|
55
|
+
- `total_matches`, `workspace_matches`, and `git_history_matches`
|
|
56
|
+
- `counts_by_severity` (`high`, `medium`, `low`)
|
|
57
|
+
- `files_scanned`, `commits_scanned`, and `rules_triggered`
|
|
58
|
+
- `matches`: up to 200 `SecretMatchSummary` entries with rule details, severity, source
|
|
59
|
+
(`workspace` or `git_history`), `file_path`, `line`, `commit_sha`, `in_head`, `entropy`, and
|
|
60
|
+
a masked `redacted_preview` (such as `AKIA...12`, `BEGIN RSA PRIVATE KEY`, or `***`).
|
|
61
|
+
- `files`: exported report paths when `output_dir` is set (SARIF 2.1.0, formula-safe CSV, and
|
|
62
|
+
printable HTML).
|
|
63
|
+
|
|
64
|
+
`findings` lists the same capped entries with file and commit evidence. Raw secret values are
|
|
65
|
+
never stored in the result or written to exported reports.
|
|
66
|
+
|
|
67
|
+
## Limits
|
|
68
|
+
|
|
69
|
+
- Relies on regular expressions and entropy heuristics; custom token formats, split values, or
|
|
70
|
+
obfuscated secrets can be missed.
|
|
71
|
+
- Placeholder and entropy filters suppress obvious documentation values and may miss weak or
|
|
72
|
+
synthetic credentials that look like placeholders.
|
|
73
|
+
- GitHub URL targets are cloned without historical blobs (`--filter=blob:none`), so git history
|
|
74
|
+
patch scanning is skipped with a warning and `partial` status. Clone the repository locally
|
|
75
|
+
to scan full git history.
|
|
76
|
+
- Git history patch scanning stops after 16 MiB of patch output or 120 seconds and marks the
|
|
77
|
+
run `partial`.
|
|
78
|
+
- `matches` and `findings` are capped at 200 entries; `total_matches` and `counts_by_severity`
|
|
79
|
+
always reflect all matches found.
|
|
80
|
+
- Previews show at most four characters of a secret: a provider's public prefix (`ghp_`,
|
|
81
|
+
`AKIA`) and the last two characters, or for other secrets of 16 characters or more the first
|
|
82
|
+
and last two. Treat any flagged credential as exposed until it is rotated and removed from
|
|
83
|
+
git history.
|
|
84
|
+
|
|
85
|
+
## Usage
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
pip install margin-cli margin-secret-leaks
|
|
89
|
+
margin run secret-leaks ./path/to/repo --format markdown
|
|
90
|
+
margin run secret-leaks ./path/to/repo --set scan_git_history=false --set min_severity=high
|
|
91
|
+
margin run secret-leaks ./path/to/repo --set output_dir=out
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
import asyncio
|
|
96
|
+
|
|
97
|
+
from secret_leaks import SecretLeaksAgent
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
async def main() -> None:
|
|
101
|
+
result = await SecretLeaksAgent().execute({"target": "."})
|
|
102
|
+
print(result.summary)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
asyncio.run(main())
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Development
|
|
109
|
+
|
|
110
|
+
This agent lives in the [margin](https://github.com/Waddah0-0/margin) monorepo, in
|
|
111
|
+
[`agents/secret_leaks`](https://github.com/Waddah0-0/margin/tree/main/agents/secret_leaks). If you are reading this in its mirror
|
|
112
|
+
repository, that copy is read-only: open issues and pull requests in the main repository.
|
|
113
|
+
|
|
114
|
+
Run its tests with `uv run python -m pytest agents/secret_leaks`.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "margin-secret-leaks"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Scans workspace files and git history for hardcoded secrets, API keys, private keys, and credentials."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.11"
|
|
7
|
+
license = "MIT"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
authors = [{ name = "Waddah Ali" }]
|
|
10
|
+
keywords = ["secrets", "security", "credentials", "git-history", "agents"]
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Development Status :: 3 - Alpha",
|
|
13
|
+
"Intended Audience :: Developers",
|
|
14
|
+
"Operating System :: OS Independent",
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Programming Language :: Python :: 3.11",
|
|
17
|
+
"Programming Language :: Python :: 3.12",
|
|
18
|
+
"Typing :: Typed",
|
|
19
|
+
"Topic :: Security",
|
|
20
|
+
]
|
|
21
|
+
dependencies = [
|
|
22
|
+
"margin-core>=0.1.3,<0.2", # 0.1.3: READ_ONLY_GIT_CONFIG, history reads never fetch
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[project.urls]
|
|
26
|
+
Homepage = "https://github.com/Waddah0-0/margin"
|
|
27
|
+
Source = "https://github.com/Waddah0-0/margin/tree/main/agents/secret_leaks"
|
|
28
|
+
Issues = "https://github.com/Waddah0-0/margin/issues"
|
|
29
|
+
Changelog = "https://github.com/Waddah0-0/margin/blob/main/agents/secret_leaks/CHANGELOG.md"
|
|
30
|
+
|
|
31
|
+
[project.entry-points."margin.agents"]
|
|
32
|
+
secret-leaks = "secret_leaks.agent:SecretLeaksAgent"
|
|
33
|
+
|
|
34
|
+
[tool.margin]
|
|
35
|
+
id = "secret-leaks"
|
|
36
|
+
stage = "experimental"
|
|
37
|
+
mirror = "Waddah0-0/margin-secret-leaks"
|
|
38
|
+
|
|
39
|
+
[build-system]
|
|
40
|
+
requires = ["hatchling"]
|
|
41
|
+
build-backend = "hatchling.build"
|
|
42
|
+
|
|
43
|
+
[tool.hatch.build.targets.wheel]
|
|
44
|
+
packages = ["src/secret_leaks"]
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""Secret Leaks agent."""
|
|
2
|
+
|
|
3
|
+
from secret_leaks.agent import SecretLeaksAgent
|
|
4
|
+
from secret_leaks.models import SecretLeaksInput, SecretLeaksOutput, SecretMatchSummary
|
|
5
|
+
|
|
6
|
+
__version__ = "0.1.0"
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"SecretLeaksAgent",
|
|
10
|
+
"SecretLeaksInput",
|
|
11
|
+
"SecretLeaksOutput",
|
|
12
|
+
"SecretMatchSummary",
|
|
13
|
+
"__version__",
|
|
14
|
+
]
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""The Secret Leaks agent."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from margin_core import AgentResult, BaseAgent, RunContext
|
|
6
|
+
|
|
7
|
+
from secret_leaks.models import SecretLeaksInput, SecretLeaksOutput
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class SecretLeaksAgent(BaseAgent):
|
|
11
|
+
id = "secret-leaks"
|
|
12
|
+
name = "Secret Leaks"
|
|
13
|
+
description = (
|
|
14
|
+
"Scans workspace files and git history for hardcoded secrets, API keys, private keys, "
|
|
15
|
+
"and database credentials, reporting only redacted previews."
|
|
16
|
+
)
|
|
17
|
+
version = "0.1.0"
|
|
18
|
+
InputModel = SecretLeaksInput
|
|
19
|
+
OutputModel = SecretLeaksOutput
|
|
20
|
+
primary_input = "target"
|
|
21
|
+
uses_llm = False
|
|
22
|
+
requires_git = False # local directory scans work without git; history uses git when available
|
|
23
|
+
|
|
24
|
+
async def run(self, input: SecretLeaksInput, ctx: RunContext) -> AgentResult:
|
|
25
|
+
import asyncio
|
|
26
|
+
|
|
27
|
+
from secret_leaks.exports import write_reports
|
|
28
|
+
from secret_leaks.scanner import SCAN_FILTERS, scan_workspace
|
|
29
|
+
|
|
30
|
+
async with await ctx.load_workspace(
|
|
31
|
+
input.target, paths=input.paths, branch=input.branch, filters=SCAN_FILTERS
|
|
32
|
+
) as ws:
|
|
33
|
+
outcome = await scan_workspace(ws, input, ctx)
|
|
34
|
+
if input.output_dir:
|
|
35
|
+
ctx.report_progress("write", f"Writing reports to {input.output_dir}", 0.95)
|
|
36
|
+
outcome.output.files = await asyncio.to_thread(
|
|
37
|
+
write_reports, input.output_dir, outcome.output
|
|
38
|
+
)
|
|
39
|
+
ctx.report_progress("done", "Finished", 1.0)
|
|
40
|
+
return self.make_result(
|
|
41
|
+
summary=outcome.summary,
|
|
42
|
+
output=outcome.output,
|
|
43
|
+
findings=outcome.findings,
|
|
44
|
+
status="partial" if outcome.partial else "ok",
|
|
45
|
+
)
|