Fix the payload filter in a checkout error reporter
Your task
An AI built an error reporter for your checkout flow that sends the whole request payload to a third-party monitoring service. That payload holds card numbers, CVVs and email addresses. Your team now sends only the fields on an allowlist and redacts everything else, so a field nobody approved never leaves the process.
An assistant wrote redact_telemetry_payload(payload_pairs, allowed_fields). It is in the editor. It has a bug. Find it and fix it.
Input and output:
payload_pairs: the payload's entries, usually writtenkey=value.allowed_fields: the field names approved for telemetry.- Return what is sent: one string per entry, in the same order.
Rules the tests check:
- An entry with no
=cannot be checked, so send"[REDACTED]"in its place. - Otherwise the key is the text before the first
=. If the key matches an allowed field, ignoring case and with nothing trimmed, send the entry unchanged. - Otherwise send the key, then
=[REDACTED]. The key stays, so engineers can still see which fields were present.
Examples
redact_telemetry_payload(payload_pairs: list[str], allowed_fields: list[str]) -> list[str]Example 1
Input
redact_telemetry_payload(["orderId=A-1001", "email=ana@example.com", "cardNumber=4111111111111111"], ["orderId", "amount"])Output
["orderId=A-1001", "email=[REDACTED]", "cardNumber=[REDACTED]"]Example 2
Input
redact_telemetry_payload(["amount=42.50", "cvv=311"], ["amount"])Output
["amount=42.50", "cvv=[REDACTED]"]Example 3
Input
redact_telemetry_payload(["note=size=large", "token=abc123"], ["note"])Output
["note=size=large", "token=[REDACTED]"]