Skip to content

PermissionDenied exception raised every now and then because 'socialaccount_state' not found in session #583

@Morpho

Description

@Morpho

In about 5% of all social userlogins django-allauth fails with exception:

Traceback (most recent call last):
File "/var/www/virtualenvs/project/local/lib/python2.7/site-packages/newrelic-2.10.1.9/newrelic/hooks/framework_django.py", line 494, in wrapper return wrapped(*args, **kwargs)
File "/var/www/virtualenvs/project/local/lib/python2.7/site-packages/allauth/socialaccount/providers/oauth2/views.py", line 51, in view return self.dispatch(request, *args, **kwargs)
File "/var/www/virtualenvs/project/local/lib/python2.7/site-packages/allauth/socialaccount/providers/oauth2/views.py", line 105, in dispatch request.REQUEST.get('state'))
File "/var/www/virtualenvs/project/local/lib/python2.7/site-packages/allauth/socialaccount/models.py", line 282, in verify_and_unstash_state raise PermissionDenied()
PermissionDenied

URL: /accounts/facebook/login/callback/

HTTP_USER_AGENT: Mozilla/5.0 (Linux; U; Android 2.3.6; es-us; GT-B5510L Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
REQUEST_METHOD: GET

The exception is raised in this location:

    @classmethod
    def verify_and_unstash_state(cls, request, verifier):
        if 'socialaccount_state' not in request.session:
            raise PermissionDenied()

So it seems like 'socialaccount_state' cannot be found in the session. Why is that the case? How can it happen that sometimes this doesnt get included in the session?

UPDATE: I got hold of one of the session object that doesnt contain "socialaccount_state". Here are two example dicts:

{'_session_key': '665mdtp4t9sl3wcv2k6fitd2bag1m6h7', 'modified': False, 'server': <redis.client.StrictRedis object at 0x3e9e3d0>, '_session_cache': {'_auth_user_id': 13349L, '_auth_user_backend': 'allauth.account.auth_backends.AuthenticationBackend', 'account_verified_email': None}, 'accessed': True, 'serializer': <class 'django.contrib.sessions.serializers.PickleSerializer'>}

{'_session_key': 'd4bnstesbwnpq1o34ulmx3cf9e5w4akr', 'modified': False, 'server': <redis.client.StrictRedis object at 0x3e42990>, '_session_cache': {'socialaccount_sociallogin': {'user': {u'username': u'', u'first_name': u'Sandra', u'last_name': u'----- removed by me -----', u'is_active': True, u'id': None, u'is_superuser': False, u'is_staff': False, u'last_login': u'2014-04-08T17:08:31.519Z', u'password': u'!', u'email': u'', u'date_joined': u'2014-04-08T17:08:31.520Z'}, 'token': {u'account_id': None, u'app_id': 1, u'expires_at': u'2014-06-07T17:08:30.992Z', u'token': u'----------removed by me----------', u'id': None, u'token_secret': u''}, 'account': {u'user_id': None, u'uid': u'----- removed by me -----', u'last_login': None, u'provider': u'facebook', u'extra_data': {u'first_name': u'Sandra', u'last_name': u'----- removed by me -----', u'verified': True, u'name': u'Sandra ----- removed by me -----', u'locale': u'en_US', u'gender': u'female', u'work': [{u'employer': {u'id': u'----- removed by me -----', u'name': u'----- removed by me -----'}}, {u'position': {u'id': u'----- removed by me -----', u'name': u'Home Depot'}, u'start_date': u'0000-00', u'location': {u'id': u'108215395870424', u'name': u'Lake Park, Georgia'}, u'description': u'House keeping', u'employer': {u'id': u'----- removed by me -----', u'name': u'"----- removed by me -----".'}}], u'updated_time': u'2014-03-23T00:52:47+0000', u'languages': [{u'id': u'110867825605119', u'name': u'English'}, {u'id': u'108177092548456', u'name': u'Espa\xf1ol'}], u'link': u'https://www.facebook. com/profile. php?id=100----- removed by me -----', u'location': {u'id': u'113132652033783', u'name': u'Omaha, Nebraska'}, u'hometown': {u'id': u'109434842408576', u'name': u'Birmingham, Alabama'}, u'timezone': -4, u'education': [{u'school': {u'id': u'----- removed by me -----', u'name': u'----- removed by me -----'}, u'type': u'High School', u'year': {u'id': u'----- removed by me -----', u'name': u'2000'}}, {u'school': {u'id': u'----- removed by me -----', u'name': u'----- removed by me -----'}, u'type': u'High School', u'year': {u'id': u'----- removed by me -----', u'name': u'1993'}}], u'id': u'----- removed by me -----'}, u'id': None, u'date_joined': None}, 'email_addresses': [], 'state': {'process': 'login', 'next': u'/vid/ next-url. html'}}}, 'accessed': True, 'serializer': <class 'django.contrib.sessions. serializers. PickleSerializer'>}  

I tried it with django's database backend and a redis session-backend. In both cases the error appears.

We re using Django 1.5.4 with django-allauth 1.16.1. Anybody knows what's going on?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions