[New-bugs-announce] [issue2988] Invalid cookies crash web applications

anatoly techtonik report at bugs.python.org
Wed May 28 10:31:24 CEST 2008

New submission from anatoly techtonik <techtonik at gmail.com>:

Current BaseCookie and SimpleCookie may crash web-application when
running on the same domain with other scripts. Other scripts may create
invalid cookies that lead to Cookie.CookieError: Illegal key value in

This created problems in:
    trac: http://trac.edgewall.org/ticket/2256
    mailman: http://bugs.python.org/issue472646

Test case consists of two scripts - one in PHP and one in Python where
the former crashes the latter when run on the same domain through IE6:

setcookie("cook:test", "php set", time()+60*60);



#!/usr/bin/env python

import Cookie
from os import environ as env

C = Cookie.SimpleCookie()
C["CUX2"] = 123
C["CUX2"]['expires'] = 60*60*60

print "Content-Type: text/html"
print C
print # blank line, end of headers

print env["HTTP_COOKIE"]
G = Cookie.SimpleCookie(env["HTTP_COOKIE"])

print "<br/>Next: "
print G

What would be the pythonic way to avoid people making their own wrappers
when stumbling upon the problem?
1. Patch *Cookie classes to display warning about invalid Cookie and
continue instead of crashing with CookieError
2. Add SilentCookie that ignores invalid Cookies
3. Patch BaseCookie.load method to include optional attribute to ignore
errors. Should it be turned on by default (like in roundup code above)
4. Add warning to BaseCookie.load documentation about the pitfall and
the need to catch CookieError here 

components: Extension Modules
messages: 67443
nosy: techtonik
severity: normal
status: open
title: Invalid cookies crash web applications
versions: Python 2.6, Python 3.0

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list