Skip to content

Commit 494abac

Browse files
authored
Merge pull request #4108 from DataDog/lloeki/deny-rubygems-update-injection
Deny `rubygems-update` injection
2 parents 48e5f09 + 20f2fa5 commit 494abac

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

lib-injection/requirements.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,40 @@
4747
],
4848
"envars": null
4949
},
50+
{
51+
"id": "ruby_disable_gems",
52+
"description": "Rubygems is required for injection to function",
53+
"os": null,
54+
"cmds": [
55+
"**/ruby"
56+
],
57+
"args": [
58+
{
59+
"args": [
60+
"--disable-gems"
61+
],
62+
"position": null
63+
}
64+
],
65+
"envars": null
66+
},
67+
{
68+
"id": "gem_update_system",
69+
"description": "Ignore the rubygems update setup.rb",
70+
"os": null,
71+
"cmds": [
72+
"**/ruby"
73+
],
74+
"args": [
75+
{
76+
"args": [
77+
"setup.rb"
78+
],
79+
"position": null
80+
}
81+
],
82+
"envars": null
83+
},
5084
{
5185
"id": "bundle_install",
5286
"description": "Ignore bundle install",

lib-injection/requirements.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,31 @@ def requirements
5050
'envars' => nil,
5151
}
5252

53+
reqs['deny'] << {
54+
'id' => 'ruby_disable_gems',
55+
'description' => 'Rubygems is required for injection to function',
56+
'os' => nil,
57+
'cmds' => [
58+
'**/ruby'
59+
],
60+
'args' => [{ 'args' => ['--disable-gems'], 'position' => nil }],
61+
'envars' => nil,
62+
}
63+
64+
# Prevent endless reexecution when RUBYOPTS is forcefully set
65+
# Command: {"Path":"/usr/local/bin/ruby","Args":["/usr/local/bin/ruby","--disable-gems","setup.rb","--no-document","--previous-version","3.3.26"]}
66+
# See: https://github.com/rubygems/rubygems/blob/90c90addee4bda3130cf44f1321eebf162367d1b/setup.rb#L13-L20
67+
reqs['deny'] << {
68+
'id' => 'gem_update_system',
69+
'description' => 'Ignore the rubygems update setup.rb',
70+
'os' => nil,
71+
'cmds' => [
72+
'**/ruby'
73+
],
74+
'args' => [{ 'args' => ['setup.rb'], 'position' => nil }],
75+
'envars' => nil,
76+
}
77+
5378
# `bundle exec` is the only command we want to inject into.
5479
# there is no `allow` overriding `deny` so we're left to exclude all of the
5580
# possible others.

lib-injection/test_block.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
{"name": "❌ gem", "filepath": "/path/to/ruby", "args": ["/path/to/ruby", "/path/to/gem" ], "envars": [], "host": {"os": "linux", "arch": "x64", "libc": "glibc:2.40"}},
1414
{"name": "❌ gem install", "filepath": "/path/to/ruby", "args": ["/path/to/ruby", "/path/to/gem", "install" ], "envars": [], "host": {"os": "linux", "arch": "x64", "libc": "glibc:2.40"}},
1515

16+
{"name": "❌ ruby disable gems", "filepath": "/path/to/ruby", "args": ["/path/to/ruby", "--disable-gems"], "envars": [], "host": {"os": "linux", "arch": "x64", "libc": "glibc:2.40"}},
17+
{"name": "❌ ruby disable gems", "filepath": "/path/to/ruby", "args": ["/path/to/ruby", "-w", "--disable-gems"], "envars": [], "host": {"os": "linux", "arch": "x64", "libc": "glibc:2.40"}},
18+
{"name": "❌ ruby disable gems", "filepath": "/path/to/ruby", "args": ["/path/to/ruby", "-w", "-w", "--disable-gems"], "envars": [], "host": {"os": "linux", "arch": "x64", "libc": "glibc:2.40"}},
19+
{"name": "❌ ruby disable gems", "filepath": "/path/to/ruby", "args": ["/path/to/ruby", "-w", "-w", "-w", "--disable-gems"], "envars": [], "host": {"os": "linux", "arch": "x64", "libc": "glibc:2.40"}},
20+
{"name": "❌ ruby disable gems", "filepath": "/path/to/ruby", "args": ["/path/to/ruby", "-w", "-w", "-w", "-w", "--disable-gems"], "envars": [], "host": {"os": "linux", "arch": "x64", "libc": "glibc:2.40"}},
21+
22+
{"name": "❌ ruby rubygems-update setup.rb", "filepath": "/path/to/ruby", "args": ["/path/to/ruby", "--disable-gems", "setup.rb", "--no-document", "--previous-version", "3.3.26"], "envars": [], "host": {"os": "linux", "arch": "x64", "libc": "glibc:2.40"}},
23+
1624
{"name": "❌ bundle" , "filepath": "/path/to/ruby", "args": ["/path/to/ruby", "/path/to/bundle", "install" ], "envars": [], "host": {"os": "linux", "arch": "x64", "libc": "glibc:2.40"}},
1725
{"name": "❌ bundle" , "filepath": "/path/to/ruby", "args": ["/path/to/ruby", "/path/to/bundle", "_2.4.0_", "install" ], "envars": [], "host": {"os": "linux", "arch": "x64", "libc": "glibc:2.40"}},
1826
{"name": "❌ bundle" , "filepath": "/path/to/ruby", "args": ["/path/to/ruby", "/path/to/bundle", "--verbose", "install" ], "envars": [], "host": {"os": "linux", "arch": "x64", "libc": "glibc:2.40"}},

0 commit comments

Comments
 (0)