fix(fastapi): use secrets module to generate random strings

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-12-03 15:13:41 -08:00
parent 81f8c23265
commit b0b5e4c9d1
No known key found for this signature in database
GPG key ID: F7E46DED420788F3

View file

@ -1,7 +1,6 @@
import base64 import base64
import copy import copy
import math import math
import random
import re import re
import secrets import secrets
import string import string
@ -25,9 +24,9 @@ from aurweb import defaults, logging
logger = logging.get_logger(__name__) logger = logging.get_logger(__name__)
def make_random_string(length): def make_random_string(length: int) -> str:
return ''.join(random.choices(string.ascii_lowercase alphanumerics = string.ascii_lowercase + string.digits
+ string.digits, k=length)) return ''.join([secrets.choice(alphanumerics) for i in range(length)])
def make_nonce(length: int = 8): def make_nonce(length: int = 8):