This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author msg555
Recipients msg555
Date 2021-04-22.08:03:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1619078625.68.0.392663181082.issue43910@roundup.psfhosted.org>
In-reply-to
Content
cgi.parse_header incorrectly handles unescaping of quoted-strings

Note that you can find the related RFCs to how HTTP encodes the Content-Type header at https://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html and further discussion on how quoted-string is defined at https://greenbytes.de/tech/webdav/draft-ietf-httpbis-p1-messaging-16.html#rfc.section.3.2.1.p.3.

The way parse_header is written it has no context to be able to tell if a backslash is escaping a double quote or if the backslash is actually the escaped character and the double quote is free-standing, unescaped. For this reason it fails to parse values that have a backslash literal at the end. e.g. the following Content-Type will fail to be parsed

a/b; foo="moo\\"; bar=baz

Example run on current cpython master demonstrating the bug:

Python 3.10.0a7+ (heads/master:660592f67c, Apr 21 2021, 22:51:04) [GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cgi
>>> query = 'a; foo="moo\\\\"; bar=cow' 
>>> print(query)
a; foo="moo\\"; bar=cow
>>> cgi.parse_header(query)
('a', {'foo': '"moo\\\\"; bar=cow'})
History
Date User Action Args
2021-04-22 08:03:45msg555setrecipients: + msg555
2021-04-22 08:03:45msg555setmessageid: <1619078625.68.0.392663181082.issue43910@roundup.psfhosted.org>
2021-04-22 08:03:45msg555linkissue43910 messages
2021-04-22 08:03:45msg555create