Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/hindsight/redaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def __init__(self, rules_path=None):
r"|(?:customer|cust|tenant)(?:[ _-]?id)?(?:\s*[:=#]\s*|\s+)"
r"(?=[A-Za-z0-9-]*\d)[A-Za-z0-9-]{4,})\b",
),
("ip", r"(?<![\w.])(?:\d{1,3}\.){3}\d{1,3}(?![\w.])"),
# A trailing "." ends a sentence; only ".<digit>" means a longer dotted number.
("ip", r"(?<![\w.])(?:\d{1,3}\.){3}\d{1,3}(?!\w|\.\d)"),
("ipv6", r"(?<![\w:])(?:[0-9a-fA-F]{0,4}:){2,}[0-9a-fA-F:]{0,39}(?![\w:])"),
]
if rules_path:
Expand Down
4 changes: 4 additions & 0 deletions tests/core/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def test_redaction_and_idempotence():
assert raw not in clean
assert clean.count("[REDACTED:customer-id]") == 5
assert redactor.redact(clean) == clean
ips = "Paged from 10.20.3.14. Then 2001:db8::1. Build 1.2.3.4.5 stays."
clean = redactor.redact(ips)
assert "10.20.3.14" not in clean and "2001:db8::1" not in clean
assert "[REDACTED:ip]. Then" in clean and "1.2.3.4.5" in clean
prose = "Customer service escalated; the tenant migration is done."
assert redactor.redact(prose) == prose
identifier = str(uuid.uuid4())
Expand Down
Loading