File size: 1,138 Bytes
87ab2b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
"""Detect obvious credential literals in deliverable text, without printing matches."""
import re
from common import *
patterns=[r'\bhf_[A-Za-z0-9]{20,}\b',r'\bsk-[A-Za-z0-9_-]{20,}\b',r'\bAKIA[A-Z0-9]{16}\b',r'-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----']
findings=[];files=0
for p in ROOT.rglob('*'):
    if not p.is_file() or any(x in p.parts for x in ['.git','__pycache__','.pytest_cache']):continue
    if p.suffix not in ['.md','.txt','.py','.json','.jsonl','.csv','.yaml','.yml','.tsv','.xml']:continue
    files+=1
    try:s=p.read_text()
    except UnicodeDecodeError:continue
    if any(re.search(pattern,s) for pattern in patterns):findings.append(str(p.relative_to(ROOT)))
dump(ROOT/'reports/release_secret_scan.json',{'passed':not findings,'text_files_scanned':files,'files_with_findings':findings,'scope':'obvious credential literals only; no secret values logged; Git object database and binary payloads excluded, canonical record checks scan all JSON fields separately'})
assert not findings,'Release scanner detected credential-shaped text in files: '+str(findings)
print('Release text scan passed:',files,'files')