Skip to content

Commit

Permalink
Added note on max password size
Browse files Browse the repository at this point in the history
  • Loading branch information
dotsdl committed Nov 19, 2024
1 parent 37095e6 commit d86eac5
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions alchemiscale/security/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@

from .models import CredentialedEntity, Token, TokenData

MAX_PASSWORD_SIZE = 4096

# we set a max size to avoid denial-of-service attacks
# since an extremely large secret attempted by an attacker can take
# increasing amounts of time or memory to validate;
# this is deliberately higher than any reasonable key length
# this is the same max size that `passlib` defaults to
MAX_SECRET_SIZE = 4096


class BcryptPasswordHandler(object):
Expand Down Expand Up @@ -59,9 +65,9 @@ def validate_secret(secret):
"""ensure secret has correct type & size"""
if not isinstance(secret, (str, bytes)):
raise TypeError("secret must be a string or bytes")
if len(secret) > MAX_PASSWORD_SIZE:
if len(secret) > MAX_SECRET_SIZE:
raise ValueError(
f"secret is too long, maximum length is {MAX_PASSWORD_SIZE} characters"
f"secret is too long, maximum length is {MAX_SECRET_SIZE} characters"
)


Expand Down

0 comments on commit d86eac5

Please sign in to comment.