How We Fixed the Dependency Confusion Vulnerability in Over 600 Ruby Applications
Shopify closed a dependency confusion hole across roughly 600 Ruby applications by migrating each `Gemfile.lock` to Bundler's newer format, which pins every gem to an explicit source. A custom Bundler plugin did the upgrade without changing dependency versions: it allowed only patch updates during regeneration, then restored the original versions. A CLI running on top of CI gave each repository its own environment, ran the migrations in parallel and opened pull requests automatically. Shopify also failed CI on outdated Bundler versions and worked with the Bundler maintainers on changes that shipped in 2.2.21 and 2.2.22, the latter preventing lockfiles from regressing to the old format.
Related posts
- The Case Against Monkey Patching, From a Rails Core Team Member
Shopify Engineering mediumAdeptMonkey patching Rails and other gems is brittle and should be avoided. Patches break silently on upgrades because private APIs carry no deprecation warnings, they can leave apps exposed after security releases, they pile up as tech debt, and they change behavior globally. Ruby refinements are not a safe alternative: at Shopify they added 13 seconds to monolith boot time by busting method caches and are now banned. Before patching, try upgrading, recheck usage, or fix the problem upstream. If a patch is unavoidable, keep it small and version-guarded in lib/patches, call super, document and test it, and plan its removal.
- Dependency prefixes are a supply chain risk: let's fix them
Sourcegraph mediumAdept
SemVer range prefixes like ^, ~ and wildcards in package.json act as a trust policy that lets compromised or hijacked packages flow into CI and production on the next install. The recommended controls are to commit lockfiles and install with npm ci, pnpm --frozen-lockfile or yarn --immutable, pin exact versions for high-blast-radius packages such as build tools, auth libraries and native-binding deps, set save-exact defaults, disable install scripts with an allowlist for exceptions, and run audits against the locked tree. To roll this out across hundreds of repositories, a Sourcegraph Batch Changes spec with a Node script rewrites React dependency ranges to approved exact versions and refreshes lockfiles without running scripts.
- Remove Circular Dependencies by Using Dependency Injection and the Repository Pattern in Ruby
Shopify Engineering mediumAdeptShopify broke a circular dependency between an internal pricing gem and its two consumers (the Shopify Core Rails monolith and the Storefront Renderer) by applying the Repository pattern with constructor-based dependency injection. The gem defines a contract, made up of shared Schema domain objects and a PricingRepositoryInterface. Each consumer implements that interface over its own data sources and passes the instance into PricingEngine::Engine, which keeps the gem stateless and unaware of how data is fetched. Sorbet signatures and interfaces enforce the contract at the type level. Testing combines mock repositories inside the gem, unit tests for each consumer's implementation, and shared integration test scripts.
- Building GitHub with Ruby and Rails
GitHub Engineering mediumAdeptGitHub's ~2M-line Rails monolith upgrades to the latest Rails main-branch commit every week via a scheduled GitHub Actions workflow that opens an automated PR, runs all builds, and ships the next day. CI also runs a parallel build against the latest Ruby commit, which let GitHub test Ruby 3.2 release candidates on production traffic, catch regressions such as a keyword-argument allocation increase before release, and adopt Ruby 3.2.1 on release day. Benefits include dropping nearly all Rails patches, avoiding big-bang migrations, and better security posture. The approach depends on a thorough test suite and progressive rollout deploys.
- Ruby2Shell (CVE-2026-132825): find vulnerable Ruby across your repos
Sourcegraph mediumAdept
Ruby2Shell (CVE-2026-132825) is a critical heap overflow in Ruby's string case conversion that researchers say default Rails and classic Sinatra apps expose without authentication, with remote code execution proofs of concept known. Fixed releases are 3.3.14, 3.4.13 and 4.0.10, and the hard part is finding which interpreter actually runs, because Dockerfiles, .ruby-version, Gemfile and Gemfile.lock can disagree and vendor products may bundle their own Ruby. Sourcegraph gives regex Code Search queries for affected version pins, a Deep Search prompt to reconcile pins per repo, and an Agentic Batch Changes prompt to bump exact pins within each series. Floating tags, unresolved build args and Ruby 3.2 or earlier are flagged for rebuild, review or migration rather than edited automatically.