From bef9ef10bb0ecaa98c0a6c95a529ca5a22312fa3 Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Tue, 18 Jun 2024 15:22:17 -0400 Subject: [PATCH] Rename delete * Include a bit of context into the name of the delete function. The HTTP_ added prepended string may be unexpected if Django's header transformation isn't top of mind. --- awx/api/generics.py | 4 ++-- awx/main/utils/proxy.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/awx/api/generics.py b/awx/api/generics.py index 024b33b79d..e17d8b7a06 100644 --- a/awx/api/generics.py +++ b/awx/api/generics.py @@ -44,7 +44,7 @@ from awx.main.models.rbac import give_creator_permissions from awx.main.access import optimize_queryset from awx.main.utils import camelcase_to_underscore, get_search_fields, getattrd, get_object_or_400, decrypt_field, get_awx_version from awx.main.utils.licensing import server_product_name -from awx.main.utils.proxy import is_proxy_in_headers, delete_headers +from awx.main.utils.proxy import is_proxy_in_headers, delete_headers_starting_with_http from awx.main.views import ApiErrorView from awx.api.serializers import ResourceAccessListElementSerializer, CopySerializer from awx.api.versioning import URLPathVersioning @@ -171,7 +171,7 @@ class APIView(views.APIView): # they respect the allowed proxy list if settings.PROXY_IP_ALLOWED_LIST: if not is_proxy_in_headers(self.request, settings.PROXY_IP_ALLOWED_LIST, remote_headers): - delete_headers(request, settings.REMOTE_HOST_HEADERS) + delete_headers_starting_with_http(request, settings.REMOTE_HOST_HEADERS) drf_request = super(APIView, self).initialize_request(request, *args, **kwargs) request.drf_request = drf_request diff --git a/awx/main/utils/proxy.py b/awx/main/utils/proxy.py index 1f96455ed0..e60155bf42 100644 --- a/awx/main/utils/proxy.py +++ b/awx/main/utils/proxy.py @@ -24,7 +24,7 @@ def is_proxy_in_headers(request: Request, proxy_list: list[str], headers: list[s return bool(remote_hosts.intersection(set(proxy_list))) -def delete_headers(request: Request, headers: list[str]): +def delete_headers_starting_with_http(request: Request, headers: list[str]): for header in headers: if header.startswith('HTTP_'): request.environ.pop(header, None)