-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
PYTHON-4468 Hide the value of sensitive subtype binary objects #1649
Conversation
0a1b266
to
8e52e2a
Compare
8e52e2a
to
4bb92c2
Compare
There was a problem hiding this 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.
There was a problem hiding this 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})" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
4bb92c2
to
87c80c2
Compare
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. |
PYTHON-4468
Summary
I noticed the
bson.binary.Binary
type include it'svalue 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 byeval
it should use< >
instead of a constructor like syntax.