hyperium / hyperium/hyper

Hyper returns status 431 instead of 414 if url overflows max_buf_size

Open
#3,874 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
Dominant language
Rust
Stars
16.3k
Forks
1.8k
Avg merge
1d 22h
Merged PRs (30d)
14

Description

Version
Hyper 0.14.30

Platform
ALL

Description

In my user case I use hyper as server and config it with a fixed http1_max_buf_size

hyper::Server::builder(incoming)
        .http1_max_buf_size(64 * 1024)
        ..serve(hyper::service::make_service_fn(... )

If the incomming url is greater than 64k, hyper returns 431 Request Header Fields Too Large instead of 414 URL TOO LONG. And since hyper will close connection afterwards, my service_fn is unable to catch this exception.(Or maybe it's possible but I just don't know how to)

I inspected the code briefly and found out the problem is here: here

if url overflows max_buf_size hyper just returns Error::new_too_large() and parsed as 431 Request Header Fields Too Large

I also inspect the parse_headers() implememtation, it seems that hyper must consume the whole buf to parse both request line and headers correctly. If the buf overflows, the current implemementation is unable to tell the difference between url too long or header too large.

I am wondering if this is a bug or any special consideration for the current implemementation/

[code sample that causes the bug]

I expected to see this happen: 414 URL TOO LONG

Instead, this happened: 431 Request Header Fields Too Large

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/proto/h1/io.rs, especially parse_headers() and the buffer-overflow handling near the reported line. Trace how an oversized request line and oversized headers become errors, then determine how the parser can distinguish them. Done means an overlong URL produces 414 while oversized headers still produce 431, with regression coverage for both cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api, backend, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.