Ruby/bundler/1.16.5
Bundler manages an application's dependencies through its entire life, across many machines, systematically and repeatably
https://rubygems.org/gems/bundler
MIT
8 Security Vulnerabilities
Local Code Execution through Argument Injection via dash leading git url parameter in Gemfile.
- https://github.com/rubygems/rubygems/security/advisories/GHSA-fj7f-vq84-fh43
- https://github.com/rubygems/rubygems/pull/5142
- https://github.com/rubygems/rubygems/commit/0fad1ccfe9dd7a3c5b82c1496df3c2b4842870d3
- https://github.com/rubygems/rubygems/commit/a4f2f8ac17e6ce81c689527a8b6f14381060d95f
- https://github.com/advisories/GHSA-fj7f-vq84-fh43
- https://nvd.nist.gov/vuln/detail/CVE-2021-43809
- https://github.com/rubysec/ruby-advisory-db/blob/master/gems/bundler/CVE-2021-43809.yml
- https://www.sonarsource.com/blog/securing-developer-tools-package-managers/
In bundler
versions before 2.2.33, when working with untrusted and apparently harmless Gemfile
's, it is not expected that they lead to execution of external code, unless that's explicit in the ruby code inside the Gemfile
itself. However, if the Gemfile
includes gem
entries that use the git
option with invalid, but seemingly harmless, values with a leading dash, this can be false.
To handle dependencies that come from a Git repository instead of a registry, Bundler uses various commands, such as git clone
. These commands are being constructed using user input (e.g. the repository URL). When building the
commands, Bundler versions before 2.2.33 correctly avoid Command Injection vulnerabilities by passing an array of arguments instead of a command string. However, there is the possibility that a user input starts with a dash (-
) and is therefore treated as an optional argument instead of a positional one. This can lead to Code Execution because some of the commands have options that can be leveraged to run arbitrary executables.
Since this value comes from the Gemfile
file, it can contain any character, including a leading dash.
Exploitation
To exploit this vulnerability, an attacker has to craft a directory containing a Gemfile
file that declares a dependency that is located in a Git repository. This dependency has to have a Git URL in the form of -u./payload
. This URL
will be used to construct a Git clone command but will be interpreted as the upload-pack argument. Then this directory needs to be shared with the victim, who then needs to run a command that evaluates the Gemfile, such as bundle lock
, inside.
Impact
This vulnerability can lead to Arbitrary Code Execution, which could potentially lead to the takeover of the system. However, as explained above, the exploitability is very low, because it requires a lot of user interaction. It still could put developers at risk when dealing with untrusted files in a way they think is safe, because the exploit still works when the victim tries to make sure nothing can happen, e.g. by manually reviewing the Gemfile
(although they would need the weird URL with a leading dash to not raise any flags).
This kind of attack vector has been used in the past to target security researchers by sending them projects to collaborate on.
Patches
Bundler 2.2.33 has patched this problem by inserting --
as an argument before any positional arguments to those Git commands that were affected by this issue.
Workarounds
Regardless of whether users can upgrade or not, they should review any untrustred Gemfile
's before running any bundler
commands that may read them, since they can contain arbitrary ruby code.
References
https://cwe.mitre.org/data/definitions/88.html
Dependency Confusion in Bundler
- https://nvd.nist.gov/vuln/detail/CVE-2020-36327
- https://github.com/advisories/GHSA-fp4w-jxhp-m23p
- https://github.com/rubygems/rubygems/issues/3982
- https://bundler.io/blog/2021/02/15/a-more-secure-bundler-we-fixed-our-source-priorities.html
- https://mensfeld.pl/2021/02/rubygems-dependency-confusion-attack-side-of-things/
- https://msrc.microsoft.com/update-guide/en-US/vulnerability/CVE-2021-24105
- https://www.zofrex.com/blog/2021/04/29/bundler-still-vulnerable-dependency-confusion-cve-2020-36327/
- https://github.com/rubygems/rubygems/pull/4609
- https://github.com/rubygems/rubygems/commit/078bf682ac40017b309b5fc69f283ff640e7c129
- https://github.com/rubygems/rubygems/blob/master/bundler/CHANGELOG.md#2218-may-25-2021
- https://github.com/rubysec/ruby-advisory-db/blob/master/gems/bundler/CVE-2020-36327.yml
- https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/MWXHK5UUHVSHF7HTHMX6JY3WXDVNIHSL/
Bundler 1.16.0 through 2.2.9 and 2.2.11 through 2.2.17 sometimes chooses a dependency source based on the highest gem version number, which means that a rogue gem found at a public source may be chosen, even if the intended choice was a private gem that is a dependency of another private gem that is explicitly depended on by the application.
Insecure path handling in Bundler
- https://nvd.nist.gov/vuln/detail/CVE-2019-3881
- https://github.com/advisories/GHSA-g98m-96g9-wfjq
- https://github.com/rubygems/bundler/issues/6501
- https://github.com/rubygems/bundler/pull/7416/commits/65cfebb041c454c246aaf32a177b0243915a9998
- https://bugzilla.redhat.com/show_bug.cgi?id=1651826
- https://github.com/rubysec/ruby-advisory-db/blob/master/gems/bundler/CVE-2019-3881.yml
Bundler prior to 2.1.0 uses a predictable path in /tmp/
, created with insecure permissions as a storage location for gems, if locations under the user's home directory are not available. If Bundler is used in a scenario where the user does not have a writable home directory, an attacker could place malicious code in this directory that would be later loaded and executed.
Bundler allows attacker to inject arbitrary code via secondary Gem source
- https://nvd.nist.gov/vuln/detail/CVE-2016-7954
- https://github.com/bundler/bundler/issues/5051
- https://github.com/bundler/bundler/issues/5062
- https://bugzilla.redhat.com/show_bug.cgi?id=1381951
- http://collectiveidea.com/blog/archives/2016/10/06/bundlers-multiple-source-security-vulnerability/
- http://www.openwall.com/lists/oss-security/2016/10/04/5
- http://www.openwall.com/lists/oss-security/2016/10/04/7
- http://www.openwall.com/lists/oss-security/2016/10/05/3
- https://collectiveidea.com/blog/archives/2016/10/06/bundlers-multiple-source-security-vulnerability
- https://github.com/rubysec/ruby-advisory-db/blob/master/gems/bundler/CVE-2016-7954.yml
- https://web.archive.org/web/20170214030311/http://www.securityfocus.com/bid/93423
- https://github.com/advisories/GHSA-jvgm-pfqv-887x
Bundler 1.x might allow remote attackers to inject arbitrary Ruby code into an application by leveraging a gem name collision on a secondary source. NOTE: this might overlap CVE-2013-0334.
Allows an attacker to inject arbitrary code into your application via any secondary Gem source declared in your Gemfile
Bundler 1.x might allow remote attackers to inject arbitrary Ruby code into an application by leveraging a Gem name collision on a secondary source.
Please note that this vulnerability only applies for Ruby
projects using Bundler < 2.0 with Gemfiles having 2 or more
source
lines.
In other words, if the user's Gemfile does not use multiple sources, this vulnerability can be ignored.
Insecure path handling in Bundler
Bundler prior to 2.1.0 uses a predictable path in /tmp/, created with insecure permissions as a storage location for gems, if locations under the user's home directory are not available. If Bundler is used in a scenario where the user does not have a writable home directory, an attacker could place malicious code in this directory that would be later loaded and executed.
Dependency Confusion in Bundler with Implicit Private Dependencies
Bundler 1.16.0 through 2.2.9 and 2.2.11 through 2.2.17 sometimes chooses a dependency source based on the highest gem version number, which means that a rogue gem found at a public source may be chosen, even if the intended choice was a private gem that is a dependency of another private gem that is explicitly depended on by the application.
Local Code Execution through Argument Injection via dash leading git url parameter in Gemfile
In bundler
versions before 2.2.33, when working with untrusted and apparently harmless
Gemfile
's, it is not expected that they lead to execution of external code, unless
that's explicit in the ruby code inside the Gemfile
itself. However, if the Gemfile
includes gem
entries that use the git
option with invalid, but seemingly harmless,
values with a leading dash, this can be false.
To handle dependencies that come from a Git repository instead of a registry, Bundler
uses various commands, such as git clone
. These commands are being constructed using
user input (e.g. the repository URL). When building the commands, Bundler versions
before 2.2.33 correctly avoid Command Injection vulnerabilities by passing an array of
arguments instead of a command string. However, there is the possibility that a user
input starts with a dash (-
) and is therefore treated as an optional argument instead
of a positional one. This can lead to Code Execution because some of the commands have
options that can be leveraged to run arbitrary executables.
Since this value comes from the Gemfile
file, it can contain any character, including
a leading dash.
Exploitation
To exploit this vulnerability, an attacker has to craft a directory containing a
Gemfile
file that declares a dependency that is located in a Git repository. This
dependency has to have a Git URL in the form of -u./payload
. This URL will be used to
construct a Git clone command but will be interpreted as the
upload-pack
argument. Then this directory needs to be shared with the victim, who then needs to run
a command that evaluates the Gemfile, such as bundle lock
, inside.
Impact
This vulnerability can lead to Arbitrary Code Execution, which could potentially lead
to the takeover of the system. However, as explained above, the exploitability is very
low, because it requires a lot of user interaction. It still could put developers at
risk when dealing with untrusted files in a way they think is safe, because the exploit
still works when the victim tries to make sure nothing can happen, e.g. by manually
reviewing the Gemfile
(although they would need the weird URL with a leading dash to
not raise any flags).
This kind of attack vector has been used in the past to target security researchers by sending them projects to collaborate on.
Patches
Bundler 2.2.33 has patched this problem by inserting --
as an argument before any
positional arguments to those Git commands that were affected by this issue.
Workarounds
Regardless of whether users can upgrade or not, they should review any untrusted
Gemfile
's before running any bundler
commands that may read them, since they
can contain arbitrary ruby code.
381 Other Versions
Version | License | Security | Released | |
---|---|---|---|---|
2.1.3 | MIT | 4 | 2020-01-02 - 12:29 | over 4 years |
2.1.2 | MIT | 4 | 2019-12-20 - 00:43 | over 4 years |
2.1.1 | MIT | 4 | 2019-12-18 - 00:13 | over 4 years |
2.1.0 | MIT | 4 | 2019-12-15 - 15:17 | over 4 years |
2.1.0.pre.1 | MIT | 6 | 2019-08-28 - 00:10 | over 4 years |
2.1.0.pre.3 | MIT | 6 | 2019-11-12 - 18:20 | over 4 years |
2.1.0.pre.2 | MIT | 6 | 2019-09-15 - 09:51 | over 4 years |
2.0.2 | MIT | 6 | 2019-06-13 - 09:15 | almost 5 years |
2.0.1 | MIT | 6 | 2019-01-04 - 00:54 | over 5 years |
2.0.0 | MIT | 6 | 2019-01-03 - 05:38 | over 5 years |
2.0.0.pre.1 | MIT | 8 | 2018-11-09 - 12:28 | over 5 years |
2.0.0.pre.3 | MIT | 8 | 2018-12-30 - 05:12 | over 5 years |
2.0.0.pre.2 | MIT | 8 | 2018-11-27 - 11:50 | over 5 years |
1.17.3 | MIT | 8 | 2018-12-27 - 04:15 | over 5 years |
1.17.2 | MIT | 8 | 2018-12-11 - 10:33 | over 5 years |
1.17.1 | MIT | 8 | 2018-10-25 - 20:39 | over 5 years |
1.17.0 | MIT | 8 | 2018-10-25 - 01:34 | over 5 years |
1.17.0.pre.1 | MIT | 8 | 2018-09-23 - 01:38 | over 5 years |
1.17.0.pre.2 | MIT | 8 | 2018-10-13 - 06:04 | over 5 years |
1.16.6 | MIT | 8 | 2018-10-05 - 06:09 | over 5 years |
1.16.5 | MIT | 8 | 2018-09-18 - 13:01 | over 5 years |
1.16.4 | MIT | 8 | 2018-08-20 - 12:40 | over 5 years |
1.16.3 | MIT | 8 | 2018-07-17 - 04:59 | almost 6 years |
1.16.2 | MIT | 8 | 2018-05-16 - 20:51 | about 6 years |
1.16.1 | MIT | 8 | 2017-12-21 - 18:46 | over 6 years |
1.16.0 | MIT | 8 | 2017-10-31 - 19:29 | over 6 years |
1.16.0.pre.1 | MIT | 6 | 2017-09-05 - 04:16 | over 6 years |
1.16.0.pre.2 | MIT | 6 | 2017-09-07 - 02:39 | over 6 years |
1.16.0.pre.3 | MIT | 6 | 2017-10-05 - 03:28 | over 6 years |
1.15.4 | MIT | 6 | 2017-08-19 - 21:01 | almost 7 years |
1.15.3 | MIT | 6 | 2017-07-21 - 19:48 | almost 7 years |
1.15.2 | MIT | 6 | 2017-07-17 - 18:31 | almost 7 years |
1.15.1 | MIT | 6 | 2017-06-02 - 05:15 | almost 7 years |
1.15.0 | MIT | 6 | 2017-05-19 - 15:45 | about 7 years |
1.15.0.pre.4 | MIT | 6 | 2017-05-10 - 18:53 | about 7 years |
1.15.0.pre.3 | MIT | 6 | 2017-05-01 - 00:17 | about 7 years |
1.15.0.pre.2 | MIT | 6 | 2017-04-23 - 08:39 | about 7 years |
1.15.0.pre.1 | MIT | 6 | 2017-04-17 - 14:25 | about 7 years |
1.14.6 | MIT | 6 | 2017-03-03 - 23:45 | about 7 years |
1.14.5 | MIT | 6 | 2017-02-22 - 01:13 | about 7 years |
1.14.4 | MIT | 6 | 2017-02-12 - 23:36 | over 7 years |
1.14.3 | MIT | 6 | 2017-01-24 - 21:44 | over 7 years |
1.14.2 | MIT | 6 | 2017-01-23 - 02:24 | over 7 years |
1.14.1 | MIT | 6 | 2017-01-21 - 20:52 | over 7 years |
1.14.0 | MIT | 6 | 2017-01-20 - 23:41 | over 7 years |
1.14.0.pre.2 | MIT | 4 | 2017-01-11 - 23:12 | over 7 years |
1.14.0.pre.1 | MIT | 4 | 2016-12-29 - 17:45 | over 7 years |
1.13.7 | MIT | 4 | 2016-12-25 - 15:11 | over 7 years |
1.13.6 | MIT | 4 | 2016-10-22 - 06:18 | over 7 years |
1.13.5 | MIT | 4 | 2016-10-15 - 06:15 | over 7 years |
1.13.4 | MIT | 4 | 2016-10-14 - 02:33 | over 7 years |
1.13.3 | MIT | 4 | 2016-10-10 - 19:33 | over 7 years |
1.13.2 | MIT | 4 | 2016-09-30 - 17:28 | over 7 years |
1.13.1 | MIT | 4 | 2016-09-13 - 16:21 | over 7 years |
1.13.0 | MIT | 4 | 2016-09-09 - 06:22 | over 7 years |
1.13.0.pre.1 | MIT | 4 | 2016-06-20 - 21:32 | almost 8 years |
1.13.0.rc.1 | MIT | 4 | 2016-06-27 - 22:10 | almost 8 years |
1.13.0.rc.2 | MIT | 4 | 2016-08-21 - 09:45 | over 7 years |
1.12.6 | MIT | 4 | 2016-10-10 - 19:29 | over 7 years |
1.12.5 | MIT | 4 | 2016-05-25 - 19:19 | almost 8 years |
1.12.4 | MIT | 4 | 2016-05-16 - 20:47 | about 8 years |
1.12.3 | MIT | 4 | 2016-05-06 - 21:55 | about 8 years |
1.12.2 | MIT | 4 | 2016-05-04 - 23:29 | about 8 years |
1.12.1 | MIT | 4 | 2016-04-30 - 07:09 | about 8 years |
1.12.0 | MIT | 4 | 2016-04-29 - 02:30 | about 8 years |
1.12.0.pre.1 | MIT | 4 | 2016-02-09 - 03:45 | over 8 years |
1.12.0.pre.2 | MIT | 4 | 2016-02-26 - 17:57 | about 8 years |
1.12.0.rc.2 | MIT | 4 | 2016-04-15 - 20:50 | about 8 years |
1.12.0.rc.4 | MIT | 4 | 2016-04-21 - 20:52 | about 8 years |
1.12.0.rc.3 | MIT | 4 | 2016-04-20 - 00:19 | about 8 years |
1.12.0.rc | MIT | 4 | 2016-03-14 - 06:00 | about 8 years |
1.11.2 | MIT | 4 | 2015-12-16 - 00:12 | over 8 years |
1.11.1 | MIT | 4 | 2015-12-15 - 11:44 | over 8 years |
1.11.0 | MIT | 4 | 2015-12-13 - 02:01 | over 8 years |
1.11.0.pre.2 | MIT | 4 | 2015-12-06 - 23:10 | over 8 years |
1.11.0.pre.1 | MIT | 4 | 2015-11-30 - 03:16 | over 8 years |
1.10.6 | MIT | 4 | 2015-07-22 - 21:34 | almost 9 years |
1.10.5 | MIT | 4 | 2015-06-24 - 20:58 | almost 9 years |
1.10.4 | MIT | 4 | 2015-06-16 - 18:45 | almost 9 years |
1.10.3 | MIT | 4 | 2015-06-04 - 02:18 | almost 9 years |
1.10.2 | MIT | 4 | 2015-05-30 - 17:01 | almost 9 years |
1.10.1 | MIT | 4 | 2015-05-29 - 05:34 | almost 9 years |
1.10.0 | MIT | 4 | 2015-05-28 - 20:25 | almost 9 years |
1.10.0.pre.1 | MIT | 4 | 2015-05-06 - 18:21 | about 9 years |
1.10.0.pre.2 | MIT | 4 | 2015-05-07 - 10:16 | about 9 years |
1.10.0.pre | MIT | 4 | 2015-05-03 - 23:31 | about 9 years |
1.10.0.rc | MIT | 4 | 2015-05-19 - 00:55 | about 9 years |
1.9.10 | MIT | 4 | 2015-06-23 - 00:14 | almost 9 years |
1.9.9 | MIT | 4 | 2015-05-17 - 05:43 | about 9 years |
1.9.8 | MIT | 4 | 2015-05-13 - 19:03 | about 9 years |
1.9.7 | MIT | 4 | 2015-05-11 - 20:13 | about 9 years |
1.9.6 | MIT | 4 | 2015-05-03 - 07:31 | about 9 years |
1.9.5 | MIT | 4 | 2015-04-30 - 03:57 | about 9 years |
1.9.4 | MIT | 4 | 2015-04-14 - 04:11 | about 9 years |
1.9.3 | MIT | 4 | 2015-04-13 - 00:12 | about 9 years |
1.9.2 | MIT | 4 | 2015-03-31 - 00:17 | about 9 years |
1.9.1 | MIT | 4 | 2015-03-22 - 06:48 | about 9 years |
1.9.0 | MIT | 4 | 2015-03-20 - 21:14 | about 9 years |
1.9.0.pre.1 | MIT | 4 | 2015-03-13 - 19:30 | about 9 years |
1.9.0.pre | MIT | 4 | 2015-03-11 - 09:19 | about 9 years |