-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Sorry for the long ticket, sometimes I feel I am too verbose, but I tried my best to justify my proposal
Context
I commit Gemfile.lock files to source control when developing Ruby libraries. This is somewhat controversial and not widely adopted, but it's currently the official recommendation of the Bundler team, and other package managers also agree (https://classic.yarnpkg.com/blog/2016/11/24/lockfiles-for-all/).
Anyways, that currently means that I get security advisories and dependabot PRs to warn me about vulnerabilities in my Gemfile.lock files and to update them.
However, sometimes dependabot is unable to create PRs for some of these security advisories, because of some special behavior it has for libraries.
The special behavior is that if it's updating a Gemfile.lock file inside a library, dependabot will parse the required_ruby_version field in the gemspec file, and use the lower bound for it as the required ruby version for the resolution. That means that sometimes it will not be able to update a Gemfile.lock file to a secure version because the secure version no longer supports the oldest Ruby version supported by the library.
An example of this is https://github.com/formtastic/formtastic/security/dependabot/15:
Dependabot is only able to update to nokogiri-1.12.5, because it adds a requirement on "Ruby 2.5" to the resolution (the gemspec includes required_ruby_version >= 2.5), and 1.12.5 is the newest nokogiri version that still supports Ruby 2.5.
Why it currently works like this?
This feature was added a very long time ago with 9d08fc2. I think the reason is the following:
-
As you probably know,
GemfileandGemfile.lockfiles in libraries are not used at all by end users of the libraries, it's theGemfileandGemfile.lockfiles in end applications using the library that get considered. The only thing actually meaningful for end users are the dependency requirements in thegemspecfile of the library. -
GemfileandGemfile.lockfiles are important though for developers of the library, since they usually determine the exact set of dependencies and their versions the library is tested against. It's normally impractical to test a library against all possible combinations of its dependencies, soGemfileandGemfile.lockfiles help choosing what's worth testing against. -
I think adding this extra requirement on the Ruby version is intended to help making sure that the set of dependencies the library is tested against is compatible with the oldest Ruby version supported by the library. And I think that's intended to avoid introducing changes that unintentionally drop support for old Rubies.
Why I think it should be changed?
I think there are a few reasons to change this:
- Simplicity. We can get rid of a lot of "library specific code". Code that's also very dependent on Bundler internals and likely to have issues, like the one fixed by Fix Ruby version conflict error detection for new Bundler versions #4820.
- Consistency. Currently dependabot does this, but only "sometimes". For example, if it finds any issues caused by the extra ruby requirement, it will retry without it. This was introduced by fcd5682.
- Not necessary most of the times. Most libraries test against all major Rubies they support, and if they have to choose, they definitely test against the oldest supported Ruby. So even if a PR created by dependabot due to this change made the library incompatible with that Ruby version, it will be cached by CI.
- Clarity. As can be seen in the above screenshot, it's currently very hard to figure out why Dependabot could not update the dependency, because this extra requirement on the Ruby version is added "silently".
And most importantly
- Security. Security issues are most important for production environments, but can also affect developer environments. By leaving
Gemfile.lockfiles out there with insecure versions of gems, we leave room for those issues hitting developer environments.
If the above makes sense, I'm happy to create a PR for this.
Thanks for reading!
