Zum Inhalt springen

Weak randomness (ARCH2115)

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Key python.security.weak-random · Severity warning · Category security · CWE CWE-338

The random module is predictable and must not be used for security-sensitive values like tokens, keys, salts, or session ids. Use the secrets module.

import random
import string
def make_token():
return "".join(random.choice(string.ascii_letters) for _ in range(32))
import secrets
def make_token():
return secrets.token_urlsafe(32)

Use a cryptographic PRNG such as secrets or os.urandom for security-sensitive values.