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.

classification
Title: CGIHttpServer leaves traces of previous requests in env
Type: behavior Stage: test needed
Components: Library (Lib) Versions: Python 3.0, Python 2.6
process
Status: closed Resolution: duplicate
Dependencies: Superseder: CGIHTTPServer poisons os.environ
View: 9272
Assigned To: Nosy List: dugan, georg.brandl, loewis, stevecassidy, techtonik
Priority: normal Keywords: easy

Created on 2007-05-03 00:28 by stevecassidy, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (5)
msg31931 - (view) Author: Steve Cassidy (stevecassidy) Date: 2007-05-03 00:28
CGIHttpserver tries to reset the environment between calls to CGI scripts by setting various variables to '' if they are not needed in the current request. In some cases this is not the correct behaviour since the presence of a null value can be interpreted by a CGI script as being significant. 

For example, if HTTP_COOKIE has a null value then a script doing the standard test:

if os.environ.has_key('HTTP_COOKIE'):
   # get the cookie

will have trouble

The problem is that CGIHTTPserver.py resets the entries in the env array which is then passed to os.environ.update(), this can only overwrite the env variables, not remove them.

An alternative is to call 

if os.environ.has_key(k):
    del os.environ[k]

inside the loop that updates the empty keys, then these variables will not be passed on to the CGI script.

Steve
msg31932 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2007-05-08 19:07
Can you provide a patch?
msg107914 - (view) Author: anatoly techtonik (techtonik) Date: 2010-06-16 11:56
I don't see why it modifies os.environ at all environ it passed as argument to child subprocess.
msg107915 - (view) Author: anatoly techtonik (techtonik) Date: 2010-06-16 11:58
I can't edit my comment. That suxx. It should be
"...at all if environ is passed..."
msg112182 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-07-31 19:10
#9272 has a patch.
History
Date User Action Args
2022-04-11 14:56:24adminsetgithub: 44922
2010-07-31 19:10:34georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg112182

superseder: CGIHTTPServer poisons os.environ
resolution: duplicate
2010-06-16 11:58:10techtoniksetmessages: + msg107915
2010-06-16 11:56:45techtoniksetnosy: + techtonik
messages: + msg107914
2009-04-22 05:08:06ajaksu2setkeywords: + easy
2009-03-31 20:58:48dugansetnosy: + dugan
2009-03-30 16:49:37ajaksu2setstage: test needed
type: behavior
components: + Library (Lib), - Extension Modules
versions: + Python 2.6, Python 3.0, - Python 2.5
2007-05-03 00:28:37stevecassidycreate