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
10 changes: 10 additions & 0 deletions ods/extensions/services/privacy-shield/pii_scrubber.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

import codecs
import ipaddress
import re
import hashlib
import secrets
Expand Down Expand Up @@ -95,6 +96,15 @@ def scrub(self, text: str) -> str:
if pii_type == 'credit_card' and not self._luhn_check(match):
continue

# The regex identifies IPv4/IPv6-shaped candidates, but it
# deliberately does not encode numeric range rules. Avoid
# scrubbing version-like values such as 999.999.999.999.
if pii_type == 'ip_address':
try:
ipaddress.ip_address(match)
except ValueError:
continue

# Check if we've seen this PII before
existing_token = None
for token, original in self.pii_map.items():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ def test_compressed_ipv6_round_trips(self, detector):
def test_clock_time_is_not_an_ip(self, detector):
result = detector.scrub("Started at 12:34:56 UTC")
assert "<PII_ip_address_" not in result
"candidate",
["999.999.999.999", "256.1.1.1", "192.168.1.999"],
)
def test_invalid_ipv4_candidate_is_not_scrubbed(self, detector, candidate):
text = f"Version-like value: {candidate}"

assert detector.scrub(text) == text


# ── API key detection ────────────────────────────────────────────────────────
Expand Down
Loading