diff options
author | Brian Coca <bcoca@users.noreply.github.com> | 2019-06-06 15:36:22 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-06 15:36:22 -0400 |
commit | b9b0b230150eceb442c34c917d9e852d5e8b7371 (patch) | |
tree | fbc45fcc4fd2765703cb1861c58651cbdfa1bd78 /lib/ansible/template/safe_eval.py | |
parent | 99f9f49ecafe3634652282139b4659e855ad8373 (diff) | |
download | ansible-b9b0b230150eceb442c34c917d9e852d5e8b7371.tar.gz |
safe_eval fix (#57188)
* just dont pass locals
- also fix globals
- added tests
* fixed tests
Diffstat (limited to 'lib/ansible/template/safe_eval.py')
-rw-r--r-- | lib/ansible/template/safe_eval.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/ansible/template/safe_eval.py b/lib/ansible/template/safe_eval.py index 9c70be4a89..4f5b856180 100644 --- a/lib/ansible/template/safe_eval.py +++ b/lib/ansible/template/safe_eval.py @@ -42,10 +42,14 @@ def safe_eval(expr, locals=None, include_exceptions=False): # define certain JSON types # eg. JSON booleans are unknown to python eval() - JSON_TYPES = { + OUR_GLOBALS = { + '__builtins__': {}, # avoid global builtins as per eval docs 'false': False, 'null': None, 'true': True, + # also add back some builtins we do need + 'True': True, + 'False': False, } # this is the whitelist of AST nodes we are going to @@ -138,7 +142,7 @@ def safe_eval(expr, locals=None, include_exceptions=False): # Note: passing our own globals and locals here constrains what # callables (and other identifiers) are recognized. this is in # addition to the filtering of builtins done in CleansingNodeVisitor - result = eval(compiled, JSON_TYPES, dict(locals)) + result = eval(compiled, OUR_GLOBALS, dict(locals)) if include_exceptions: return (result, None) |