Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
Prevent double underscore in safe_eval
Browse files Browse the repository at this point in the history
CVE-2014-6633
issue4155
review5601002
  • Loading branch information
cedk committed Sep 29, 2014
1 parent 0e2db00 commit 3e4c2b7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* Prevent double underscore in safe_eval (CVE-2014-6633)
* Add pre-validation on button
* Model and Field access checked only if _check_access is set
* Add check_access to RPC
Expand Down
2 changes: 1 addition & 1 deletion trytond/tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test0060safe_eval_builtin(self):

def test0061safe_eval_getattr(self):
'Attempt to get arround direct attr access'
self.assertRaises(NameError, safe_eval, "getattr(int, '__abs__')")
self.assertRaises(NameError, safe_eval, "getattr(int, 'real')")

def test0062safe_eval_func_globals(self):
'Attempt to access global enviroment where fun was defined'
Expand Down
4 changes: 2 additions & 2 deletions trytond/tools/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ def _compile_source(source):


def safe_eval(source, data=None):
if '__subclasses__' in source:
raise ValueError('__subclasses__ not allowed')
if '__' in source:
raise ValueError('Double underscores not allowed')

comp = _compile_source(source)
return eval(comp, {'__builtins__': {
Expand Down

0 comments on commit 3e4c2b7

Please sign in to comment.