Scrub the database hostname from Sentry events - #5592
Conversation
send_default_pii=False and Sentry's key-based scrubbing don't cover infrastructure hostnames that reach Sentry as free text — inside breadcrumbs, span descriptions or exception messages. The database DNS name can leak there. Add a before_send/before_send_transaction hook that redacts the configured database hostname wherever it appears in an event, before it leaves the process (client-side, so the value is never stored in Sentry at all). Non-sensitive defaults like localhost are ignored. Fixes WordPress#670
|
A quick note on the red CI, since none of it looks related to this change:
Happy to rebase or adjust anything. Thanks for taking a look! |
|
Following up with a likely root cause for the The failing step is
&& pip install --upgrade pipenv
...
RUN pipenv install --system --deploy --devSo the build always pulls the latest pipenv at build time. When a pipenv release changes lockfile hashing/validation, Two directions, whichever the team prefers:
Happy to open a separate PR for whichever approach you'd like — I'd just want to build the image against the pinned version to confirm the fix before sending it. |
Fixes
Fixes #670
Description
send_default_pii=Falseand Sentry's server-side scrubbing only cover known PII fields by key. Infrastructure hostnames such as the database DNS name can still reach Sentry as free text — inside breadcrumbs, span descriptions or exception messages — where key-based scrubbing never sees them.This adds a
before_send/before_send_transactionhook that redacts the configured database hostname wherever it appears, as a substring, anywhere in an event.A note on approach: the issue links to Sentry's server-side scrubbing docs, but doing this client-side is strictly safer — the value is redacted before the event leaves the process, so it is never stored in Sentry at all. It also keeps the rule in version control next to the rest of the Sentry config.
Details:
api/utils/sentry.pyas a small, dependency-free helper so it can be unit-tested in isolation.localhost,127.0.0.1,::1, empty) are ignored, so local/dev never redacts noise.Testing Instructions
just api/test test/unit/utils/test_sentry.py— or, since the helper is dependency-free:The added unit tests cover redaction across a nested event, ignored default hosts, the no-op case, and the overlapping-hostname ordering.
Checklist
Update index.md).main).Note / follow-up
This covers the API (Django) side. The ingestion server initialises Sentry separately (
ingestion_server/ingestion_server/api.py); happy to extend the same approach there in this PR or a follow-up — whichever the maintainers prefer.