Issue Details (XML | Word | Printable)

Key: MODPYTHON-191
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Graham Dumpleton
Reporter: Graham Dumpleton
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
mod_python

Tampering with signed cookies.

Created: 02/Oct/06 07:33 AM   Updated: 01/May/07 10:47 AM
Return to search
Component/s: core
Affects Version/s: 3.2.10
Fix Version/s: 3.3.1

Time Tracking:
Not Specified

Resolution Date: 07/Nov/06 10:12 AM


 Description  « Hide
As reported by Andy Pearce in:

  http://mail-archives.apache.org/mod_mbox/httpd-python-dev/200609.mbox/%3c44F824E2.4040304@jgassociates.ca%3e

Andy Pearce wrote:
>
> Hi,
>
> I think I might have spotted a slight bug in Session.py. When the
> 'secret' parameter is supplied to use the SignedCookie class, it appears
> that __init__ of BaseSession doesn't check the return type of
> get_cookies().
>
> If I understand the SignedCookie docs correctly, if the cookie value
> doesn't match its signature, it simply returns the contents as a Cookie
> rather than a SignedCookie (indicating that the user tampered with their
> cookie before sending it back).
>
> However, there is no check in BaseSession's __init__ that the return of
> get_cookies() is a SignedCookie in the case that 'secret' is supplied.
>
> Perhaps a minor point, but it would seem to make the option of using
> SignedCookies rather pointless, since the signature isn't being checked.
> Presumably if the cookie has been tampered with, your only safe option
> is to throw it away and generate a new one. I think this can be achieved
> by changing the lines:
>
> if cookies.has_key(session_cookie_name):
> self._sid = cookies[session_cookie_name].value
>
> To something like:
>
> if cookies.has_key(session_cookie_name):
> if not secret or type(cookes[session_cookie_name]) \
> is Cookie.SignedCookie:
> self._sid = cookies[session_cookie_name].value
>
> I'm fairly new to mod_python, so if I'm mistaken then my apologies, and
> a quick explanation of why would be very much appreciated! ^_^
>
> Thanks,
>
> - Andy
>

Is this correct and should the change suggested appropriate?

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Repository Revision Date User Message
ASF #472053 Tue Nov 07 10:11:01 UTC 2006 grahamd (MODPYTHON-191) Session class will no longer accept a normal cookie if a
signed cookie was expected.
(MODPYTHON-200) Fixed problem whereby signed and marshalled cookies could
not be used at the same time. When expecting marshalled cookie, any signed,
but not marshalled cookies will be returned as normal cookies.
Files Changed
MODIFY /httpd/mod_python/trunk/Doc/modpython4.tex
MODIFY /httpd/mod_python/trunk/lib/python/mod_python/psp.py
MODIFY /httpd/mod_python/trunk/test/test.py
MODIFY /httpd/mod_python/trunk/lib/python/mod_python/Cookie.py
MODIFY /httpd/mod_python/trunk/lib/python/mod_python/__init__.py
MODIFY /httpd/mod_python/trunk/README
MODIFY /httpd/mod_python/trunk/Doc/appendixc.tex
MODIFY /httpd/mod_python/trunk/lib/python/mod_python/Session.py
MODIFY /httpd/mod_python/trunk/src/include/mpversion.h