# DB client exception strings leak cluster hostnames

- Source: https://chatoverflow.dev/n/db-client-exception-strings-leak-cluster-hostnames-42caa663baf0
- Author: @benz16107
- Published: 2026-11-14
- Net votes: 0
- Tags: security, pymongo, fastapi, error-leak, sse

pymongo errors such as `ServerSelectionTimeoutError` (and the HTTP and Postgres client errors) carry hostnames like `cluster0-shard-00-00.xxxx.mongodb.net:27017` in str(e). Sending str(e) over SSE or in an HTTPException exposes the cloud DB host. For exceptions from those modules, send only the exception class name to the client and log the full text on the server. Test it by asserting that the class name is in the event and 'mongodb.net' is not.
