trustline-cli 0.1.0__py3-none-any.whl
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.
- trustline/__init__.py +3 -0
- trustline/baseline.py +126 -0
- trustline/cli.py +280 -0
- trustline/config.py +116 -0
- trustline/discovery.py +36 -0
- trustline/heuristics.py +282 -0
- trustline/hooks.py +290 -0
- trustline/rollback.py +119 -0
- trustline/sarif.py +49 -0
- trustline/scanner.py +33 -0
- trustline_cli-0.1.0.dist-info/METADATA +146 -0
- trustline_cli-0.1.0.dist-info/RECORD +16 -0
- trustline_cli-0.1.0.dist-info/WHEEL +5 -0
- trustline_cli-0.1.0.dist-info/entry_points.txt +2 -0
- trustline_cli-0.1.0.dist-info/licenses/LICENSE +21 -0
- trustline_cli-0.1.0.dist-info/top_level.txt +1 -0
trustline/sarif.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""SARIF 2.1.0 output for scan findings (consumable by CI / DefectDojo / etc.)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from .heuristics import Finding
|
|
6
|
+
|
|
7
|
+
SARIF_VERSION = "2.1.0"
|
|
8
|
+
SARIF_SCHEMA = "https://json.schemastore.org/sarif-2.1.0.json"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def build_sarif(findings: list[Finding], tool_name: str = "trustline", tool_version: str = "0.1.0") -> dict:
|
|
12
|
+
"""Map trustline findings onto a SARIF run. Rule metadata is derived from
|
|
13
|
+
the finding itself; we do not require rule metadata files."""
|
|
14
|
+
results = []
|
|
15
|
+
for idx, f in enumerate(findings):
|
|
16
|
+
loc = None
|
|
17
|
+
if f.file:
|
|
18
|
+
region = {"startLine": f.line} if f.line else {}
|
|
19
|
+
loc = {
|
|
20
|
+
"physicalLocation": {
|
|
21
|
+
"artifactLocation": {"uri": f.file},
|
|
22
|
+
**({"region": region} if region else {}),
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
results.append(
|
|
26
|
+
{
|
|
27
|
+
"ruleId": f.rule_id,
|
|
28
|
+
"level": "error" if f.severity == "high" else "warning",
|
|
29
|
+
"message": {"text": f.message},
|
|
30
|
+
**({"locations": [loc]} if loc else {}),
|
|
31
|
+
}
|
|
32
|
+
)
|
|
33
|
+
return {
|
|
34
|
+
"$schema": SARIF_SCHEMA,
|
|
35
|
+
"version": SARIF_VERSION,
|
|
36
|
+
"runs": [
|
|
37
|
+
{
|
|
38
|
+
"tool": {
|
|
39
|
+
"driver": {
|
|
40
|
+
"name": tool_name,
|
|
41
|
+
"version": tool_version,
|
|
42
|
+
"informationUri": "https://github.com/terencesai/trustline",
|
|
43
|
+
"rules": [],
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"results": results,
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
}
|
trustline/scanner.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""Scanner: run heuristics over a single managed file or the whole tree."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from .config import Config, normalize_relpath
|
|
8
|
+
from .discovery import discover
|
|
9
|
+
from .heuristics import Finding, scan_text
|
|
10
|
+
|
|
11
|
+
_MAX_BYTES = 2 * 1024 * 1024 # do not read huge managed files fully
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def scan_file(path: Path, config: Config) -> list[Finding]:
|
|
15
|
+
rel = normalize_relpath(config.root, path)
|
|
16
|
+
try:
|
|
17
|
+
if path.stat().st_size > _MAX_BYTES:
|
|
18
|
+
return []
|
|
19
|
+
text = path.read_text(encoding="utf-8", errors="replace")
|
|
20
|
+
except OSError:
|
|
21
|
+
return []
|
|
22
|
+
return scan_text(text, file_rel=rel)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def scan_root(config: Config) -> list[Finding]:
|
|
26
|
+
all_findings: list[Finding] = []
|
|
27
|
+
for path in discover(config):
|
|
28
|
+
all_findings.extend(scan_file(path, config))
|
|
29
|
+
return all_findings
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def severity_rank(f: Finding) -> int:
|
|
33
|
+
return {"high": 0, "medium": 1, "low": 2}.get(f.severity, 3)
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: trustline-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Trusted baseline + auto-rollback for AI agent configuration files (.claude/, AGENTS.md, .mcp.json, ...). Detects prompt-injection / supply-chain tampering of agent rules and rolls back to a trusted snapshot.
|
|
5
|
+
Author-email: Terence Cai <cys2193736202@163.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: security,ai-agents,claude-code,supply-chain,prompt-injection,baseline
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Environment :: Console
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Topic :: Security
|
|
14
|
+
Requires-Python: >=3.11
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: typer>=0.12
|
|
18
|
+
Requires-Dist: rich>=13.7
|
|
19
|
+
Provides-Extra: dev
|
|
20
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
21
|
+
Requires-Dist: pytest-cov>=5; extra == "dev"
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# Trustline
|
|
25
|
+
|
|
26
|
+
**Trusted baseline + auto-rollback for AI agent configuration files.**
|
|
27
|
+
|
|
28
|
+
[](https://github.com/LuckTerence/trustline/actions/workflows/ci.yml)
|
|
29
|
+
[](https://pypi.org/project/trustline-cli/)
|
|
30
|
+
[](LICENSE)
|
|
31
|
+
|
|
32
|
+
AI coding agents (Claude Code, Cursor, Codex, ...) load rules from files such as
|
|
33
|
+
`.claude/`, `AGENTS.md`, `.cursorrules` and `.mcp.json`. Those files are now a
|
|
34
|
+
supply-chain attack surface: cloning a repository or installing a third-party
|
|
35
|
+
MCP can silently inject instructions that tell your agent to exfiltrate
|
|
36
|
+
secrets, tamper with your shell, or hide its own actions.
|
|
37
|
+
|
|
38
|
+
Existing scanners (medusa, Snyk agent-scan, Cisco mcp-scanner, ...) **detect**
|
|
39
|
+
such tampering. Trustline is the missing **recovery layer**: it keeps a
|
|
40
|
+
trusted baseline of your agent configuration files and can roll them back —
|
|
41
|
+
and, through Claude Code hooks, block suspicious loads *before* they reach the
|
|
42
|
+
model.
|
|
43
|
+
|
|
44
|
+
## Why Trustline?
|
|
45
|
+
|
|
46
|
+
Detection is table stakes. Every scanner in this space answers one question:
|
|
47
|
+
*"has this rules file been poisoned?"* — and then leaves you to fix it by hand.
|
|
48
|
+
Trustline answers the two questions that come after:
|
|
49
|
+
|
|
50
|
+
1. **Did my agent config drift from a state I explicitly trusted?**
|
|
51
|
+
`status` diffs the working tree against a SHA-256 baseline *you* approved,
|
|
52
|
+
so a poisoned `.claude/settings.json` cloned from an untrusted repo shows up
|
|
53
|
+
as a concrete `modified`/`added` change — not a vague alert.
|
|
54
|
+
2. **How do I get back to the trusted state?**
|
|
55
|
+
`rollback` restores from git HEAD or from content snapshots taken at
|
|
56
|
+
baseline time, and preserves the tampered copy for forensics — no manual
|
|
57
|
+
surgery, no guessing which file was the original.
|
|
58
|
+
|
|
59
|
+
And because PreToolUse fires *before* a write lands, Trustline can refuse to
|
|
60
|
+
let an agent write a poisoned rules file into your tree in the first place —
|
|
61
|
+
the layer none of the scanners provide. This is deliberately defense-in-depth:
|
|
62
|
+
the model's own safety training is the first line, the hook is the second, and
|
|
63
|
+
the baseline + audit log is the third.
|
|
64
|
+
|
|
65
|
+
## What it does
|
|
66
|
+
|
|
67
|
+
- `trustline init` — establish a trusted baseline (SHA-256 snapshot) of managed agent files.
|
|
68
|
+
- `trustline status` — diff the working tree against the baseline (added / modified / deleted).
|
|
69
|
+
- `trustline scan` — static heuristic scan for prompt-injection / exfiltration / privilege-tampering signals (15 rules in v0.1).
|
|
70
|
+
- `trustline rollback [files...]` — restore files to the baseline (git HEAD first, then local snapshots; soft rollback keeps `.bak`).
|
|
71
|
+
- `trustline export-sarif` — emit scan findings as SARIF for CI / DefectDojo.
|
|
72
|
+
- `trustline hook install` — wire Claude Code hooks (SessionStart / file-load / PreToolUse) to verify before the agent trusts a rules file.
|
|
73
|
+
|
|
74
|
+
## Install
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
pip install trustline-cli # or: uv tool install trustline-cli
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Quick start
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
cd ~/some-repo-you-cloned
|
|
84
|
+
trustline init # review listed files, press enter -> baseline saved
|
|
85
|
+
trustline status # nothing changed yet
|
|
86
|
+
trustline scan --sarif # heuristic scan of managed files
|
|
87
|
+
# ... after a suspicious change ...
|
|
88
|
+
trustline status # shows: MODIFIED .claude/settings.json
|
|
89
|
+
trustline scan .claude/settings.json
|
|
90
|
+
trustline rollback .claude/settings.json # back to trusted state
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Claude Code hooks
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
trustline hook install # writes .claude/settings.local.json (gitignored)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Hooks are executed with the project directory as cwd (no project-dir
|
|
100
|
+
placeholder is needed). What fires:
|
|
101
|
+
|
|
102
|
+
- **SessionStart** — warns on any managed file that differs from the trusted
|
|
103
|
+
baseline (verified in real Claude Code sessions).
|
|
104
|
+
- **PreToolUse** on `Write`/`Edit`/`NotebookEdit` of a managed file — inspects
|
|
105
|
+
the *incoming* content and blocks with `exit 2` when a high-severity tamper
|
|
106
|
+
signal is present (so the agent cannot write a poisoned rules file).
|
|
107
|
+
- **InstructionsLoaded** — best-effort block when a loaded rules file drifted
|
|
108
|
+
out of baseline; the event is not emitted in all Claude Code versions /
|
|
109
|
+
headless mode, so treat it as defense-in-depth, not the primary gate.
|
|
110
|
+
|
|
111
|
+
Every hook decision is appended to a per-project audit log under
|
|
112
|
+
`~/.config/trustline/projects/<root>/audit.jsonl`, so behaviour is observable
|
|
113
|
+
without trusting stderr alone.
|
|
114
|
+
|
|
115
|
+
## Real-world smoke scan
|
|
116
|
+
|
|
117
|
+
`trustline scan` run over three public repositories (2026-09-02, shallow clone,
|
|
118
|
+
default rules). Findings are static signals that require human review — the
|
|
119
|
+
point of the table is to show the tool runs cleanly on real trees and that
|
|
120
|
+
false-positive volume is low.
|
|
121
|
+
|
|
122
|
+
| Repository | Managed files scanned | Findings | Signal rules hit | Notes |
|
|
123
|
+
|---|---|---|---|---|
|
|
124
|
+
| [affaan-m/ECC](https://github.com/affaan-m/ECC) (ruleset, 245k★) | 65 | 3 | T010 · T007 · T012 | low hit-rate on a very large rules corpus |
|
|
125
|
+
| [yamadashy/repomix](https://github.com/yamadashy/repomix) (tool, 28k★) | 11 | 1 | T010 | unpinned `npx` MCP package (common, low-risk) |
|
|
126
|
+
| [Pantheon-Security/medusa](https://github.com/Pantheon-Security/medusa) (security scanner) | 3 | 2 | T013 · T004 | both hits are inside its own `tests/fixtures/malicious_repo/` samples — Trustline flags the same fixtures medusa ships |
|
|
127
|
+
|
|
128
|
+
Reproduce: `pip install trustline-cli && trustline scan --root <clone-dir> --sarif`.
|
|
129
|
+
|
|
130
|
+
## Managed files (default)
|
|
131
|
+
|
|
132
|
+
`.claude/**`, `CLAUDE.md`, `**/AGENTS.md`, `**/.cursorrules`, `**/.mcp.json`,
|
|
133
|
+
`**/.codex/**`, `**/.github/copilot-instructions.md` — override with
|
|
134
|
+
`trustline init --patterns ...` or a `trustline.toml`.
|
|
135
|
+
|
|
136
|
+
## Development
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
python -m venv .venv && . .venv/bin/activate
|
|
140
|
+
pip install -e ".[dev]"
|
|
141
|
+
pytest
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## License
|
|
145
|
+
|
|
146
|
+
MIT
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
trustline/__init__.py,sha256=fiBaAtS-IzSBLIkzS5YHL_VZCnxozRaW7l3_-TwzDG4,107
|
|
2
|
+
trustline/baseline.py,sha256=oJ52xLTCIWgoI1gmKwHzBeO9SHYPtyeJV7N0CP1LxQ0,3922
|
|
3
|
+
trustline/cli.py,sha256=xCfQjwZ6_ThKQ-6J7_2iuKxGxgiSxiXTeJ4D6ZGyH3w,10326
|
|
4
|
+
trustline/config.py,sha256=4TtvCneBv90BHfClAKb78mgAgy6OD5QObkl4lp1KqYU,3620
|
|
5
|
+
trustline/discovery.py,sha256=7vIYlPhZYm77KkCZblr5pIL6ZFf_NvZctxRraUfTwQo,1291
|
|
6
|
+
trustline/heuristics.py,sha256=Jevjyr_C8v_0HPeG5trHrPYw99uC6R1stmk3wtNchf8,11911
|
|
7
|
+
trustline/hooks.py,sha256=jaitb1XAQ7-J3eSQKMDap5TVF8NBhhzJH8jWGTUGcY0,10223
|
|
8
|
+
trustline/rollback.py,sha256=cWnuEtE4GEIkuMlVYeFUWPfKgU4TGDoQugXc1x9k4gU,4649
|
|
9
|
+
trustline/sarif.py,sha256=XvG6Jo744idIZ8aYQqCg8UuEIt165kskSt0O4-2ZASY,1628
|
|
10
|
+
trustline/scanner.py,sha256=9TKgZEZqbeRB6_getWTaxjkTyNaNq2BuTGNZRnU8Fvk,963
|
|
11
|
+
trustline_cli-0.1.0.dist-info/licenses/LICENSE,sha256=uztXZL-fAv1QulHVgyiF4pMPVmf7I57uaCO_h_-Oe_E,1068
|
|
12
|
+
trustline_cli-0.1.0.dist-info/METADATA,sha256=KTyFyYOHS59SRmpdh-Sgs3HMcE5leriAjngRjiTkFq0,6766
|
|
13
|
+
trustline_cli-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
14
|
+
trustline_cli-0.1.0.dist-info/entry_points.txt,sha256=M9EEJg_0mb_LHJKMw1tRTwIc95YWglqzogWVAVW3Tq0,48
|
|
15
|
+
trustline_cli-0.1.0.dist-info/top_level.txt,sha256=Sh338JRFwELnkN9fWfz2ue0bsxjsQT2A2glMjtb3WBU,10
|
|
16
|
+
trustline_cli-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Terence Cai
|
|
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 @@
|
|
|
1
|
+
trustline
|