Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
python: Convert deprecated Django is_safe_url.
Anders Kaseorgdcdb00a5e67a
diff --git a/zerver/lib/thumbnail.py b/zerver/lib/thumbnail.pyindex 7704dda9706..02304f12a4c 100644--- a/zerver/lib/thumbnail.py+++ b/zerver/lib/thumbnail.py@@ -6,7 +6,7 @@ import urllibfrom urllib.parse import urljoinfrom django.conf import settings-from django.utils.http import is_safe_url+from django.utils.http import url_has_allowed_host_and_schemefrom libthumbor import CryptoURLZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))@@ -21,7 +21,9 @@ def is_thumbor_enabled() -> bool:def user_uploads_or_external(url: str) -> bool:- return not is_safe_url(url, allowed_hosts=None) or url.startswith("/user_uploads/")+ return not url_has_allowed_host_and_scheme(url, allowed_hosts=None) or url.startswith(+ "/user_uploads/"+ )def get_source_type(url: str) -> str:@@ -38,11 +40,13 @@ def generate_thumbnail_url(path: str, size: str = "0x0", is_camo_url: bool = Falpath = urljoin("/", path)if not is_thumbor_enabled():- if is_safe_url(path, allowed_hosts=None):+ if url_has_allowed_host_and_scheme(path, allowed_hosts=None):return pathreturn get_camo_url(path)- if is_safe_url(path, allowed_hosts=None) and not path.startswith("/user_uploads/"):+ if url_has_allowed_host_and_scheme(path, allowed_hosts=None) and not path.startswith(+ "/user_uploads/"+ ):return pathsource_type = get_source_type(path)diff --git a/zerver/views/auth.py b/zerver/views/auth.pyindex 1ef5e0fc0b5..5713979548c 100644--- a/zerver/views/auth.py+++ b/zerver/views/auth.py@@ -16,7 +16,7 @@ from django.http import HttpRequest, HttpResponse, HttpResponseRedirect, HttpResfrom django.shortcuts import redirect, renderfrom django.template.response import SimpleTemplateResponsefrom django.urls import reverse-from django.utils.http import is_safe_url+from django.utils.http import url_has_allowed_host_and_schemefrom django.utils.translation import gettext as _from django.views.decorators.csrf import csrf_exemptfrom django.views.decorators.http import require_safe@@ -79,7 +79,7 @@ ExtraContext = Optional[Dict[str, Any]]def get_safe_redirect_to(url: str, redirect_host: str) -> str:- is_url_safe = is_safe_url(url=url, allowed_hosts=None)+ is_url_safe = url_has_allowed_host_and_scheme(url=url, allowed_hosts=None)if is_url_safe:# Mark as safe to prevent Pysa from surfacing false positives for# open redirects. In this branch, we have already checked that the URL