Описание
Http4s vulnerable to HTTP Request Smuggling due to improper handling of HTTP trailer section
Summary
http4s is vulnerable to HTTP Request Smuggling due to improper handling of HTTP trailer section. This vulnerability could enable attackers to:
- Bypass front-end servers security controls
- Launch targeted attacks against active users
- Poison web caches
Pre-requisites for the exploitation: the web appication has to be deployed behind a reverse-proxy that forwards trailer headers.
Details
The HTTP chunked message parser, after parsing the last body chunk, calls parseTrailers (ember-core/shared/src/main/scala/org/http4s/ember/core/ChunkedEncoding.scala#L122-142).
This method parses the trailer section using Parser.parse, where the issue originates.
parse has a bug that allows to terminate the parsing before finding the double CRLF condition: when it finds an header line that does not include the colon character, it continues parsing with state=false looking for the header name till reaching the condition else if (current == lf && (idx > 0 && message(idx - 1) == cr)) that sets complete=true even if no \r\n\r\n is found.
The remainder left in the buffer is then parsed as another request leading to HTTP Request Smuggling.
PoC
Start a simple webserver that echoes the received requests:
build.sbt
Send the following request:
You can do that with the following command:
printf 'POST / HTTP/1.1\r\nHost: localhost\r\nTransfer-Encoding: chunked\r\n\r\n2\r\naa\r\n0\r\nTest: smuggling\r\na\r\nGET /admin HTTP/1.1\r\nHost: localhost\r\n\r\n' | nc localhost 8080
You will see that the request is interpreted as two separate requests
Пакеты
org.http4s:http4s-ember-core_2.12
< 0.23.31
0.23.31
org.http4s:http4s-ember-core_2.13
< 0.23.31
0.23.31
org.http4s:http4s-ember-core_3
< 0.23.31
0.23.31
org.http4s:http4s-ember-core_2.13
>= 1.0.0-M1, < 1.0.0-M45
1.0.0-M45
org.http4s:http4s-ember-core_3
>= 1.0.0-M1, < 1.0.0-M45
1.0.0-M45
Связанные уязвимости
Http4s is a Scala interface for HTTP services. In versions from 1.0.0-M1 to before 1.0.0-M45 and before 0.23.31, http4s is vulnerable to HTTP Request Smuggling due to improper handling of HTTP trailer section. This vulnerability could enable attackers to bypass front-end servers security controls, launch targeted attacks against active users, and poison web caches. A pre-requisite for exploitation involves the web application being deployed behind a reverse-proxy that forwards trailer headers. This issue has been patched in versions 1.0.0-M45 and 0.23.31.