mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-25 14:20:22 -07:00
Fixing security bugs for CVE-2016-9587
This commit is contained in:
parent
258c6ada52
commit
a6fff93967
7 changed files with 129 additions and 47 deletions
|
@ -28,8 +28,10 @@ from ansible.errors import AnsibleError, AnsibleUndefinedVariable
|
|||
from ansible.playbook.attribute import FieldAttribute
|
||||
from ansible.template import Templar
|
||||
from ansible.module_utils._text import to_native
|
||||
from ansible.vars.unsafe_proxy import wrap_var
|
||||
|
||||
DEFINED_REGEX = re.compile(r'(hostvars\[.+\]|[\w_]+)\s+(not\s+is|is|is\s+not)\s+(defined|undefined)')
|
||||
LOOKUP_REGEX = re.compile(r'lookup\s*\(')
|
||||
|
||||
class Conditional:
|
||||
|
||||
|
@ -127,9 +129,12 @@ class Conditional:
|
|||
return conditional
|
||||
|
||||
# a Jinja2 evaluation that results in something Python can eval!
|
||||
if hasattr(conditional, '__UNSAFE__') and LOOKUP_REGEX.match(conditional):
|
||||
raise AnsibleError("The conditional '%s' contains variables which came from an unsafe " \
|
||||
"source and also contains a lookup() call, failing conditional check" % conditional)
|
||||
|
||||
presented = "{%% if %s %%} True {%% else %%} False {%% endif %%}" % conditional
|
||||
conditional = templar.template(presented)
|
||||
val = conditional.strip()
|
||||
val = templar.template(presented).strip()
|
||||
if val == "True":
|
||||
return True
|
||||
elif val == "False":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue