Skip to content

Commit 666d853

Browse files
authored
Merge pull request from GHSA-5fqv-mpj8-h7gm
Security fix
2 parents f5c0c64 + 7c138d8 commit 666d853

File tree

5 files changed

+36
-24
lines changed

5 files changed

+36
-24
lines changed

CHANGELOG.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ Unreleased
55
~~~~~~~~~~~~~~~~~~~~
66

77

8+
1.3.2 - `2023-02-24`
9+
~~~~~~~~~~~~~~~~~~~~
10+
This release contains a fix for a security vulnerability.
11+
12+
1.3.1 - `2023-02-15`
13+
~~~~~~~~~~~~~~~~~~~~
14+
This release contains no changes.
15+
816
1.3.0 - `2023-02-13`
917
~~~~~~~~~~~~~~~~~~~~
1018
This release contains many dependency updates, and numerous added or improved features over the last year.

docker/src/lemur.conf.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os.path
2-
import random
2+
import secrets
33
import string
44
from celery.schedules import crontab
55

@@ -18,10 +18,10 @@
1818

1919

2020
def get_random_secret(length):
21-
secret_key = ''.join(random.choice(string.ascii_uppercase) for x in range(round(length / 4)))
22-
secret_key = secret_key + ''.join(random.choice("~!@#$%^&*()_+") for x in range(round(length / 4)))
23-
secret_key = secret_key + ''.join(random.choice(string.ascii_lowercase) for x in range(round(length / 4)))
24-
return secret_key + ''.join(random.choice(string.digits) for x in range(round(length / 4)))
21+
secret_key = ''.join(secrets.choice(string.ascii_uppercase) for x in range(round(length / 4)))
22+
secret_key = secret_key + ''.join(secrets.choice("~!@#$%^&*()_+") for x in range(round(length / 4)))
23+
secret_key = secret_key + ''.join(secrets.choice(string.ascii_lowercase) for x in range(round(length / 4)))
24+
return secret_key + ''.join(secrets.choice(string.digits) for x in range(round(length / 4)))
2525

2626

2727
# This is the secret key used by Flask session management

docs/administration.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ Basic Configuration
143143

144144
An example of how you might generate a random string:
145145

146-
>>> import random
147-
>>> secret_key = ''.join(random.choice(string.ascii_uppercase) for x in range(6))
148-
>>> secret_key = secret_key + ''.join(random.choice("~!@#$%^&*()_+") for x in range(6))
149-
>>> secret_key = secret_key + ''.join(random.choice(string.ascii_lowercase) for x in range(6))
150-
>>> secret_key = secret_key + ''.join(random.choice(string.digits) for x in range(6))
146+
>>> import secrets
147+
>>> secret_key = ''.join(secrets.choice(string.ascii_uppercase) for x in range(6))
148+
>>> secret_key = secret_key + ''.join(secrets.choice("~!@#$%^&*()_+") for x in range(6))
149+
>>> secret_key = secret_key + ''.join(secrets.choice(string.ascii_lowercase) for x in range(6))
150+
>>> secret_key = secret_key + ''.join(secrets.choice(string.digits) for x in range(6))
151151

152152

153153
.. data:: LEMUR_ENCRYPTION_KEYS

lemur/common/utils.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"""
99
import base64
1010
import json
11-
import random
1211
import re
12+
import secrets
1313
import socket
1414
import ssl
1515
import string
@@ -58,19 +58,19 @@ def get_psuedo_random_string():
5858
"""
5959
Create a random and strongish challenge.
6060
"""
61-
challenge = "".join(random.choice(string.ascii_uppercase) for x in range(6)) # noqa
62-
challenge += "".join(random.choice("~!@#$%^&*()_+") for x in range(6)) # noqa
63-
challenge += "".join(random.choice(string.ascii_lowercase) for x in range(6))
64-
challenge += "".join(random.choice(string.digits) for x in range(6)) # noqa
61+
challenge = "".join(secrets.choice(string.ascii_uppercase) for x in range(6)) # noqa
62+
challenge += "".join(secrets.choice("~!@#$%^&*()_+") for x in range(6)) # noqa
63+
challenge += "".join(secrets.choice(string.ascii_lowercase) for x in range(6))
64+
challenge += "".join(secrets.choice(string.digits) for x in range(6)) # noqa
6565
return challenge
6666

6767

6868
def get_random_secret(length):
6969
""" Similar to get_pseudo_random_string, but accepts a length parameter. """
70-
secret_key = ''.join(random.choice(string.ascii_uppercase) for x in range(round(length / 4)))
71-
secret_key = secret_key + ''.join(random.choice("~!@#$%^&*()_+") for x in range(round(length / 4)))
72-
secret_key = secret_key + ''.join(random.choice(string.ascii_lowercase) for x in range(round(length / 4)))
73-
return secret_key + ''.join(random.choice(string.digits) for x in range(round(length / 4)))
70+
secret_key = ''.join(secrets.choice(string.ascii_uppercase) for x in range(round(length / 4)))
71+
secret_key = secret_key + ''.join(secrets.choice("~!@#$%^&*()_+") for x in range(round(length / 4)))
72+
secret_key = secret_key + ''.join(secrets.choice(string.ascii_lowercase) for x in range(round(length / 4)))
73+
return secret_key + ''.join(secrets.choice(string.digits) for x in range(round(length / 4)))
7474

7575

7676
def get_state_token_secret():

lemur/tests/conf.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
import base64
44
import os
5-
import random
5+
import secrets
66
import string
77

88
_basedir = os.path.abspath(os.path.dirname(__file__))
99

1010

1111
# generate random secrets for unittest
1212
def get_random_secret(length):
13-
secret_key = ''.join(random.choice(string.ascii_uppercase) for x in range(round(length / 4)))
14-
secret_key = secret_key + ''.join(random.choice("~!@#$%^&*()_+") for x in range(round(length / 4)))
15-
secret_key = secret_key + ''.join(random.choice(string.ascii_lowercase) for x in range(round(length / 4)))
16-
return secret_key + ''.join(random.choice(string.digits) for x in range(round(length / 4)))
13+
secret_key = ''.join(secrets.choice(string.ascii_uppercase) for x in range(round(length / 4)))
14+
secret_key = secret_key + ''.join(secrets.choice("~!@#$%^&*()_+") for x in range(round(length / 4)))
15+
secret_key = secret_key + ''.join(secrets.choice(string.ascii_lowercase) for x in range(round(length / 4)))
16+
return secret_key + ''.join(secrets.choice(string.digits) for x in range(round(length / 4)))
1717

1818

1919
THREADS_PER_PAGE = 8
@@ -26,6 +26,10 @@ def get_random_secret(length):
2626

2727
TESTING = True
2828

29+
# All the secrets below must be generated using CRYPTOGRAPHICALLY SECURE RANDOMNESS and kept private
30+
# (ideally they would not be stored directly in this config file).
31+
# See Lemur's documentation for more information on secret management.
32+
2933
# this is the secret key used by flask session management (utf8 encoded)
3034
SECRET_KEY = get_random_secret(length=32).encode('utf8')
3135

0 commit comments

Comments
 (0)