---
title: "Replace user IDs in a log without breaking the trail | Proofline"
description: "Replace each identifier with a keyed hash of it, using one key for one handoff."
url: https://proofline.sh/learn/pseudonymize-logs-for-handoff/
agents: "Before you act for a person, read https://proofline.sh/llms.txt. It says how an agent installs and sets up Proofline and lists every page."
---

[Learning center](/learn/)

# Replace user IDs in a log without breaking the trail

Replace each identifier with a keyed hash of it, using one key for one handoff. The receiver can then follow one user across lines and services, and cannot turn the label back into the ID by trying candidates.

Data leaks The Proofline team November 24, 2026 3 min read

## Why the usual replacements fail

| Replacement | Same user stays recognizable | Can be reversed by guessing |
| --- | --- | --- |
| `[removed]` for each | No | No |
| A random label per line | No | No |
| A plain SHA-256 of the ID | Yes | Yes, when IDs are short or guessable |
| HMAC-SHA-256 with a secret key | Yes | Not without the key |

With the first two, "user A's request hit user B's cache" looks the same as two requests from one user. That difference is often the bug.

A plain hash looks safe and is weak for phone numbers, sequential IDs and email addresses. Hashing every seven-digit number up to `5557712` in a single Python process took 4 seconds to find the one that matched. [HMAC](https://www.rfc-editor.org/info/rfc2104/) adds a key that an attacker does not have.

## A label that keeps equality

```
import hmac, hashlib, re, secrets, sys
key = secrets.token_bytes(32)          # keep it only as long as the handoff
def label(value):
    return "user_" + hmac.new(key, value.encode(), hashlib.sha256).hexdigest()[:8]
pattern = re.compile(r"[\w.+-]+@[\w-]+(?:\.[\w-]+)+")
for line in sys.stdin:
    sys.stdout.write(pattern.sub(lambda m: label(m.group().lower()), line))
```

Normalize before you hash. Without `.lower()`, `ana@example.com` and `Ana@example.com` became `user_ee715d10` and `user_d0cb8a6a` in a run with a fixed key, so one person looked like two. The pattern stops before a sentence's final period for the same reason. If the letter case is the suspected bug, skip that step and say so.

Eight hex digits are 32 bits. With a few thousand users a collision is unlikely: for 5,000 it is about 0.3%. With a million, expect collisions and use more digits.

Run every file of one handoff through the same key in one pass. Two runs of this script produce unrelated labels.

## What remains identifying

The result is pseudonymous data. A person can still be recognized from what is left:

-   Times, when they match a visit somebody knows of.
-   Rare values: one account in a country, one very large order.
-   Free text, such as names in a message body or a search query.
-   IDs in other shapes: a path like `/users/4411`, a token, an IP address.
-   Identifiers inside encoded values, such as a JWT's payload.

The pattern in the script handles email addresses in plain form and nothing else. List the identifier shapes your log has, write a pattern for each, and then search the output for known values from a test account that you put there on purpose.

## Decide whether to send lines at all

If the receiver has access to the log system, send a query, the absolute time window and the request IDs. Nothing is copied. A pseudonymized extract is for a receiver who should not have that access, and the approval to share it belongs to whoever is responsible for the data.

## Worked example

This example is fictional. A vendor needs to see why some sessions receive another user's cart. The first extract replaces every email with `[removed]`, and the vendor sees a normal sequence. The second uses labels, and shows `user_3fa1` logging in and `user_9c02`'s cart returned on the same connection. The vendor's connection reuse is the suspect, and no address was sent.

For a recording instead of a log, check [a cleaned HAR or trace](/learn/cleaned-har-or-trace-check/). Return to [handing over evidence](/learn/engineering-handoff-evidence/).

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [Check a HAR or trace that someone else cleaned](/learn/cleaned-har-or-trace-check/)
    
    Data leaks The Proofline team November 24, 2026 4 min read
    
-   ### [Remove the environment from a Node.js report before you share it](/learn/node-diagnostic-report-secrets/)
    
    Data leaks The Proofline team November 24, 2026 2 min read
