leakkill 0.7.0__tar.gz → 0.7.2__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.
- {leakkill-0.7.0/src/leakkill.egg-info → leakkill-0.7.2}/PKG-INFO +7 -5
- {leakkill-0.7.0 → leakkill-0.7.2}/README.md +6 -4
- {leakkill-0.7.0 → leakkill-0.7.2}/src/leakkill/__init__.py +1 -1
- {leakkill-0.7.0 → leakkill-0.7.2}/src/leakkill/cli.py +36 -1
- {leakkill-0.7.0 → leakkill-0.7.2}/src/leakkill/scanner.py +97 -10
- {leakkill-0.7.0 → leakkill-0.7.2/src/leakkill.egg-info}/PKG-INFO +7 -5
- {leakkill-0.7.0 → leakkill-0.7.2}/src/leakkill.egg-info/SOURCES.txt +1 -0
- {leakkill-0.7.0 → leakkill-0.7.2}/tests/test_cli.py +10 -0
- leakkill-0.7.2/tests/test_real_world.py +99 -0
- {leakkill-0.7.0 → leakkill-0.7.2}/LICENSE +0 -0
- {leakkill-0.7.0 → leakkill-0.7.2}/THIRD_PARTY_NOTICES.md +0 -0
- {leakkill-0.7.0 → leakkill-0.7.2}/pyproject.toml +0 -0
- {leakkill-0.7.0 → leakkill-0.7.2}/setup.cfg +0 -0
- {leakkill-0.7.0 → leakkill-0.7.2}/src/leakkill/__main__.py +0 -0
- {leakkill-0.7.0 → leakkill-0.7.2}/src/leakkill/agents.py +0 -0
- {leakkill-0.7.0 → leakkill-0.7.2}/src/leakkill/aws.py +0 -0
- {leakkill-0.7.0 → leakkill-0.7.2}/src/leakkill/baseline.py +0 -0
- {leakkill-0.7.0 → leakkill-0.7.2}/src/leakkill/gitleaks_rules.py +0 -0
- {leakkill-0.7.0 → leakkill-0.7.2}/src/leakkill/guard.py +0 -0
- {leakkill-0.7.0 → leakkill-0.7.2}/src/leakkill/providers.py +0 -0
- {leakkill-0.7.0 → leakkill-0.7.2}/src/leakkill/report.py +0 -0
- {leakkill-0.7.0 → leakkill-0.7.2}/src/leakkill/sarif.py +0 -0
- {leakkill-0.7.0 → leakkill-0.7.2}/src/leakkill.egg-info/dependency_links.txt +0 -0
- {leakkill-0.7.0 → leakkill-0.7.2}/src/leakkill.egg-info/entry_points.txt +0 -0
- {leakkill-0.7.0 → leakkill-0.7.2}/src/leakkill.egg-info/top_level.txt +0 -0
- {leakkill-0.7.0 → leakkill-0.7.2}/tests/test_agents.py +0 -0
- {leakkill-0.7.0 → leakkill-0.7.2}/tests/test_coverage_gaps.py +0 -0
- {leakkill-0.7.0 → leakkill-0.7.2}/tests/test_fuzz.py +0 -0
- {leakkill-0.7.0 → leakkill-0.7.2}/tests/test_guard.py +0 -0
- {leakkill-0.7.0 → leakkill-0.7.2}/tests/test_guard_agents.py +0 -0
- {leakkill-0.7.0 → leakkill-0.7.2}/tests/test_import_gitleaks.py +0 -0
- {leakkill-0.7.0 → leakkill-0.7.2}/tests/test_providers.py +0 -0
- {leakkill-0.7.0 → leakkill-0.7.2}/tests/test_redos.py +0 -0
- {leakkill-0.7.0 → leakkill-0.7.2}/tests/test_scanner.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: leakkill
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.2
|
|
4
4
|
Summary: Find leaked secrets, check if they're live, revoke them in one command, and keep them out of AI coding agents
|
|
5
5
|
Author-email: Ayush <andymylove24@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -70,7 +70,7 @@ docker run --rm -v "$PWD:/scan" ghcr.io/ayushanand27/leakkill --history # every
|
|
|
70
70
|
| `leakkill install-hook` | Git pre-commit hook that blocks commits containing secrets | Never |
|
|
71
71
|
| `leakkill install-agent-hooks` | Stop AI coding agents (Claude Code, Cursor, GitHub Copilot, OpenAI Codex) reading `.env` and keys, sending secrets in prompts, or writing secrets into code | Never |
|
|
72
72
|
|
|
73
|
-
Every scan command also accepts `--staged` (pre-commit), `--history` (every commit on every branch,
|
|
73
|
+
Every scan command also accepts `--include-ignored` (also scan `.gitignore`d files, which are left out by default), `--staged` (pre-commit), `--history` (every commit on every branch,
|
|
74
74
|
including secrets you already "deleted"), `--agents` (secrets your AI coding agents stored on this machine, see
|
|
75
75
|
below), `--exclude-tests` and `--json`.
|
|
76
76
|
|
|
@@ -144,10 +144,12 @@ End to end on Windows with real, throwaway credentials:
|
|
|
144
144
|
| Slack webhook | LIVE | (died with the app) | DEAD |
|
|
145
145
|
| Stripe test key | LIVE, correct account, "test mode" | manual roll in dashboard | |
|
|
146
146
|
| Hugging Face token | LIVE, correct user and token role | manual delete | |
|
|
147
|
+
| Postman API key | LIVE, correct username | manual delete (page linked) | DEAD |
|
|
148
|
+
| Netlify access token | LIVE, correct account email | manual delete (page linked) | DEAD |
|
|
147
149
|
|
|
148
150
|
Against the real AWS, GitLab, Anthropic and npm APIs, invalid keys are correctly reported DEAD.
|
|
149
151
|
Providers not yet tested with a live key (OpenAI, OpenRouter, Groq, Replicate, DigitalOcean,
|
|
150
|
-
SendGrid, Telegram, and the
|
|
152
|
+
SendGrid, Telegram, and the other 13 added in 0.7) are covered by tests using simulated API responses.
|
|
151
153
|
|
|
152
154
|
### Accuracy (independent dataset)
|
|
153
155
|
|
|
@@ -171,7 +173,7 @@ leakkill somewhat; false alarms on four clean repositories (requests, flask, dja
|
|
|
171
173
|
|
|
172
174
|
### How it's tested
|
|
173
175
|
|
|
174
|
-
-
|
|
176
|
+
- 163 tests on Linux, macOS and Windows with Python 3.9 and 3.13; CI fails below 88% branch coverage (currently 93%).
|
|
175
177
|
- Property-based fuzz tests: the scanner never crashes on random input, never prints a raw secret, finds a
|
|
176
178
|
planted token in any surrounding text, and gives the same answer scanning a whole file or line by line.
|
|
177
179
|
(Fuzzing found two real bugs before release: a guard crash and a slow-input case, both fixed.)
|
|
@@ -323,7 +325,7 @@ baseline doesn't make it safe: revoke real keys first.
|
|
|
323
325
|
# .pre-commit-config.yaml
|
|
324
326
|
repos:
|
|
325
327
|
- repo: https://github.com/ayushanand27/leakkill
|
|
326
|
-
rev: v0.7.
|
|
328
|
+
rev: v0.7.2
|
|
327
329
|
hooks:
|
|
328
330
|
- id: leakkill
|
|
329
331
|
```
|
|
@@ -50,7 +50,7 @@ docker run --rm -v "$PWD:/scan" ghcr.io/ayushanand27/leakkill --history # every
|
|
|
50
50
|
| `leakkill install-hook` | Git pre-commit hook that blocks commits containing secrets | Never |
|
|
51
51
|
| `leakkill install-agent-hooks` | Stop AI coding agents (Claude Code, Cursor, GitHub Copilot, OpenAI Codex) reading `.env` and keys, sending secrets in prompts, or writing secrets into code | Never |
|
|
52
52
|
|
|
53
|
-
Every scan command also accepts `--staged` (pre-commit), `--history` (every commit on every branch,
|
|
53
|
+
Every scan command also accepts `--include-ignored` (also scan `.gitignore`d files, which are left out by default), `--staged` (pre-commit), `--history` (every commit on every branch,
|
|
54
54
|
including secrets you already "deleted"), `--agents` (secrets your AI coding agents stored on this machine, see
|
|
55
55
|
below), `--exclude-tests` and `--json`.
|
|
56
56
|
|
|
@@ -124,10 +124,12 @@ End to end on Windows with real, throwaway credentials:
|
|
|
124
124
|
| Slack webhook | LIVE | (died with the app) | DEAD |
|
|
125
125
|
| Stripe test key | LIVE, correct account, "test mode" | manual roll in dashboard | |
|
|
126
126
|
| Hugging Face token | LIVE, correct user and token role | manual delete | |
|
|
127
|
+
| Postman API key | LIVE, correct username | manual delete (page linked) | DEAD |
|
|
128
|
+
| Netlify access token | LIVE, correct account email | manual delete (page linked) | DEAD |
|
|
127
129
|
|
|
128
130
|
Against the real AWS, GitLab, Anthropic and npm APIs, invalid keys are correctly reported DEAD.
|
|
129
131
|
Providers not yet tested with a live key (OpenAI, OpenRouter, Groq, Replicate, DigitalOcean,
|
|
130
|
-
SendGrid, Telegram, and the
|
|
132
|
+
SendGrid, Telegram, and the other 13 added in 0.7) are covered by tests using simulated API responses.
|
|
131
133
|
|
|
132
134
|
### Accuracy (independent dataset)
|
|
133
135
|
|
|
@@ -151,7 +153,7 @@ leakkill somewhat; false alarms on four clean repositories (requests, flask, dja
|
|
|
151
153
|
|
|
152
154
|
### How it's tested
|
|
153
155
|
|
|
154
|
-
-
|
|
156
|
+
- 163 tests on Linux, macOS and Windows with Python 3.9 and 3.13; CI fails below 88% branch coverage (currently 93%).
|
|
155
157
|
- Property-based fuzz tests: the scanner never crashes on random input, never prints a raw secret, finds a
|
|
156
158
|
planted token in any surrounding text, and gives the same answer scanning a whole file or line by line.
|
|
157
159
|
(Fuzzing found two real bugs before release: a guard crash and a slow-input case, both fixed.)
|
|
@@ -303,7 +305,7 @@ baseline doesn't make it safe: revoke real keys first.
|
|
|
303
305
|
# .pre-commit-config.yaml
|
|
304
306
|
repos:
|
|
305
307
|
- repo: https://github.com/ayushanand27/leakkill
|
|
306
|
-
rev: v0.7.
|
|
308
|
+
rev: v0.7.2
|
|
307
309
|
hooks:
|
|
308
310
|
- id: leakkill
|
|
309
311
|
```
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"""leakkill: find leaked secrets, check if they're live, revoke them, and guard AI coding agents."""
|
|
2
|
-
__version__ = "0.7.
|
|
2
|
+
__version__ = "0.7.2"
|
|
@@ -35,6 +35,21 @@ class Item:
|
|
|
35
35
|
result: providers.Result = None
|
|
36
36
|
|
|
37
37
|
|
|
38
|
+
def note_skipped():
|
|
39
|
+
"""Never let "Clean." hide that some files were not looked at."""
|
|
40
|
+
if scanner.SKIPPED:
|
|
41
|
+
why = {}
|
|
42
|
+
for sk in scanner.SKIPPED:
|
|
43
|
+
why.setdefault(sk.reason, []).append(sk.path)
|
|
44
|
+
parts = "; ".join(f"{len(v)} {r} (e.g. {', '.join(v[:2])})" for r, v in why.items())
|
|
45
|
+
print(f"leakkill: skipped {len(scanner.SKIPPED)} file(s) it could not scan: {parts}", file=sys.stderr)
|
|
46
|
+
if scanner.IGNORED:
|
|
47
|
+
roots = scanner.IGNORED_ROOTS
|
|
48
|
+
print(f"leakkill: left out {len(scanner.IGNORED)} git-ignored file(s) (they can't be committed): "
|
|
49
|
+
f"{', '.join(roots[:3])}{', ...' if len(roots) > 3 else ''}. Add --include-ignored to scan them too.",
|
|
50
|
+
file=sys.stderr)
|
|
51
|
+
|
|
52
|
+
|
|
38
53
|
def collect(args):
|
|
39
54
|
if args.agents:
|
|
40
55
|
found = agents.scan_agents()
|
|
@@ -43,7 +58,8 @@ def collect(args):
|
|
|
43
58
|
elif args.staged:
|
|
44
59
|
found = scanner.scan_staged()
|
|
45
60
|
else:
|
|
46
|
-
found = scanner.scan_paths(args.paths or ["."])
|
|
61
|
+
found = scanner.scan_paths(args.paths or ["."], include_ignored=args.include_ignored)
|
|
62
|
+
note_skipped()
|
|
47
63
|
ignores = scanner.load_ignores()
|
|
48
64
|
found = [f for f in found if not scanner.ignored(f.path, ignores)]
|
|
49
65
|
if args.exclude_tests:
|
|
@@ -106,6 +122,21 @@ def summary(items):
|
|
|
106
122
|
return s + "."
|
|
107
123
|
|
|
108
124
|
|
|
125
|
+
def next_step(items, args, verified):
|
|
126
|
+
"""One line telling a newcomer what to run next (text output only)."""
|
|
127
|
+
if not items:
|
|
128
|
+
return ""
|
|
129
|
+
flags = "".join(f" --{f}" for f in ("agents", "history", "staged") if getattr(args, f, False))
|
|
130
|
+
if not verified:
|
|
131
|
+
return (f"Next: `leakkill verify{flags}` checks which still work and whose they are. "
|
|
132
|
+
"False alarm? Add `leakkill:ignore` to that line.")
|
|
133
|
+
live = sum(1 for i in items if i.result and i.result.status == providers.LIVE)
|
|
134
|
+
if live:
|
|
135
|
+
return (f"Next: `leakkill revoke{flags}` shows how to kill the {live} live key(s) (add --yes to do it); "
|
|
136
|
+
f"`leakkill report{flags}` writes the cleanup steps.")
|
|
137
|
+
return f"None are live, but still remove them from the code: `leakkill report{flags}` lists the steps."
|
|
138
|
+
|
|
139
|
+
|
|
109
140
|
def _target(args):
|
|
110
141
|
return "AI agent files" if args.agents else "git history" if args.history else "staged changes" if args.staged else " ".join(args.paths or ["."])
|
|
111
142
|
|
|
@@ -124,6 +155,9 @@ def cmd_scan(args, verify=False):
|
|
|
124
155
|
else:
|
|
125
156
|
print_items(items)
|
|
126
157
|
print(summary(items))
|
|
158
|
+
hint = next_step(items, args, verify)
|
|
159
|
+
if hint:
|
|
160
|
+
print(hint)
|
|
127
161
|
if args.agents and items:
|
|
128
162
|
print("\n" + agents.ADVICE)
|
|
129
163
|
if args.report:
|
|
@@ -200,6 +234,7 @@ def parser():
|
|
|
200
234
|
common.add_argument("--history", action="store_true", help="scan every commit on every branch")
|
|
201
235
|
common.add_argument("--agents", action="store_true",
|
|
202
236
|
help="scan AI agents' files on this machine: MCP configs, settings, session transcripts")
|
|
237
|
+
common.add_argument("--include-ignored", action="store_true", help="also scan files that .gitignore excludes")
|
|
203
238
|
common.add_argument("--exclude-tests", action="store_true", help="skip test_* files and tests/ dirs")
|
|
204
239
|
common.add_argument("--json", action="store_true", help="machine-readable output")
|
|
205
240
|
common.add_argument("--baseline", metavar="FILE", help="ignore secrets listed in this baseline file")
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"""Find secrets in files, staged changes and git history. Never touches the network."""
|
|
2
|
-
import base64, bisect, fnmatch, math, os, re, subprocess
|
|
2
|
+
import base64, bisect, codecs, fnmatch, math, os, re, stat, subprocess
|
|
3
3
|
from concurrent.futures import ProcessPoolExecutor
|
|
4
4
|
from dataclasses import dataclass
|
|
5
5
|
|
|
@@ -352,14 +352,57 @@ def iter_files(paths):
|
|
|
352
352
|
yield os.path.join(root, f)
|
|
353
353
|
|
|
354
354
|
|
|
355
|
+
MAX_SCAN_BYTES = 2_000_000
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
@dataclass
|
|
359
|
+
class Skipped:
|
|
360
|
+
path: str
|
|
361
|
+
reason: str # "too large" | "unreadable"
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
SKIPPED = [] # files the last scan_paths() could not scan, so callers can say so instead of claiming "Clean."
|
|
365
|
+
IGNORED = [] # git-ignored files the last scan_paths() left out (they can't be committed, so they aren't leaks)
|
|
366
|
+
IGNORED_ROOTS = [] # ...and the ignored folders/files they belong to, for a short message
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
def decode_text(raw):
|
|
370
|
+
"""Bytes -> text for UTF-8 (tried first: the common case), UTF-16 (Windows PowerShell `echo >` writes it) and
|
|
371
|
+
single-byte text such as Latin-1. Returns None for binary data."""
|
|
372
|
+
if raw.startswith((codecs.BOM_UTF16_LE, codecs.BOM_UTF16_BE)):
|
|
373
|
+
try:
|
|
374
|
+
return raw.decode("utf-16")
|
|
375
|
+
except UnicodeDecodeError:
|
|
376
|
+
return None
|
|
377
|
+
sample = raw[:4096]
|
|
378
|
+
if b"\x00" in sample: # UTF-16 without a BOM looks like ASCII with a NUL on every other byte
|
|
379
|
+
n = len(sample) // 2
|
|
380
|
+
odd, even = sample[1::2].count(0), sample[0::2].count(0)
|
|
381
|
+
enc = "utf-16-le" if odd > 0.9 * n and even < 0.1 * n else "utf-16-be" if even > 0.9 * n and odd < 0.1 * n else None
|
|
382
|
+
if enc:
|
|
383
|
+
try:
|
|
384
|
+
return raw.decode(enc)
|
|
385
|
+
except UnicodeDecodeError:
|
|
386
|
+
return None
|
|
387
|
+
try:
|
|
388
|
+
return raw.decode("utf-8-sig")
|
|
389
|
+
except UnicodeDecodeError:
|
|
390
|
+
return None if b"\x00" in raw[:8192] else raw.decode("latin-1")
|
|
391
|
+
|
|
392
|
+
|
|
355
393
|
def _scan_file(f):
|
|
356
394
|
try:
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
395
|
+
st = os.stat(f)
|
|
396
|
+
if not stat.S_ISREG(st.st_mode):
|
|
397
|
+
return [] # pipes, sockets and devices: opening a pipe blocks forever, and they hold no source code
|
|
398
|
+
if st.st_size > MAX_SCAN_BYTES:
|
|
399
|
+
return [Skipped(f, "too large")]
|
|
400
|
+
with open(f, "rb") as fh:
|
|
401
|
+
raw = fh.read()
|
|
402
|
+
except OSError:
|
|
403
|
+
return [Skipped(f, "unreadable")]
|
|
404
|
+
text = decode_text(raw)
|
|
405
|
+
return scan_text(text, os.path.relpath(f)) if text is not None else []
|
|
363
406
|
|
|
364
407
|
|
|
365
408
|
def _parallel(fn, items, jobs=None):
|
|
@@ -374,9 +417,53 @@ def _parallel(fn, items, jobs=None):
|
|
|
374
417
|
return [f for item in items for f in fn(item)]
|
|
375
418
|
|
|
376
419
|
|
|
377
|
-
def
|
|
378
|
-
"""
|
|
379
|
-
|
|
420
|
+
def _git_ignored(path):
|
|
421
|
+
"""(files, directories) under `path` that git ignores and does not track; empty outside a git repository,
|
|
422
|
+
and empty when `path` itself is ignored (you named a folder like `data/`: you want it scanned)."""
|
|
423
|
+
try:
|
|
424
|
+
if subprocess.run(["git", "-C", path, "check-ignore", "-q", "."], capture_output=True, timeout=30).returncode == 0:
|
|
425
|
+
return set(), []
|
|
426
|
+
r = subprocess.run(["git", "-C", path, "ls-files", "--others", "--ignored", "--exclude-standard",
|
|
427
|
+
"--directory", "-z"], capture_output=True, timeout=30)
|
|
428
|
+
except (OSError, subprocess.SubprocessError):
|
|
429
|
+
return set(), []
|
|
430
|
+
if r.returncode:
|
|
431
|
+
return set(), []
|
|
432
|
+
files, dirs = set(), []
|
|
433
|
+
for rel in r.stdout.decode("utf-8", "replace").split("\0"):
|
|
434
|
+
if rel:
|
|
435
|
+
full = os.path.normpath(os.path.join(os.path.abspath(path), rel))
|
|
436
|
+
(dirs.append(full + os.sep) if rel.endswith("/") else files.add(full))
|
|
437
|
+
return files, dirs
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
def scan_paths(paths, jobs=None, include_ignored=False):
|
|
441
|
+
"""Scan files, in parallel across CPU cores when there are many of them.
|
|
442
|
+
|
|
443
|
+
Inside a git repository, files git ignores (a `.env` in .gitignore) are left out, because they can never be
|
|
444
|
+
committed; tracked files are always scanned. They are listed in IGNORED; `include_ignored` scans them too."""
|
|
445
|
+
files = list(iter_files(paths))
|
|
446
|
+
IGNORED[:] = []
|
|
447
|
+
IGNORED_ROOTS[:] = []
|
|
448
|
+
if not include_ignored:
|
|
449
|
+
skip_files, skip_dirs = set(), []
|
|
450
|
+
for p in paths:
|
|
451
|
+
if os.path.isdir(p):
|
|
452
|
+
f, d = _git_ignored(p)
|
|
453
|
+
skip_files |= f
|
|
454
|
+
skip_dirs += d
|
|
455
|
+
if skip_files or skip_dirs:
|
|
456
|
+
def root_of(f): # the git-ignored folder (or the file itself) that covers f, else None
|
|
457
|
+
full = os.path.normpath(os.path.abspath(f))
|
|
458
|
+
return full if full in skip_files else next((d for d in skip_dirs if full.startswith(d)), None)
|
|
459
|
+
roots = {f: root_of(f) for f in files}
|
|
460
|
+
IGNORED[:] = [f for f in files if roots[f]]
|
|
461
|
+
IGNORED_ROOTS[:] = sorted({os.path.relpath(roots[f]) + (os.sep if roots[f].endswith(os.sep) else "")
|
|
462
|
+
for f in IGNORED})
|
|
463
|
+
files = [f for f in files if not roots[f]]
|
|
464
|
+
out = _parallel(_scan_file, files, jobs)
|
|
465
|
+
SKIPPED[:] = [r for r in out if isinstance(r, Skipped)]
|
|
466
|
+
return [r for r in out if not isinstance(r, Skipped)]
|
|
380
467
|
|
|
381
468
|
|
|
382
469
|
def _git(*args):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: leakkill
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.2
|
|
4
4
|
Summary: Find leaked secrets, check if they're live, revoke them in one command, and keep them out of AI coding agents
|
|
5
5
|
Author-email: Ayush <andymylove24@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -70,7 +70,7 @@ docker run --rm -v "$PWD:/scan" ghcr.io/ayushanand27/leakkill --history # every
|
|
|
70
70
|
| `leakkill install-hook` | Git pre-commit hook that blocks commits containing secrets | Never |
|
|
71
71
|
| `leakkill install-agent-hooks` | Stop AI coding agents (Claude Code, Cursor, GitHub Copilot, OpenAI Codex) reading `.env` and keys, sending secrets in prompts, or writing secrets into code | Never |
|
|
72
72
|
|
|
73
|
-
Every scan command also accepts `--staged` (pre-commit), `--history` (every commit on every branch,
|
|
73
|
+
Every scan command also accepts `--include-ignored` (also scan `.gitignore`d files, which are left out by default), `--staged` (pre-commit), `--history` (every commit on every branch,
|
|
74
74
|
including secrets you already "deleted"), `--agents` (secrets your AI coding agents stored on this machine, see
|
|
75
75
|
below), `--exclude-tests` and `--json`.
|
|
76
76
|
|
|
@@ -144,10 +144,12 @@ End to end on Windows with real, throwaway credentials:
|
|
|
144
144
|
| Slack webhook | LIVE | (died with the app) | DEAD |
|
|
145
145
|
| Stripe test key | LIVE, correct account, "test mode" | manual roll in dashboard | |
|
|
146
146
|
| Hugging Face token | LIVE, correct user and token role | manual delete | |
|
|
147
|
+
| Postman API key | LIVE, correct username | manual delete (page linked) | DEAD |
|
|
148
|
+
| Netlify access token | LIVE, correct account email | manual delete (page linked) | DEAD |
|
|
147
149
|
|
|
148
150
|
Against the real AWS, GitLab, Anthropic and npm APIs, invalid keys are correctly reported DEAD.
|
|
149
151
|
Providers not yet tested with a live key (OpenAI, OpenRouter, Groq, Replicate, DigitalOcean,
|
|
150
|
-
SendGrid, Telegram, and the
|
|
152
|
+
SendGrid, Telegram, and the other 13 added in 0.7) are covered by tests using simulated API responses.
|
|
151
153
|
|
|
152
154
|
### Accuracy (independent dataset)
|
|
153
155
|
|
|
@@ -171,7 +173,7 @@ leakkill somewhat; false alarms on four clean repositories (requests, flask, dja
|
|
|
171
173
|
|
|
172
174
|
### How it's tested
|
|
173
175
|
|
|
174
|
-
-
|
|
176
|
+
- 163 tests on Linux, macOS and Windows with Python 3.9 and 3.13; CI fails below 88% branch coverage (currently 93%).
|
|
175
177
|
- Property-based fuzz tests: the scanner never crashes on random input, never prints a raw secret, finds a
|
|
176
178
|
planted token in any surrounding text, and gives the same answer scanning a whole file or line by line.
|
|
177
179
|
(Fuzzing found two real bugs before release: a guard crash and a slow-input case, both fixed.)
|
|
@@ -323,7 +325,7 @@ baseline doesn't make it safe: revoke real keys first.
|
|
|
323
325
|
# .pre-commit-config.yaml
|
|
324
326
|
repos:
|
|
325
327
|
- repo: https://github.com/ayushanand27/leakkill
|
|
326
|
-
rev: v0.7.
|
|
328
|
+
rev: v0.7.2
|
|
327
329
|
hooks:
|
|
328
330
|
- id: leakkill
|
|
329
331
|
```
|
|
@@ -131,3 +131,13 @@ def test_replacements_file_is_owner_only_and_never_overwrites(tmp_path, monkeypa
|
|
|
131
131
|
(tmp_path / "keep.txt").write_text("important")
|
|
132
132
|
assert cli.main(["report", "--replacements", "keep.txt"]) == 2
|
|
133
133
|
assert (tmp_path / "keep.txt").read_text() == "important" and "not overwriting" in capsys.readouterr().err
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def test_next_step_hints(tmp_path, monkeypatch, capsys):
|
|
137
|
+
project(tmp_path, monkeypatch); fake_verify(monkeypatch)
|
|
138
|
+
cli.main(["scan"])
|
|
139
|
+
assert "Next: `leakkill verify`" in capsys.readouterr().out
|
|
140
|
+
cli.main(["verify"])
|
|
141
|
+
assert "Next: `leakkill revoke`" in capsys.readouterr().out
|
|
142
|
+
cli.main(["scan", "--json"])
|
|
143
|
+
assert "Next:" not in capsys.readouterr().out # machine output stays pure JSON
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"""Bugs found by using leakkill like a newcomer on Windows and in a normal git project."""
|
|
2
|
+
import os, subprocess, sys
|
|
3
|
+
|
|
4
|
+
import pytest
|
|
5
|
+
|
|
6
|
+
from leakkill import cli, scanner
|
|
7
|
+
|
|
8
|
+
GH = "ghp_" + "a1B2c3D4e5F6g7H8i9J0k1L2m3N4o5P6q7R8"
|
|
9
|
+
LINE = f'TOKEN = "{GH}"\n'
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def found(tmp_path, **kw):
|
|
13
|
+
return {os.path.basename(f.path) for f in scanner.scan_paths([str(tmp_path)], **kw)}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_text_in_other_encodings_is_scanned(tmp_path):
|
|
17
|
+
(tmp_path / "utf16_bom.py").write_bytes(LINE.replace("\n", "\r\n").encode("utf-16")) # PowerShell 5 `echo >`
|
|
18
|
+
(tmp_path / "utf16_le_nobom.txt").write_bytes(LINE.encode("utf-16-le"))
|
|
19
|
+
(tmp_path / "utf16_be_nobom.txt").write_bytes(LINE.encode("utf-16-be"))
|
|
20
|
+
(tmp_path / "latin1.py").write_bytes(("# caf\xe9\n" + LINE).encode("latin-1"))
|
|
21
|
+
(tmp_path / "bom.py").write_bytes(b"\xef\xbb\xbf" + LINE.encode())
|
|
22
|
+
(tmp_path / "plain.py").write_text(LINE)
|
|
23
|
+
assert found(tmp_path) == {"utf16_bom.py", "utf16_le_nobom.txt", "utf16_be_nobom.txt", "latin1.py", "bom.py",
|
|
24
|
+
"plain.py"}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_decode_text_binary_and_edges():
|
|
28
|
+
assert scanner.decode_text(b"\xff\xfe\x00\x00\xd8") is None or True # never raises
|
|
29
|
+
assert scanner.decode_text(b"\x00\x01\xff\xfe\x00\x80" * 50) is None # binary with invalid UTF-8
|
|
30
|
+
assert scanner.decode_text(b"") == ""
|
|
31
|
+
assert scanner.decode_text("héllo".encode("utf-8")) == "héllo"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@pytest.mark.skipif(not hasattr(os, "mkfifo"), reason="needs named pipes")
|
|
35
|
+
def test_named_pipe_does_not_hang_the_scan(tmp_path):
|
|
36
|
+
os.mkfifo(tmp_path / "pipe")
|
|
37
|
+
(tmp_path / "app.py").write_text(LINE)
|
|
38
|
+
code = ("import sys; from leakkill import scanner; "
|
|
39
|
+
f"print(len(scanner.scan_paths([{str(tmp_path)!r}], jobs=1)))")
|
|
40
|
+
r = subprocess.run([sys.executable, "-c", code], capture_output=True, text=True, timeout=30)
|
|
41
|
+
assert r.stdout.strip() == "1" # a blocked read would have hit the timeout
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_skipped_files_are_reported_not_hidden(tmp_path, monkeypatch, capsys):
|
|
45
|
+
(tmp_path / "huge.sql").write_text(LINE * 5)
|
|
46
|
+
monkeypatch.setattr(scanner, "MAX_SCAN_BYTES", 10)
|
|
47
|
+
assert scanner.scan_paths([str(tmp_path)]) == []
|
|
48
|
+
assert [(os.path.basename(s.path), s.reason) for s in scanner.SKIPPED] == [("huge.sql", "too large")]
|
|
49
|
+
cli.note_skipped()
|
|
50
|
+
assert "skipped 1 file(s) it could not scan: 1 too large" in capsys.readouterr().err
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def git(cwd, *args):
|
|
54
|
+
subprocess.run(["git", *args], cwd=cwd, check=True, capture_output=True)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def test_gitignored_files_are_left_out_but_tracked_ones_never(tmp_path, capsys):
|
|
58
|
+
git(tmp_path, "init", "-q")
|
|
59
|
+
git(tmp_path, "config", "user.email", "t@example.com")
|
|
60
|
+
git(tmp_path, "config", "user.name", "t")
|
|
61
|
+
(tmp_path / ".gitignore").write_text(".env\nprivate/\n")
|
|
62
|
+
(tmp_path / "private").mkdir()
|
|
63
|
+
(tmp_path / "private" / "out.py").write_text(LINE)
|
|
64
|
+
(tmp_path / ".env").write_text(LINE)
|
|
65
|
+
(tmp_path / "app.py").write_text(LINE)
|
|
66
|
+
(tmp_path / "old.env.py").write_text(LINE)
|
|
67
|
+
git(tmp_path, "add", "-f", "old.env.py") # tracked
|
|
68
|
+
(tmp_path / ".gitignore").write_text(".env\nprivate/\nold.env.py\n") # ignored later, but still tracked
|
|
69
|
+
assert found(tmp_path) == {"app.py", "old.env.py"}
|
|
70
|
+
assert sorted(os.path.basename(f) for f in scanner.IGNORED) == [".env", "out.py"]
|
|
71
|
+
cli.note_skipped()
|
|
72
|
+
assert "left out 2 git-ignored file(s)" in capsys.readouterr().err
|
|
73
|
+
assert found(tmp_path, include_ignored=True) == {"app.py", "old.env.py", ".env", "out.py"}
|
|
74
|
+
assert scanner.IGNORED == []
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def test_no_git_means_everything_is_scanned(tmp_path):
|
|
78
|
+
(tmp_path / ".gitignore").write_text(".env\n") # not a repository: the file means nothing
|
|
79
|
+
(tmp_path / ".env").write_text(LINE)
|
|
80
|
+
assert found(tmp_path) == {".env"}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def test_cli_include_ignored_flag(tmp_path, monkeypatch):
|
|
84
|
+
git(tmp_path, "init", "-q")
|
|
85
|
+
(tmp_path / ".gitignore").write_text(".env\n")
|
|
86
|
+
(tmp_path / ".env").write_text(LINE)
|
|
87
|
+
monkeypatch.chdir(tmp_path)
|
|
88
|
+
assert cli.main(["scan"]) == 0
|
|
89
|
+
assert cli.main(["scan", "--include-ignored"]) == 1
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def test_naming_an_ignored_folder_scans_it(tmp_path):
|
|
93
|
+
git(tmp_path, "init", "-q")
|
|
94
|
+
(tmp_path / ".gitignore").write_text("data/\n")
|
|
95
|
+
(tmp_path / "data").mkdir()
|
|
96
|
+
(tmp_path / "data" / "dump.txt").write_text(LINE)
|
|
97
|
+
assert {os.path.basename(f.path) for f in scanner.scan_paths([str(tmp_path / "data")])} == {"dump.txt"}
|
|
98
|
+
assert scanner.IGNORED == []
|
|
99
|
+
assert found(tmp_path) == set() and len(scanner.IGNORED) == 1 # but scanning the repo root leaves it out
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|