-
Notifications
You must be signed in to change notification settings - Fork 41
Fixes some potentially unsafe variables not being wrapped correctly #114 #543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes some potentially unsafe variables not being wrapped correctly #114 #543
Conversation
|
@joewesch Could you please review this and see what you think:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that we should probably move check_needs_wrapping to a central utils folder since it doesn't seem to be required to be a method. It will make it much easier to unit test that way as well.
edit to add: module_utils.utils is a common location for all plugin types - not just modules - so that would probably be my vote on where to put it.
3bd1b97 to
6bd3fd1
Compare
ccdb9d8 to
d616d66
Compare
1ef06e3 to
04312c1
Compare
7388efd to
2fcbb64
Compare
Co-authored-by: Josh VanDeraa <josh@josh-v.com>
|
Just need to figure out where to put the tests for |
These are done now. Due to the fact that |
f55879e to
efc05d1
Compare
|
@joewesch I believe this is ready to go! 🚀 |
joewesch
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything LGTM so far. I'm going to pull down your branch and run some more tests locally before approving.
| @@ -0,0 +1,56 @@ | |||
| - hosts: all | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seeing debug instead of assert might be confusing for anyone in the future reviewing this code. Let's add some comments at the top of this file like you did for the unsafe_vars.yml file that explain what these tests are doing would help with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call - done; see what you think.
|
The tests were passing yesterday, and the only addition has been some comments. I believe the tests are now failing due to a new module field in v2.4.11 called |
Closes #114
What's Changed
Summary
inventory.pyandgql_inventory.pyboth had issues where Jinja 2 delimeters were being unexpectedly processed rather than passed through, which led to unpredictable and undesirable behaviour.In both cases, these have been modified so that both the hostname and other variables are passed to Ansible's
wrap_vardocumentation as described in the official documentationSupporting tests have also been added to ensure that these fixes are not regressed and that the lookup modules, which are not vulnerable to the same issue, remain so.
The lookup modules are not vulnerable due to this built-in protection, as per docs at https://docs.ansible.com/ansible/latest/plugins/lookup.html -
"By default, lookup return values are marked as unsafe for security reasons. If you trust the outside source for your lookup accesses, pass allow_unsafe=True to allow Jinja2 templates to evaluate lookup values."
Before with
{{}}in vars (inventory.py)After with hostname changed to include
{{}}as well (inventory.py)Before with
{{}}in vars (gql_inventory.py)After with hostname changed to include
{{}}as well (gql_inventory.py)