Skip to content

Commit

Permalink
mark entire module result untrusted as template (#55717)
Browse files Browse the repository at this point in the history
* prevents accidental templating on intra-action postprocessing of an untrusted module result
* makes the view of a module result within an action consistent with the way it would be stored for future use (eg facts, register)
  • Loading branch information
nitzmahone committed Apr 24, 2019
1 parent 34e9c0f commit 03cac39
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion changelogs/fragments/ensure_facts_safe.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
bugfixes:
- ensure facts are always unsafe objects and don't rely on plugin returns
- ensure module results and facts are marked untrusted as templates for safer use within the same task
7 changes: 4 additions & 3 deletions lib/ansible/plugins/action/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,10 @@ def _execute_module(self, module_name=None, module_args=None, tmp=None, task_var
data['deprecations'] = []
data['deprecations'].extend(self._discovery_deprecation_warnings)

# mark the entire module results untrusted as a template right here, since the current action could
# possibly template one of these values.
data = wrap_var(data)

display.debug("done with _execute_module (%s, %s)" % (module_name, module_args))
return data

Expand All @@ -978,9 +982,6 @@ def _parse_returned_data(self, res):
display.warning(w)

data = json.loads(filtered_output)

if 'ansible_facts' in data and isinstance(data['ansible_facts'], dict):
data['ansible_facts'] = wrap_var(data['ansible_facts'])
data['_ansible_parsed'] = True
except ValueError:
# not valid json, lets try to capture error
Expand Down

0 comments on commit 03cac39

Please sign in to comment.