0.0
The project is in a healthy, maintained state
bundle-patch is a CLI tool that detects vulnerable gems in your Gemfile and automatically upgrades them to a patchable version based on your configured strategy (patch/minor/all). Uses bundler-audit under the hood.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 5.0

Runtime

 Project Readme

๐Ÿ”’ bundle-patch

A command-line tool to automatically patch vulnerable gems in your Gemfile using bundler-audit under the hood.

It parses audit output, finds the best patchable version for each vulnerable gem, and updates your Gemfile accordingly.


โœจ Features

  • Runs bundle audit and parses vulnerabilities
  • Computes the minimal patchable version required
  • Updates your Gemfile (and optionally runs bundle install)
  • Supports patch/minor/major upgrade strategies
  • Handles indirect dependencies by explicitly adding them
  • Has a dry-run mode
  • Creates backup of your Gemfile before changes

๐Ÿ“‹ Requirements

  • Ruby 2.6 or later
  • Bundler installed
  • bundler-audit installed (will be installed automatically if missing)

๐Ÿ“ฆ Installation

Add this gem to your system:

gem install bundle-patch

Or add it to your project's Gemfile for use in development:

# Gemfile
group :development do
  gem 'bundle-patch'
end

And then:

bundle install

๐Ÿ’ก Examples

Basic Usage

bundle-patch

This will run in patch mode (default) and update only patch versions.

Minor Version Updates

bundle-patch --mode=minor

Example output:

๐Ÿ” Running `bundle-audit check --format json`...
๐Ÿ”’ Found 2 vulnerabilities:
- sidekiq (5.2.10): sidekiq Denial of Service vulnerability
  โœ… Patchable โ†’ 6.5.10
- actionpack (6.1.4.1): XSS vulnerability
  โœ… Patchable โ†’ 6.1.7.7
๐Ÿ“ Backing up Gemfile to Gemfile.bak...
๐Ÿ”ง Updating existing gem: actionpack to '6.1.7.7'
โž• Gem sidekiq is a dependency. Adding it explicitly to Gemfile with version 6.5.10.
โœ… Gemfile updated!
๐Ÿ“ฆ Running `bundle install`...
โœ… bundle install completed successfully

Dry Run Mode

bundle-patch --dry-run

This will show what would be changed without making any actual changes.

Skip Bundle Install

bundle-patch --skip-bundle-install

This will update the Gemfile but skip running bundle install.

Major Version Updates

bundle-patch --mode=all

This will allow updates to any version that fixes the vulnerability.


โš™๏ธ Options

Option Description Default
--mode=patch Only allow patch-level updates (e.g., 1.0.0 โ†’ 1.0.1) โœ“
--mode=minor Allow minor version updates (e.g., 1.0.0 โ†’ 1.1.0)
--mode=all Allow all updates including major versions (e.g., 1.0.0 โ†’ 2.0.0)
--dry-run Only print what would be changed, don't touch the Gemfile or install gems false
--skip-bundle-install Modify the Gemfile, but skip bundle install false

๐Ÿงผ How it works

  1. Runs bundle audit check --format json
  2. Groups advisories by gem
  3. Determines the best patchable version for each gem based on --mode
  4. Creates a backup of your Gemfile (Gemfile.bak)
  5. Ensures the gem is either updated or explicitly added to the Gemfile
  6. Optionally runs bundle install (unless --skip-bundle-install or --dry-run is used)

๐Ÿ” Troubleshooting

Bundle Install Fails

If bundle install fails after updating:

  1. Check the error message
  2. You can revert to the backup: cp Gemfile.bak Gemfile
  3. Try running bundle install manually to see more detailed errors

Gem Can't Be Patched

If a gem can't be patched in your chosen mode:

  1. Try running with --mode=all to see all possible updates
  2. Check if there are any version conflicts in your Gemfile
  3. Consider manually updating the gem to a specific version

Security Considerations

  • Always review the changes made to your Gemfile
  • Test your application after applying updates
  • Consider running your test suite after updates
  • Check the changelog of updated gems for breaking changes

๐Ÿค Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/yourusername/bundle-patch.


๐Ÿ“„ License

The gem is available as open source under the terms of the MIT License.