Skip to content

Commit bfd023c

Browse files
committed
Fixes netbox-community#16702: Fix validation of return_url query parameter
1 parent f4ac23d commit bfd023c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

netbox/utilities/views.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from django.core.exceptions import ImproperlyConfigured
55
from django.urls import reverse
66
from django.urls.exceptions import NoReverseMatch
7+
from django.utils.http import url_has_allowed_host_and_scheme
78
from django.utils.translation import gettext_lazy as _
89

910
from netbox.plugins import PluginConfig
@@ -123,7 +124,7 @@ def get_return_url(self, request, obj=None):
123124
# First, see if `return_url` was specified as a query parameter or form data. Use this URL only if it's
124125
# considered safe.
125126
return_url = request.GET.get('return_url') or request.POST.get('return_url')
126-
if return_url and return_url.startswith('/'):
127+
if return_url and url_has_allowed_host_and_scheme(return_url, allowed_hosts=None):
127128
return return_url
128129

129130
# Next, check if the object being modified (if any) has an absolute URL.

0 commit comments

Comments
 (0)