Skip to content

Commit 5f01591

Browse files
committed
fix: use django redirect function
1 parent 543a991 commit 5f01591

1 file changed

Lines changed: 3 additions & 11 deletions

File tree

custom_auth/views.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from django.contrib.auth import authenticate, login, views
55
from django.core.exceptions import SuspiciousOperation
66
from django.http import HttpResponse, HttpResponseForbidden, HttpResponseRedirect
7-
from django.shortcuts import render
7+
from django.shortcuts import redirect, render
88
from django.urls import reverse
99
from django.utils.decorators import method_decorator
1010
from django.utils.http import url_has_allowed_host_and_scheme
@@ -47,16 +47,8 @@ def email_token_login(request: HttpRequest) -> HttpResponse:
4747

4848
if res is not None:
4949
login(request, res)
50-
next_url = request.POST.get("next", None)
51-
# Validate the next URL to prevent open redirects
52-
if next_url and url_has_allowed_host_and_scheme(
53-
url=next_url,
54-
allowed_hosts={request.get_host()},
55-
require_https=request.is_secure(),
56-
):
57-
return HttpResponseRedirect(next_url)
58-
else:
59-
return HttpResponseRedirect(settings.LOGIN_REDIRECT_URL)
50+
next_url = request.POST.get("next", settings.LOGIN_REDIRECT_URL)
51+
return redirect(next_url)
6052
else:
6153
return render(request, "auth/token_login.html", context={"error": True})
6254

0 commit comments

Comments
 (0)