File tree Expand file tree Collapse file tree 3 files changed +18
-3
lines changed Expand file tree Collapse file tree 3 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ Changes
1010 it as ``getattr `` implementation. Such use should now follow the same policy
1111 and give the same level of protection as direct attribute access in an
1212 environment based on ``RestrictedPython ``'s ``safe_builtints ``.
13+ - Prevent information leakage via ``AttributeError.obj ``
14+ and the ``string `` module.
1315
1416
15177.2 (2024-08-02)
Original file line number Diff line number Diff line change @@ -29,7 +29,11 @@ def __getattr__(self, attr):
2929 if attr in self .__excludes :
3030 raise NotImplementedError (
3131 f"{ self .__mod .__name__ } .{ attr } is not safe" )
32- return getattr (self .__mod , attr )
32+ try :
33+ return getattr (self .__mod , attr )
34+ except AttributeError as e :
35+ e .obj = self
36+ raise
3337
3438
3539utility_builtins ['string' ] = _AttributeDelegator (string , "Formatter" )
Original file line number Diff line number Diff line change @@ -7,8 +7,17 @@ def test_string_in_utility_builtins():
77 from RestrictedPython .Utilities import utility_builtins
88
99 # we no longer provide access to ``string`` itself, only to
10- # a restricted view of it
11- assert utility_builtins ['string' ].__name__ == string .__name__
10+ # a restricted view of it (``rstring``)
11+ rstring = utility_builtins ['string' ]
12+ assert rstring .__name__ == string .__name__
13+
14+ # ensure it does not provide access to ``string`` via
15+ # ``AttributeError.obj``
16+ try :
17+ rstring .unexisting_attribute
18+ except AttributeError as e :
19+ assert e .obj is rstring
20+
1221
1322
1423def test_math_in_utility_builtins ():
You can’t perform that action at this time.
0 commit comments