Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

werkzeug.contrib.securecookie bug with Python 3 #1204

Closed
simonw opened this issue Dec 2, 2017 · 0 comments
Closed

werkzeug.contrib.securecookie bug with Python 3 #1204

simonw opened this issue Dec 2, 2017 · 0 comments
Milestone

Comments

@simonw
Copy link

simonw commented Dec 2, 2017

In [1]: from werkzeug.contrib.securecookie import SecureCookie
In [2]: SecureCookie({'hello': 'world'}, 'cookie-secret').serialize()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-3fd8875133b9> in <module>()
----> 1 SecureCookie({'hello': 'world'}, 'cookie-secret').serialize()

.venv/lib/python3.6/site-packages/werkzeug/contrib/securecookie.py in __init__(self, data, secret_key, new)
    153         # no longer performs an implicit string conversion on hmac
    154         if secret_key is not None:
--> 155             secret_key = bytes(secret_key)
    156         self.secret_key = secret_key
    157         self.new = new

TypeError: string argument without an encoding

It looks like this code assumes Python 2:

def __init__(self, data=None, secret_key=None, new=True):
ModificationTrackingDict.__init__(self, data or ())
# explicitly convert it into a bytestring because python 2.6
# no longer performs an implicit string conversion on hmac
if secret_key is not None:
secret_key = bytes(secret_key)

grahamlyons added a commit to grahamlyons/werkzeug that referenced this issue Dec 4, 2017
When using a string for the `secret_key` (as per the docs) Python 3
fails with a `TypeError`.

This catches the error and uses the `encode` method instead.

Addresses pallets#1204
davidism pushed a commit to grahamlyons/werkzeug that referenced this issue Dec 4, 2017
When using a string for the `secret_key` (as per the docs) Python 3
fails with a `TypeError`.

This catches the error and uses the `encode` method instead.

Addresses pallets#1204
@davidism davidism closed this as completed Dec 4, 2017
@davidism davidism added this to the 0.13 milestone Dec 5, 2017
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants