report: Split hostname from port more carefully.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2020-06-26 18:05:47 -07:00 committed by Tim Abbott
parent 51b8b1f879
commit d6ecb67d75
2 changed files with 4 additions and 2 deletions

View File

@ -5,6 +5,7 @@ import platform
import subprocess
import traceback
from typing import Any, Dict, Optional
from urllib.parse import SplitResult
from django.conf import settings
from django.http import HttpRequest
@ -60,7 +61,7 @@ def add_request_metadata(report: Dict[str, Any], request: HttpRequest) -> None:
report['data'] = {}
try:
report['host'] = request.get_host().split(':')[0]
report['host'] = SplitResult("", request.get_host(), "", "", "").hostname
except Exception:
# request.get_host() will throw a DisallowedHost
# exception if the host is invalid

View File

@ -2,6 +2,7 @@
import logging
import subprocess
from typing import Any, Dict, Mapping, Optional
from urllib.parse import SplitResult
from django.conf import settings
from django.http import HttpRequest, HttpResponse
@ -127,7 +128,7 @@ def report_error(request: HttpRequest, user_profile: UserProfile, message: str=R
queue_json_publish('error_reports', dict(
type = "browser",
report = dict(
host = request.get_host().split(":")[0],
host = SplitResult("", request.get_host(), "", "", "").hostname,
ip_address = remote_ip,
user_email = email,
user_full_name = full_name,