Skip to content

fix: PII scrubber keeps timestamps and IDs (Luhn-checked cards, formatted phones) (Fixes #205) - #217

Merged
OkiriGabriel merged 1 commit into
mainfrom
fix/scrubber-card-luhn-205
Nov 26, 2026
Merged

OkiriGabriel merged 1 commit into
mainfrom
fix/scrubber-card-luhn-205

Conversation

@OkiriGabriel

Copy link
Copy Markdown
Collaborator

Fixes #205.

Problem

The scrubber runs on every log line and tool result before the LLM, Slack and storage see them, and it redacted any run of 13–16 digits as a card number. Investigating this found the phone rule had the same problem with any 10 digits:

Input Before After
ts=1732600000123 (epoch ms) ts=[REDACTED_CARD] unchanged
epoch=1732600000 (epoch s) epoch=[REDACTED_PHONE] unchanged
took 1234567890123 ns [REDACTED_CARD] unchanged
order 12345678901234 [REDACTED_CARD] unchanged
call (555) 123-4567 call ([REDACTED_PHONE] (stray () call [REDACTED_PHONE]
4111 1111 1111 1111 [REDACTED_CARD] [REDACTED_CARD]

The agent was losing the timeline of every JSON log (Loki, CloudWatch) and the long request and order IDs it needs to correlate events.

Change (services/pii_scrubber.py)

  • Cards: a 13–19 digit candidate, with spaces or dashes allowed, is redacted only if it passes the Luhn check and starts with a real card-network prefix (Visa 4; Mastercard 51–55 and 2221–2720; Amex 34/37; Discover 6011/65/644–649; JCB 3528–3589; Diners 300–305/36/38; UnionPay 62; Maestro). Epoch-ms timestamps start with 1, so they never match.
  • Phones: separators (-, . or a space) or (xxx) are now required, with an optional +1. A bare 10-digit run isn't a phone number.
  • SSN, email, token, JWT, key and secret redaction are unchanged.

Tests

tests/test_pii_scrubber.py, 23 tests:

  • 11 timestamp, ID, trace and version strings that must be kept, including a Luhn-failing "card".
  • 7 real test card numbers across the networks that must be redacted.
  • 4 phone formats, plus SSN and email.

Full suite: 1471 passed, 4 skipped. Bandit is clean, and Flake8 (CI selection) is clean. The only other lint notes are on long lines that were already in the file.

…phones (#205)

- Card numbers: a 13-19 digit candidate (spaces/dashes allowed) is redacted
  only when it passes the Luhn check and starts with a card-network prefix
  (Visa, Mastercard incl. 2-series, Amex, Discover, JCB, Diners, UnionPay,
  Maestro). Epoch-ms timestamps, ns durations and long IDs are kept.
- Phone numbers need separators or parentheses; a bare 10-digit run (epoch
  seconds, IDs) is kept. "(555) 123-4567" is now redacted whole.
- tests/test_pii_scrubber.py: kept vs redacted cases for both.

Fixes #205
@OkiriGabriel
OkiriGabriel merged commit b433497 into main Nov 26, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] PII scrubber redacts epoch-ms timestamps and long IDs as card numbers (no Luhn check)

1 participant