Avoid shell interpretation of HAB_LISTEN_CTL in secrets bootstrap#4205
Open
tas50 wants to merge 1 commit into
Open
Avoid shell interpretation of HAB_LISTEN_CTL in secrets bootstrap#4205tas50 wants to merge 1 commit into
tas50 wants to merge 1 commit into
Conversation
The secrets bootstrap loop built a 'hab config apply' command as a
single string and ran it with `system cmd`, appending the value of the
HAB_LISTEN_CTL environment variable unescaped:
cmd += " --remote-sup #{sup_listen_ctl}" if sup_listen_ctl
system cmd
Passing a single string to system runs it through a shell, so any shell
metacharacters in HAB_LISTEN_CTL would be interpreted rather than passed
to hab as a literal argument.
Build an explicit argument vector and call system(*cmd) so no shell is
involved and the environment variable is treated as a single literal
argument. The Habitat template placeholder is unchanged and continues
to be rendered before the script runs.
Signed-off-by: Tim Smith <tsmith84@proton.me>
👷 Deploy Preview for chef-server processing.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The secrets bootstrap loop in
src/chef-server-ctl/habitat/config/secrets-bootstrap.rbbuilds ahab config applycommand as a single string and executes it withsystem cmd, appending the value of theHAB_LISTEN_CTLenvironment variable unescaped:Passing a single string to
systemruns it through a shell. Any shell metacharacters inHAB_LISTEN_CTLare therefore interpreted by the shell instead of being passed tohabas a literal argument, allowing command injection via that environment variable.Fix
Build an explicit argument vector and call
system(*cmd). With multiple arguments Ruby does not invoke a shell, soHAB_LISTEN_CTLis delivered tohabas a single literal argument:The Habitat template placeholder (
{{pkg.svc_data_path}}) is unchanged and is still rendered before the script runs, exactly as it is for the adjacentFile.writecall.Note: this file is a Habitat config template; I verified the Ruby with
ruby -c.