otynx 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.
- otynx-0.1.0/LICENSE +21 -0
- otynx-0.1.0/PKG-INFO +119 -0
- otynx-0.1.0/README.md +89 -0
- otynx-0.1.0/pyproject.toml +61 -0
- otynx-0.1.0/setup.cfg +4 -0
- otynx-0.1.0/src/otynx/__init__.py +4 -0
- otynx-0.1.0/src/otynx/__main__.py +6 -0
- otynx-0.1.0/src/otynx/agent_config.py +194 -0
- otynx-0.1.0/src/otynx/cli.py +72 -0
- otynx-0.1.0/src/otynx/detectors.py +241 -0
- otynx-0.1.0/src/otynx/finding.py +55 -0
- otynx-0.1.0/src/otynx/home.py +290 -0
- otynx-0.1.0/src/otynx/masking.py +36 -0
- otynx-0.1.0/src/otynx/report.py +96 -0
- otynx-0.1.0/src/otynx/rules.py +222 -0
- otynx-0.1.0/src/otynx/scanner.py +75 -0
- otynx-0.1.0/src/otynx/scoring.py +70 -0
- otynx-0.1.0/src/otynx/walker.py +110 -0
- otynx-0.1.0/src/otynx.egg-info/PKG-INFO +119 -0
- otynx-0.1.0/src/otynx.egg-info/SOURCES.txt +30 -0
- otynx-0.1.0/src/otynx.egg-info/dependency_links.txt +1 -0
- otynx-0.1.0/src/otynx.egg-info/entry_points.txt +2 -0
- otynx-0.1.0/src/otynx.egg-info/requires.txt +5 -0
- otynx-0.1.0/src/otynx.egg-info/top_level.txt +1 -0
- otynx-0.1.0/tests/test_agent_config.py +93 -0
- otynx-0.1.0/tests/test_cli.py +108 -0
- otynx-0.1.0/tests/test_detectors.py +148 -0
- otynx-0.1.0/tests/test_home.py +96 -0
- otynx-0.1.0/tests/test_masking.py +27 -0
- otynx-0.1.0/tests/test_scoring.py +63 -0
- otynx-0.1.0/tests/test_setup.py +8 -0
- otynx-0.1.0/tests/test_walker.py +92 -0
otynx-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vaibhav Tiwari
|
|
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.
|
otynx-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: otynx
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Sniff out the keys your AI agent could grab: an offline scanner for secrets and risky AI-agent settings.
|
|
5
|
+
Author: Vaibhav Tiwari
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://otynx.com
|
|
8
|
+
Project-URL: Repository, https://github.com/BuildsVaibhav/otynx
|
|
9
|
+
Project-URL: Issues, https://github.com/BuildsVaibhav/otynx/issues
|
|
10
|
+
Keywords: security,secrets,scanner,ai-agents,mcp,claude-code,cursor,cli
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Topic :: Security
|
|
21
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
22
|
+
Requires-Python: >=3.11
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: typer>=0.12
|
|
26
|
+
Requires-Dist: rich>=13
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# Otynx
|
|
32
|
+
|
|
33
|
+
*Sniff out the keys your AI agent could grab.* · [otynx.com](https://otynx.com)
|
|
34
|
+
|
|
35
|
+
In April 2026 an AI coding agent fixing a small bug found an unrelated API
|
|
36
|
+
token in a project file, and used it to delete a company's live database and
|
|
37
|
+
backups in 9 seconds. Rules in a prompt are suggestions: the only real
|
|
38
|
+
protection is that dangerous keys aren't reachable in the first place.
|
|
39
|
+
|
|
40
|
+
**Otynx shows you what your agent can reach, before you let it loose.**
|
|
41
|
+
It scans a folder for secret keys and risky AI-agent settings, ranks them by
|
|
42
|
+
how much damage they could do, and tells you how to fix each one.
|
|
43
|
+
It's read-only, works offline and never sends anything anywhere.
|
|
44
|
+
|
|
45
|
+

|
|
46
|
+
|
|
47
|
+
## Quick start
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install otynx
|
|
51
|
+
otynx scan . # scan the current folder
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Requires Python 3.11+. Status: v0.1.0, alpha. Feedback and new rules welcome!
|
|
55
|
+
|
|
56
|
+
## Options
|
|
57
|
+
|
|
58
|
+
| Command | What it does |
|
|
59
|
+
| --- | --- |
|
|
60
|
+
| `otynx scan <folder>` | Scan a project folder (default: `.`) |
|
|
61
|
+
| `--home` | Also check credential files in your home folder: `~/.aws`, `~/.kube`, `~/.docker`, `~/.npmrc`, `~/.pypirc`, `~/.netrc`, `~/.git-credentials`, gcloud, Azure, and `~/.ssh` (only checks that key files *exist*, never reads them) |
|
|
62
|
+
| `--json` | Print results as JSON for scripts and CI |
|
|
63
|
+
| `--list-files` | Also list every file that was scanned |
|
|
64
|
+
|
|
65
|
+
**Exit code:** `1` if anything is CRITICAL, otherwise `0`. Use it in CI or as a
|
|
66
|
+
pre-agent hook. You can also run it with `python -m otynx scan <folder>`.
|
|
67
|
+
|
|
68
|
+
## What it checks
|
|
69
|
+
|
|
70
|
+
- **Secrets:** database URLs with passwords, AWS keys, GitHub tokens, OpenAI and
|
|
71
|
+
Anthropic keys, Stripe live and test keys, Supabase service-role keys, Slack
|
|
72
|
+
tokens, Google API keys, private keys, npm and PyPI tokens, and any
|
|
73
|
+
random-looking value stored under a name like `SECRET`, `TOKEN`, `PASSWORD`
|
|
74
|
+
or `API_KEY`.
|
|
75
|
+
- **Agent configs:** secrets written straight into `.mcp.json`,
|
|
76
|
+
`.cursor/mcp.json` or `.vscode/mcp.json` instead of loaded from the
|
|
77
|
+
environment, and `.claude/settings.json` files that allow every Bash
|
|
78
|
+
command with no deny rules (or turn permission prompts off).
|
|
79
|
+
- **Skipped:** `node_modules`, `.git`, `venv`, binary files, files over 1 MB,
|
|
80
|
+
and placeholders like `your-key-here`, `xxxx`, `<API_KEY>` or `${TOKEN}`.
|
|
81
|
+
|
|
82
|
+
## How the danger level is worked out
|
|
83
|
+
|
|
84
|
+
Each finding starts with points for the worst thing its key can do: **40** if
|
|
85
|
+
it controls real systems (databases, cloud, private keys), **30** if it changes
|
|
86
|
+
code or money (GitHub, Stripe live), **20** if it spends money or reads data
|
|
87
|
+
(OpenAI, Slack, Google), and **10** for test or unknown keys. Then it gets
|
|
88
|
+
**+10** if it looks live (`prod`, `production`, `live` nearby), **−10** if it
|
|
89
|
+
looks safe (`localhost`, `test`, `dev`, `sandbox`), **+5** if it's inside the
|
|
90
|
+
project folder, **+5** if the same secret is in more than one file, and **+5**
|
|
91
|
+
if tools load it automatically (a `.env` file or the default AWS profile).
|
|
92
|
+
**45+ is CRITICAL, 30–44 HIGH, 20–29 MEDIUM, under 20 LOW.** Loose agent
|
|
93
|
+
permissions aren't secrets, so they're always MEDIUM.
|
|
94
|
+
|
|
95
|
+
## Safety promises
|
|
96
|
+
|
|
97
|
+
1. **Read-only.** Otynx never edits, moves or deletes a file.
|
|
98
|
+
2. **Offline.** No network calls, ever.
|
|
99
|
+
3. **Masked.** Secrets are always shown masked, e.g. `sk_live_****9f2a`, in the
|
|
100
|
+
terminal, in JSON and in errors.
|
|
101
|
+
4. **Never reads `~/.ssh`.** It only reports that private key files exist.
|
|
102
|
+
5. **Home folder is opt-in.** It looks outside the project only with `--home`.
|
|
103
|
+
6. **No telemetry.** Nothing about you or your scans is collected.
|
|
104
|
+
|
|
105
|
+
Only scan projects and computers you own or are allowed to check.
|
|
106
|
+
|
|
107
|
+
## Developing
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
python -m venv .venv
|
|
111
|
+
.venv\Scripts\activate # Windows (macOS/Linux: source .venv/bin/activate)
|
|
112
|
+
pip install -e ".[dev]"
|
|
113
|
+
pytest
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
The full plan is in [SPEC.md](SPEC.md). To add a detection rule, add one
|
|
117
|
+
`Rule(...)` to `src/otynx/rules.py` and a must-find and must-ignore test to
|
|
118
|
+
`tests/test_detectors.py`. Never put a real-looking secret in a file: build
|
|
119
|
+
fake ones at runtime (see `tests/fake_secrets.py`).
|
otynx-0.1.0/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Otynx
|
|
2
|
+
|
|
3
|
+
*Sniff out the keys your AI agent could grab.* · [otynx.com](https://otynx.com)
|
|
4
|
+
|
|
5
|
+
In April 2026 an AI coding agent fixing a small bug found an unrelated API
|
|
6
|
+
token in a project file, and used it to delete a company's live database and
|
|
7
|
+
backups in 9 seconds. Rules in a prompt are suggestions: the only real
|
|
8
|
+
protection is that dangerous keys aren't reachable in the first place.
|
|
9
|
+
|
|
10
|
+
**Otynx shows you what your agent can reach, before you let it loose.**
|
|
11
|
+
It scans a folder for secret keys and risky AI-agent settings, ranks them by
|
|
12
|
+
how much damage they could do, and tells you how to fix each one.
|
|
13
|
+
It's read-only, works offline and never sends anything anywhere.
|
|
14
|
+
|
|
15
|
+

|
|
16
|
+
|
|
17
|
+
## Quick start
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install otynx
|
|
21
|
+
otynx scan . # scan the current folder
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Requires Python 3.11+. Status: v0.1.0, alpha. Feedback and new rules welcome!
|
|
25
|
+
|
|
26
|
+
## Options
|
|
27
|
+
|
|
28
|
+
| Command | What it does |
|
|
29
|
+
| --- | --- |
|
|
30
|
+
| `otynx scan <folder>` | Scan a project folder (default: `.`) |
|
|
31
|
+
| `--home` | Also check credential files in your home folder: `~/.aws`, `~/.kube`, `~/.docker`, `~/.npmrc`, `~/.pypirc`, `~/.netrc`, `~/.git-credentials`, gcloud, Azure, and `~/.ssh` (only checks that key files *exist*, never reads them) |
|
|
32
|
+
| `--json` | Print results as JSON for scripts and CI |
|
|
33
|
+
| `--list-files` | Also list every file that was scanned |
|
|
34
|
+
|
|
35
|
+
**Exit code:** `1` if anything is CRITICAL, otherwise `0`. Use it in CI or as a
|
|
36
|
+
pre-agent hook. You can also run it with `python -m otynx scan <folder>`.
|
|
37
|
+
|
|
38
|
+
## What it checks
|
|
39
|
+
|
|
40
|
+
- **Secrets:** database URLs with passwords, AWS keys, GitHub tokens, OpenAI and
|
|
41
|
+
Anthropic keys, Stripe live and test keys, Supabase service-role keys, Slack
|
|
42
|
+
tokens, Google API keys, private keys, npm and PyPI tokens, and any
|
|
43
|
+
random-looking value stored under a name like `SECRET`, `TOKEN`, `PASSWORD`
|
|
44
|
+
or `API_KEY`.
|
|
45
|
+
- **Agent configs:** secrets written straight into `.mcp.json`,
|
|
46
|
+
`.cursor/mcp.json` or `.vscode/mcp.json` instead of loaded from the
|
|
47
|
+
environment, and `.claude/settings.json` files that allow every Bash
|
|
48
|
+
command with no deny rules (or turn permission prompts off).
|
|
49
|
+
- **Skipped:** `node_modules`, `.git`, `venv`, binary files, files over 1 MB,
|
|
50
|
+
and placeholders like `your-key-here`, `xxxx`, `<API_KEY>` or `${TOKEN}`.
|
|
51
|
+
|
|
52
|
+
## How the danger level is worked out
|
|
53
|
+
|
|
54
|
+
Each finding starts with points for the worst thing its key can do: **40** if
|
|
55
|
+
it controls real systems (databases, cloud, private keys), **30** if it changes
|
|
56
|
+
code or money (GitHub, Stripe live), **20** if it spends money or reads data
|
|
57
|
+
(OpenAI, Slack, Google), and **10** for test or unknown keys. Then it gets
|
|
58
|
+
**+10** if it looks live (`prod`, `production`, `live` nearby), **−10** if it
|
|
59
|
+
looks safe (`localhost`, `test`, `dev`, `sandbox`), **+5** if it's inside the
|
|
60
|
+
project folder, **+5** if the same secret is in more than one file, and **+5**
|
|
61
|
+
if tools load it automatically (a `.env` file or the default AWS profile).
|
|
62
|
+
**45+ is CRITICAL, 30–44 HIGH, 20–29 MEDIUM, under 20 LOW.** Loose agent
|
|
63
|
+
permissions aren't secrets, so they're always MEDIUM.
|
|
64
|
+
|
|
65
|
+
## Safety promises
|
|
66
|
+
|
|
67
|
+
1. **Read-only.** Otynx never edits, moves or deletes a file.
|
|
68
|
+
2. **Offline.** No network calls, ever.
|
|
69
|
+
3. **Masked.** Secrets are always shown masked, e.g. `sk_live_****9f2a`, in the
|
|
70
|
+
terminal, in JSON and in errors.
|
|
71
|
+
4. **Never reads `~/.ssh`.** It only reports that private key files exist.
|
|
72
|
+
5. **Home folder is opt-in.** It looks outside the project only with `--home`.
|
|
73
|
+
6. **No telemetry.** Nothing about you or your scans is collected.
|
|
74
|
+
|
|
75
|
+
Only scan projects and computers you own or are allowed to check.
|
|
76
|
+
|
|
77
|
+
## Developing
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
python -m venv .venv
|
|
81
|
+
.venv\Scripts\activate # Windows (macOS/Linux: source .venv/bin/activate)
|
|
82
|
+
pip install -e ".[dev]"
|
|
83
|
+
pytest
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The full plan is in [SPEC.md](SPEC.md). To add a detection rule, add one
|
|
87
|
+
`Rule(...)` to `src/otynx/rules.py` and a must-find and must-ignore test to
|
|
88
|
+
`tests/test_detectors.py`. Never put a real-looking secret in a file: build
|
|
89
|
+
fake ones at runtime (see `tests/fake_secrets.py`).
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# pyproject.toml is the "ID card" of the project.
|
|
2
|
+
# It tells Python (and PyPI) the project's name, version, which Python
|
|
3
|
+
# it needs, which other libraries it borrows, and what to show on PyPI.
|
|
4
|
+
|
|
5
|
+
[build-system]
|
|
6
|
+
# The tool that turns this folder into an installable package.
|
|
7
|
+
requires = ["setuptools>=77"]
|
|
8
|
+
build-backend = "setuptools.build_meta"
|
|
9
|
+
|
|
10
|
+
[project]
|
|
11
|
+
name = "otynx"
|
|
12
|
+
version = "0.1.0"
|
|
13
|
+
description = "Sniff out the keys your AI agent could grab: an offline scanner for secrets and risky AI-agent settings."
|
|
14
|
+
readme = "README.md"
|
|
15
|
+
license = "MIT"
|
|
16
|
+
license-files = ["LICENSE"]
|
|
17
|
+
authors = [{ name = "Vaibhav Tiwari" }]
|
|
18
|
+
requires-python = ">=3.11"
|
|
19
|
+
keywords = ["security", "secrets", "scanner", "ai-agents", "mcp", "claude-code", "cursor", "cli"]
|
|
20
|
+
classifiers = [
|
|
21
|
+
"Development Status :: 3 - Alpha",
|
|
22
|
+
"Environment :: Console",
|
|
23
|
+
"Intended Audience :: Developers",
|
|
24
|
+
"Operating System :: OS Independent",
|
|
25
|
+
"Programming Language :: Python :: 3",
|
|
26
|
+
"Programming Language :: Python :: 3.11",
|
|
27
|
+
"Programming Language :: Python :: 3.12",
|
|
28
|
+
"Programming Language :: Python :: 3.13",
|
|
29
|
+
"Programming Language :: Python :: 3.14",
|
|
30
|
+
"Topic :: Security",
|
|
31
|
+
"Topic :: Software Development :: Quality Assurance",
|
|
32
|
+
]
|
|
33
|
+
# Libraries Otynx itself needs to run (from SPEC.md "Tech stack").
|
|
34
|
+
# (pyyaml isn't needed: YAML files are checked line by line as text.)
|
|
35
|
+
dependencies = [
|
|
36
|
+
"typer>=0.12", # makes the `otynx scan` command
|
|
37
|
+
"rich>=13", # coloured terminal output
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[project.urls]
|
|
41
|
+
Homepage = "https://otynx.com"
|
|
42
|
+
Repository = "https://github.com/BuildsVaibhav/otynx"
|
|
43
|
+
Issues = "https://github.com/BuildsVaibhav/otynx/issues"
|
|
44
|
+
|
|
45
|
+
[project.scripts]
|
|
46
|
+
# Makes the `otynx` command run the `app` in otynx/cli.py.
|
|
47
|
+
otynx = "otynx.cli:app"
|
|
48
|
+
|
|
49
|
+
[project.optional-dependencies]
|
|
50
|
+
# Extra tools only needed while developing, not by users.
|
|
51
|
+
dev = [
|
|
52
|
+
"pytest>=8", # runs our tests
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
[tool.setuptools.packages.find]
|
|
56
|
+
# Our code lives in src/, so look for packages there.
|
|
57
|
+
where = ["src"]
|
|
58
|
+
|
|
59
|
+
[tool.pytest.ini_options]
|
|
60
|
+
# Tell pytest where the tests live.
|
|
61
|
+
testpaths = ["tests"]
|
otynx-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"""Check AI-agent settings files for secrets and loose permissions.
|
|
2
|
+
|
|
3
|
+
- MCP configs (.mcp.json, .cursor/mcp.json, .vscode/mcp.json): secrets
|
|
4
|
+
written straight into "env" or "headers" instead of loaded from the
|
|
5
|
+
environment.
|
|
6
|
+
- Claude Code settings (.claude/settings.json, .claude/settings.local.json):
|
|
7
|
+
all Bash commands allowed with no deny rules for destructive commands.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
import re
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
from otynx.detectors import (
|
|
15
|
+
context_clues,
|
|
16
|
+
find_line_number,
|
|
17
|
+
find_secrets_in_line,
|
|
18
|
+
fingerprint,
|
|
19
|
+
is_placeholder,
|
|
20
|
+
)
|
|
21
|
+
from otynx.finding import Finding
|
|
22
|
+
from otynx.masking import mask
|
|
23
|
+
|
|
24
|
+
MCP_FILES = (".mcp.json", ".cursor/mcp.json", ".vscode/mcp.json")
|
|
25
|
+
CLAUDE_SETTINGS_FILES = (".claude/settings.json", ".claude/settings.local.json")
|
|
26
|
+
|
|
27
|
+
MCP_FIX = (
|
|
28
|
+
'Load it from an environment variable instead, e.g. "${GITHUB_TOKEN}", '
|
|
29
|
+
"and keep the real value outside the project."
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
# Names that suggest a value is a secret.
|
|
33
|
+
SECRET_NAME = re.compile(r"(?i)secret|token|passw|pwd|api[_-]?key|access[_-]?key|private[_-]?key|auth|credential")
|
|
34
|
+
|
|
35
|
+
# Allow rules that mean "the agent may run ANY shell command".
|
|
36
|
+
BROAD_BASH_RULES = {"Bash", "Bash(*)", "Bash(**)", "Bash(:*)"}
|
|
37
|
+
|
|
38
|
+
# Deny rules that block at least one destructive command.
|
|
39
|
+
DESTRUCTIVE = re.compile(r"(?i)(?<![a-z])(?:rm|drop|delete|truncate|mkfs|dd)(?![a-z])|--force|reset --hard")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def check_agent_configs(root: Path) -> list[Finding]:
|
|
43
|
+
"""Run every agent-config check on the project folder `root`."""
|
|
44
|
+
findings = []
|
|
45
|
+
for name in MCP_FILES:
|
|
46
|
+
path = root / name
|
|
47
|
+
if path.is_file():
|
|
48
|
+
findings += check_mcp_file(path, name)
|
|
49
|
+
for name in CLAUDE_SETTINGS_FILES:
|
|
50
|
+
path = root / name
|
|
51
|
+
if path.is_file():
|
|
52
|
+
findings += check_claude_settings(path, name)
|
|
53
|
+
return findings
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def load_json(path: Path) -> tuple[object, str]:
|
|
57
|
+
"""Return (parsed JSON or None, raw text). Broken JSON gives None."""
|
|
58
|
+
try:
|
|
59
|
+
text = path.read_text(encoding="utf-8", errors="replace")
|
|
60
|
+
except OSError:
|
|
61
|
+
return None, ""
|
|
62
|
+
try:
|
|
63
|
+
return json.loads(text), text
|
|
64
|
+
except ValueError:
|
|
65
|
+
return None, text
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def is_reference(value: str) -> bool:
|
|
69
|
+
"""True when a value points to the environment instead of holding a secret.
|
|
70
|
+
|
|
71
|
+
e.g. "${GITHUB_TOKEN}", "${env:GITHUB_TOKEN}", "$TOKEN", or "".
|
|
72
|
+
"""
|
|
73
|
+
value = value.strip()
|
|
74
|
+
return value == "" or value.startswith(("$", "{{", "%")) or value.lower().startswith("env:")
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
# ---------- MCP configs ----------
|
|
78
|
+
|
|
79
|
+
def check_mcp_file(path: Path, display: str) -> list[Finding]:
|
|
80
|
+
"""Find secrets written directly into an MCP config."""
|
|
81
|
+
data, text = load_json(path)
|
|
82
|
+
if not isinstance(data, dict):
|
|
83
|
+
return []
|
|
84
|
+
|
|
85
|
+
# Claude Code and Cursor use "mcpServers"; VS Code uses "servers".
|
|
86
|
+
servers = data.get("mcpServers") or data.get("servers") or {}
|
|
87
|
+
if not isinstance(servers, dict):
|
|
88
|
+
return []
|
|
89
|
+
|
|
90
|
+
findings = []
|
|
91
|
+
for server_name, server in servers.items():
|
|
92
|
+
if not isinstance(server, dict):
|
|
93
|
+
continue
|
|
94
|
+
for section in ("env", "headers"):
|
|
95
|
+
values = server.get(section)
|
|
96
|
+
if not isinstance(values, dict):
|
|
97
|
+
continue
|
|
98
|
+
for key, value in values.items():
|
|
99
|
+
if isinstance(value, str) and not is_reference(value):
|
|
100
|
+
findings += _secrets_in_mcp_value(key, value, str(server_name), display, text)
|
|
101
|
+
return findings
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def _secrets_in_mcp_value(key: str, value: str, server: str, display: str, text: str) -> list[Finding]:
|
|
105
|
+
line_number = find_line_number(text, value)
|
|
106
|
+
live, safe = context_clues(f"{key} {server} {display}")
|
|
107
|
+
common = dict(
|
|
108
|
+
file_path=display,
|
|
109
|
+
line_number=line_number,
|
|
110
|
+
fix=MCP_FIX,
|
|
111
|
+
looks_live=live,
|
|
112
|
+
looks_safe=safe,
|
|
113
|
+
in_project=True,
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
# 1. A value with a known shape (GitHub token, Stripe key, ...).
|
|
117
|
+
matches = find_secrets_in_line(value, skip_generic=True)
|
|
118
|
+
if matches:
|
|
119
|
+
return [
|
|
120
|
+
Finding(
|
|
121
|
+
rule_id=m.rule.id,
|
|
122
|
+
title=f"{m.rule.title} written inside MCP config",
|
|
123
|
+
masked_value=m.shown,
|
|
124
|
+
what_it_can_do=m.rule.what_it_can_do,
|
|
125
|
+
base_points=m.rule.base_points,
|
|
126
|
+
fingerprint=fingerprint(m.secret) if m.rule.has_secret_value else "",
|
|
127
|
+
**common,
|
|
128
|
+
)
|
|
129
|
+
for m in matches
|
|
130
|
+
]
|
|
131
|
+
|
|
132
|
+
# 2. Unknown shape, but the name says it's a secret.
|
|
133
|
+
if SECRET_NAME.search(key) and len(value) >= 8 and not is_placeholder(value):
|
|
134
|
+
return [
|
|
135
|
+
Finding(
|
|
136
|
+
rule_id="mcp-secret",
|
|
137
|
+
title=f"Secret written inside MCP config ({key})",
|
|
138
|
+
masked_value=mask(value),
|
|
139
|
+
what_it_can_do=f"Unknown: anything the '{server}' MCP server can do with it.",
|
|
140
|
+
base_points=10,
|
|
141
|
+
fingerprint=fingerprint(value),
|
|
142
|
+
**common,
|
|
143
|
+
)
|
|
144
|
+
]
|
|
145
|
+
return []
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
# ---------- Claude Code settings ----------
|
|
149
|
+
|
|
150
|
+
def check_claude_settings(path: Path, display: str) -> list[Finding]:
|
|
151
|
+
"""Flag very loose permissions in .claude/settings*.json."""
|
|
152
|
+
data, text = load_json(path)
|
|
153
|
+
if not isinstance(data, dict):
|
|
154
|
+
return []
|
|
155
|
+
|
|
156
|
+
permissions = data.get("permissions")
|
|
157
|
+
if not isinstance(permissions, dict):
|
|
158
|
+
permissions = {}
|
|
159
|
+
allow = [rule for rule in permissions.get("allow") or [] if isinstance(rule, str)]
|
|
160
|
+
deny = [rule for rule in permissions.get("deny") or [] if isinstance(rule, str)]
|
|
161
|
+
|
|
162
|
+
findings = []
|
|
163
|
+
|
|
164
|
+
broad = [rule for rule in allow if rule.replace(" ", "") in BROAD_BASH_RULES]
|
|
165
|
+
has_destructive_deny = any(rule.startswith("Bash") and DESTRUCTIVE.search(rule) for rule in deny)
|
|
166
|
+
if broad and not has_destructive_deny:
|
|
167
|
+
findings.append(
|
|
168
|
+
Finding(
|
|
169
|
+
rule_id="agent-loose-bash",
|
|
170
|
+
title="Bash commands allowed with no deny rules",
|
|
171
|
+
file_path=display,
|
|
172
|
+
line_number=find_line_number(text, f'"{broad[0]}"'),
|
|
173
|
+
masked_value=f'allow: "{broad[0]}"',
|
|
174
|
+
what_it_can_do="The agent can run rm -rf, DROP TABLE, etc. without asking.",
|
|
175
|
+
fix='Add deny rules for destructive commands, e.g. "Bash(rm:*)", "Bash(git push --force:*)".',
|
|
176
|
+
is_permission=True,
|
|
177
|
+
)
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
if permissions.get("defaultMode") == "bypassPermissions":
|
|
181
|
+
findings.append(
|
|
182
|
+
Finding(
|
|
183
|
+
rule_id="agent-bypass-permissions",
|
|
184
|
+
title="Permission prompts are turned off (bypassPermissions)",
|
|
185
|
+
file_path=display,
|
|
186
|
+
line_number=find_line_number(text, "bypassPermissions"),
|
|
187
|
+
masked_value='defaultMode: "bypassPermissions"',
|
|
188
|
+
what_it_can_do="The agent can run any command and edit any file without asking.",
|
|
189
|
+
fix="Remove bypassPermissions and allow only the commands you need.",
|
|
190
|
+
is_permission=True,
|
|
191
|
+
)
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
return findings
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""The `otynx scan` command.
|
|
2
|
+
|
|
3
|
+
typer turns the scan() function below into a command: its parameters
|
|
4
|
+
become the command's options, and its docstring becomes the --help text.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import sys
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Annotated
|
|
10
|
+
|
|
11
|
+
import typer
|
|
12
|
+
|
|
13
|
+
from otynx.report import print_report, safe, to_json
|
|
14
|
+
from otynx.scanner import run_scan
|
|
15
|
+
|
|
16
|
+
app = typer.Typer(
|
|
17
|
+
add_completion=False,
|
|
18
|
+
no_args_is_help=True,
|
|
19
|
+
help="Otynx: see which secrets your AI agent could reach.",
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@app.callback()
|
|
24
|
+
def main() -> None:
|
|
25
|
+
"""Sniff out the keys your AI agent could grab."""
|
|
26
|
+
# Having this callback makes `scan` a sub-command: `otynx scan .`
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@app.command()
|
|
30
|
+
def scan(
|
|
31
|
+
# Annotated[type, extra info] lets typer know how to treat each parameter.
|
|
32
|
+
folder: Annotated[
|
|
33
|
+
Path,
|
|
34
|
+
typer.Argument(help="The project folder to scan.", exists=True, file_okay=False, dir_okay=True),
|
|
35
|
+
] = Path("."),
|
|
36
|
+
home: Annotated[
|
|
37
|
+
bool,
|
|
38
|
+
typer.Option("--home", help="Also check credential files in your home folder (~/.aws, ~/.kube, ...)."),
|
|
39
|
+
] = False,
|
|
40
|
+
json_output: Annotated[
|
|
41
|
+
bool,
|
|
42
|
+
typer.Option("--json", help="Print the results as JSON instead of a coloured report."),
|
|
43
|
+
] = False,
|
|
44
|
+
list_files: Annotated[
|
|
45
|
+
bool,
|
|
46
|
+
typer.Option("--list-files", help="Also print every file that was scanned."),
|
|
47
|
+
] = False,
|
|
48
|
+
) -> None:
|
|
49
|
+
"""Scan FOLDER for secrets and risky AI-agent settings. Read-only and offline."""
|
|
50
|
+
_make_output_safe()
|
|
51
|
+
result = run_scan(folder, include_home=home)
|
|
52
|
+
|
|
53
|
+
if json_output:
|
|
54
|
+
typer.echo(to_json(result))
|
|
55
|
+
else:
|
|
56
|
+
if list_files:
|
|
57
|
+
for path in result.scanned_paths:
|
|
58
|
+
typer.echo(safe(path)) # file names can hold terminal control codes
|
|
59
|
+
typer.echo()
|
|
60
|
+
print_report(result)
|
|
61
|
+
|
|
62
|
+
# Exit code 1 = something CRITICAL was found (useful in CI and hooks).
|
|
63
|
+
raise typer.Exit(code=result.exit_code)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _make_output_safe() -> None:
|
|
67
|
+
"""Some Windows terminals can't show symbols like '→'. Show '?' instead of crashing."""
|
|
68
|
+
for stream in (sys.stdout, sys.stderr):
|
|
69
|
+
try:
|
|
70
|
+
stream.reconfigure(errors="replace")
|
|
71
|
+
except (AttributeError, ValueError):
|
|
72
|
+
pass
|