Skip to content

fix: redact sensitive url query values and pymongo document values in exception messages - #496

Merged
vastin merged 1 commit into
masterfrom
fix/redact-sensitive-data-in-exception-messages
Oct 20, 2026
Merged

vastin merged 1 commit into
masterfrom
fix/redact-sensitive-data-in-exception-messages

Conversation

@vastin

@vastin vastin commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Issue #, if available: n/a

Description of changes:

Follow-up to #495. Recorded exception messages still included sensitive values:

  • requests: the failed url with its query string, e.g. the signature and session token of a presigned S3 url, although http.url drops the query.
  • pymongo: the server error document (consideredValue, keyValue, op) and dup key values, which fix(pymongo): don't record failure document values by default #495 removed from the failure metadata. insert_one/update_one failures never reach failed().

Heads-up: these values are now recorded as REDACTED, with keys kept, e.g. ?X-Amz-Signature=REDACTED or full error: {'ok': 0.0, 'errmsg': 'REDACTED', 'code': 121, 'codeName': 'DocumentValidationFailure', 'errInfo': 'REDACTED'}. A pymongo listener with record_full_documents=True turns off the pymongo part for the whole process.

Changes:

  • core/utils/redaction.py: an extensible list of sensitive query parameters (SigV2/SigV4 presigned urls, token), masked in every recorded message
  • core/models/throwable.py: redaction rules run when an exception is recorded; pymongo documents keep the fields of fix(pymongo): don't record failure document values by default #495; the message is dropped if a rule fails
  • docs and CHANGELOG

Testing:

  • tox py312 core and 15 ext envs; py3.8
  • Checked against MongoDB 8 and a local HTTP server

Follow-up: release needed after merge, together with #495.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

… exception messages

requests exception messages include the url of the request with its query
string, e.g. the signature and session token of a presigned S3 url, while
the url recorded by the requests patch has the query string removed.
pymongo exception messages include the server error document, with the
value that failed document validation (consideredValue), which can be a
value already stored in the document, duplicate key values and failed
operations (op), which the failure metadata no longer records since #495.
Both were recorded as is whenever the exception went through a traced
function or framework middleware.

Redact exception messages when they are recorded with a list of rules,
which record redacted values as REDACTED:
- pymongo errors: like the failure metadata, keep only the ok, code,
  codeName, errorLabels and errtype values of the error document, also of
  the error that caused the exception, and the position of write errors
  in a bulk write, and redact the other values, and the duplicate key
  values in the server message, which is otherwise kept. A pymongo
  listener that records full documents (record_full_documents=True) stops
  this in the whole process.
- all errors: the values of a list of sensitive url query parameters,
  e.g. of presigned urls, keeping the keys,
  e.g. "Max retries exceeded with url: /object.txt?X-Amz-Signature=REDACTED"

Messages are not recorded if a rule fails.
@vastin
vastin requested a review from a team as a code owner October 20, 2026 23:25
@vastin
vastin merged commit dfb6e30 into master Oct 20, 2026
15 checks passed
@vastin
vastin deleted the fix/redact-sensitive-data-in-exception-messages branch October 20, 2026 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants