[GH-ISSUE #898] Generated secret key causes unicode_escape error #788

Closed
opened 2026-02-27 11:13:32 +03:00 by kerem · 1 comment
Owner

Originally created by @qskousen on GitHub (Jul 18, 2016).
Original GitHub issue: https://github.com/modoboa/modoboa/issues/898

With commit https://github.com/tonioo/modoboa/issues/769 you started generating a default secret key, which is great. However, when trying to load this key from the database, it can cause an error if they key has a \ in it. For instance, my key has a \ on the end and trying to start uwsgi results in this error being thrown:

Traceback (most recent call last):
  File "./instance/wsgi.py", line 16, in <module>
    application = get_wsgi_application()
  File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
    django.setup()
  File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/apps/registry.py", line 115, in populate
    app_config.ready()
  File "/srv/modoboa/env/local/lib/python2.7/site-packages/modoboa/core/apps.py", line 66, in ready
    load_core_settings()
  File "/srv/modoboa/env/local/lib/python2.7/site-packages/modoboa/core/apps.py", line 54, in load_core_settings
    parameters.register(GeneralParametersForm, ugettext_lazy("General"))
  File "/srv/modoboa/env/local/lib/python2.7/site-packages/modoboa/lib/parameters.py", line 191, in register
    form = formclass()
  File "/srv/modoboa/env/local/lib/python2.7/site-packages/modoboa/core/app_settings.py", line 274, in __init__
    super(GeneralParametersForm, self).__init__(*args, **kwargs)
  File "/srv/modoboa/env/local/lib/python2.7/site-packages/modoboa/lib/parameters.py", line 61, in __init__
    self._load_initial_values()
  File "/srv/modoboa/env/local/lib/python2.7/site-packages/modoboa/lib/parameters.py", line 101, in _load_initial_values
    self.fields[p.shortname].initial = self._decode_value(p.value)
  File "/srv/modoboa/env/local/lib/python2.7/site-packages/modoboa/lib/parameters.py", line 67, in _decode_value
    return value.decode('unicode_escape').replace('\\r\\n', '\n')
UnicodeDecodeError: 'unicodeescape' codec can't decode byte 0x5c in position 15: \ at end of string
Mon Jul 18 15:43:59 2016 - unable to load app 0 (mountpoint='') (callable not found or import error)

How can I safely regenerate this key without invalidating the current password, or regenerate the key and the admin password? This is a fresh install (obviously, since I can't load the site) on Ubuntu 16.04, installed using the easy install script.

You may want to test the secret key before inserting it in the database.

Originally created by @qskousen on GitHub (Jul 18, 2016). Original GitHub issue: https://github.com/modoboa/modoboa/issues/898 With commit https://github.com/tonioo/modoboa/issues/769 you started generating a default secret key, which is great. However, when trying to load this key from the database, it can cause an error if they key has a \ in it. For instance, my key has a \ on the end and trying to start uwsgi results in this error being thrown: ``` Traceback (most recent call last): File "./instance/wsgi.py", line 16, in <module> application = get_wsgi_application() File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application django.setup() File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/__init__.py", line 18, in setup apps.populate(settings.INSTALLED_APPS) File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/apps/registry.py", line 115, in populate app_config.ready() File "/srv/modoboa/env/local/lib/python2.7/site-packages/modoboa/core/apps.py", line 66, in ready load_core_settings() File "/srv/modoboa/env/local/lib/python2.7/site-packages/modoboa/core/apps.py", line 54, in load_core_settings parameters.register(GeneralParametersForm, ugettext_lazy("General")) File "/srv/modoboa/env/local/lib/python2.7/site-packages/modoboa/lib/parameters.py", line 191, in register form = formclass() File "/srv/modoboa/env/local/lib/python2.7/site-packages/modoboa/core/app_settings.py", line 274, in __init__ super(GeneralParametersForm, self).__init__(*args, **kwargs) File "/srv/modoboa/env/local/lib/python2.7/site-packages/modoboa/lib/parameters.py", line 61, in __init__ self._load_initial_values() File "/srv/modoboa/env/local/lib/python2.7/site-packages/modoboa/lib/parameters.py", line 101, in _load_initial_values self.fields[p.shortname].initial = self._decode_value(p.value) File "/srv/modoboa/env/local/lib/python2.7/site-packages/modoboa/lib/parameters.py", line 67, in _decode_value return value.decode('unicode_escape').replace('\\r\\n', '\n') UnicodeDecodeError: 'unicodeescape' codec can't decode byte 0x5c in position 15: \ at end of string Mon Jul 18 15:43:59 2016 - unable to load app 0 (mountpoint='') (callable not found or import error) ``` How can I safely regenerate this key without invalidating the current password, or regenerate the key and the admin password? This is a fresh install (obviously, since I can't load the site) on Ubuntu 16.04, installed using the easy install script. You may want to test the secret key before inserting it in the database.
kerem 2026-02-27 11:13:32 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@tonioo commented on GitHub (Jul 19, 2016):

I think the best would be to limit the character set used to generate this key. FYI, this key is only used to encrypt passwords into user sessions so you can change it, you'll just have to disconnect/connect once again.

<!-- gh-comment-id:233589755 --> @tonioo commented on GitHub (Jul 19, 2016): I think the best would be to limit the character set used to generate this key. FYI, this key is only used to encrypt passwords into user sessions so you can change it, you'll just have to disconnect/connect once again.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/modoboa-modoboa#788
No description provided.