Skip to content

Commit f4400f7

Browse files
committed
Mark cookies HttpOnly and -- if https is used -- secure.
Fixes issue2550689, but is untested if this really works in browsers.
1 parent 50a007a commit f4400f7

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ Fixed:
7777
for the patch.
7878
- Fix another XSS with the "otk" parameter, thanks to Jesse Ruderman for
7979
reporting. (Ralf)
80+
- Mark cookies HttpOnly and -- if https is used -- secure. Fixes
81+
issue2550689, but is untested if this really works in browsers. (Ralf)
8082

8183

8284
2011-07-15: 1.4.19

roundup/cgi/client.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ def __init__(self, instance, request, env, form=None, translator=None):
296296
# this is the base URL for this tracker
297297
self.base = self.instance.config.TRACKER_WEB
298298

299+
# should cookies be secure?
300+
self.secure = self.base.startswith ('https')
301+
299302
# check the tracker_we setting
300303
if not self.base.endswith('/'):
301304
self.base = self.base + '/'
@@ -1475,6 +1478,11 @@ def header(self, headers=None, response=None):
14751478
cookie = "%s=%s; Path=%s;"%(name, value, path)
14761479
if expire is not None:
14771480
cookie += " expires=%s;"%get_cookie_date(expire)
1481+
# mark as secure if https, see issue2550689
1482+
if self.secure:
1483+
cookie += " secure;"
1484+
# prevent theft of session cookie, see issue2550689
1485+
cookie += " HttpOnly;"
14781486
headers.append(('Set-Cookie', cookie))
14791487

14801488
self._socket_op(self.request.start_response, headers, response)
@@ -1508,17 +1516,6 @@ def add_cookie(self, name, value, expire=86400*365, path=None):
15081516
expire = -1
15091517
self._cookies[(path, name)] = (value, expire)
15101518

1511-
def set_cookie(self, user, expire=None):
1512-
"""Deprecated. Use session_api calls directly
1513-
1514-
XXX remove
1515-
"""
1516-
1517-
# insert the session in the session db
1518-
self.session_api.set(user=user)
1519-
# refresh session cookie
1520-
self.session_api.update(set_cookie=True, expire=expire)
1521-
15221519
def make_user_anonymous(self):
15231520
""" Make us anonymous
15241521

0 commit comments

Comments
 (0)