Skip to content

Commit

Permalink
utils: use SystemRandom when generating random password. (#204)
Browse files Browse the repository at this point in the history
As noticed by Seth Arnold, non-deterministic SystemRandom should be
used when creating security sensitive random strings.
  • Loading branch information
xnox committed Feb 18, 2020
1 parent c90932f commit 3e2f735
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cloudinit/util.py
Expand Up @@ -397,9 +397,10 @@ def translate_bool(val, addons=None):


def rand_str(strlen=32, select_from=None):
r = random.SystemRandom()
if not select_from:
select_from = string.ascii_letters + string.digits
return "".join([random.choice(select_from) for _x in range(0, strlen)])
return "".join([r.choice(select_from) for _x in range(0, strlen)])


def rand_dict_key(dictionary, postfix=None):
Expand Down

0 comments on commit 3e2f735

Please sign in to comment.