elixir-mint / mint

Functional HTTP client for Elixir with support for HTTP/1 and HTTP/2 🌱
Apache License 2.0
1.36k stars 106 forks source link

When Mint encounters invalid HTTP/2 frames it crashes instead of discarding them #346

Closed DunyaKokoschka closed 2 years ago

DunyaKokoschka commented 2 years ago

Some Cloudflare hosted sites send back an Origin frame (https://httpwg.org/specs/rfc8336.html) this causes the Mint HTTP2 client to crash when processing them.

This PR resolves the issue: https://github.com/elixir-mint/mint/pull/345

The error looks something like:

     ** (FunctionClauseError) no function clause matching in Mint.HTTP2.Frame.decode_contents/4

     The following arguments were given to Mint.HTTP2.Frame.decode_contents/4:

         # 1
         12

         # 2
         0

         # 3
         0

         # 4
         <<0, 28, 104, 116, 116, 112, 115, 58, 47, 47, 100, 114, 97, 110, 100, 46, 99, 108, 111, 117, 100, 102, 108, 97, 114, 101, 46, 99, 111, 109>>

     Attempted function clauses (showing 10 out of 10):

         defp decode_contents(9, flags, stream_id, payload)
         defp decode_contents(0, flags, stream_id, payload)
         defp decode_contents(7, flags, stream_id, payload)
         defp decode_contents(1, flags, stream_id, payload)
         defp decode_contents(6, flags, stream_id, payload)
         defp decode_contents(2, flags, stream_id, payload)
         defp decode_contents(5, flags, stream_id, payload)
         defp decode_contents(3, flags, stream_id, payload)
         defp decode_contents(4, flags, stream_id, payload)
         defp decode_contents(8, flags, stream_id, payload)

     code: HTTP2.stream(
     stacktrace:
       (mint 1.4.0) lib/mint/http2/frame.ex:118: Mint.HTTP2.Frame.decode_contents/4
       (mint 1.4.0) lib/mint/http2/frame.ex:90: Mint.HTTP2.Frame.decode_next/2
       (mint 1.4.0) lib/mint/http2.ex:1379: Mint.HTTP2.handle_new_data/3
       (mint 1.4.0) lib/mint/http2.ex:1374: Mint.HTTP2.maybe_concat_and_handle_new_data/2
       (mint 1.4.0) lib/mint/http2.ex:795: Mint.HTTP2.stream/2
whatyouhide commented 2 years ago

Nice catch! Closing the issue in favor of the PR #345. 🙃