tide icon indicating copy to clipboard operation
tide copied to clipboard

Panics with non-ASCII header value

Open IVogel opened this issue 3 years ago • 2 comments

It panics due to lack of the string validity check in async-h1 and due to unwrap in http-types. Also, there is second unwrap that will panic if two fields with similar values exists, but second has valid UTF-8 string.

Minimal code for replication

#[async_std::main]
async fn main() -> tide::Result<()> {
    let mut app = tide::new();
    app.at("/").get( |_| async {
        Ok(tide::Response::new(200))
    });
    app.listen("0.0.0.0:8080").await?;
    Ok(())
}

Note, header value should be an valid UTF-8 string.

curl --header "Test: тест" http://0.0.0.0:8080
# or
curl --header "Test: test" --header "Test: тест" http://0.0.0.0:8088

Sorry if this is wrong repo. I don't really know to which repo this issue related to, because tide uses async-h1 which uses http-types. And I have got this error while using tide.

IVogel avatar Oct 07 '21 17:10 IVogel

Thanks for raising this! You're right we should probably remove the unwraps from both those locations. Unfortunately HTTP headers are required to be ASCII to reliably work (see this SO question), so that restriction cannot go away. But on our end we should make it so that we don't unwrap within http-types.

Tasks

  • change signature of {Request,Response,Headers}::append to return Result
  • change signature of {Request,Response,Headers}::insert to return Result

yoshuawuyts avatar Oct 08 '21 10:10 yoshuawuyts

Thanks for your reply. Yes, I know that headers should be all in ASCII. Wrote this because yesterday somebody has crashed my auth server. ¯\_( :| )_/¯ Looking forward to updates.

But for now, I'll just drop these non-ASCII headers.

IVogel avatar Oct 08 '21 11:10 IVogel