mirror of
https://github.com/umap-project/umap.git
synced 2025-04-29 11:52:38 +02:00
chore: more logs in the ajax proxy validate url (#2362)
This should only be used in localhost, but there are a bunch of check and it's often that we need to add print to understand why the URL does not validate, which is usually an issue with the SITE_URL or this kind. So let's make those print permanent.
This commit is contained in:
commit
30b685ae43
1 changed files with 14 additions and 13 deletions
|
@ -452,27 +452,27 @@ showcase = MapsShowCase.as_view()
|
||||||
|
|
||||||
|
|
||||||
def validate_url(request):
|
def validate_url(request):
|
||||||
assert request.method == "GET"
|
assert request.method == "GET", "Wrong HTTP method"
|
||||||
url = request.GET.get("url")
|
url = request.GET.get("url")
|
||||||
assert url
|
assert url, "Missing URL"
|
||||||
try:
|
try:
|
||||||
URLValidator(url)
|
URLValidator(url)
|
||||||
except ValidationError:
|
except ValidationError as err:
|
||||||
raise AssertionError()
|
raise AssertionError(err)
|
||||||
assert "HTTP_REFERER" in request.META
|
assert "HTTP_REFERER" in request.META, "Missing HTTP_REFERER"
|
||||||
referer = urlparse(request.META.get("HTTP_REFERER"))
|
referer = urlparse(request.META.get("HTTP_REFERER"))
|
||||||
toproxy = urlparse(url)
|
toproxy = urlparse(url)
|
||||||
local = urlparse(settings.SITE_URL)
|
local = urlparse(settings.SITE_URL)
|
||||||
assert toproxy.hostname
|
assert toproxy.hostname, "No hostname"
|
||||||
assert referer.hostname == local.hostname
|
assert referer.hostname == local.hostname, f"{referer.hostname} != {local.hostname}"
|
||||||
assert toproxy.hostname != "localhost"
|
assert toproxy.hostname != "localhost", "Invalid localhost target"
|
||||||
assert toproxy.netloc != local.netloc
|
assert toproxy.netloc != local.netloc, "Invalid netloc"
|
||||||
try:
|
try:
|
||||||
# clean this when in python 3.4
|
# clean this when in python 3.4
|
||||||
ipaddress = socket.gethostbyname(toproxy.hostname)
|
ipaddress = socket.gethostbyname(toproxy.hostname)
|
||||||
except:
|
except Exception as err:
|
||||||
raise AssertionError()
|
raise AssertionError(err)
|
||||||
assert not PRIVATE_IP.match(ipaddress)
|
assert not PRIVATE_IP.match(ipaddress), "Private IP"
|
||||||
return url
|
return url
|
||||||
|
|
||||||
|
|
||||||
|
@ -480,7 +480,8 @@ class AjaxProxy(View):
|
||||||
def get(self, *args, **kwargs):
|
def get(self, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
url = validate_url(self.request)
|
url = validate_url(self.request)
|
||||||
except AssertionError:
|
except AssertionError as err:
|
||||||
|
print(f"AjaxProxy: {err}")
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
try:
|
try:
|
||||||
ttl = int(self.request.GET.get("ttl"))
|
ttl = int(self.request.GET.get("ttl"))
|
||||||
|
|
Loading…
Reference in a new issue