@@ -760,17 +760,16 @@ def validate_cycler(s):
760760 # might come from the internet (future plans), this
761761 # could be downright dangerous.
762762 # I locked it down by only having the 'cycler()' function
763- # available. Imports and defs should not
764- # be possible. However, it is entirely possible that
765- # a security hole could open up via attributes to the
766- # function (this is why I decided against allowing the
767- # Cycler class object just to reduce the number of
768- # degrees of freedom (but maybe it is safer to use?).
769- # One possible hole I can think of (in theory) is if
770- # someone managed to hack the cycler module. But, if
771- # someone does that, this wouldn't make anything
772- # worse because we have to import the module anyway.
773- s = eval (s , {'cycler' : cycler })
763+ # available.
764+ # UPDATE: Partly plugging a security hole.
765+ # I really should have read this:
766+ # http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html
767+ # We should replace this eval with a combo of PyParsing and
768+ # ast.literal_eval()
769+ if '.__' in s .replace (' ' , '' ):
770+ raise ValueError ("'%s' seems to have dunder methods. Raising"
771+ " an exception for your safety" )
772+ s = eval (s , {'cycler' : cycler , '__builtins__' : {}})
774773 except BaseException as e :
775774 raise ValueError ("'%s' is not a valid cycler construction: %s" %
776775 (s , e ))
0 commit comments