Skip to content

Commit

Permalink
Split domain and port as Django does it
Browse files Browse the repository at this point in the history
  • Loading branch information
amureki committed Jul 28, 2023
1 parent cad0dbe commit 6c120dc
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions emark/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django import http
from django.conf import settings
from django.http.request import validate_host
from django.http.request import split_domain_port, validate_host
from django.views import View
from django.views.generic.detail import SingleObjectMixin

Expand Down Expand Up @@ -49,19 +49,18 @@ def get(self, request, *args, **kwargs):
# or malformed. We use Django's URL validation to ensure that it
# is safe to redirect to.
parsed_url = urlparse(redirect_to)
domain, _port = split_domain_port(parsed_url.netloc)
allowed_hosts = settings.ALLOWED_HOSTS
if settings.DEBUG:
allowed_hosts = settings.ALLOWED_HOSTS + [
".localhost",
".localhost:8000",
"127.0.0.1",
"127.0.0.1:8000",
"[::1]",
]
if any(
[
not parsed_url.netloc,
not validate_host(parsed_url.netloc, allowed_hosts),
not domain,
not validate_host(domain, allowed_hosts),
request.scheme != parsed_url.scheme,
]
):
Expand Down

0 comments on commit 6c120dc

Please sign in to comment.