From 649161cec52608850b3e4960f2d7692a152aba80 Mon Sep 17 00:00:00 2001 From: Lars Stegman Date: Mon, 15 Nov 2021 22:54:03 +0100 Subject: [PATCH] Add authentication requires args length check (#1335) * Add authentication requires args length check * Update authentication.py Fix linting * Remove unneeded check * Fix lifting * Fix linting Co-authored-by: Lars Stegman --- starlette/authentication.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/starlette/authentication.py b/starlette/authentication.py index 44a9847fc..b4882070d 100644 --- a/starlette/authentication.py +++ b/starlette/authentication.py @@ -40,7 +40,9 @@ def decorator(func: typing.Callable) -> typing.Callable: async def websocket_wrapper( *args: typing.Any, **kwargs: typing.Any ) -> None: - websocket = kwargs.get("websocket", args[idx] if args else None) + websocket = kwargs.get( + "websocket", args[idx] if idx < len(args) else None + ) assert isinstance(websocket, WebSocket) if not has_required_scope(websocket, scopes_list): @@ -56,7 +58,7 @@ async def websocket_wrapper( async def async_wrapper( *args: typing.Any, **kwargs: typing.Any ) -> Response: - request = kwargs.get("request", args[idx] if args else None) + request = kwargs.get("request", args[idx] if idx < len(args) else None) assert isinstance(request, Request) if not has_required_scope(request, scopes_list): @@ -73,7 +75,7 @@ async def async_wrapper( # Handle sync request/response functions. @functools.wraps(func) def sync_wrapper(*args: typing.Any, **kwargs: typing.Any) -> Response: - request = kwargs.get("request", args[idx] if args else None) + request = kwargs.get("request", args[idx] if idx < len(args) else None) assert isinstance(request, Request) if not has_required_scope(request, scopes_list):