-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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
Added template rendering to shell_command component #2268
Conversation
This has a big security vulnerability. If a user has a bad crafted template, an attacker would be able to run any command in the shell by setting a specific state and calling a service. I wonder if it would be possible to do this safely. |
Good point. What if we sanitized the template values before passing them to the command and only allowed |
The first word in the shell cmd should be fixed, or any word that follows && / || and only inject numbers and letters like you suggest |
I think that disabling But even then, I might prefer that we only allow writing dynamic content to STDIN. That's what we do with the command line notify platform. That way if people really want dynamic commands, they can make a bash script to execute STDIN but they will have to go through hoops to do it. |
The latest commit is an attempt to alleviate some of these concerns.
For further sanitizing the templates, I looked into the I did attempt to get the |
Alright. That seems ok. This would still require tests to be written. I have one more thing that you could add is passing the service variables as template variables to the render method. rendered_args = template.render(hass, args, variables=call.data) That way you can call a service and the service data can be used to render the command. |
Better failure when template is invalid in shell_command
Looks good! 🐬 |
Description:
This allows the
shell_command
component to accept templates. I use it to customize the commands that get sent over LIRC to my A/C based on an input slider value.Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#
Example entry for
configuration.yaml
(if applicable):Checklist:
If user exposed functionality or configuration variables are added/changed:
If the code does not interact with devices:
tox
run successfully. Your PR cannot be merged unless tests pass