Skip to content

Commit a151e45

Browse files
committed
fix(core): redact phone numbers after a JSON escape in serialized text
#244's (?<!\w) lookbehind keeps digits inside longer identifiers intact, but a JSON-escaped newline, tab or return before a phone number (for example in serialized metadata) put a word character in front of it and the number was exported. Also start a match after a backslash escape; long identifiers after an escape are still not phone numbers.
1 parent 4a3b47f commit a151e45

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎python/fi_instrumentation/instrumentation/pii_redaction.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,11 @@ def _redact_email_addresses(text: str) -> str:
123123
# Do not match the last ten/eleven digits of a longer identifier. A negative
124124
# word lookbehind also keeps the full leading '+'/'(' in a telephone match;
125125
# placing a word boundary before those non-word characters would leave them.
126+
# A JSON escape before the number (backslash followed by n, t or r) also starts a
127+
# match, so a phone after a newline in serialized metadata or messages is found.
126128
_PHONE_RE = re.compile(
127-
r"(?<!\w)(?:\+?1[\s\-\.]?)?\(?\d{3}\)?[\s\-\.]?\d{3}[\s\-\.]?\d{4}\b"
129+
r"(?:(?<!\w)|(?<=\\[ntr]))"
130+
r"(?:\+?1[\s\-\.]?)?\(?\d{3}\)?[\s\-\.]?\d{3}[\s\-\.]?\d{4}\b"
128131
)
129132

130133
_IP_RE = re.compile(

0 commit comments

Comments
 (0)