Privacy engineering

Keep Secrets and Personal Data Out of Application Logs

Design diagnostic events that explain application behavior without copying credentials, private messages or unnecessary customer data into logs.

Useful logs explain an event without automatically copying everything involved in it. Start by deciding what an operator needs to know, then define a small event schema that carries that information. Logging an entire request because it might help later creates an uncontrolled second data store, often with a different audience and retention policy from the application itself.

The OWASP Logging Cheat Sheet recommends purpose-driven logging and protection of the resulting records. It identifies secrets and sensitive data that should generally be excluded or appropriately treated. The practical exercise here uses a fictional support application to show how a team can turn that principle into a reviewed event contract. The example fields and workflow are editorial suggestions, not a universal logging standard.

Begin with an operational question

Consider a support application that sends a notification after a customer opens a request. An operator wants to answer, “Why did this notification fail?” The complete customer message is unlikely to be the first piece of information needed. A delivery attempt identifier, a provider response category and a timestamp may be enough to locate the failure.

Write the question beside each proposed event. If nobody can explain what decision a field supports, leave it out until there is a concrete reason to include it. This is particularly important for free text, because a field with an innocent name can contain whatever a customer chose to type. A subject line can reveal as much as a message body.

Separate events for application behavior from records intended for other purposes. A diagnostic event, an account audit event and a business report may need different content and different readers. Combining them in one stream for convenience can make access decisions harder to explain.

Replace object dumps with explicit event fields

A common shortcut is to pass a request object or exception object directly to a logging function. The resulting fields depend on the object’s structure, serialization behavior and future changes. A new property can silently become part of the log even though no one changed the logging statement.

Prefer an explicit construction for important events. In the fictional example, the event could contain an event name, an attempt identifier, a result category and a bounded error code. The developer selects these values deliberately rather than inheriting everything from a third-party response. The exact schema should follow the operator’s needs and the system’s data classification.

Treat nested structures with the same care. An allowlisted top-level field named details is not useful protection if its value is an unrestricted object. Define its permitted structure, or replace it with a small set of named values. Review serialization at the point where the event leaves the application, not only at the call site.

Trace the event beyond the first logger

The application logger is only one stage. A hosting platform, collector, error tracker and incident export can each receive a copy. An engineer may remove a field from application events while an automatic request-capture feature continues to send it elsewhere.

Draw the path for one event and identify where enrichment occurs. Does the collector append an account email? Does an exception tracker attach local variables? Does a reverse proxy retain full query strings? Does a support integration copy an alert into a shared chat? The answer should come from configuration or an authorized test, not from a general assumption about the product.

Record the audiences for each destination. “Internal” is not a complete access description. Developers, customer support staff, contractors and an external vendor may have different permissions. If an event needs a restricted destination, confirm that downstream forwarding does not widen its audience.

Design correlation without exposing the original value

Operators need to connect related events. That does not mean the original credential or customer content must become the correlation key. A generated interaction identifier can connect events from one task without embedding the task’s entire payload. Define its scope so readers understand whether it identifies a request, an account or a delivery attempt.

Do not casually label a transformed identifier anonymous. A stable value can still connect activity, and a lookup table may connect it back to a person. If a team uses a derived identifier, document what it permits someone to infer and who can perform any reverse lookup. The access and retention decisions should reflect those capabilities.

In the support example, an operator might begin with an attempt identifier and consult the application through its normal authorization path when more context is needed. That keeps the log from becoming an alternative interface for reading customer messages. Whether this separation fits a real system depends on its support and incident requirements.

Test with unmistakable synthetic markers

Create a test request with invented values that are easy to recognize. Put different markers in a credential-like field, a free-text field and a safe reference field. Run the normal success path and a controlled failure in a nonproduction environment where the team is authorized to inspect every destination.

Search the resulting event stores for the markers. The test should check both that prohibited values are absent and that the useful event still exists. A logging system that suppresses everything avoids one problem by making investigation impossible. The acceptance condition should preserve the operational purpose while respecting the field contract.

Repeat the exercise for nested errors, validation failures and retries. These paths often use different logging code. Also test unusually long input and delimiter characters using harmless fixtures. The goal is to observe whether the event remains a bounded, structured record rather than becoming misleading or unmanageable output.

Keep the review table small enough to maintain

A short event inventory gives reviewers something concrete to examine during changes. It is more actionable than a general instruction to “avoid sensitive logging.”

Event Operational question Proposed fields Explicit exclusion
Notification attempt Did delivery complete? Attempt reference, result category, time Customer message and credentials
Permission denial Which operation was refused? Action name, scoped actor reference, result Full protected record
Export completion Did the export job finish? Job reference, status, record count Exported contents
Cleanup failure What needs reconciliation? Job reference, store, error category Deleted record contents

The table is illustrative. A real event may need additional approved information, but that should be an explicit decision. Include the destination and owner in the maintained version so changes can be routed to someone who understands the purpose.

Treat redaction as a fallback with limits

A redaction filter can be useful when a field may contain a recognizable secret. It is harder to rely on a filter to understand every sensitive fact in unrestricted prose. A customer’s message can disclose private information without matching any familiar token pattern.

For that reason, decide whether the field should be collected before deciding how to redact it. If the event does not need free text, omitting it is simpler to reason about than trying to sanitize every possible message. If a diagnostic workflow genuinely requires a payload, make the collection narrow, time-limited and separately authorized under the organization’s process.

Test any filter against representative formats and edge cases. Record what the filter is designed to recognize, and avoid claiming broader protection than the test supports. A changed token format or a new nested field can invalidate an earlier assumption even when the filter code is unchanged.

Have a response for an accidental disclosure

If a secret or private record reaches a log, deleting the visible entry may not address every copy. Identify the destinations, their retention and export behavior, and the people who can access them. Follow the organization’s incident process to decide what containment, credential rotation or further review is appropriate.

Do not paste the exposed value into a new ticket as proof. Record a restricted reference and the minimum information needed for the responsible team to investigate. Preserve evidence according to the incident process without spreading the material into additional systems. The correct response depends on what was exposed and where it traveled.

After the immediate issue is handled, fix the event contract and add a regression check. A reminder in a chat is weaker than a test that fails when the prohibited field reappears. Review the data flow map and the retention schedule as part of that change. Logs are part of the application’s data system, and their content should be as deliberate as any other stored record.