Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use pyramid.SignedCookieSessionFactory instead of `UnencryptedCooki…
…eSessionFactoryConfig`
  • Loading branch information
Preston-Landers committed Jul 23, 2017
commit e630a349c432ba3f1a7b4ea7d57c441f9d1de6f0
19 changes: 13 additions & 6 deletions velruse/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys

from anykeystore import create_store_from_settings

Expand All @@ -16,6 +17,8 @@

log = __import__('logging').getLogger(__name__)

PYTHON_2 = sys.version_info.major == 2


def auth_complete_view(context, request):
endpoint = request.registry.settings.get('endpoint')
Expand Down Expand Up @@ -77,7 +80,8 @@ def default_setup(config):
specified then an in-memory storage backend will be used.

"""
from pyramid.session import UnencryptedCookieSessionFactoryConfig
# from pyramid.session import UnencryptedCookieSessionFactoryConfig
from pyramid.session import SignedCookieSessionFactory

log.info('Using an unencrypted cookie-based session. This can be '
'changed by pointing the "velruse.setup" setting at a different '
Expand All @@ -87,15 +91,18 @@ def default_setup(config):
secret = settings.get('session.secret')
cookie_name = settings.get('session.cookie_name', 'velruse.session')
if secret is None:
log.warn('Configuring unencrypted cookie-based session with a '
'random secret which will invalidate old cookies when '
'restarting the app.')
log.info(
'Configuring unencrypted cookie-based session with a '
'random secret which will invalidate old cookies when '
'restarting the app.')
if secrets is not None:
secret = secrets.token_urlsafe(32)
else:
elif PYTHON_2:
secret = ''.join('%02x' % ord(x) for x in os.urandom(16))
else:
secret = ''.join('%02x' % x for x in os.urandom(16))
log.info('autogenerated session secret: %s', secret)
factory = UnencryptedCookieSessionFactoryConfig(
factory = SignedCookieSessionFactory(
secret, cookie_name=cookie_name)
config.set_session_factory(factory)

Expand Down