Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Added base64 encoding to session data.
The session data was not JSON serializable (it was passing binary
strings). I added a call to base64.b64encode (and a matching decode) on
session keys to get around this.
  • Loading branch information
prsteele authored and puiterwijk committed Sep 14, 2015
1 parent 4fe5bd1 commit 0b8daa5059996a6022c3c28a7ace972f06a9d453
Showing 1 changed file with 4 additions and 2 deletions.
@@ -18,6 +18,7 @@
from functools import wraps
from datetime import date
import sys
import base64

from flask import request, session, redirect, current_app, url_for
from werkzeug.urls import url_quote
@@ -123,14 +124,15 @@ def __getitem__(self, name):
rv = session[self.name_mapping.get(name, name)]
if isinstance(rv, dict) and len(rv) == 1 and ' p' in rv:
try:
return pickle.loads(rv[' p'].encode('utf-8'))
return pickle.loads(base64.b64decode(rv[' p'].encode('utf-8')))
except:
return pickle.loads(rv[' p'])
return rv

def __setitem__(self, name, value):
if not getattr(current_app.session_interface, 'pickle_based', True):
value = {' p': pickle.dumps(value, 0)}
b64 = base64.b64encode(pickle.dumps(value, 0))
value = {' p': b64.decode('utf-8')}
session[self.name_mapping.get(name, name)] = value

def __delitem__(self, name):

0 comments on commit 0b8daa5

Please sign in to comment.