From ac66c9dfd290e1451e0ca08f0d7db5f55b39f564 Mon Sep 17 00:00:00 2001 From: Terry Patterson Date: Thu, 30 May 2024 17:44:06 -0400 Subject: [PATCH] PYTHON-4468 Hide the value of sensitive subtype binary objects (#1649) Co-authored-by: Steven Silvester --- bson/binary.py | 5 ++++- doc/changelog.rst | 2 ++ doc/contributors.rst | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/bson/binary.py b/bson/binary.py index be3346446..5fe1bacd1 100644 --- a/bson/binary.py +++ b/bson/binary.py @@ -364,4 +364,7 @@ class Binary(bytes): return not self == other def __repr__(self) -> str: - return f"Binary({bytes.__repr__(self)}, {self.__subtype})" + if self.__subtype == SENSITIVE_SUBTYPE: + return f"" + else: + return f"Binary({bytes.__repr__(self)}, {self.__subtype})" diff --git a/doc/changelog.rst b/doc/changelog.rst index 0fbc49fda..1f6dec2f8 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -6,6 +6,8 @@ Changes in Version 4.8.0 The handshake metadata for "os.name" on Windows has been simplified to "Windows" to improve import time. +The repr of ``bson.binary.Binary`` is now redacted when the subtype is SENSITIVE_SUBTYPE(8). + .. warning:: PyMongo 4.8 drops support for Python 3.7 and PyPy 3.8: Python 3.8+ or PyPy 3.9+ is now required. Changes in Version 4.7.3 diff --git a/doc/contributors.rst b/doc/contributors.rst index d7f103032..49fb2d844 100644 --- a/doc/contributors.rst +++ b/doc/contributors.rst @@ -100,3 +100,4 @@ The following is a list of people who have contributed to - Stephan Hof (stephan-hof) - Casey Clements (caseyclements) - Ivan Lukyanchikov (ilukyanchikov) +- Terry Patterson