Skip to content

PYTHON-4468 Hide the value of sensitive subtype binary objects #1649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 30, 2024

Conversation

TerryRPatterson
Copy link
Contributor

PYTHON-4468

Summary

I noticed the bson.binary.Binary type include it's
value even when the subtype is sensitive (8)

Changes in this PR

This PR changes the Binary type's repr to be <Binary ### {self.__subtype}> when the subtype is 8.
The < > representation follow general guideline that when a repr can't be roundtripped by eval it should use < > instead of a constructor like syntax.

@TerryRPatterson TerryRPatterson force-pushed the redact_sensitive_bytes branch 2 times, most recently from 0a1b266 to 8e52e2a Compare May 30, 2024 15:08
@TerryRPatterson TerryRPatterson force-pushed the redact_sensitive_bytes branch from 8e52e2a to 4bb92c2 Compare May 30, 2024 16:03
blink1073
blink1073 previously approved these changes May 30, 2024
Copy link
Member

@blink1073 blink1073 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you! I'll wait for our Evergreen tests to finish before merging.

Copy link
Member

@ShaneHarvey ShaneHarvey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @TerryRPatterson, do you mind adding a mention of this change in the doc/changelog.rst?

bson/binary.py Outdated
@@ -364,4 +364,7 @@ def __ne__(self, other: Any) -> bool:
return not self == other

def __repr__(self) -> str:
return f"Binary({bytes.__repr__(self)}, {self.__subtype})"
if self.__subtype == SENSITIVE_SUBTYPE:
return f"Binary('<redacted>', {self.__subtype})"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is no longer an accurate representation of the object we need to surround it with <> so that repr+eval() will raise an error instead of silently changing the data, like this:

return f"<Binary(REDACTED, {self.__subtype})>"

Reference: https://docs.python.org/3/library/functions.html#repr

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added an entry to the changelog. Since the the jira is tagged Fixes 4.7.3 I assumed that is the release. I don't know how to get a link to the release notes from jira so I didn't include the link.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I added the link.

@blink1073 blink1073 requested a review from ShaneHarvey May 30, 2024 21:00
@ShaneHarvey
Copy link
Member

FYI since this is a minor breaking behavior change it can't go into 4.7.3 and has to wait for 4.8.

@blink1073
Copy link
Member

FYI since this is a minor breaking behavior change it can't go into 4.7.3 and has to wait for 4.8.

I updated the changelog.

@blink1073 blink1073 merged commit ac66c9d into mongodb:master May 30, 2024
29 of 31 checks passed
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.

3 participants