Skip to content

Commit

Permalink
Added httponly only option to sessions and enabled it by default (tx …
Browse files Browse the repository at this point in the history
…Justin Davis)
  • Loading branch information
anandology committed Nov 24, 2010
1 parent c73da11 commit dc961c9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions web/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
'ignore_change_ip': True,
'secret_key': 'fLjUfxqXtfNoIldA0A0J',
'expired_message': 'Session expired',
'httponly': True
})

class SessionExpired(web.HTTPError):
Expand Down Expand Up @@ -64,6 +65,7 @@ def _load(self):
"""Load the session from the store, by the id from cookie"""
cookie_name = self._config.cookie_name
cookie_domain = self._config.cookie_domain
httponly = self._config.httponly
self.session_id = web.cookies().get(cookie_name)

# protection against session_id tampering
Expand Down Expand Up @@ -104,11 +106,13 @@ def _validate_ip(self):
def _save(self):
cookie_name = self._config.cookie_name
cookie_domain = self._config.cookie_domain
httponly = self._config.httponly

if not self.get('_killed'):
web.setcookie(cookie_name, self.session_id, domain=cookie_domain)
web.setcookie(cookie_name, self.session_id, domain=cookie_domain, httponly=httponly)
self.store[self.session_id] = dict(self)
else:
web.setcookie(cookie_name, self.session_id, expires=-1, domain=cookie_domain)
web.setcookie(cookie_name, self.session_id, expires=-1, domain=cookie_domain, httponly=httponly)

def _generate_session_id(self):
"""Generate a random id for session"""
Expand Down

2 comments on commit dc961c9

@aaronsw
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also allow a secure option.

@anandology
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.