Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CGIHttpServer leaves traces of previous requests in env #44922

Closed
stevecassidy mannequin opened this issue May 3, 2007 · 5 comments
Closed

CGIHttpServer leaves traces of previous requests in env #44922

stevecassidy mannequin opened this issue May 3, 2007 · 5 comments
Labels
easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@stevecassidy
Copy link
Mannequin

stevecassidy mannequin commented May 3, 2007

BPO 1711605
Nosy @loewis, @birkenfeld
Superseder
  • bpo-9272: CGIHTTPServer poisons os.environ
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2010-07-31.19:10:34.896>
    created_at = <Date 2007-05-03.00:28:37.000>
    labels = ['easy', 'type-bug', 'library']
    title = 'CGIHttpServer leaves traces of previous requests in env'
    updated_at = <Date 2010-07-31.19:10:34.894>
    user = 'https://bugs.python.org/stevecassidy'

    bugs.python.org fields:

    activity = <Date 2010-07-31.19:10:34.894>
    actor = 'georg.brandl'
    assignee = 'none'
    closed = True
    closed_date = <Date 2010-07-31.19:10:34.896>
    closer = 'georg.brandl'
    components = ['Library (Lib)']
    creation = <Date 2007-05-03.00:28:37.000>
    creator = 'stevecassidy'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 1711605
    keywords = ['easy']
    message_count = 5.0
    messages = ['31931', '31932', '107914', '107915', '112182']
    nosy_count = 5.0
    nosy_names = ['loewis', 'georg.brandl', 'techtonik', 'stevecassidy', 'dugan']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'test needed'
    status = 'closed'
    superseder = '9272'
    type = 'behavior'
    url = 'https://bugs.python.org/issue1711605'
    versions = ['Python 2.6', 'Python 3.0']

    @stevecassidy
    Copy link
    Mannequin Author

    stevecassidy mannequin commented May 3, 2007

    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

    @stevecassidy stevecassidy mannequin added extension-modules C modules in the Modules dir labels May 3, 2007
    @loewis
    Copy link
    Mannequin

    loewis mannequin commented May 8, 2007

    Can you provide a patch?

    @devdanzin devdanzin mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error and removed extension-modules C modules in the Modules dir labels Mar 30, 2009
    @devdanzin devdanzin mannequin added easy labels Apr 22, 2009
    @techtonik
    Copy link
    Mannequin

    techtonik mannequin commented Jun 16, 2010

    I don't see why it modifies os.environ at all environ it passed as argument to child subprocess.

    @techtonik
    Copy link
    Mannequin

    techtonik mannequin commented Jun 16, 2010

    I can't edit my comment. That suxx. It should be
    "...at all if environ is passed..."

    @birkenfeld
    Copy link
    Member

    bpo-9272 has a patch.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant