Skip to content

Commit ac66c9d

Browse files
PYTHON-4468 Hide the value of sensitive subtype binary objects (#1649)
Co-authored-by: Steven Silvester <[email protected]>
1 parent 49987e6 commit ac66c9d

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

bson/binary.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,4 +364,7 @@ def __ne__(self, other: Any) -> bool:
364364
return not self == other
365365

366366
def __repr__(self) -> str:
367-
return f"Binary({bytes.__repr__(self)}, {self.__subtype})"
367+
if self.__subtype == SENSITIVE_SUBTYPE:
368+
return f"<Binary(REDACTED, {self.__subtype})>"
369+
else:
370+
return f"Binary({bytes.__repr__(self)}, {self.__subtype})"

doc/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Changes in Version 4.8.0
66

77
The handshake metadata for "os.name" on Windows has been simplified to "Windows" to improve import time.
88

9+
The repr of ``bson.binary.Binary`` is now redacted when the subtype is SENSITIVE_SUBTYPE(8).
10+
911
.. warning:: PyMongo 4.8 drops support for Python 3.7 and PyPy 3.8: Python 3.8+ or PyPy 3.9+ is now required.
1012

1113
Changes in Version 4.7.3

doc/contributors.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,4 @@ The following is a list of people who have contributed to
100100
- Stephan Hof (stephan-hof)
101101
- Casey Clements (caseyclements)
102102
- Ivan Lukyanchikov (ilukyanchikov)
103+
- Terry Patterson

0 commit comments

Comments
 (0)