agenttrail-scrub-lite 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.
- agenttrail_scrub_lite-0.1.0.dist-info/METADATA +155 -0
- agenttrail_scrub_lite-0.1.0.dist-info/RECORD +7 -0
- agenttrail_scrub_lite-0.1.0.dist-info/WHEEL +5 -0
- agenttrail_scrub_lite-0.1.0.dist-info/entry_points.txt +2 -0
- agenttrail_scrub_lite-0.1.0.dist-info/licenses/LICENSE +21 -0
- agenttrail_scrub_lite-0.1.0.dist-info/top_level.txt +1 -0
- agenttrail_scrub_lite.py +291 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agenttrail-scrub-lite
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Claude Code secret scanner: find API keys and tokens leaked in AI agent transcripts.
|
|
5
|
+
Author: Alessio Auretto
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/alessio1999xx-debug/agenttrail-scrub-lite
|
|
8
|
+
Project-URL: Repository, https://github.com/alessio1999xx-debug/agenttrail-scrub-lite
|
|
9
|
+
Project-URL: Pro version, https://py-forge.com/products/agenttrail-scrub-ai-transcript-secret-cleaner?utm_source=pypi&utm_medium=project_page&utm_campaign=agenttrail-scrub-lite
|
|
10
|
+
Keywords: claude-code,ai-agents,llm-security,secret-scanning,secrets-detection,api-keys,credential-leak,devsecops,security-scanner,cli,stdlib
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
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.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Security
|
|
22
|
+
Classifier: Topic :: Utilities
|
|
23
|
+
Requires-Python: >=3.9
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# agenttrail-scrub-lite: scan Claude Code transcripts for leaked secrets
|
|
29
|
+
|
|
30
|
+
Claude Code saves every session transcript as local JSONL under `~/.claude`, including any API key, token or `.env` value that passed through the terminal or a pasted file. agenttrail-scrub-lite helps you find those secrets with a read-only scan using only the standard library: it reports where they are and never modifies your files.
|
|
31
|
+
|
|
32
|
+
Need to scan other AI coding agents, redact secrets in place, or get a per-provider rotation checklist? That is the full [AgentTrail Scrub](https://py-forge.com/products/agenttrail-scrub-ai-transcript-secret-cleaner?utm_source=github&utm_medium=readme&utm_campaign=agenttrail-scrub-lite) (one-time payment, yours to keep, no subscription). A table later in this README lists what lite does and what the paid tool adds. Or get every PyForge tool, current and future, with the [All-Access Pass](https://py-forge.com/pass?utm_source=github&utm_medium=readme&utm_campaign=agenttrail-scrub-lite) ($99, one payment).
|
|
33
|
+
|
|
34
|
+
- One file, Python 3.9+. Nothing to `pip install`.
|
|
35
|
+
- Default target: `~/.claude/projects/**/*.jsonl` (override with `--path`).
|
|
36
|
+
- Masked previews only; exit code `1` when at least one secret pattern is reported.
|
|
37
|
+
|
|
38
|
+
## Install
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
curl -fsSLO https://raw.githubusercontent.com/alessio1999xx-debug/agenttrail-scrub-lite/main/agenttrail_scrub_lite.py
|
|
42
|
+
chmod +x agenttrail_scrub_lite.py
|
|
43
|
+
python agenttrail_scrub_lite.py --help
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Where Claude Code stores transcripts (and why secrets end up there)
|
|
47
|
+
|
|
48
|
+
Claude Code keeps project session logs under `~/.claude/projects/`, usually as `.jsonl` files (one JSON object per line). Anything you typed, pasted, or that an agent echoed — including `export` lines, `.env` snippets, and provider tokens — can sit there in plaintext. Sharing a transcript, opening a bug report, or syncing that folder to a backup is how keys leak.
|
|
49
|
+
|
|
50
|
+
agenttrail-scrub-lite walks that tree (or a path you pass), opens each `.jsonl` as text, and matches **common patterns** for provider credentials. It does not claim to find every possible secret.
|
|
51
|
+
|
|
52
|
+
Patterns currently checked:
|
|
53
|
+
|
|
54
|
+
| Provider / kind | Example shape (not a real key) |
|
|
55
|
+
|---|---|
|
|
56
|
+
| Anthropic API key | `sk-ant-api03-…` |
|
|
57
|
+
| Anthropic legacy key | `sk-ant-…` |
|
|
58
|
+
| OpenAI API key | `sk-…` / `sk-proj-…` |
|
|
59
|
+
| Google Gemini / Cloud | `AIzaSy…` |
|
|
60
|
+
| GitHub PAT / OAuth | `ghp_` / `gho_` / … |
|
|
61
|
+
| GitHub fine-grained | `github_pat_…` |
|
|
62
|
+
| AWS access key id | `AKIA…` / `ASIA…` |
|
|
63
|
+
| AWS secret access key | `aws_secret_access_key=…` |
|
|
64
|
+
| Stripe secret / restricted | `sk_live_` / `sk_test_` / `rk_…` |
|
|
65
|
+
| Slack token | `xoxb-` / `xoxp-` / … |
|
|
66
|
+
| Private key header | `-----BEGIN … PRIVATE KEY-----` |
|
|
67
|
+
| JWT | `eyJh….….…` |
|
|
68
|
+
| Generic `.env` assignment | `API_KEY=` / `TOKEN=` / … |
|
|
69
|
+
|
|
70
|
+
## Scan Claude Code logs for API keys and tokens
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
# default: ~/.claude/projects
|
|
74
|
+
python agenttrail_scrub_lite.py
|
|
75
|
+
|
|
76
|
+
# one project folder or a single .jsonl file
|
|
77
|
+
python agenttrail_scrub_lite.py --path ~/.claude/projects/my-encoded-path
|
|
78
|
+
python agenttrail_scrub_lite.py --path ./session.jsonl
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Example output, recorded 25 Nov 2026 (Europe/Rome) on a throwaway sample JSONL. The token is fake and is shown only as a masked preview. Exit code `1`.
|
|
82
|
+
|
|
83
|
+
```text
|
|
84
|
+
================================================================================
|
|
85
|
+
AGENTTRAIL-SCRUB-LITE SCAN REPORT
|
|
86
|
+
================================================================================
|
|
87
|
+
Target : session.jsonl
|
|
88
|
+
JSONL Files Scanned : 1
|
|
89
|
+
Findings : 1
|
|
90
|
+
Secrets Reported : 1
|
|
91
|
+
--------------------------------------------------------------------------------
|
|
92
|
+
Findings (1 total):
|
|
93
|
+
|
|
94
|
+
1. Provider : OpenAI API Key
|
|
95
|
+
Path : session.jsonl
|
|
96
|
+
Line : 1
|
|
97
|
+
Preview : sk-p...aaa
|
|
98
|
+
Details : OpenAI API Key match (masked preview)
|
|
99
|
+
================================================================================
|
|
100
|
+
Read-only scan. No files were modified. Rotate any real credentials at the provider.
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The report lists provider, file path, line number and a masked preview (`abcd...xyz`). Nothing is written back to disk. If matches appear, rotate the real credentials at the provider — this tool only helps you find them.
|
|
104
|
+
|
|
105
|
+
## Run it before sharing a transcript or a bug report
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
python agenttrail_scrub_lite.py --path ./transcript-to-share.jsonl
|
|
109
|
+
echo $? # 0 = no common patterns found; 1 = at least one match
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Use the exit code in a pre-share checklist or a local hook so you do not paste a log that still holds keys.
|
|
113
|
+
|
|
114
|
+
## agenttrail-scrub-lite vs AgentTrail Scrub (redact and clean)
|
|
115
|
+
|
|
116
|
+
agenttrail-scrub-lite checks **Claude Code** JSONL transcripts only, with regex patterns and a text report. It is read-only.
|
|
117
|
+
|
|
118
|
+
| Capability | Lite (free) | Paid AgentTrail Scrub |
|
|
119
|
+
| --- | --- | --- |
|
|
120
|
+
| Default scan target | Claude Code `~/.claude/projects` (override with `--path`) | Discovers Claude Code, Cursor, Gemini CLI, Aider, Codex, Continue.dev and Open Interpreter, plus any `--paths` you pass |
|
|
121
|
+
| Detection | Regex patterns (Anthropic, OpenAI, Google, GitHub, AWS, Stripe, Slack, JWT, private-key headers, `.env`-style assignments) | Regex plus Shannon entropy checks |
|
|
122
|
+
| Redact secrets in the files | No (read-only) | Yes (`--redact`, with a backup first) |
|
|
123
|
+
| Allowlist for known-safe values | No | Yes (`--allowlist`) |
|
|
124
|
+
| Retention / cleanup of old transcripts | No | Yes (`--apply-retention`, `--retention-days`) |
|
|
125
|
+
| Per-provider rotation checklist | No | Yes (`--rotation-guide`) |
|
|
126
|
+
| Output | Plain text | Text or JSON (`--json`) |
|
|
127
|
+
|
|
128
|
+
One-time payment, yours to keep. No subscription. Full tool: [AgentTrail Scrub](https://py-forge.com/products/agenttrail-scrub-ai-transcript-secret-cleaner?utm_source=github&utm_medium=readme&utm_campaign=agenttrail-scrub-lite). Or get every PyForge tool, current and future, with the [All-Access Pass](https://py-forge.com/pass?utm_source=github&utm_medium=readme&utm_campaign=agenttrail-scrub-lite) ($99, one payment).
|
|
129
|
+
|
|
130
|
+
## Need more?
|
|
131
|
+
|
|
132
|
+
Need the full version? **AgentTrail Scrub** on PyForge: https://py-forge.com/products/agenttrail-scrub-ai-transcript-secret-cleaner?utm_source=github&utm_medium=readme&utm_campaign=agenttrail-scrub-lite
|
|
133
|
+
|
|
134
|
+
Or get every PyForge tool, current and future, with the All-Access Pass: https://py-forge.com/pass?utm_source=github&utm_medium=readme&utm_campaign=agenttrail-scrub-lite
|
|
135
|
+
|
|
136
|
+
## Tests
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
python3 test_agenttrail_scrub_lite.py
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## More free tools from the same author
|
|
143
|
+
|
|
144
|
+
- [agentconfig-audit-lite](https://github.com/alessio1999xx-debug/agentconfig-audit-lite) — Audit MCP config for secrets: plaintext tokens and unpinned npx/uvx servers in `.mcp.json` and `CLAUDE.md`.
|
|
145
|
+
- [cronpulse-lite](https://github.com/alessio1999xx-debug/cronpulse-lite) — Cron job monitoring in one Python file: alerts to Slack/Discord/webhook on failure or hang.
|
|
146
|
+
- [depcooldown-lite](https://github.com/alessio1999xx-debug/depcooldown-lite) — Dependency cooldown check: fail CI when a pinned PyPI or npm package is newer than N days.
|
|
147
|
+
- [homelab-doctor-lite](https://github.com/alessio1999xx-debug/homelab-doctor-lite) — Read-only homelab health check: stale images, exposed ports, expiring certs, silent cron, disk.
|
|
148
|
+
- [imagenudge-lite](https://github.com/alessio1999xx-debug/imagenudge-lite) — Docker image update checker: find running containers with a newer image (digest or tag).
|
|
149
|
+
- [pthguard-lite](https://github.com/alessio1999xx-debug/pthguard-lite) — Scan Python site-packages for malicious `.pth` files and startup backdoors.
|
|
150
|
+
- [pulseping-lite](https://github.com/alessio1999xx-debug/pulseping-lite) — Check SSL certificate expiry and URL/port uptime from cron.
|
|
151
|
+
- [secenv-lite](https://github.com/alessio1999xx-debug/secenv-lite) — Find `.env` files committed to git or missing from `.gitignore`, plus obvious API keys inside.
|
|
152
|
+
|
|
153
|
+
## License
|
|
154
|
+
|
|
155
|
+
MIT (this lite version). The full AgentTrail Scrub tool is sold separately under its own license.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
agenttrail_scrub_lite.py,sha256=fVHiRb-_RKxGgazK1B1gxbJcvbvp3a0b8YUst7ypyT4,10174
|
|
2
|
+
agenttrail_scrub_lite-0.1.0.dist-info/licenses/LICENSE,sha256=UogbiChOs5hJVxEarcfEGO-mtfsJmsPtvoSAB493trg,1082
|
|
3
|
+
agenttrail_scrub_lite-0.1.0.dist-info/METADATA,sha256=4TeP-XZPQZDkKBvGUrYnud7-wriUxd4PhkDlzd-kVuM,9314
|
|
4
|
+
agenttrail_scrub_lite-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
5
|
+
agenttrail_scrub_lite-0.1.0.dist-info/entry_points.txt,sha256=CAK6Dz7f9GKcNav_yEaAeOxdElWQP8KsFMmvafbXbHE,69
|
|
6
|
+
agenttrail_scrub_lite-0.1.0.dist-info/top_level.txt,sha256=XmK69L4cfTJHna8wpcm5I7UyKetGMbhQTfWNd00l7AI,22
|
|
7
|
+
agenttrail_scrub_lite-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Alessio Auretto (PyForge)
|
|
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
|
+
agenttrail_scrub_lite
|
agenttrail_scrub_lite.py
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""agenttrail-scrub-lite: read-only scan of Claude Code transcripts for leaked secrets.
|
|
3
|
+
|
|
4
|
+
Single file, Python 3.9+ standard library only. Finds common provider API keys
|
|
5
|
+
and tokens in ~/.claude/projects/*.jsonl (or a --path you pass). Reports masked
|
|
6
|
+
previews; never modifies files.
|
|
7
|
+
|
|
8
|
+
python agenttrail_scrub_lite.py
|
|
9
|
+
python agenttrail_scrub_lite.py --path /custom/dir
|
|
10
|
+
python agenttrail_scrub_lite.py --help
|
|
11
|
+
|
|
12
|
+
Full version (other agents, entropy checks, --redact with backups, allowlist,
|
|
13
|
+
retention, rotation checklist):
|
|
14
|
+
https://py-forge.com/products/agenttrail-scrub-ai-transcript-secret-cleaner?utm_source=github&utm_medium=code&utm_content=agenttrail-scrub-lite
|
|
15
|
+
"""
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import argparse
|
|
19
|
+
import os
|
|
20
|
+
import pathlib
|
|
21
|
+
import re
|
|
22
|
+
import sys
|
|
23
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
24
|
+
|
|
25
|
+
__version__ = "0.1.0"
|
|
26
|
+
|
|
27
|
+
# High-confidence provider signatures. Lite uses regex only (no entropy filter).
|
|
28
|
+
# Patterns report the captured secret group when present, else the full match.
|
|
29
|
+
SECRET_PATTERNS: List[Tuple[str, re.Pattern[str]]] = [
|
|
30
|
+
(
|
|
31
|
+
"Anthropic API Key",
|
|
32
|
+
re.compile(r"\b(sk-ant-api03-[A-Za-z0-9_-]{80,120})\b"),
|
|
33
|
+
),
|
|
34
|
+
(
|
|
35
|
+
"Anthropic Legacy Key",
|
|
36
|
+
re.compile(r"\b(sk-ant-(?!api03)[A-Za-z0-9_-]{32,80})\b"),
|
|
37
|
+
),
|
|
38
|
+
(
|
|
39
|
+
"OpenAI API Key",
|
|
40
|
+
re.compile(r"\b(sk-(?!ant-)(?:proj-)?[A-Za-z0-9_-]{32,120})\b"),
|
|
41
|
+
),
|
|
42
|
+
(
|
|
43
|
+
"Google Gemini / Cloud API Key",
|
|
44
|
+
re.compile(r"\b(AIzaSy[A-Za-z0-9_-]{33})\b"),
|
|
45
|
+
),
|
|
46
|
+
(
|
|
47
|
+
"GitHub Personal Access / OAuth Token",
|
|
48
|
+
re.compile(r"\b((?:ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9]{36,255})\b"),
|
|
49
|
+
),
|
|
50
|
+
(
|
|
51
|
+
"GitHub Fine-Grained Token",
|
|
52
|
+
re.compile(r"\b(github_pat_[A-Za-z0-9_]{82})\b"),
|
|
53
|
+
),
|
|
54
|
+
(
|
|
55
|
+
"AWS Access Key ID",
|
|
56
|
+
re.compile(r"\b((?:AKIA|ABIA|ACCA|ASIA)[0-9A-Z]{16})\b"),
|
|
57
|
+
),
|
|
58
|
+
(
|
|
59
|
+
"AWS Secret Access Key",
|
|
60
|
+
re.compile(
|
|
61
|
+
r"(?i)(?:aws_secret_access_key|aws_secret_key|secret_key)\s*[:=]\s*"
|
|
62
|
+
r"['\"]?([A-Za-z0-9/+=]{40})['\"]?"
|
|
63
|
+
),
|
|
64
|
+
),
|
|
65
|
+
(
|
|
66
|
+
"Stripe Secret Key",
|
|
67
|
+
re.compile(r"\b((?:sk|rk)_(?:live|test)_[A-Za-z0-9]{16,})\b"),
|
|
68
|
+
),
|
|
69
|
+
(
|
|
70
|
+
"Slack Token",
|
|
71
|
+
re.compile(r"\b(xox[baprs]-[A-Za-z0-9-]{10,})\b"),
|
|
72
|
+
),
|
|
73
|
+
(
|
|
74
|
+
"Private Key Header",
|
|
75
|
+
re.compile(r"(-----BEGIN [A-Z0-9_-]+ PRIVATE KEY-----)"),
|
|
76
|
+
),
|
|
77
|
+
(
|
|
78
|
+
"JSON Web Token (JWT)",
|
|
79
|
+
re.compile(
|
|
80
|
+
r"\b(eyJh[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,})\b"
|
|
81
|
+
),
|
|
82
|
+
),
|
|
83
|
+
(
|
|
84
|
+
"Generic Token Assignment (.env style)",
|
|
85
|
+
re.compile(
|
|
86
|
+
r"(?i)\b(?:api_key|apikey|secret|token|auth_token|access_token|"
|
|
87
|
+
r"private_key|app_secret)\s*[:=]\s*"
|
|
88
|
+
r"['\"]?([A-Za-z0-9_\-+=/]{16,128})['\"]?"
|
|
89
|
+
),
|
|
90
|
+
),
|
|
91
|
+
]
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def default_claude_projects_dir() -> pathlib.Path:
|
|
95
|
+
return pathlib.Path.home() / ".claude" / "projects"
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def mask_secret(value: str) -> str:
|
|
99
|
+
"""Produce a safe masked preview of a secret string."""
|
|
100
|
+
clean = value.strip().replace("\n", "").replace("\r", "")
|
|
101
|
+
if len(clean) <= 8:
|
|
102
|
+
return "[REDACTED]"
|
|
103
|
+
return f"{clean[:4]}...{clean[-3:]}"
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def collect_jsonl_files(root: pathlib.Path) -> List[pathlib.Path]:
|
|
107
|
+
"""Collect .jsonl files under root (or return root if it is a .jsonl file)."""
|
|
108
|
+
if not root.exists():
|
|
109
|
+
return []
|
|
110
|
+
if root.is_file():
|
|
111
|
+
return [root] if root.suffix.lower() == ".jsonl" else []
|
|
112
|
+
found: List[pathlib.Path] = []
|
|
113
|
+
for dirpath, _dirnames, filenames in os.walk(root, followlinks=False):
|
|
114
|
+
current = pathlib.Path(dirpath)
|
|
115
|
+
for fname in filenames:
|
|
116
|
+
if fname.lower().endswith(".jsonl"):
|
|
117
|
+
found.append(current / fname)
|
|
118
|
+
return sorted(found)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def scan_file(file_path: pathlib.Path) -> List[Dict[str, Any]]:
|
|
122
|
+
"""Scan one transcript file line by line for provider secret patterns."""
|
|
123
|
+
hits: List[Dict[str, Any]] = []
|
|
124
|
+
try:
|
|
125
|
+
text = file_path.read_text(encoding="utf-8", errors="replace")
|
|
126
|
+
except (OSError, PermissionError) as exc:
|
|
127
|
+
return [
|
|
128
|
+
{
|
|
129
|
+
"provider": "UNREADABLE_FILE",
|
|
130
|
+
"path": str(file_path),
|
|
131
|
+
"line": 0,
|
|
132
|
+
"masked": "",
|
|
133
|
+
"description": f"Cannot read file: {exc}",
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
|
|
137
|
+
seen: set[Tuple[int, str, str]] = set()
|
|
138
|
+
for line_no, line in enumerate(text.splitlines(), start=1):
|
|
139
|
+
for provider, pattern in SECRET_PATTERNS:
|
|
140
|
+
for match in pattern.finditer(line):
|
|
141
|
+
raw = match.group(1) if match.lastindex else match.group(0)
|
|
142
|
+
key = (line_no, provider, raw)
|
|
143
|
+
if key in seen:
|
|
144
|
+
continue
|
|
145
|
+
seen.add(key)
|
|
146
|
+
hits.append(
|
|
147
|
+
{
|
|
148
|
+
"provider": provider,
|
|
149
|
+
"path": str(file_path),
|
|
150
|
+
"line": line_no,
|
|
151
|
+
"masked": mask_secret(raw),
|
|
152
|
+
"description": f"{provider} match (masked preview)",
|
|
153
|
+
}
|
|
154
|
+
)
|
|
155
|
+
return hits
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
class LiteScanner:
|
|
159
|
+
"""Read-only Claude Code transcript secret scanner (lite)."""
|
|
160
|
+
|
|
161
|
+
def __init__(self, target: pathlib.Path) -> None:
|
|
162
|
+
self.target = target
|
|
163
|
+
self.files_scanned = 0
|
|
164
|
+
self.findings: List[Dict[str, Any]] = []
|
|
165
|
+
|
|
166
|
+
def run(self) -> Dict[str, Any]:
|
|
167
|
+
files = collect_jsonl_files(self.target)
|
|
168
|
+
if not self.target.exists():
|
|
169
|
+
self.findings.append(
|
|
170
|
+
{
|
|
171
|
+
"provider": "PATH_NOT_FOUND",
|
|
172
|
+
"path": str(self.target),
|
|
173
|
+
"line": 0,
|
|
174
|
+
"masked": "",
|
|
175
|
+
"description": "Scan target path does not exist",
|
|
176
|
+
}
|
|
177
|
+
)
|
|
178
|
+
elif self.target.is_file() and self.target.suffix.lower() != ".jsonl":
|
|
179
|
+
self.findings.append(
|
|
180
|
+
{
|
|
181
|
+
"provider": "NOT_JSONL",
|
|
182
|
+
"path": str(self.target),
|
|
183
|
+
"line": 0,
|
|
184
|
+
"masked": "",
|
|
185
|
+
"description": "Target file is not a .jsonl transcript",
|
|
186
|
+
}
|
|
187
|
+
)
|
|
188
|
+
else:
|
|
189
|
+
for fpath in files:
|
|
190
|
+
self.files_scanned += 1
|
|
191
|
+
self.findings.extend(scan_file(fpath))
|
|
192
|
+
|
|
193
|
+
secret_hits = [
|
|
194
|
+
f
|
|
195
|
+
for f in self.findings
|
|
196
|
+
if f["provider"]
|
|
197
|
+
not in ("PATH_NOT_FOUND", "NOT_JSONL", "UNREADABLE_FILE")
|
|
198
|
+
]
|
|
199
|
+
return {
|
|
200
|
+
"summary": {
|
|
201
|
+
"target": str(self.target),
|
|
202
|
+
"files_scanned": self.files_scanned,
|
|
203
|
+
"findings": len(self.findings),
|
|
204
|
+
"secrets_found": len(secret_hits),
|
|
205
|
+
},
|
|
206
|
+
"findings": self.findings,
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def format_text_report(results: Dict[str, Any]) -> str:
|
|
211
|
+
summary = results["summary"]
|
|
212
|
+
findings = results["findings"]
|
|
213
|
+
lines = [
|
|
214
|
+
"================================================================================",
|
|
215
|
+
" AGENTTRAIL-SCRUB-LITE SCAN REPORT ",
|
|
216
|
+
"================================================================================",
|
|
217
|
+
f"Target : {summary['target']}",
|
|
218
|
+
f"JSONL Files Scanned : {summary['files_scanned']}",
|
|
219
|
+
f"Findings : {summary['findings']}",
|
|
220
|
+
f"Secrets Reported : {summary['secrets_found']}",
|
|
221
|
+
"--------------------------------------------------------------------------------",
|
|
222
|
+
]
|
|
223
|
+
if summary["secrets_found"] == 0 and not any(
|
|
224
|
+
f["provider"] in ("PATH_NOT_FOUND", "NOT_JSONL", "UNREADABLE_FILE")
|
|
225
|
+
for f in findings
|
|
226
|
+
):
|
|
227
|
+
lines.append(
|
|
228
|
+
"[+] Status: CLEAN. No common provider secret patterns detected "
|
|
229
|
+
"in scanned transcripts."
|
|
230
|
+
)
|
|
231
|
+
else:
|
|
232
|
+
lines.append(f"Findings ({len(findings)} total):")
|
|
233
|
+
for i, f in enumerate(findings, start=1):
|
|
234
|
+
lines.append(f"\n{i}. Provider : {f['provider']}")
|
|
235
|
+
lines.append(f" Path : {f['path']}")
|
|
236
|
+
if f["line"]:
|
|
237
|
+
lines.append(f" Line : {f['line']}")
|
|
238
|
+
if f["masked"]:
|
|
239
|
+
lines.append(f" Preview : {f['masked']}")
|
|
240
|
+
lines.append(f" Details : {f['description']}")
|
|
241
|
+
lines.append("================================================================================")
|
|
242
|
+
lines.append(
|
|
243
|
+
"Read-only scan. No files were modified. Rotate any real credentials "
|
|
244
|
+
"at the provider."
|
|
245
|
+
)
|
|
246
|
+
return "\n".join(lines)
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
250
|
+
p = argparse.ArgumentParser(
|
|
251
|
+
prog="agenttrail-scrub-lite",
|
|
252
|
+
description=(
|
|
253
|
+
"Read-only scan of Claude Code JSONL transcripts for common "
|
|
254
|
+
"provider API keys and tokens (Anthropic, OpenAI, Google, GitHub, "
|
|
255
|
+
"AWS, Stripe, Slack, JWT, private-key headers, .env-style "
|
|
256
|
+
"assignments). Stdlib only; never modifies files."
|
|
257
|
+
),
|
|
258
|
+
epilog=(
|
|
259
|
+
"Full version: https://py-forge.com/products/"
|
|
260
|
+
"agenttrail-scrub-ai-transcript-secret-cleaner"
|
|
261
|
+
"?utm_source=github&utm_medium=cli&utm_content=agenttrail-scrub-lite"
|
|
262
|
+
),
|
|
263
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
264
|
+
)
|
|
265
|
+
p.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
|
|
266
|
+
p.add_argument(
|
|
267
|
+
"--path",
|
|
268
|
+
metavar="DIR_OR_FILE",
|
|
269
|
+
help=(
|
|
270
|
+
"Override the default Claude Code projects dir "
|
|
271
|
+
"(~/.claude/projects). Pass a directory of .jsonl files or one "
|
|
272
|
+
".jsonl file."
|
|
273
|
+
),
|
|
274
|
+
)
|
|
275
|
+
return p
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def main(argv: Optional[List[str]] = None) -> int:
|
|
279
|
+
args = build_parser().parse_args(argv)
|
|
280
|
+
if args.path:
|
|
281
|
+
target = pathlib.Path(args.path).expanduser()
|
|
282
|
+
else:
|
|
283
|
+
target = default_claude_projects_dir()
|
|
284
|
+
|
|
285
|
+
results = LiteScanner(target).run()
|
|
286
|
+
print(format_text_report(results))
|
|
287
|
+
return 1 if results["summary"]["secrets_found"] > 0 else 0
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
if __name__ == "__main__":
|
|
291
|
+
sys.exit(main())
|