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
10
10
it as ``getattr `` implementation. Such use should now follow the same policy
11
11
and give the same level of protection as direct attribute access in an
12
12
environment based on ``RestrictedPython ``'s ``safe_builtints ``.
13
+ - Prevent information leakage via ``AttributeError.obj ``
14
+ and the ``string `` module.
13
15
14
16
15
17
7.2 (2024-08-02)
Original file line number Diff line number Diff line change @@ -29,7 +29,11 @@ def __getattr__(self, attr):
29
29
if attr in self .__excludes :
30
30
raise NotImplementedError (
31
31
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
33
37
34
38
35
39
utility_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():
7
7
from RestrictedPython .Utilities import utility_builtins
8
8
9
9
# 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
+
12
21
13
22
14
23
def test_math_in_utility_builtins ():
You can’t perform that action at this time.
0 commit comments