Skip to content

Commit

Permalink
Add additional validation checks
Browse files Browse the repository at this point in the history
These additional checks aren't necessary in theory (and we do already have tests covering these edge cases), but I think they still make sense to make them explicit and to be more resilient against potential future changes.
  • Loading branch information
tillprochaska committed Jan 20, 2025
1 parent 0382b3c commit 326ff1b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions aleph/model/role.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
from datetime import datetime, timezone
from normality import stringify
from sqlalchemy import or_, not_, func
from sqlalchemy import and_, or_, not_, func
from itsdangerous import URLSafeTimedSerializer
from werkzeug.security import generate_password_hash, check_password_hash

Expand Down Expand Up @@ -197,13 +197,18 @@ def by_email(cls, email):

@classmethod
def by_api_key(cls, api_key):
if api_key is None:
if api_key is None or not len(api_key.strip()):
return None

q = cls.all()

digest = hash_api_key(api_key)
q = q.filter(cls.api_key_digest == digest)
q = q.filter(
and_(
cls.api_key_digest != None, # noqa: E711
cls.api_key_digest == digest,
)
)

utcnow = datetime.now(timezone.utc)
# TODO: Exclude API keys without expiration date after deadline
Expand Down

0 comments on commit 326ff1b

Please sign in to comment.