Cryptography

PySecrets

The secrets module provides cryptographically strong random values suitable for managing authentication tokens. Use secrets instead of the random module for session IDs, tokens, and CSRF nonces.

5 sanitizers

Sanitizers

.token_bytes()Sanitizer
#
Signature
secrets.token_bytes(nbytes: int | None = None) -> bytes

Cryptographically secure random bytes. Safe source for tokens.

tracks:return
.token_hex()Sanitizer
#
Signature
secrets.token_hex(nbytes: int | None = None) -> str

Hex-encoded secure random token. Safe.

tracks:return
.token_urlsafe()Sanitizer
#
Signature
secrets.token_urlsafe(nbytes: int | None = None) -> str

URL-safe base64 secure random token. Safe.

tracks:return
.compare_digest()Sanitizer
#
Signature
secrets.compare_digest(a, b) -> bool

Constant-time comparison. Sanitizer for secret comparison.

tracks:return
.choice()Sanitizer
#
Signature
secrets.choice(seq)

Cryptographically secure random choice from a non-empty sequence.

tracks:return

Fully-Qualified Names

FQNField
secretsfqns[0]

Wrong FQN → 0 findings. Verify with: change fqns to garbage → must produce 0 results.

Import

rule.py
from codepathfinder.go_rule import PySecrets