File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4545 ignore-vulns : |
4646 GHSA-w596-4wvx-j9j6 # subversion related git pull, dependency for pytest. There is no impact here.
4747 CVE-2026-26007 # dependency for entraid tests
48+ CVE-2026-32597 # PyJWT does not validate the crit (Critical) Header Parameter defined in RFC 7515, this will be fixed in the next release
4849
4950 lint :
5051 name : Code linters
Original file line number Diff line number Diff line change @@ -1308,8 +1308,23 @@ def __init__(
13081308 if self ._event_dispatcher is None :
13091309 self ._event_dispatcher = EventDispatcher ()
13101310
1311+ # Keys that should be redacted in __repr__ to avoid exposing sensitive information
1312+ SENSITIVE_REPR_KEYS = frozenset (
1313+ {
1314+ "password" ,
1315+ "username" ,
1316+ "ssl_password" ,
1317+ "credential_provider" ,
1318+ }
1319+ )
1320+
13111321 def __repr__ (self ):
1312- conn_kwargs = "," .join ([f"{ k } ={ v } " for k , v in self .connection_kwargs .items ()])
1322+ conn_kwargs = "," .join (
1323+ [
1324+ f"{ k } ={ '<REDACTED>' if k in self .SENSITIVE_REPR_KEYS else v } "
1325+ for k , v in self .connection_kwargs .items ()
1326+ ]
1327+ )
13131328 return (
13141329 f"<{ self .__class__ .__module__ } .{ self .__class__ .__name__ } "
13151330 f"(<{ self .connection_class .__module__ } .{ self .connection_class .__name__ } "
Original file line number Diff line number Diff line change @@ -2845,8 +2845,23 @@ def __init__(
28452845
28462846 self .reset ()
28472847
2848+ # Keys that should be redacted in __repr__ to avoid exposing sensitive information
2849+ SENSITIVE_REPR_KEYS = frozenset (
2850+ {
2851+ "password" ,
2852+ "username" ,
2853+ "ssl_password" ,
2854+ "credential_provider" ,
2855+ }
2856+ )
2857+
28482858 def __repr__ (self ) -> str :
2849- conn_kwargs = "," .join ([f"{ k } ={ v } " for k , v in self .connection_kwargs .items ()])
2859+ conn_kwargs = "," .join (
2860+ [
2861+ f"{ k } ={ '<REDACTED>' if k in self .SENSITIVE_REPR_KEYS else v } "
2862+ for k , v in self .connection_kwargs .items ()
2863+ ]
2864+ )
28502865 return (
28512866 f"<{ self .__class__ .__module__ } .{ self .__class__ .__name__ } "
28522867 f"(<{ self .connection_class .__module__ } .{ self .connection_class .__name__ } "
Original file line number Diff line number Diff line change @@ -418,6 +418,31 @@ def test_repr_contains_db_info_unix(self):
418418 expected = "path=abc,db=0,client_name=test-client"
419419 assert expected in repr (pool )
420420
421+ def test_repr_redacts_sensitive_information (self ):
422+ """Test that __repr__ redacts sensitive values like password and username."""
423+ pool = ConnectionPool (
424+ host = "localhost" ,
425+ port = 6379 ,
426+ password = "secret_password_123" ,
427+ username = "myuser" ,
428+ ssl_password = "ssl_secret_456" ,
429+ db = 0 ,
430+ )
431+ repr_output = repr (pool )
432+
433+ # Verify sensitive values are redacted
434+ assert "secret_password_123" not in repr_output
435+ assert "myuser" not in repr_output
436+ assert "ssl_secret_456" not in repr_output
437+
438+ # Verify the REDACTED placeholder is present
439+ assert "<REDACTED>" in repr_output
440+
441+ # Verify non-sensitive values are still visible
442+ assert "host=localhost" in repr_output
443+ assert "port=6379" in repr_output
444+ assert "db=0" in repr_output
445+
421446
422447class TestConnectionPoolURLParsing :
423448 def test_hostname (self ):
Original file line number Diff line number Diff line change @@ -259,6 +259,31 @@ def test_repr_contains_db_info_unix(self):
259259 expected = "path=abc,db=0,client_name=test-client"
260260 assert expected in repr (pool )
261261
262+ def test_repr_redacts_sensitive_information (self ):
263+ """Test that __repr__ redacts sensitive values like password and username."""
264+ pool = redis .ConnectionPool (
265+ host = "localhost" ,
266+ port = 6379 ,
267+ password = "secret_password_123" ,
268+ username = "myuser" ,
269+ ssl_password = "ssl_secret_456" ,
270+ db = 0 ,
271+ )
272+ repr_output = repr (pool )
273+
274+ # Verify sensitive values are redacted
275+ assert "secret_password_123" not in repr_output
276+ assert "myuser" not in repr_output
277+ assert "ssl_secret_456" not in repr_output
278+
279+ # Verify the REDACTED placeholder is present
280+ assert "<REDACTED>" in repr_output
281+
282+ # Verify non-sensitive values are still visible
283+ assert "host=localhost" in repr_output
284+ assert "port=6379" in repr_output
285+ assert "db=0" in repr_output
286+
262287 @pytest .mark .onlynoncluster
263288 @skip_if_resp_version (2 )
264289 @skip_if_server_version_lt ("7.4.0" )
You can’t perform that action at this time.
0 commit comments