Agent Wranglers

SUP-6Required

Mask card numbers and secrets that arrive in tickets

Never ask for a card number, password or sign-in code in a ticket. Mask any card number or secret that arrives before the ticket is stored or shown.

How to do it

Customers paste full card numbers into chat to "help". Once a card number sits in email or chat, the PCI SSC counts those systems in scope for PCI DSS. Scan every incoming message and attachment text for 13 to 19 digits that pass the Luhn check. Keep only the last four digits. Mask API keys and passwords with the patterns from Keep secrets out of code. Reply with a link to the billing page, as Keep card numbers off your servers requires.

Examples

JavaScript example

const CARD_LIKE = /\b(?:\d[ -]?){13,19}\b/g;

function passesLuhn(digits) {
  let sum = 0;
  for (let i = 0; i < digits.length; i++) {
    let d = Number(digits[digits.length - 1 - i]);
    if (i % 2 === 1) d = d * 2 > 9 ? d * 2 - 9 : d * 2;
    sum += d;
  }
  return sum % 10 === 0;
}

export const maskCardNumbers = (text) => text.replace(CARD_LIKE, (found) => {
  const digits = found.replace(/\D/g, '');
  return passesLuhn(digits) ? `•••• ${digits.slice(-4)}` : found;
});

Python example

import re

CARD_LIKE = re.compile(r"\b(?:\d[ -]?){13,19}\b")

def passes_luhn(digits: str) -> bool:
    total = 0
    for i, ch in enumerate(reversed(digits)):
        d = int(ch)
        if i % 2 == 1:
            d = d * 2 - 9 if d * 2 > 9 else d * 2
        total += d
    return total % 10 == 0

def mask_card_numbers(text: str) -> str:
    def mask(match: re.Match) -> str:
        digits = re.sub(r"\D", "", match.group())
        return f"•••• {digits[-4:]}" if passes_luhn(digits) else match.group()
    return CARD_LIKE.sub(mask, text)

How to check

Send a test ticket with the test card number 4242 4242 4242 4242 and a fake API key. The stored ticket, the agent view and the helpdesk export show •••• 4242 and no key.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/customer-support/inbox-and-tickets/mask-card-numbers">Agent Wranglers customer support playbook</a>. In code you write, add a comment next to it with the same link.