Skip to content

Commit

Permalink
Merge pull request from GHSA-qcx9-j53g-ccgf
Browse files Browse the repository at this point in the history
  • Loading branch information
dataflake committed Jul 30, 2021
1 parent 5af868c commit b42dd4b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ For changes before version 3.0, see ``HISTORY.rst``.
5.1 (unreleased)
----------------

- Nothing changed yet.
- Fix a remote code execution issue by preventing access to
``string.Formatter`` from restricted code.


5.0 (2020-10-07)
Expand Down
8 changes: 8 additions & 0 deletions src/AccessControl/ZopeGuards.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from RestrictedPython.Utilities import utility_builtins
from zExceptions import Unauthorized

from AccessControl.SecurityInfo import ModuleSecurityInfo
from AccessControl.SecurityInfo import secureModule
from AccessControl.SecurityManagement import getSecurityManager
from AccessControl.SimpleObjectPolicies import ContainerAssertions
Expand Down Expand Up @@ -57,6 +58,13 @@
math.__allow_access_to_unprotected_subobjects__ = 1
random.__allow_access_to_unprotected_subobjects__ = 1

# Mark some unprotected module attributes as private, these should not be
# used in untrusted Python code such as Scripts (Python)
string_modsec = ModuleSecurityInfo('string')
for name in ('Formatter', 'Template'):
string_modsec.declarePrivate(name) # NOQA: D001
secureModule('string')

# AccessControl.Implementation inserts these names into this module as
# module globals: aq_validate, guarded_getattr

Expand Down
13 changes: 13 additions & 0 deletions src/AccessControl/tests/testZopeSecurityPolicy.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,19 @@ def testAccessToSimpleContainer(self):
c.attr = PublicMethod()
self.assertPolicyAllows(c, 'attr')

def testAccessToStringModule(self):
# The string module is available to restricted code and its members are
# explicitly allowed via a
# ``__allow_access_to_unprotected_subobjects__`` declaration. However,
# a few classes are exempted and declared private, they can indirectly
# provide uncontrolled access to system libraries from within
# restricted code.
import string

self.assertPolicyAllows(string, 'printable')
self.assertPolicyDenies(string, 'Formatter')
self.assertPolicyDenies(string, 'Template')

def testUnicodeAttributeLookups(self):
item = self.item
r_item = self.a.r_item
Expand Down

0 comments on commit b42dd4b

Please sign in to comment.