Harden security controls from REPORT findings
This commit is contained in:
@@ -59,13 +59,21 @@ def get_request_role(
|
||||
credentials: Annotated[HTTPAuthorizationCredentials | None, Depends(bearer_auth)],
|
||||
settings: Annotated[Settings, Depends(get_settings)],
|
||||
) -> str:
|
||||
"""Authenticates request token and returns its authorization role."""
|
||||
"""Authenticates request token and returns its authorization role.
|
||||
|
||||
Development environments can optionally allow tokenless user access for non-admin routes to
|
||||
preserve local workflow compatibility while production remains token-enforced.
|
||||
"""
|
||||
|
||||
if credentials is None:
|
||||
if settings.allow_development_anonymous_user_access and settings.app_env.strip().lower() in {"development", "dev"}:
|
||||
return AuthRole.USER
|
||||
_raise_unauthorized()
|
||||
|
||||
token = credentials.credentials.strip()
|
||||
if not token:
|
||||
if settings.allow_development_anonymous_user_access and settings.app_env.strip().lower() in {"development", "dev"}:
|
||||
return AuthRole.USER
|
||||
_raise_unauthorized()
|
||||
return _resolve_token_role(token=token, settings=settings)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user