Skip to content

Commit 49930d0

Browse files
Merge pull request #4667 from sonalkr132/platform-validation
Verify plaform before installing (cherry picked from commit 3aeab0d)
1 parent f574f9f commit 49930d0

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

Manifest.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ test/rubygems/invalidchild_cert.pem
538538
test/rubygems/invalidchild_cert_32.pem
539539
test/rubygems/invalidchild_key.pem
540540
test/rubygems/packages/ascii_binder-0.1.10.1.gem
541+
test/rubygems/packages/ill-formatted-platform-1.0.0.10.gem
541542
test/rubygems/plugin/exception/rubygems_plugin.rb
542543
test/rubygems/plugin/load/rubygems_plugin.rb
543544
test/rubygems/plugin/standarderror/rubygems_plugin.rb

lib/rubygems/installer.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,10 @@ def verify_spec
728728
raise Gem::InstallError, "#{spec} has an invalid extensions"
729729
end
730730

731+
if spec.platform.to_s =~ /\R/
732+
raise Gem::InstallError, "#{spec.platform} is an invalid platform"
733+
end
734+
731735
unless spec.specification_version.to_s =~ /\A\d+\z/
732736
raise Gem::InstallError, "#{spec} has an invalid specification_version"
733737
end
10 KB
Binary file not shown.

test/rubygems/test_gem_installer.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,6 +1776,26 @@ def spec.validate(*args); end
17761776
end
17771777
end
17781778

1779+
def test_pre_install_checks_malicious_platform_before_eval
1780+
gem_with_ill_formated_platform = File.expand_path("packages/ill-formatted-platform-1.0.0.10.gem", __dir__)
1781+
1782+
installer = Gem::Installer.at(
1783+
gem_with_ill_formated_platform,
1784+
:install_dir => @gem_home,
1785+
:user_install => false,
1786+
:force => true
1787+
)
1788+
1789+
use_ui @ui do
1790+
e = assert_raise Gem::InstallError do
1791+
installer.pre_install_checks
1792+
end
1793+
1794+
assert_equal "x86-mswin32\n system('id > /tmp/nyangawa')# is an invalid platform", e.message
1795+
assert_empty @ui.output
1796+
end
1797+
end
1798+
17791799
def test_shebang
17801800
installer = setup_base_installer
17811801

0 commit comments

Comments
 (0)