Skip to content
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

Adds a check for command injections in the input for hg and git #124

Merged
merged 1 commit into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ All CocoaPods development happens on GitHub, there is a repository for [CocoaPod

Follow [@CocoaPods](http://twitter.com/CocoaPods) to get up to date information about what's going on in the CocoaPods world.

## Development

You need to have `svn`, `bzr`, `hg` and `git` installed to run the specs. There are some specs which require `hdiutil` which will only run on macOS.

## License

This gem and CocoaPods are available under the MIT license.
9 changes: 8 additions & 1 deletion lib/cocoapods-downloader/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def checkout_options
end

def self.preprocess_options(options)
validate_input options
return options unless options[:branch]

command = ['ls-remote',
Expand Down Expand Up @@ -57,7 +58,13 @@ def self.commit_from_ls_remote(output, branch_name)
match[1] unless match.nil?
end

private_class_method :commit_from_ls_remote
def self.validate_input(options)
input = [options[:git], options[:branch], options[:commit], options[:tag]]
invalid = input.compact.any? { |value| value.start_with?('--') || value.include?(' --') }
raise DownloaderError, "Provided unsafe input for git #{options}." if invalid
end

private_class_method :commit_from_ls_remote, :validate_input

private

Expand Down
13 changes: 13 additions & 0 deletions lib/cocoapods-downloader/mercurial.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ def checkout_options
end
end

def self.preprocess_options(options)
validate_input options
options
end

def self.validate_input(options)
input = [options[:hg], options[:revision], options[:branch], options[:tag]].map(&:to_s)
invalid = input.compact.any? { |value| value.start_with?('--') || value.include?(' --') }
raise DownloaderError, "Provided unsafe input for hg #{options}." if invalid
end

private_class_method :validate_input

private

executable :hg
Expand Down
20 changes: 20 additions & 0 deletions spec/git_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,26 @@ def ensure_only_one_ref(folder)
new_options[:branch].should == 'aaaa'
end
end

describe ':bad input' do
it 'bails when you provide a bad input' do
options = { :git => '--upload-pack=touch ./HELLO1;', :branch => 'foo' }
e = lambda { Downloader.preprocess_options(options) }.should.raise DownloaderError
e.message.should.match /Provided unsafe input/
end

it 'bails when you provide a bad input after valid input' do
options = { :git => 'github.com --upload-pack=touch ./HELLO1;', :branch => 'foo' }
e = lambda { Downloader.preprocess_options(options) }.should.raise DownloaderError
e.message.should.match /Provided unsafe input/
end

it 'bails with other fields' do
options = { :branch => '--upload-pack=touch ./HELLO1;', :git => 'foo' }
e = lambda { Downloader.preprocess_options(options) }.should.raise DownloaderError
e.message.should.match /Provided unsafe input/
end
end
end
end
end
8 changes: 8 additions & 0 deletions spec/mercurial_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,13 @@ module Downloader
new_options.should == options
end
end

describe ':bad input' do
it 'bails when you provide a bad input' do
options = { :hg => '--config=alias.clone=!touch ./HELLO2;' }
e = lambda { Downloader.preprocess_options(options) }.should.raise DownloaderError
e.message.should.match /Provided unsafe input/
end
end
end
end