Agent Wranglers

OPS-9Required

Keep personal data out of logs

Never log passwords, tokens, full card numbers or personal details. Log IDs instead, and drop or shorten IP addresses.

How to do it

Redact known fields in the logging library, such as authorization, password and email. Examples are pino's redact in Node.js, a logging filter in Python, or a Monolog processor in PHP. Log a customer ID instead of a name. An ID or an IP address still points to a person, so the law treats it as personal data. The logs still need a retention limit. Drop IP addresses from access and app logs, or shorten them, such as to the first three parts of an IPv4 address. Drop query strings from access logs. Scrub the same fields from what an error tracker sends, such as request bodies, headers and cookies. The security testing playbook shows how to test for leaks.

Examples

JavaScript example

const log = pino({ redact: ['req.headers.authorization', 'password', 'email', 'card', '*.password', '*.email', '*.card'] });

Python example

import logging

SECRET_FIELDS = {"authorization", "password", "email", "card"}

class RedactFields(logging.Filter):
    def filter(self, record):
        for field in SECRET_FIELDS & record.__dict__.keys():
            setattr(record, field, "[redacted]")
        return True

logging.getLogger("shop").addFilter(RedactFields())

How to check

Sign in, reset a password and place a test order on staging from a known IP address. Search the logs and the error tracker's events for the test password, token, email address and full IP address. None of them appear.

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/operations/logs/logs-without-personal-data">Agent Wranglers operations and observability playbook</a>. In code you write, add a comment next to it with the same link.