leashscan 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.
- leashscan-0.1.1/LICENSE +21 -0
- leashscan-0.1.1/PKG-INFO +170 -0
- leashscan-0.1.1/README.md +152 -0
- leashscan-0.1.1/pyproject.toml +30 -0
- leashscan-0.1.1/setup.cfg +4 -0
- leashscan-0.1.1/src/leashscan/__init__.py +4 -0
- leashscan-0.1.1/src/leashscan/__main__.py +3 -0
- leashscan-0.1.1/src/leashscan/cli.py +151 -0
- leashscan-0.1.1/src/leashscan/findings.py +73 -0
- leashscan-0.1.1/src/leashscan/injection.py +122 -0
- leashscan-0.1.1/src/leashscan/mcp.py +216 -0
- leashscan-0.1.1/src/leashscan/minitoml.py +82 -0
- leashscan-0.1.1/src/leashscan/patterns.py +56 -0
- leashscan-0.1.1/src/leashscan/permissions.py +154 -0
- leashscan-0.1.1/src/leashscan/report.py +201 -0
- leashscan-0.1.1/src/leashscan/secrets.py +173 -0
- leashscan-0.1.1/src/leashscan/walker.py +103 -0
- leashscan-0.1.1/src/leashscan.egg-info/PKG-INFO +170 -0
- leashscan-0.1.1/src/leashscan.egg-info/SOURCES.txt +21 -0
- leashscan-0.1.1/src/leashscan.egg-info/dependency_links.txt +1 -0
- leashscan-0.1.1/src/leashscan.egg-info/entry_points.txt +2 -0
- leashscan-0.1.1/src/leashscan.egg-info/top_level.txt +1 -0
- leashscan-0.1.1/tests/test_scan.py +140 -0
leashscan-0.1.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 leashscan 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.
|
leashscan-0.1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: leashscan
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Is your AI agent on a leash? Scan what Claude Code, Cursor, Codex, Copilot and MCP servers can reach: secrets, risky configs, YOLO permissions and hidden prompt injection.
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Homepage, https://github.com/amisellati123/leashscan
|
|
7
|
+
Project-URL: Issues, https://github.com/amisellati123/leashscan/issues
|
|
8
|
+
Keywords: security,ai-agents,mcp,claude-code,cursor,codex,prompt-injection,secrets,scanner,devsecops
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Environment :: Console
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Topic :: Security
|
|
14
|
+
Requires-Python: >=3.9
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
<div align="center">
|
|
20
|
+
|
|
21
|
+
# 🐕 leashscan
|
|
22
|
+
|
|
23
|
+
### Is your AI agent on a leash?
|
|
24
|
+
|
|
25
|
+
**See what Claude Code, Cursor, Codex, Copilot, Windsurf and your MCP servers can actually reach:**
|
|
26
|
+
leaked secrets, YOLO permissions, risky MCP configs and invisible prompt injection. One command. Offline. Zero dependencies.
|
|
27
|
+
|
|
28
|
+
[](https://github.com/amisellati123/leashscan/actions)
|
|
29
|
+
[](https://pypi.org/project/leashscan/)
|
|
30
|
+

|
|
31
|
+

|
|
32
|
+

|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pipx run leashscan # or: uvx leashscan
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
<img src="docs/screenshot.png" alt="leashscan output showing an F grade" width="820">
|
|
39
|
+
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Why this exists
|
|
45
|
+
|
|
46
|
+
You gave an AI agent a terminal, your files and a dozen MCP servers. Now ask yourself:
|
|
47
|
+
|
|
48
|
+
- Can it read your `.env`, `~/.aws/credentials` or unencrypted SSH key? (Yes, probably.)
|
|
49
|
+
- Did someone's `AGENTS.md` or README hide **invisible Unicode instructions** your agent will happily follow?
|
|
50
|
+
- Is that MCP server pulling `@latest` from npm on every launch, as you?
|
|
51
|
+
- Did a repo you cloned ship a `.claude/settings.json` hook that runs `curl … | sh`?
|
|
52
|
+
- Is "auto-approve everything" switched on somewhere you forgot about?
|
|
53
|
+
|
|
54
|
+
Secret scanners don't check agent configs. Agent tools don't check your secrets. **leashscan checks both**, in seconds, without sending a single byte anywhere.
|
|
55
|
+
|
|
56
|
+
## What it checks
|
|
57
|
+
|
|
58
|
+
| Area | Examples |
|
|
59
|
+
|---|---|
|
|
60
|
+
| 🔑 **Secrets in the workspace** | OpenAI / Anthropic / AWS / GitHub / Stripe / Slack / HF keys, private keys, `.env` files not gitignored, hardcoded passwords |
|
|
61
|
+
| 🏠 **Home folder credentials** (`--home`) | SSH keys with no passphrase, `~/.aws/credentials`, kubeconfig tokens, npm/PyPI/Docker/gh tokens, keys in shell history |
|
|
62
|
+
| 🔌 **MCP servers** | plain-text tokens in configs, unpinned `npx`/`uvx` packages, filesystem servers rooted at `/` or `~`, shell-exec servers, `http://` remotes, `docker --privileged`, `curl \| sh` installs |
|
|
63
|
+
| 🛂 **Agent permissions** | Claude Code `bypassPermissions`, `Bash(*)`, auto-run repo hooks, `enableAllProjectMcpServers`; Codex `danger-full-access`; VS Code / Copilot auto-approve; Gemini CLI auto-accept |
|
|
64
|
+
| 🕵️ **Prompt injection** | invisible Unicode tag text (decoded so you can read it!), Trojan Source bidi chars, zero-width smuggling, hidden HTML comments aimed at AI, injection phrases in `AGENTS.md`, `CLAUDE.md`, `.cursorrules` and friends |
|
|
65
|
+
|
|
66
|
+
Supports configs from **Claude Code, Claude Desktop, Cursor, VS Code / Copilot, Windsurf, Codex CLI, Gemini CLI, Roo and Cline.**
|
|
67
|
+
|
|
68
|
+
Every finding comes with a **specific fix**, not just a warning.
|
|
69
|
+
|
|
70
|
+
## Usage
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
leashscan # scan the current project
|
|
74
|
+
leashscan --home # + your home folder and global agent configs
|
|
75
|
+
leashscan ~/code/* # many repos, one combined report
|
|
76
|
+
leashscan -f html -o report.html # shareable report (great for security reviews)
|
|
77
|
+
leashscan -f sarif -o out.sarif # GitHub code scanning
|
|
78
|
+
leashscan -f json # pipe into anything
|
|
79
|
+
leashscan --fail-on high # non-zero exit for CI
|
|
80
|
+
leashscan --badge # get a README badge for your grade
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**False positive?** Add a `leashscan:ignore` comment on or above the line, or list paths in `.leashscanignore`:
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
docs/security-talk.md # ignore everything in this file
|
|
87
|
+
README.md:INJ010 # ignore one rule in one file
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Install it for good with `pipx install leashscan` or `pip install leashscan`.
|
|
91
|
+
|
|
92
|
+
### Try it on a deliberately leaky project
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
git clone https://github.com/amisellati123/leashscan && cd leashscan
|
|
96
|
+
python demo/make_demo.py /tmp/leaky-app
|
|
97
|
+
leashscan /tmp/leaky-app
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## GitHub Action
|
|
101
|
+
|
|
102
|
+
Block risky agent configs and hidden prompt injection before they merge:
|
|
103
|
+
|
|
104
|
+
```yaml
|
|
105
|
+
# .github/workflows/leashscan.yml
|
|
106
|
+
name: leashscan
|
|
107
|
+
on: [push, pull_request]
|
|
108
|
+
jobs:
|
|
109
|
+
scan:
|
|
110
|
+
runs-on: ubuntu-latest
|
|
111
|
+
permissions: { contents: read, security-events: write }
|
|
112
|
+
steps:
|
|
113
|
+
- uses: actions/checkout@v5
|
|
114
|
+
- uses: amisellati123/leashscan@v0.1.1
|
|
115
|
+
with:
|
|
116
|
+
fail-on: high
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
You get a summary on every run, results in the Security tab, and a failed check when something high or critical shows up.
|
|
120
|
+
|
|
121
|
+
## In your IDE
|
|
122
|
+
|
|
123
|
+
Works in the integrated terminal of VS Code, Cursor, JetBrains or anything else. For one-click runs, copy [`.vscode/tasks.json`](.vscode/tasks.json) into your project and use **Terminal → Run Task → leashscan**.
|
|
124
|
+
|
|
125
|
+
## For forward deployed engineers and security reviews
|
|
126
|
+
|
|
127
|
+
Rolling out AI agents at a customer? The first question from their security team is *"what will this thing be able to touch?"* Run this on day one:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
leashscan ~/client-repos/* --home -f html -o agent-exposure-report.html
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
- **Safe on customer machines:** read-only, fully offline, no telemetry, secrets always redacted
|
|
134
|
+
- **Nothing to install** beyond Python 3.9+ (standard library only, easy to vendor or audit, about 1,000 lines)
|
|
135
|
+
- **One report for many repos,** with a letter grade, severity counts and a concrete fix for every item
|
|
136
|
+
- Re-run after hardening and show the grade going from **F → A**
|
|
137
|
+
|
|
138
|
+
## Grading
|
|
139
|
+
|
|
140
|
+
Each finding costs points by severity (critical 30, high 12, medium 4, low 1, with diminishing cost for repeats of the same rule). Any critical finding caps the grade at **D**.
|
|
141
|
+
`A ≥ 90 · B ≥ 75 · C ≥ 60 · D ≥ 40 · F < 40`
|
|
142
|
+
|
|
143
|
+
Got an A? Show it off:
|
|
144
|
+
|
|
145
|
+
```markdown
|
|
146
|
+
[](https://github.com/amisellati123/leashscan)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Privacy
|
|
150
|
+
|
|
151
|
+
leashscan never makes a network request, never writes anything except the report file you ask for, and never prints a full secret. Read the source: it is small on purpose.
|
|
152
|
+
|
|
153
|
+
## Responsible use
|
|
154
|
+
|
|
155
|
+
Scan machines and repositories you own or are authorized to assess. If you find exposed credentials in someone else's project, report them privately to the maintainers.
|
|
156
|
+
|
|
157
|
+
## Contributing
|
|
158
|
+
|
|
159
|
+
New detection rules are the best contribution. Each scanner is a single file in [`src/leashscan/`](src/leashscan/), and tests live in [`tests/`](tests/). Ideas we'd love help with:
|
|
160
|
+
- more agent config formats (Zed, Continue, Amp, JetBrains AI)
|
|
161
|
+
- a `--fix` mode that applies the safe changes automatically
|
|
162
|
+
- a pre-commit hook and an npm wrapper (`npx leashscan`)
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
pip install -e . pytest && pytest
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## License
|
|
169
|
+
|
|
170
|
+
MIT
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# 🐕 leashscan
|
|
4
|
+
|
|
5
|
+
### Is your AI agent on a leash?
|
|
6
|
+
|
|
7
|
+
**See what Claude Code, Cursor, Codex, Copilot, Windsurf and your MCP servers can actually reach:**
|
|
8
|
+
leaked secrets, YOLO permissions, risky MCP configs and invisible prompt injection. One command. Offline. Zero dependencies.
|
|
9
|
+
|
|
10
|
+
[](https://github.com/amisellati123/leashscan/actions)
|
|
11
|
+
[](https://pypi.org/project/leashscan/)
|
|
12
|
+

|
|
13
|
+

|
|
14
|
+

|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pipx run leashscan # or: uvx leashscan
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
<img src="docs/screenshot.png" alt="leashscan output showing an F grade" width="820">
|
|
21
|
+
|
|
22
|
+
</div>
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Why this exists
|
|
27
|
+
|
|
28
|
+
You gave an AI agent a terminal, your files and a dozen MCP servers. Now ask yourself:
|
|
29
|
+
|
|
30
|
+
- Can it read your `.env`, `~/.aws/credentials` or unencrypted SSH key? (Yes, probably.)
|
|
31
|
+
- Did someone's `AGENTS.md` or README hide **invisible Unicode instructions** your agent will happily follow?
|
|
32
|
+
- Is that MCP server pulling `@latest` from npm on every launch, as you?
|
|
33
|
+
- Did a repo you cloned ship a `.claude/settings.json` hook that runs `curl … | sh`?
|
|
34
|
+
- Is "auto-approve everything" switched on somewhere you forgot about?
|
|
35
|
+
|
|
36
|
+
Secret scanners don't check agent configs. Agent tools don't check your secrets. **leashscan checks both**, in seconds, without sending a single byte anywhere.
|
|
37
|
+
|
|
38
|
+
## What it checks
|
|
39
|
+
|
|
40
|
+
| Area | Examples |
|
|
41
|
+
|---|---|
|
|
42
|
+
| 🔑 **Secrets in the workspace** | OpenAI / Anthropic / AWS / GitHub / Stripe / Slack / HF keys, private keys, `.env` files not gitignored, hardcoded passwords |
|
|
43
|
+
| 🏠 **Home folder credentials** (`--home`) | SSH keys with no passphrase, `~/.aws/credentials`, kubeconfig tokens, npm/PyPI/Docker/gh tokens, keys in shell history |
|
|
44
|
+
| 🔌 **MCP servers** | plain-text tokens in configs, unpinned `npx`/`uvx` packages, filesystem servers rooted at `/` or `~`, shell-exec servers, `http://` remotes, `docker --privileged`, `curl \| sh` installs |
|
|
45
|
+
| 🛂 **Agent permissions** | Claude Code `bypassPermissions`, `Bash(*)`, auto-run repo hooks, `enableAllProjectMcpServers`; Codex `danger-full-access`; VS Code / Copilot auto-approve; Gemini CLI auto-accept |
|
|
46
|
+
| 🕵️ **Prompt injection** | invisible Unicode tag text (decoded so you can read it!), Trojan Source bidi chars, zero-width smuggling, hidden HTML comments aimed at AI, injection phrases in `AGENTS.md`, `CLAUDE.md`, `.cursorrules` and friends |
|
|
47
|
+
|
|
48
|
+
Supports configs from **Claude Code, Claude Desktop, Cursor, VS Code / Copilot, Windsurf, Codex CLI, Gemini CLI, Roo and Cline.**
|
|
49
|
+
|
|
50
|
+
Every finding comes with a **specific fix**, not just a warning.
|
|
51
|
+
|
|
52
|
+
## Usage
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
leashscan # scan the current project
|
|
56
|
+
leashscan --home # + your home folder and global agent configs
|
|
57
|
+
leashscan ~/code/* # many repos, one combined report
|
|
58
|
+
leashscan -f html -o report.html # shareable report (great for security reviews)
|
|
59
|
+
leashscan -f sarif -o out.sarif # GitHub code scanning
|
|
60
|
+
leashscan -f json # pipe into anything
|
|
61
|
+
leashscan --fail-on high # non-zero exit for CI
|
|
62
|
+
leashscan --badge # get a README badge for your grade
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**False positive?** Add a `leashscan:ignore` comment on or above the line, or list paths in `.leashscanignore`:
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
docs/security-talk.md # ignore everything in this file
|
|
69
|
+
README.md:INJ010 # ignore one rule in one file
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Install it for good with `pipx install leashscan` or `pip install leashscan`.
|
|
73
|
+
|
|
74
|
+
### Try it on a deliberately leaky project
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
git clone https://github.com/amisellati123/leashscan && cd leashscan
|
|
78
|
+
python demo/make_demo.py /tmp/leaky-app
|
|
79
|
+
leashscan /tmp/leaky-app
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## GitHub Action
|
|
83
|
+
|
|
84
|
+
Block risky agent configs and hidden prompt injection before they merge:
|
|
85
|
+
|
|
86
|
+
```yaml
|
|
87
|
+
# .github/workflows/leashscan.yml
|
|
88
|
+
name: leashscan
|
|
89
|
+
on: [push, pull_request]
|
|
90
|
+
jobs:
|
|
91
|
+
scan:
|
|
92
|
+
runs-on: ubuntu-latest
|
|
93
|
+
permissions: { contents: read, security-events: write }
|
|
94
|
+
steps:
|
|
95
|
+
- uses: actions/checkout@v5
|
|
96
|
+
- uses: amisellati123/leashscan@v0.1.1
|
|
97
|
+
with:
|
|
98
|
+
fail-on: high
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
You get a summary on every run, results in the Security tab, and a failed check when something high or critical shows up.
|
|
102
|
+
|
|
103
|
+
## In your IDE
|
|
104
|
+
|
|
105
|
+
Works in the integrated terminal of VS Code, Cursor, JetBrains or anything else. For one-click runs, copy [`.vscode/tasks.json`](.vscode/tasks.json) into your project and use **Terminal → Run Task → leashscan**.
|
|
106
|
+
|
|
107
|
+
## For forward deployed engineers and security reviews
|
|
108
|
+
|
|
109
|
+
Rolling out AI agents at a customer? The first question from their security team is *"what will this thing be able to touch?"* Run this on day one:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
leashscan ~/client-repos/* --home -f html -o agent-exposure-report.html
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
- **Safe on customer machines:** read-only, fully offline, no telemetry, secrets always redacted
|
|
116
|
+
- **Nothing to install** beyond Python 3.9+ (standard library only, easy to vendor or audit, about 1,000 lines)
|
|
117
|
+
- **One report for many repos,** with a letter grade, severity counts and a concrete fix for every item
|
|
118
|
+
- Re-run after hardening and show the grade going from **F → A**
|
|
119
|
+
|
|
120
|
+
## Grading
|
|
121
|
+
|
|
122
|
+
Each finding costs points by severity (critical 30, high 12, medium 4, low 1, with diminishing cost for repeats of the same rule). Any critical finding caps the grade at **D**.
|
|
123
|
+
`A ≥ 90 · B ≥ 75 · C ≥ 60 · D ≥ 40 · F < 40`
|
|
124
|
+
|
|
125
|
+
Got an A? Show it off:
|
|
126
|
+
|
|
127
|
+
```markdown
|
|
128
|
+
[](https://github.com/amisellati123/leashscan)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Privacy
|
|
132
|
+
|
|
133
|
+
leashscan never makes a network request, never writes anything except the report file you ask for, and never prints a full secret. Read the source: it is small on purpose.
|
|
134
|
+
|
|
135
|
+
## Responsible use
|
|
136
|
+
|
|
137
|
+
Scan machines and repositories you own or are authorized to assess. If you find exposed credentials in someone else's project, report them privately to the maintainers.
|
|
138
|
+
|
|
139
|
+
## Contributing
|
|
140
|
+
|
|
141
|
+
New detection rules are the best contribution. Each scanner is a single file in [`src/leashscan/`](src/leashscan/), and tests live in [`tests/`](tests/). Ideas we'd love help with:
|
|
142
|
+
- more agent config formats (Zed, Continue, Amp, JetBrains AI)
|
|
143
|
+
- a `--fix` mode that applies the safe changes automatically
|
|
144
|
+
- a pre-commit hook and an npm wrapper (`npx leashscan`)
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
pip install -e . pytest && pytest
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## License
|
|
151
|
+
|
|
152
|
+
MIT
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "leashscan"
|
|
7
|
+
version = "0.1.1"
|
|
8
|
+
description = "Is your AI agent on a leash? Scan what Claude Code, Cursor, Codex, Copilot and MCP servers can reach: secrets, risky configs, YOLO permissions and hidden prompt injection."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
dependencies = []
|
|
13
|
+
keywords = ["security", "ai-agents", "mcp", "claude-code", "cursor", "codex", "prompt-injection", "secrets", "scanner", "devsecops"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Environment :: Console",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Topic :: Security",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
[project.urls]
|
|
23
|
+
Homepage = "https://github.com/amisellati123/leashscan"
|
|
24
|
+
Issues = "https://github.com/amisellati123/leashscan/issues"
|
|
25
|
+
|
|
26
|
+
[project.scripts]
|
|
27
|
+
leashscan = "leashscan.cli:main"
|
|
28
|
+
|
|
29
|
+
[tool.setuptools.packages.find]
|
|
30
|
+
where = ["src"]
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"""Command-line entry point."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import fnmatch
|
|
7
|
+
import sys
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from . import __version__, injection, mcp, permissions, report, secrets
|
|
11
|
+
from .findings import SEVERITY_RANK, Finding, dedupe
|
|
12
|
+
|
|
13
|
+
EPILOG = """examples:
|
|
14
|
+
leashscan scan the current project
|
|
15
|
+
leashscan --home also check ~/.ssh, ~/.aws, global MCP + agent configs
|
|
16
|
+
leashscan repo1 repo2 repo3 one combined report for many repos
|
|
17
|
+
leashscan --format html -o report.html client-ready report
|
|
18
|
+
leashscan --format sarif -o leashscan.sarif for GitHub code scanning
|
|
19
|
+
leashscan --fail-on high exit 1 in CI if anything high or worse is found
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def apply_ignores(root: Path, findings: list[Finding]) -> list[Finding]:
|
|
24
|
+
"""Honor `.leashscanignore` globs (path or path:RULE_ID) and inline `leashscan:ignore` comments."""
|
|
25
|
+
rules: list[tuple[str, str | None]] = []
|
|
26
|
+
ig = root / ".leashscanignore"
|
|
27
|
+
if ig.is_file():
|
|
28
|
+
for raw in ig.read_text(errors="ignore").splitlines():
|
|
29
|
+
line = raw.split("#", 1)[0].strip()
|
|
30
|
+
if line:
|
|
31
|
+
pat, _, rule = line.partition(":")
|
|
32
|
+
rules.append((pat.strip(), rule.strip() or None))
|
|
33
|
+
cache: dict[str, list[str]] = {}
|
|
34
|
+
kept = []
|
|
35
|
+
for f in findings:
|
|
36
|
+
p = f.path.replace("\\", "/")
|
|
37
|
+
if any((fnmatch.fnmatch(p, pat) or fnmatch.fnmatch(p, pat.rstrip("/") + "/*"))
|
|
38
|
+
and (rule is None or rule == f.rule_id) for pat, rule in rules):
|
|
39
|
+
continue
|
|
40
|
+
if f.line and not p.startswith("~"):
|
|
41
|
+
if p not in cache:
|
|
42
|
+
try:
|
|
43
|
+
cache[p] = (root / p).read_text(errors="ignore").splitlines()
|
|
44
|
+
except OSError:
|
|
45
|
+
cache[p] = []
|
|
46
|
+
lines = cache[p]
|
|
47
|
+
near = lines[max(0, f.line - 2):f.line]
|
|
48
|
+
if any("leashscan:ignore" in ln for ln in near):
|
|
49
|
+
continue
|
|
50
|
+
kept.append(f)
|
|
51
|
+
return kept
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def scan_paths(paths: list[Path], include_home: bool, max_size: int, only: set[str] | None = None) -> list[Finding]:
|
|
55
|
+
findings: list[Finding] = []
|
|
56
|
+
multi = len(paths) > 1
|
|
57
|
+
for root in paths:
|
|
58
|
+
root = root.resolve()
|
|
59
|
+
part: list[Finding] = []
|
|
60
|
+
if not only or "secrets" in only:
|
|
61
|
+
part += secrets.scan_repo(root, max_size)
|
|
62
|
+
if not only or "mcp" in only:
|
|
63
|
+
part += mcp.scan(root, include_home=False)
|
|
64
|
+
if not only or "permissions" in only:
|
|
65
|
+
part += permissions.scan(root, include_home=False)
|
|
66
|
+
if not only or "injection" in only:
|
|
67
|
+
part += injection.scan(root, max_size)
|
|
68
|
+
part = apply_ignores(root, part)
|
|
69
|
+
if multi:
|
|
70
|
+
for f in part:
|
|
71
|
+
f.path = f"{root.name}/{f.path}"
|
|
72
|
+
findings += part
|
|
73
|
+
if include_home:
|
|
74
|
+
home = Path.home()
|
|
75
|
+
if not only or "home" in only:
|
|
76
|
+
findings += secrets.scan_home(home)
|
|
77
|
+
if not only or "mcp" in only:
|
|
78
|
+
findings += mcp.scan(Path("/nonexistent-leashscan"), include_home=True, home=home)
|
|
79
|
+
if not only or "permissions" in only:
|
|
80
|
+
findings += permissions.scan(Path("/nonexistent-leashscan"), include_home=True, home=home)
|
|
81
|
+
return dedupe(findings)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def main(argv: list[str] | None = None) -> int:
|
|
85
|
+
ap = argparse.ArgumentParser(
|
|
86
|
+
prog="leashscan",
|
|
87
|
+
description="See what your AI coding agents and MCP servers can reach: secrets, risky configs, "
|
|
88
|
+
"over-broad permissions and hidden prompt injection. Offline, read-only, zero dependencies.",
|
|
89
|
+
epilog=EPILOG, formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
90
|
+
)
|
|
91
|
+
ap.add_argument("paths", nargs="*", default=["."], help="folders to scan (default: current folder)")
|
|
92
|
+
ap.add_argument("--home", action="store_true", help="also scan your home folder credentials and global agent configs")
|
|
93
|
+
ap.add_argument("-f", "--format", choices=["text", "json", "sarif", "markdown", "html"], default="text")
|
|
94
|
+
ap.add_argument("-o", "--output", help="write report to a file instead of stdout")
|
|
95
|
+
ap.add_argument("--fail-on", choices=["critical", "high", "medium", "low", "none"], default="none",
|
|
96
|
+
help="exit with code 1 if a finding at or above this severity exists")
|
|
97
|
+
ap.add_argument("--only", help="comma list: secrets,home,mcp,permissions,injection")
|
|
98
|
+
ap.add_argument("--min-severity", choices=["critical", "high", "medium", "low"], default="low",
|
|
99
|
+
help="hide findings below this severity")
|
|
100
|
+
ap.add_argument("--max-file-size", type=int, default=1_000_000, help="skip files bigger than this (bytes)")
|
|
101
|
+
ap.add_argument("--no-color", action="store_true")
|
|
102
|
+
ap.add_argument("-v", "--verbose", action="store_true", help="show every finding")
|
|
103
|
+
ap.add_argument("--badge", action="store_true", help="print a README badge for your grade")
|
|
104
|
+
ap.add_argument("--version", action="version", version=f"leashscan {__version__}")
|
|
105
|
+
args = ap.parse_args(argv)
|
|
106
|
+
|
|
107
|
+
paths = [Path(p) for p in args.paths]
|
|
108
|
+
for p in paths:
|
|
109
|
+
if not p.is_dir():
|
|
110
|
+
print(f"leashscan: not a folder: {p}", file=sys.stderr)
|
|
111
|
+
return 2
|
|
112
|
+
only = {s.strip() for s in args.only.split(",")} if args.only else None
|
|
113
|
+
findings = scan_paths(paths, args.home, args.max_file_size, only)
|
|
114
|
+
cutoff = SEVERITY_RANK[args.min_severity]
|
|
115
|
+
findings = [f for f in findings if SEVERITY_RANK[f.severity] <= cutoff]
|
|
116
|
+
|
|
117
|
+
targets = [str(p.resolve().name or p.resolve()) for p in paths] + (["~ (home)"] if args.home else [])
|
|
118
|
+
if args.format == "json":
|
|
119
|
+
out = report.json_report(findings, targets)
|
|
120
|
+
elif args.format == "sarif":
|
|
121
|
+
out = report.sarif_report(findings, targets)
|
|
122
|
+
elif args.format == "markdown":
|
|
123
|
+
out = report.markdown_report(findings, targets)
|
|
124
|
+
elif args.format == "html":
|
|
125
|
+
out = report.html_report(findings, targets)
|
|
126
|
+
else:
|
|
127
|
+
color = report.use_color(args.no_color) and not args.output
|
|
128
|
+
out = report.text_report(findings, targets, color, args.verbose)
|
|
129
|
+
|
|
130
|
+
if args.output:
|
|
131
|
+
Path(args.output).write_text(out, encoding="utf-8")
|
|
132
|
+
_, grade = report.score(findings)
|
|
133
|
+
print(f"leashscan: grade {grade}, {len(findings)} finding(s), report written to {args.output}", file=sys.stderr)
|
|
134
|
+
else:
|
|
135
|
+
try:
|
|
136
|
+
sys.stdout.write(out)
|
|
137
|
+
except UnicodeEncodeError:
|
|
138
|
+
sys.stdout.write(out.encode("ascii", "replace").decode())
|
|
139
|
+
if args.badge:
|
|
140
|
+
_, grade = report.score(findings)
|
|
141
|
+
print(f"\n[})]({report.REPO_URL})", file=sys.stderr)
|
|
142
|
+
|
|
143
|
+
if args.fail_on != "none":
|
|
144
|
+
limit = SEVERITY_RANK[args.fail_on]
|
|
145
|
+
if any(SEVERITY_RANK[f.severity] <= limit for f in findings):
|
|
146
|
+
return 1
|
|
147
|
+
return 0
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
if __name__ == "__main__":
|
|
151
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""Finding model and scoring."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import asdict, dataclass
|
|
6
|
+
|
|
7
|
+
SEVERITIES = ("critical", "high", "medium", "low")
|
|
8
|
+
SEVERITY_RANK = {s: i for i, s in enumerate(SEVERITIES)}
|
|
9
|
+
SEVERITY_WEIGHT = {"critical": 30, "high": 12, "medium": 4, "low": 1}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass
|
|
13
|
+
class Finding:
|
|
14
|
+
rule_id: str
|
|
15
|
+
severity: str
|
|
16
|
+
category: str
|
|
17
|
+
title: str
|
|
18
|
+
path: str
|
|
19
|
+
line: int | None = None
|
|
20
|
+
detail: str = ""
|
|
21
|
+
fix: str = ""
|
|
22
|
+
|
|
23
|
+
def key(self) -> tuple:
|
|
24
|
+
return (self.rule_id, self.path, self.line, self.detail)
|
|
25
|
+
|
|
26
|
+
def to_dict(self) -> dict:
|
|
27
|
+
return asdict(self)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def dedupe(findings: list[Finding]) -> list[Finding]:
|
|
31
|
+
seen: set[tuple] = set()
|
|
32
|
+
out: list[Finding] = []
|
|
33
|
+
for f in findings:
|
|
34
|
+
if f.key() in seen:
|
|
35
|
+
continue
|
|
36
|
+
seen.add(f.key())
|
|
37
|
+
out.append(f)
|
|
38
|
+
out.sort(key=lambda f: (SEVERITY_RANK[f.severity], f.category, f.path, f.line or 0))
|
|
39
|
+
return out
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def score(findings: list[Finding]) -> tuple[int, str]:
|
|
43
|
+
"""Return (score 0-100, letter grade)."""
|
|
44
|
+
penalty = 0
|
|
45
|
+
# Diminishing returns per rule so one noisy rule can't dominate.
|
|
46
|
+
per_rule: dict[str, int] = {}
|
|
47
|
+
for f in findings:
|
|
48
|
+
n = per_rule.get(f.rule_id, 0)
|
|
49
|
+
per_rule[f.rule_id] = n + 1
|
|
50
|
+
w = SEVERITY_WEIGHT[f.severity]
|
|
51
|
+
penalty += w if n == 0 else max(1, w // (n + 1))
|
|
52
|
+
value = max(0, 100 - penalty)
|
|
53
|
+
if value >= 90:
|
|
54
|
+
grade = "A"
|
|
55
|
+
elif value >= 75:
|
|
56
|
+
grade = "B"
|
|
57
|
+
elif value >= 60:
|
|
58
|
+
grade = "C"
|
|
59
|
+
elif value >= 40:
|
|
60
|
+
grade = "D"
|
|
61
|
+
else:
|
|
62
|
+
grade = "F"
|
|
63
|
+
if any(f.severity == "critical" for f in findings) and grade in "ABC":
|
|
64
|
+
grade = "D"
|
|
65
|
+
value = min(value, 59)
|
|
66
|
+
return value, grade
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def counts(findings: list[Finding]) -> dict[str, int]:
|
|
70
|
+
c = {s: 0 for s in SEVERITIES}
|
|
71
|
+
for f in findings:
|
|
72
|
+
c[f.severity] += 1
|
|
73
|
+
return c
|