Fedora Account System
Red Hat Associate
Red Hat Customer
Summary When a bundler registry proxy is configured (HERMETO_BUNDLER__PROXY_URL), hermeto downloads every gem through it, including gems the Gemfile.lock declares from a private registry. This exposes builds to dependency confusion: a gem with the same name and version on the proxy's public upstream is fetched instead, while the SBOM still names the private registry as the source. Details _download_gems rewrites every gem download URL to the proxy without checking the gem's declared source. The rewrite keeps only the URL path, so remote: https://gems.corp.example/ becomes <proxy>/downloads/<gem> and the private host is dropped. Every non-rubygems GEM section in the lockfile is affected. Credentials embedded in a remote: URL are dropped together with the host, so they do not leak to the proxy. Other hermeto backends with proxy support only proxy their canonical public registry and leave custom sources alone. If the Gemfile.lock has no CHECKSUMS section, nothing detects the substitution: hermeto logs a warning that no checksum was found and continues. Bundler writes CHECKSUMS by default only since 4.0.0, so lockfiles created with older versions usually lack it. A regular bundle install of the same lockfile is not affected. Since 2.2.18 (the fix for CVE-2020-36327) Bundler fetches an explicitly scoped gem only from its declared source. Affected versions: proxy support was added in commit c3a6041e, first released in 0.60.0. All releases from 0.60.0 through 0.64.0 are affected, and it is unfixed on main. Proof of concept Reproduced with the hermeto 0.64.0 container image and against main. Two gems are built with the same name and version (corp-secret-1.0.0) but different content. Neither runs code; they differ only by a string constant. Private gem, ORIGIN="PRIVATE server", served on http://127.0.0.1:8101. Stands in for a private registry. Impostor gem, ORIGIN="PUBLIC impostor", served on http://127.0.0.1:8102. Stands in for the proxy's upstream, where someone has published a gem with the same name. A git-tracked project declares the private source and has no CHECKSUMS: Gemfile.lock: GEM remote: http://127.0.0.1:8101/ specs: corp-secret (1.0.0) PLATFORMS ruby DEPENDENCIES corp-secret BUNDLED WITH 2.5.22 Run with the proxy pointed at the impostor server: HERMETO_BUNDLER__PROXY_URL="http://127.0.0.1:8102" \ hermeto fetch-deps --source ./project --output ./out '{"type":"bundler","path":"."}' hermeto logs: INFO Using registry proxy http://127.0.0.1:8102/ for registry dependencies WARNING No checksum found for corp-secret-1.0.0, skipping verification INFO All dependencies fetched successfully \o/ The private server receives no request. The downloaded out/deps/bundler/corp-secret-1.0.0.gem is byte-identical to the impostor. out/bom.json reports the component as pkg:gem/corp-secret.0?repository_url=http://127.0.0.1:8101, naming the private registry as the source. Impact Whenever a bundler proxy is configured, the private source is bypassed and the private gem's name and version are requested from the public upstream, which reveals them to that registry. If the upstream has no such gem, the build fails. If it has one with the same name and version, hermeto fetches it silently and the SBOM records the wrong source. An attacker can exploit this through dependency confusion, by publishing a gem with the same name and version on the public registry. The gem does not run during prefetch. It runs during the image build when native extensions are compiled, or when the application loads it. Either way its code ends up in the built image. In builds with network access it can also send data out. The attacker needs no access to the repository or the pipeline, only a public registry account. On the victim's side this is ordinary configuration, and the proxy is often set by the build platform rather than the repository owner. Exploitation additionally requires a Gemfile.lock without CHECKSUMS and a gem name the organization has not registered on the public registry. Proxies that apply malware policies to ingested packages may block a known-malicious gem, but they do not prevent the source bypass or the incorrect SBOM. References hermeto#1834: the same class of issue in the pip backend (SBOM reporting only), fixed in hermeto#1836. CVE-2020-36327: dependency confusion in Bundler itself. CVSS Score (based on GitHub): 5.9