"""Secret-shaped strings, shared by secret_guard (bridged repos) and public_secret_scan (weekly, every public repo). A finding NEVER carries the value: only its kind and sha256[:8] (house rule 10). Leak hunt 09-24: @Windy_0_bot's token sat in a public repo's test fixture for five months.""" from __future__ import annotations import hashlib import re # (kind, regex). Order matters only for readability; each match is reported once. PATTERNS: list[tuple[str, re.Pattern[str]]] = [ ("telegram bot token", re.compile(r"(? str: return hashlib.sha256(value.encode() if isinstance(value, str) else value).hexdigest()[:8] def find(text: str) -> list[tuple[str, str]]: """[(kind, hash8)] for every secret-shaped string in `text`. Values never leave.""" out = [] for kind, rx in PATTERNS: for m in rx.finditer(text): out.append((kind, h8(m.group(0)))) return out