Skip to content

Dependencies are duplicated which could cause auth checks to run twice within the API #4797

@JC-wk

Description

@JC-wk

Describe the bug
Dependencies are duplicated which would cause auth checks to run twice within the API
e.g get_current_tre_user_or_tre_admin in api_app/api/routes/shared_services.py

shared_services_router = APIRouter(dependencies=[Depends(**get_current_tre_user_or_tre_admin**)])
@shared_services_router.get("/shared-services", response_model=SharedServicesInList, name=strings.API_GET_ALL_SHARED_SERVICES, dependencies=[Depends(**get_current_tre_user_or_tre_admin**)])

If you attach the same auth dependency both at the router level (via APIRouter(dependencies=[Depends(auth)])) >and again on the endpoint (either in dependencies=[Depends(auth)] or as a parameter user = Depends(auth)), >FastAPI will execute it twice because each Depends(...) occurrence is evaluated independently; router-level >dependencies are simply added to the route’s dependency list. [fastapi.tiangolo.com]

Azure TRE release version (e.g. v0.14.0 or main):
main

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions