-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpii _detection.py
More file actions
25 lines (21 loc) · 889 Bytes
/
Copy pathpii _detection.py
File metadata and controls
25 lines (21 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import re
# Example naive regex for emails & phone numbers.
# Real PII detection might use Presidio or other advanced techniques.
EMAIL_REGEX = re.compile(r"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}")
PHONE_REGEX = re.compile(r"\b\d{3}[-.\s]\d{3}[-.\s]\d{4}\b")
def run_pii_detection(file_path, file_content):
"""
Checks if file content might contain PII (e.g., email, phone).
In real usage, you'd:
1) Call Presidio or other library
2) Possibly do dynamic tests (adversarial inputs)
Returns a list of warning messages if found.
"""
warnings = []
emails = EMAIL_REGEX.findall(file_content)
phones = PHONE_REGEX.findall(file_content)
if emails:
warnings.append(f"Possible email addresses in {file_path}: {emails}")
if phones:
warnings.append(f"Possible phone numbers in {file_path}: {phones}")
return warnings