You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There appears to have been a bug in how HTTP_ACCEPT is parsed living in
run_cgi() for eons, perhaps from the time it was written. Perhaps not
many are using this code (I'm not either) but recent (post 3.0 Release)
Python 3.x appear to have broken something in getallmatchingheaders()
(which originates in Message) and I happened to stumble upon this
condition while searching through the stdlib code.
line[:1] in '\t\n\r' clearly was meant to to be line[-1].
However that doesn't fix completely this chunk of code as it makes some
assumptions about what getallmatchingheaders() delivers which aren't
accurate. The following behaves as expected and feels safer:
Note that post Python 3.0 release,
http.client.HTTPMessage.getallmatchingheaders() was broken. I've
reported this just now and proposed a fix in bpo-5053.
BTW in the original code, I think line[:1] in "\t\n\r " might have been correct. It looks like the getallmatchinheaders() method was actually meant to return continued lines separately, prefixed with whitespace. My patch is probably only appropriate for Python 3; maybe Mike’s code will work for Python 2.
New changeset b630ca7 by Miss Islington (bot) in branch '3.9':
[3.9] bpo-5054: CGIHTTPRequestHandler.run_cgi() HTTP_ACCEPT improperly parsed (GH-23638) (GH-23657) b630ca7
Activity
mwatkins commentedon Jan 25, 2009
There appears to have been a bug in how HTTP_ACCEPT is parsed living in
run_cgi() for eons, perhaps from the time it was written. Perhaps not
many are using this code (I'm not either) but recent (post 3.0 Release)
Python 3.x appear to have broken something in getallmatchingheaders()
(which originates in Message) and I happened to stumble upon this
condition while searching through the stdlib code.
From Line 980 of http.server
line[:1] in '\t\n\r' clearly was meant to to be line[-1].
However that doesn't fix completely this chunk of code as it makes some
assumptions about what getallmatchingheaders() delivers which aren't
accurate. The following behaves as expected and feels safer:
Note that post Python 3.0 release,
http.client.HTTPMessage.getallmatchingheaders() was broken. I've
reported this just now and proposed a fix in bpo-5053.
terryjreedy commentedon Jun 26, 2010
I hope that someone who knows more than me on this subject takes a look at this.
vadmium commentedon Feb 15, 2015
Posting a patch for this so that we can get rid of the broken HTTPMessage.getallmatchingheaders() method in bpo-5053.
vadmium commentedon Feb 15, 2015
BTW in the original code, I think line[:1] in "\t\n\r " might have been correct. It looks like the getallmatchinheaders() method was actually meant to return continued lines separately, prefixed with whitespace. My patch is probably only appropriate for Python 3; maybe Mike’s code will work for Python 2.
miss-islington commentedon Dec 5, 2020
New changeset b630ca7 by Miss Islington (bot) in branch '3.9':
[3.9] bpo-5054: CGIHTTPRequestHandler.run_cgi() HTTP_ACCEPT improperly parsed (GH-23638) (GH-23657)
b630ca7
orsenthil commentedon Dec 5, 2020
This was also resolved in 3.10 #23638