Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Jérome Perrin
erp5
Commits
d9d1caa3
Commit
d9d1caa3
authored
Jan 27, 2020
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
patches/Restricted: allow collections.Counter
parent
f25ef810
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
1 deletion
+19
-1
product/ERP5Type/patches/Restricted.py
product/ERP5Type/patches/Restricted.py
+10
-0
product/ERP5Type/tests/testRestrictedPythonSecurity.py
product/ERP5Type/tests/testRestrictedPythonSecurity.py
+9
-1
No files found.
product/ERP5Type/patches/Restricted.py
View file @
d9d1caa3
...
...
@@ -12,6 +12,7 @@
##############################################################################
import
sys
import
copy
from
RestrictedPython.RestrictionMutator
import
RestrictionMutator
...
...
@@ -181,6 +182,9 @@ ModuleSecurityInfo('collections').declarePublic('OrderedDict')
from
collections
import
defaultdict
ModuleSecurityInfo
(
'collections'
).
declarePublic
(
'defaultdict'
)
from
collections
import
Counter
ModuleSecurityInfo
(
'collections'
).
declarePublic
(
'Counter'
)
from
AccessControl.ZopeGuards
import
_dict_white_list
# Attributes cannot be set on defaultdict, thus modify 'safetype' dict
...
...
@@ -195,6 +199,12 @@ ContainerAssertions[OrderedDict] = _check_access_wrapper(OrderedDict, _dict_whit
OrderedDict
.
__guarded_setitem__
=
OrderedDict
.
__setitem__
.
__func__
OrderedDict
.
__guarded_delitem__
=
OrderedDict
.
__delitem__
.
__func__
_counter_white_list
=
copy
.
copy
(
_dict_white_list
)
_counter_white_list
[
'most_common'
]
=
1
ContainerAssertions
[
Counter
]
=
_check_access_wrapper
(
Counter
,
_counter_white_list
)
Counter
.
__guarded_setitem__
=
dict
.
__setitem__
Counter
.
__guarded_delitem__
=
dict
.
__delitem__
# given as example in Products.PythonScripts.module_access_examples
allow_module
(
'base64'
)
allow_module
(
'binascii'
)
...
...
product/ERP5Type/tests/testRestrictedPythonSecurity.py
View file @
d9d1caa3
...
...
@@ -136,4 +136,12 @@ class TestRestrictedPythonSecurity(ERP5TypeTestCase):
self
.
assertRaises
(
Unauthorized
,
self
.
createAndRunScript
,
'import os'
,
'return os.system'
)
def
test_collections_Counter
(
self
):
self
.
createAndRunScript
(
'from collections import Counter'
,
'c = Counter(["a", "b"])'
,
'c["a"] = c["a"] + 1'
,
'c.update({"a": 1})'
,
'return c.most_common(1)'
,
expected
=
[(
'a'
,
3
)]
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment