opyeb logscrub

Log masking methods compared

2026-11-29 · 2 min read

One-line answer: use partial masking when a human must recognise the value, full redaction for anything published, and keyed pseudonymisation when the same value must be linked across events.

Five methods

Partial masking keeps part of the value: 203.0.113.24 becomes 203.0.***.*** and minji.kim@example.com becomes m***@example.com. It is easy to see that a value changed, but the remaining fragments can still be guessed.

Full redaction replaces the value with a marker such as [REDACTED]. It is the safest and cannot correlate equal values. A plain hash is irreversible but weak against dictionary attacks unless salted. Tokenisation stores the original in a separate vault and leaves only a reference in the log.

Comparison
MethodExampleReversibleCorrelatesBest for
Partial203.0.***.***No (part exposed)YesInternal debugging
Full redaction[REDACTED]NoNoPublic tickets
HMAC pseudonymip_3f2a9c1dKey holder onlyYesAnalysis and metrics
Salted hashsha256:9a2f…NoYesDuplicate detection
Tokenisationtok_8f21Via vaultYesPayment or customer ids

Choosing per field

IP addresses are used for analysis, so a pseudonym fits well: repeat visitors and error clusters remain countable. If the /24 network matters, keep the first two octets with partial masking instead.

Passwords, API keys and session tokens should never use partial masking. A fragment can be reused and the value is not an analysis dimension. For e-mail, keeping the domain helps identify a customer organisation; for phone numbers, the last four digits are a reasonable balance.

Managing the pseudonym key

HMAC makes the original unrecoverable without the key. The same key gives the same token for the same value, which enables analysis over time; changing the key changes every token. Keep a key for the analysis window and destroy it when the purpose ends.

Never keep the key in the same repository as the logs. Use a key-management service or an environment secret, and plan rotation so that old and new tokens can be distinguished if needed.

token = first 8 hex of HMAC-SHA-256(key, "ipv4:203.0.113.24")
→ ip_3f2a9c1d   (same key, same token, always)

Common mistakes

Masking one field while the same value remains elsewhere is the first. Hiding a user id but leaving an e-mail in the query string achieves nothing. The second is personal data inside the path itself, such as /users/minji.kim@example.com/profile, which numeric normalisation does not fix.

The third is keeping the original in a comment beside the masked value. The fourth is publishing pseudonyms while storing the key in the same bucket. Masking has to be a rule of the whole pipeline, not a single function call.

Questions

Is partial masking enough?

For a quick internal look it can be, but not for publication or long retention. The remaining characters can be guessed and combined with other fields to identify a person.

How is a hash different from HMAC?

A hash gives the same output for the same input but is open to dictionary attacks because no secret is involved. HMAC mixes in a secret key, so short values such as IPs and phone numbers are safer.

Sources

Every example here can be pasted into the workbench as it is.

Open the workbench