Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add authentication args length check #1335

Merged
merged 5 commits into from
Nov 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions starlette/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
LarsStegman marked this conversation as resolved.
Show resolved Hide resolved
assert isinstance(websocket, WebSocket)

if not has_required_scope(websocket, scopes_list):
Expand All @@ -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):
Expand All @@ -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):
Expand Down