Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

report: Split hostname from port more carefully.

Anders Kaseorgd6ecb67d7557
diff --git a/zerver/logging_handlers.py b/zerver/logging_handlers.py
index f5261f16ba5..7c22968821f 100644
--- a/zerver/logging_handlers.py
+++ b/zerver/logging_handlers.py
@@ -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
diff --git a/zerver/views/report.py b/zerver/views/report.py
index 4fc05cc0d0d..c408cf9c456 100644
--- a/zerver/views/report.py
+++ b/zerver/views/report.py
@@ -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,