leakkill 0.4.0__tar.gz → 0.4.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: leakkill
3
- Version: 0.4.0
3
+ Version: 0.4.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
@@ -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.4.0"
2
+ __version__ = "0.4.2"
@@ -11,7 +11,7 @@
11
11
  Common options: --staged (pre-commit), --history (all commits), --exclude-tests, --json.
12
12
  Ignore a line with `leakkill:ignore`; ignore paths with globs in .leakkillignore.
13
13
  """
14
- import argparse, json, os, sys
14
+ import argparse, difflib, json, os, sys
15
15
  from concurrent.futures import ThreadPoolExecutor
16
16
  from dataclasses import dataclass
17
17
 
@@ -189,6 +189,16 @@ def parser():
189
189
  return p
190
190
 
191
191
 
192
+ def check_paths(paths):
193
+ """A security tool must never report 'Clean.' for something it didn't scan (e.g. a typo'd command)."""
194
+ missing = [p for p in paths if not os.path.exists(p)]
195
+ for p in missing:
196
+ hint = difflib.get_close_matches(p, sorted(COMMANDS), n=1)
197
+ print(f"leakkill: no such file or directory: {p}" + (f" (did you mean `leakkill {hint[0]}`?)" if hint else ""),
198
+ file=sys.stderr)
199
+ return not missing
200
+
201
+
192
202
  def main(argv=None):
193
203
  argv = list(sys.argv[1:] if argv is None else argv)
194
204
  if argv and argv[0] in LEGACY:
@@ -196,6 +206,8 @@ def main(argv=None):
196
206
  if not argv or (argv[0] not in COMMANDS and argv[0] not in ("-h", "--help", "--version")):
197
207
  argv.insert(0, "scan")
198
208
  args = parser().parse_args(argv)
209
+ if args.cmd in ("scan", "verify", "revoke", "report") and not check_paths(args.paths):
210
+ return 2
199
211
  if args.cmd == "guard":
200
212
  return guard_mod.guard(sys.stdin.read())
201
213
  if args.cmd == "install-hook":
@@ -1,5 +1,5 @@
1
1
  """Claude Code hook: keep secrets out of AI coding agents (prompts, file reads, shell reads, generated code)."""
2
- import json, os, re, sys
2
+ import json, os, re, stat, sys
3
3
 
4
4
  from .scanner import scan_text
5
5
 
@@ -92,6 +92,6 @@ def install_git_hook():
92
92
  cmd = _self_cmd("scan --staged").replace("\\", "/")
93
93
  with open(hook, "w", newline="\n") as f:
94
94
  f.write(f'#!/bin/sh\n{cmd} || {{ echo "Commit blocked by leakkill."; exit 1; }}\n')
95
- os.chmod(hook, 0o755)
95
+ os.chmod(hook, os.stat(hook).st_mode | stat.S_IXUSR) # git only needs the owner to be able to run it
96
96
  print("Installed", hook)
97
97
  return 0
@@ -35,9 +35,10 @@ RULES = {
35
35
  "JWT": re.compile(r"\b(eyJ[A-Za-z0-9_-]{10,}\.eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,})"),
36
36
  "Credentials in URL": re.compile(r"\b([a-z][a-z0-9+]*://[^\s:/@]+:[^\s:/@]{3,}@[^\s/\"']+)"),
37
37
  }
38
- # key = "value" where the key name looks sensitive and the value looks random
38
+ # key = "value" where the key name looks sensitive and the value looks random.
39
+ # Name parts are length-bounded so matching stays linear on huge (e.g. minified) lines.
39
40
  ASSIGN = re.compile(
40
- r"""(?i)\b[\w.-]*(?:secret|token|passwd|password|api[_-]?key|private[_-]?key|auth)[\w.-]*\b
41
+ r"""(?i)(?<![\w.-])[\w.-]{0,40}?(?:secret|token|passwd|password|api[_-]?key|private[_-]?key|auth)[\w.-]{0,40}
41
42
  \s*[:=]\s*["']([^"'\s]{12,})["']""", re.X)
42
43
  PLACEHOLDER = re.compile(r"(?i)example|placeholder|changeme|your[_-]|xxx|<.*>|\$\{|\{\{|dummy|sample|test")
43
44
  SKIP_DIRS = {".git", "node_modules", "venv", ".venv", "__pycache__", "dist", "build", ".idea", ".tox", ".mypy_cache"}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: leakkill
3
- Version: 0.4.0
3
+ Version: 0.4.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
@@ -76,3 +76,16 @@ def test_revoke_dry_run_warns_about_side_effects(tmp_path, monkeypatch, capsys):
76
76
  project(tmp_path, monkeypatch); fake_verify(monkeypatch)
77
77
  cli.main(["revoke"])
78
78
  assert "GitHub emails the token's owner" in capsys.readouterr().out
79
+
80
+
81
+ def test_typo_command_is_an_error_not_clean(tmp_path, monkeypatch, capsys):
82
+ monkeypatch.chdir(tmp_path)
83
+ assert cli.main(["verfiy"]) == 2
84
+ out = capsys.readouterr()
85
+ assert "Clean" not in out.out and "did you mean `leakkill verify`" in out.err
86
+
87
+
88
+ def test_missing_path_is_an_error(tmp_path, monkeypatch, capsys):
89
+ monkeypatch.chdir(tmp_path)
90
+ assert cli.main(["scan", "does-not-exist"]) == 2
91
+ assert "no such file or directory: does-not-exist" in capsys.readouterr().err
@@ -79,3 +79,12 @@ def test_new_providers_detected_exactly():
79
79
  assert kinds(f'x = "{token}"') == [kind], (kind, kinds(f'x = "{token}"'))
80
80
  def test_openrouter_not_reported_as_openai():
81
81
  assert "OpenAI API key" not in kinds(NEW["OpenRouter key"])
82
+
83
+
84
+ def test_huge_lines_scan_in_linear_time():
85
+ """Minified bundles can have megabyte-long lines; a backtracking regex must not stall the scan."""
86
+ import time
87
+ for line in ("secret" * 100_000, 'api_key="' * 60_000, "awssecret" * 60_000):
88
+ t = time.perf_counter()
89
+ scan_line(line)
90
+ assert time.perf_counter() - t < 3, line[:20]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes