Re: Permitted characters in HTTP/2 fields

Willy Tarreau <w@1wt.eu> Fri, 21 May 2021 06:20 UTC

Return-Path: <ietf-http-wg-request+bounce-httpbisa-archive-bis2juki=lists.ie@listhub.w3.org>
X-Original-To: ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com
Delivered-To: ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 205463A1A3E for <ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com>; Thu, 20 May 2021 23:20:21 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.649
X-Spam-Level:
X-Spam-Status: No, score=-2.649 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_BLOCKED=0.001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9D8hTDHfm7Ym for <ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com>; Thu, 20 May 2021 23:20:19 -0700 (PDT)
Received: from lyra.w3.org (lyra.w3.org [128.30.52.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id F19C83A1A3B for <httpbisa-archive-bis2Juki@lists.ietf.org>; Thu, 20 May 2021 23:20:18 -0700 (PDT)
Received: from lists by lyra.w3.org with local (Exim 4.92) (envelope-from <ietf-http-wg-request@listhub.w3.org>) id 1ljyTc-00080X-DC for ietf-http-wg-dist@listhub.w3.org; Fri, 21 May 2021 06:17:40 +0000
Resent-Date: Fri, 21 May 2021 06:17:40 +0000
Resent-Message-Id: <E1ljyTc-00080X-DC@lyra.w3.org>
Received: from mimas.w3.org ([128.30.52.79]) by lyra.w3.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from <w@1wt.eu>) id 1ljyTZ-0007zh-63 for ietf-http-wg@listhub.w3.org; Fri, 21 May 2021 06:17:37 +0000
Received: from wtarreau.pck.nerim.net ([62.212.114.60] helo=1wt.eu) by mimas.w3.org with esmtp (Exim 4.92) (envelope-from <w@1wt.eu>) id 1ljyTW-0007In-CW for ietf-http-wg@w3.org; Fri, 21 May 2021 06:17:36 +0000
Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 14L6HHMf023996; Fri, 21 May 2021 08:17:17 +0200
Date: Fri, 21 May 2021 08:17:17 +0200
From: Willy Tarreau <w@1wt.eu>
To: Martin Thomson <mt@lowentropy.net>
Cc: ietf-http-wg@w3.org
Message-ID: <20210521061717.GA23962@1wt.eu>
References: <f8e10178-62e0-466b-a561-10bde3297e73@www.fastmail.com> <20210427123819.GA1303@1wt.eu> <CAAPGdfEKiSFCNzGsyNOSRptdMLHwhC7j=DmaOmb-h9ZTfuHvTg@mail.gmail.com> <cd1ac1e9-5587-4dc0-bd81-2e64bf553847@www.fastmail.com> <20210520165910.GB22995@1wt.eu> <abe41b99-6ed5-451f-88f6-ff9ab600862d@www.fastmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: inline
In-Reply-To: <abe41b99-6ed5-451f-88f6-ff9ab600862d@www.fastmail.com>
User-Agent: Mutt/1.10.1 (2018-07-13)
Received-SPF: pass client-ip=62.212.114.60; envelope-from=w@1wt.eu; helo=1wt.eu
X-W3C-Hub-Spam-Status: No, score=-7.9
X-W3C-Hub-Spam-Report: BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, W3C_AA=-1, W3C_IRA=-1, W3C_IRR=-3, W3C_WL=-1
X-W3C-Scan-Sig: mimas.w3.org 1ljyTW-0007In-CW ab93b1fe430b381de64ce4cbeb775d31
X-Original-To: ietf-http-wg@w3.org
Subject: Re: Permitted characters in HTTP/2 fields
Archived-At: <https://www.w3.org/mid/20210521061717.GA23962@1wt.eu>
Resent-From: ietf-http-wg@w3.org
X-Mailing-List: <ietf-http-wg@w3.org> archive/latest/38802
X-Loop: ietf-http-wg@w3.org
Resent-Sender: ietf-http-wg-request@w3.org
Precedence: list
List-Id: <ietf-http-wg.w3.org>
List-Help: <https://www.w3.org/Mail/>
List-Post: <mailto:ietf-http-wg@w3.org>
List-Unsubscribe: <mailto:ietf-http-wg-request@w3.org?subject=unsubscribe>

Hi Martin,

On Fri, May 21, 2021 at 11:19:35AM +1000, Martin Thomson wrote:
> Hey Willy,
> 
> On Fri, May 21, 2021, at 02:59, Willy Tarreau wrote:
> > I really agree. I don't remember if 0x80 and above are forbidden in H2 but
> > I'd personally prefer to block them so that we don't needlessly introduce
> > the risk of aliasing due to different codings being used. Protocol elements
> > that define how messages should be delimited/routed/etc must be strictly
> > defined and easy to enforce in implementations and applications.
> 
> We never really said before.  I'm happy to extend the 0x7f to 0x7f-0xff if
> that is what others want.  It's not quite the same as limiting the grammar to
> what is permitted for field names, but it might be OK.

I was fine as well with limiting to what is permitted (and I personally use
a bit field to match them) but I agree that using a few ranges is even easier
to implement (especially for small & simple implementations that at least want
to make the effort of staying safe).

> field-name is "!" / "#" / "$" / "%" / "&" / "'" / "*" / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~" / DIGIT / ALPHA
> 
> That amounts to a whole bunch of characters less than %x21-7E (minus ':').  A
> simpler check for c >= 0x21 && c <= 0x7e && c != ':' seems reasonable to me.
> Then we don't have to worry about Unicode field names.  That's not a whole
> lot different than c >= 0x21 && c != 0x7e && c != ':' as the current PR has.

Yep in terms of computation it's the same and can be simplified to:

   (uint8_t)(c - 0x21) <= (0x7e - 0x21) && c != ':'

> I had the distinct impression that we DID see Unicode field names in some cases though.

This is exactly the horror that worries me. I really don't want to open
that pandora box, or we can say byebye to HTTP as a safe transport protocol
for applications. Just imagine a client emitting a POST to an H2-to-H1
gateway, with "content-length: 1000" and "Tran\xd1\x95fer-encoding: chunked",
the latter passing through a string manipulation function which
transliterates it to "Transfer-encoding: chunked" on the other side...
And that's just a single example, there are so many possibilities that
it could almost be funny if we weren't concerned a bit by security,
especially as by experience we know that if it can happen it will happen :-/

> We wanted to avoid backward incompatibility issues that might result from
> tighter constraints on field *values*, which is why we never said anything
> before, but names might be easier.

I have no problem with field values as basically anything besides
control chars and heading/trailing blanks, can already appear there
in previous HTTP versions. In practice the only header fields that
could cause trouble when reading incorrectly matched tokens are
Connection and Transfer-encoding, and both of these are already
forbidden in H2.

Thanks,
Willy