SRH-12Required
Keep personal data out of search logs
Log searches without user, account or session IDs, and drop queries that look like an email address, a phone number or an ID number. Delete raw search logs after a fixed time, such as 90 days.
How to do it
People paste names, order numbers and addresses into search boxes, so a search log fills with personal data nobody planned for. The logs still serve their purpose without the person, since quality work needs only the query text, the hit count and the clicked position. Mask anything matching an email or a run of 8 or more digits before it is written. Keep counts per query longer, without IDs. Build the fixed query set from these cleaned logs. The general rule is keep personal data out of logs.
Examples
JavaScript example
const PERSONAL = /[^\s@]+@[^\s@]+|\d[\d -]{7,}\d/g;
export const cleanQuery = query => query.replace(PERSONAL, '[removed]').slice(0, 200);
export function logSearch(query, hitCount) {
searchLog.write({ query: cleanQuery(query), hits: hitCount, at: new Date().toISOString() });
}
Python example
import re
PERSONAL = re.compile(r"[^\s@]+@[^\s@]+|\d[\d -]{7,}\d")
def clean_query(query: str) -> str:
return PERSONAL.sub("[removed]", query)[:200]
How to check
Search for anna@example.com and 19840512-1234 on staging. The search log holds neither, and no log row has a user or session ID. A query finds no raw log row older than the stated period.
Sources
Related rules
- SRH-17 Test search results with a fixed query set in Search
- OPS-9 Keep personal data out of logs in Operations and observability
- SRH-19 Watch searches that find nothing or get no click in Search
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/search/access-and-limits/search-log-privacy">Agent Wranglers search playbook</a>. In code you write, add a comment next to it with the same link.