Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
deps: upgrade requests-hardened to latest version (#17132)
Mikail5fe1e784620f
diff --git a/poetry.lock b/poetry.lockindex 6b6bc48967..aaedf45d22 100644--- a/poetry.lock+++ b/poetry.lock@@ -3947,19 +3947,16 @@ use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"][[package]]name = "requests-hardened"-version = "1.0.0b4"+version = "1.0.0b5"description = "A library that overrides the default behaviors of the requests library, and adds new security features."optional = false-python-versions = ">=3.8"+python-versions = "<4.0,>=3.8"files = [- {file = "requests_hardened-1.0.0b4.tar.gz", hash = "sha256:1fc29dbae273a61980d015f1948404374ee1f7b0f9e464a564af12b9d0c5ebde"},+ {file = "requests_hardened-1.0.0b5.tar.gz", hash = "sha256:98736b46f7793605da5b8b53ecacdb00fbc3b3c099f0e1730701b6f40fca7cd9"},][package.dependencies]-requests = ">=2.0.1,<3.0.0"--[package.extras]-dev = ["mypy (>=1.5.1,<1.6.0)", "pytest (>=7.4.0,<7.5.0)", "trustme (>=1.1.0,<2.0.0)", "types-requests (>=2.0.1,<3.0.0)"]+requests = ">=2.32.3,<3.0.0"[[package]]name = "rich"@@ -5276,4 +5273,4 @@ type = ["pytest-mypy"][metadata]lock-version = "2.0"python-versions = "~3.12"-content-hash = "47e9c755b3c5841c7739a1d4423e942b7f0edce19674cacef97bdfa5a6b1f1f8"+content-hash = "61f9ae26ba57510dd32a6f924df553a8efc400b76575d692f3996711827e0645"diff --git a/pyproject.toml b/pyproject.tomlindex f79cebcbae..3d5bae2871 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -73,7 +73,7 @@ package-mode = falserazorpay = "^1.2"redis = "^5.0.1"requests = "^2.32"- requests-hardened = "1.0.0b4"+ requests-hardened = "1.0.0b5"Rx = "^1.6.3"semantic-version = "^2.10.0"sendgrid = "^6.7.1"@@ -131,7 +131,7 @@ package-mode = falsetypes-setuptools = "^74.1.0.20240907"types-python-dateutil = "^2.8.19"types-redis = "^4.6.0"- types-requests = "^2.31.0"+ types-requests = "^2.31.0" # Cannot upgrade due to using an old version of urllib3 (https://github.com/saleor/saleor/issues/17130)types-six = "^1.16.17"vcrpy = ">=4.0,<7.0"diff --git a/saleor/core/tests/cassettes/test_http_client/test_http_client_disallows_private_ip_ranges[http].yaml b/saleor/core/tests/cassettes/test_http_client/test_http_client_disallows_private_ip_ranges[http].yamlnew file mode 100644index 0000000000..d4955631a0--- /dev/null+++ b/saleor/core/tests/cassettes/test_http_client/test_http_client_disallows_private_ip_ranges[http].yaml@@ -0,0 +1,62 @@+interactions:+- request:+ body: null+ headers:+ Accept:+ - '*/*'+ Accept-Encoding:+ - gzip, deflate, br+ Connection:+ - keep-alive+ Host:+ - example.com+ User-Agent:+ - Saleor/3.21+ method: GET+ uri: http://93.184.215.14/+ response:+ body:+ string: !!binary |+ H4sIAMIVqF0AA31UTXPbIBC9+1ds1UsyIyQnaRqPLWn6mWkPaQ9pDz0SsbKYCFAByfZ08t+7Qo4j+ N5makYFdeLvvsZC9Eqb0uxah9qopZtljh1wUM6Bf5qVvsPi85aptED4ZxaXO0tE6G5co9BzKmluH+ Po86X7FFBGkxcdbetwx/d7LPo49Ge9SeDWEjKMdZHnnc+nQIvzpAvYSkucI86iVuWmP9ZP9GCl/n+ AntZIguTGKSWXvKGuZI3mJ89QTm/IzJDBvvApXPR6LszYgd/wjBMeXm/tqbTgpWmMXYJr6s5tfPV+ YYnidi31EuZPppYLIfX6yFZRpqziSja7JTDekpzM7ZxHFcPYs07G8KGR+v6Gl7fBdE2bYohucW0Q+ fn6NaPy9RQ23XLth8gWbHr0sOXzDDslyMMTw3hJ3wqalzKGV1VMuYfAQ/oXsJ3SDcEt4O5+32+cM+ L1EB77x5geg5qtV/RRPUJhncGSvQMsuF7BzplFweAZgtczUXZkPI7RYu6Luibxjb9R0/mcehJfPz+ 09WEDF8O6sXU99JJj2JC7TGTi8WbxWKSyXD+TGBpLPfSEEttNE5B3ykUksOJ4lu21+dq0Od0An6s+ 4lFV/KPYROVjx8MkZJaGCi3CWWXpeB1n2VCbdDsp2L6O67NnN5NMo68tftTSgQh2oFFlLHQOYZg1+ Tef8QLhHwBHBDQ56DjpF98kl8Mt0RGIXtnhCGqtlj6ahIXkJoLNIdHxtOg+tlRSiNHS0Ugcxgebc+ 3VOFhOgtWiWdI0eSpe0hz4weCItVHg3PhFum6WazSSTXPDF2nY4hXbpPMypujB1IEKAKQZKE0HgR+ ELM0iJOle6nS8UH7CyjrfG/oBAAA+ headers:+ Accept-Ranges:+ - bytes+ Age:+ - '458251'+ Cache-Control:+ - max-age=604800+ Content-Encoding:+ - gzip+ Content-Length:+ - '648'+ Content-Type:+ - text/html; charset=UTF-8+ Date:+ - Tue, 03 Dec 2024 09:52:20 GMT+ Etag:+ - '"3147526947"'+ Expires:+ - Tue, 10 Dec 2024 09:52:20 GMT+ Last-Modified:+ - Thu, 17 Oct 2019 07:18:26 GMT+ Server:+ - ECAcc (nyd/D188)+ Vary:+ - Accept-Encoding+ X-Cache:+ - HIT+ status:+ code: 200+ message: OK+version: 1diff --git a/saleor/core/tests/cassettes/test_http_client/test_http_client_disallows_private_ip_ranges[https].yaml b/saleor/core/tests/cassettes/test_http_client/test_http_client_disallows_private_ip_ranges[https].yamlnew file mode 100644index 0000000000..bd86664e4b--- /dev/null+++ b/saleor/core/tests/cassettes/test_http_client/test_http_client_disallows_private_ip_ranges[https].yaml@@ -0,0 +1,62 @@+interactions:+- request:+ body: null+ headers:+ Accept:+ - '*/*'+ Accept-Encoding:+ - gzip, deflate, br+ Connection:+ - keep-alive+ Host:+ - example.com+ User-Agent:+ - Saleor/3.21+ method: GET+ uri: https://93.184.215.14/+ response:+ body:+ string: !!binary |+ H4sIAMIVqF0AA31UTXPbIBC9+1ds1UsyIyQnaRqPLWn6mWkPaQ9pDz0SsbKYCFAByfZ08t+7Qo4j+ N5makYFdeLvvsZC9Eqb0uxah9qopZtljh1wUM6Bf5qVvsPi85aptED4ZxaXO0tE6G5co9BzKmluH+ Po86X7FFBGkxcdbetwx/d7LPo49Ge9SeDWEjKMdZHnnc+nQIvzpAvYSkucI86iVuWmP9ZP9GCl/n+ AntZIguTGKSWXvKGuZI3mJ89QTm/IzJDBvvApXPR6LszYgd/wjBMeXm/tqbTgpWmMXYJr6s5tfPV+ YYnidi31EuZPppYLIfX6yFZRpqziSja7JTDekpzM7ZxHFcPYs07G8KGR+v6Gl7fBdE2bYohucW0Q+ fn6NaPy9RQ23XLth8gWbHr0sOXzDDslyMMTw3hJ3wqalzKGV1VMuYfAQ/oXsJ3SDcEt4O5+32+cM+ L1EB77x5geg5qtV/RRPUJhncGSvQMsuF7BzplFweAZgtczUXZkPI7RYu6Luibxjb9R0/mcehJfPz+ 09WEDF8O6sXU99JJj2JC7TGTi8WbxWKSyXD+TGBpLPfSEEttNE5B3ykUksOJ4lu21+dq0Od0An6s+ 4lFV/KPYROVjx8MkZJaGCi3CWWXpeB1n2VCbdDsp2L6O67NnN5NMo68tftTSgQh2oFFlLHQOYZg1+ Tef8QLhHwBHBDQ56DjpF98kl8Mt0RGIXtnhCGqtlj6ahIXkJoLNIdHxtOg+tlRSiNHS0Ugcxgebc+ 3VOFhOgtWiWdI0eSpe0hz4weCItVHg3PhFum6WazSSTXPDF2nY4hXbpPMypujB1IEKAKQZKE0HgR+ ELM0iJOle6nS8UH7CyjrfG/oBAAA+ headers:+ Accept-Ranges:+ - bytes+ Age:+ - '400176'+ Cache-Control:+ - max-age=604800+ Content-Encoding:+ - gzip+ Content-Length:+ - '648'+ Content-Type:+ - text/html; charset=UTF-8+ Date:+ - Tue, 03 Dec 2024 09:52:42 GMT+ Etag:+ - '"3147526947+gzip"'+ Expires:+ - Tue, 10 Dec 2024 09:52:42 GMT+ Last-Modified:+ - Thu, 17 Oct 2019 07:18:26 GMT+ Server:+ - ECAcc (nyd/D120)+ Vary:+ - Accept-Encoding+ X-Cache:+ - HIT+ status:+ code: 200+ message: OK+version: 1diff --git a/saleor/core/tests/test_http_client.py b/saleor/core/tests/test_http_client.pyindex a18e830db4..2cce2a6b0d 100644--- a/saleor/core/tests/test_http_client.py+++ b/saleor/core/tests/test_http_client.py@@ -1,16 +1,10 @@+import pytestimport requests_hardened-from django.conf import settingsfrom requests import Request+from requests_hardened.ip_filter import InvalidIPAddressfrom ... import user_agent_version--HTTPConfig = requests_hardened.Config(- ip_filter_enable=settings.HTTP_IP_FILTER_ENABLED,- ip_filter_allow_loopback_ips=settings.HTTP_IP_FILTER_ALLOW_LOOPBACK_IPS,- never_redirect=True,- default_timeout=(2, 10),- user_agent_override=user_agent_version,-)+from ..http_client import HTTPClient, HTTPConfigdef test_user_agent_override():@@ -25,3 +19,26 @@ def test_user_agent_override():# thenassert request.headers.get("User-Agent") == user_agent_version++[email protected]("protocol", ["https", "http"])+def test_http_client_disallows_private_ip_ranges(protocol):+ """Ensure requests made to private IP address ranges leads to an error to be raised.++ This test ensures that the requests-hardened library works correctly,+ especially when using untested 'requests' and 'urllib3' versions+ that may potentially be unsupported by this library.+ """++ # Enable IP filtering (disabled by default in tests)+ http_manager = HTTPClient.clone()+ http_manager.config.ip_filter_enable = True # Block private ranges.++ # Should reject the IP address (expect error to be raised)+ with pytest.raises(InvalidIPAddress, match="10.0.0.1"):+ http_manager.send_request("GET", f"{protocol}://10.0.0.1", timeout=0.1)++ # Should not reject public IP ranges (sanity check).+ response = http_manager.send_request("GET", f"{protocol}://example.com")+ assert response.status_code == 200