Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
a83e10d7
Commit
a83e10d7
authored
Apr 10, 2013
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use safe_eval vs eval.
parent
fecfbf92
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
2 deletions
+30
-2
lib/ansible/runner/lookup_plugins/items.py
+3
-1
lib/ansible/utils/__init__.py
+27
-1
No files found.
lib/ansible/runner/lookup_plugins/items.py
View file @
a83e10d7
...
@@ -15,6 +15,8 @@
...
@@ -15,6 +15,8 @@
# You should have received a copy of the GNU General Public License
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
from
ansible.utils
import
safe_eval
def
flatten
(
terms
):
def
flatten
(
terms
):
ret
=
[]
ret
=
[]
for
term
in
terms
:
for
term
in
terms
:
...
@@ -34,7 +36,7 @@ class LookupModule(object):
...
@@ -34,7 +36,7 @@ class LookupModule(object):
if
'{'
or
'['
in
terms
:
if
'{'
or
'['
in
terms
:
# Jinja2-ified list needs to be converted back to a real type
# Jinja2-ified list needs to be converted back to a real type
# TODO: something a bit less heavy than eval
# TODO: something a bit less heavy than eval
terms
=
eval
(
terms
)
terms
=
safe_
eval
(
terms
)
terms
=
[
terms
]
terms
=
[
terms
]
return
flatten
(
terms
)
return
flatten
(
terms
)
...
...
lib/ansible/utils/__init__.py
View file @
a83e10d7
...
@@ -162,7 +162,7 @@ def check_conditional(conditional):
...
@@ -162,7 +162,7 @@ def check_conditional(conditional):
try
:
try
:
conditional
=
conditional
.
replace
(
"
\n
"
,
"
\\
n"
)
conditional
=
conditional
.
replace
(
"
\n
"
,
"
\\
n"
)
result
=
eval
(
conditional
)
result
=
safe_
eval
(
conditional
)
if
result
not
in
[
True
,
False
]:
if
result
not
in
[
True
,
False
]:
raise
errors
.
AnsibleError
(
"Conditional expression must evaluate to True or False:
%
s"
%
conditional
)
raise
errors
.
AnsibleError
(
"Conditional expression must evaluate to True or False:
%
s"
%
conditional
)
return
result
return
result
...
@@ -684,3 +684,29 @@ def is_list_of_strings(items):
...
@@ -684,3 +684,29 @@ def is_list_of_strings(items):
return
False
return
False
return
True
return
True
def
safe_eval
(
str
):
'''
this is intended for allowing things like:
with_items: {{ a_list_variable }}
where Jinja2 would return a string
but we do not want to allow it to call functions (outside of Jinja2, where
the env is constrained)
'''
# FIXME: is there a more native way to do this?
# do not allow method calls
if
re
.
search
(
r'\w\.\w+\('
,
str
):
print
"C1"
return
str
# do not allow imports
if
re
.
search
(
r'import \w+'
,
str
):
print
"C2"
return
str
return
eval
(
str
)
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