From 6c7e30083a6bb5b319cbf6f1ac5ff9d76abdc905 Mon Sep 17 00:00:00 2001 From: Yourun-Proger Date: Wed, 16 Mar 2022 18:33:42 +0300 Subject: [PATCH 1/2] Remove deprecation warnings --- docs/arguments.rst | 6 +++++- src/waitress/adjustments.py | 20 +++----------------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/docs/arguments.rst b/docs/arguments.rst index f9b9310f..4045f642 100644 --- a/docs/arguments.rst +++ b/docs/arguments.rst @@ -158,7 +158,11 @@ clear_untrusted_proxy_headers "X-Forwared-For", "X-Forwarded-By", "X-Forwarded-Host", "X-Forwarded-Port", "X-Forwarded-Proto") not explicitly allowed by ``trusted_proxy_headers``. - Default: ``False`` + Default: ``True`` + + .. versionchanged:: 2.1.1 + In this version default value is set to ``True`` and deprecation warning + doesn't show up anymore. .. versionadded:: 1.2.0 diff --git a/src/waitress/adjustments.py b/src/waitress/adjustments.py index 466b5c4a..85689d44 100644 --- a/src/waitress/adjustments.py +++ b/src/waitress/adjustments.py @@ -95,10 +95,6 @@ class _int_marker(int): pass -class _bool_marker: - pass - - class Adjustments: """This class contains tunable parameters.""" @@ -179,10 +175,9 @@ class Adjustments: # sense to set when you have a trusted_proxy, and you expect the upstream # proxy server to filter invalid headers log_untrusted_proxy_headers = False - - # Should waitress clear any proxy headers that are not deemed trusted from - # the environ? Change to True by default in 2.x - clear_untrusted_proxy_headers = _bool_marker + + # Changed this parameter to True by default in 2.x + clear_untrusted_proxy_headers = True # default ``wsgi.url_scheme`` value url_scheme = "http" @@ -445,15 +440,6 @@ def __init__(self, **kw): ) self.trusted_proxy_headers = {"x-forwarded-proto"} - if self.clear_untrusted_proxy_headers is _bool_marker: - warnings.warn( - "In future versions of Waitress clear_untrusted_proxy_headers will be " - "set to True by default. You may opt-out by setting this value to " - "False, or opt-in explicitly by setting this to True.", - DeprecationWarning, - ) - self.clear_untrusted_proxy_headers = False - self.listen = wanted_sockets self.check_sockets(self.sockets) From 131838f6d48f09a76cebd5d943857ed84fe4e87f Mon Sep 17 00:00:00 2001 From: Yourun-Proger Date: Fri, 18 Mar 2022 17:18:37 +0300 Subject: [PATCH 2/2] Small fix --- docs/arguments.rst | 2 +- src/waitress/adjustments.py | 2 +- tests/test_adjustments.py | 14 -------------- 3 files changed, 2 insertions(+), 16 deletions(-) diff --git a/docs/arguments.rst b/docs/arguments.rst index 4045f642..db765e45 100644 --- a/docs/arguments.rst +++ b/docs/arguments.rst @@ -160,7 +160,7 @@ clear_untrusted_proxy_headers Default: ``True`` - .. versionchanged:: 2.1.1 + .. versionchanged:: 2.1.2 In this version default value is set to ``True`` and deprecation warning doesn't show up anymore. diff --git a/src/waitress/adjustments.py b/src/waitress/adjustments.py index 85689d44..6e9b7029 100644 --- a/src/waitress/adjustments.py +++ b/src/waitress/adjustments.py @@ -175,7 +175,7 @@ class Adjustments: # sense to set when you have a trusted_proxy, and you expect the upstream # proxy server to filter invalid headers log_untrusted_proxy_headers = False - + # Changed this parameter to True by default in 2.x clear_untrusted_proxy_headers = True diff --git a/tests/test_adjustments.py b/tests/test_adjustments.py index 69cdf513..cbbb0063 100644 --- a/tests/test_adjustments.py +++ b/tests/test_adjustments.py @@ -354,20 +354,6 @@ def test_no_trusted_proxy_headers_trusted_proxy(self): self.assertTrue(issubclass(w[0].category, DeprecationWarning)) self.assertIn("Implicitly trusting X-Forwarded-Proto", str(w[0])) - def test_clear_untrusted_proxy_headers(self): - with warnings.catch_warnings(record=True) as w: - warnings.resetwarnings() - warnings.simplefilter("always") - self._makeOne( - trusted_proxy="localhost", trusted_proxy_headers={"x-forwarded-for"} - ) - - self.assertGreaterEqual(len(w), 1) - self.assertTrue(issubclass(w[0].category, DeprecationWarning)) - self.assertIn( - "clear_untrusted_proxy_headers will be set to True", str(w[0]) - ) - def test_deprecated_send_bytes(self): with warnings.catch_warnings(record=True) as w: warnings.resetwarnings()