Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
change `User-Agent` header for webhooks to `Saleor/version`
Artur Pietrachac38263743e9e
diff --git a/poetry.lock b/poetry.lockindex 9a6389e30d..5c76f353b7 100644--- a/poetry.lock+++ b/poetry.lock@@ -2676,16 +2676,6 @@ files = [{file = "MarkupSafe-2.1.3-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:5bbe06f8eeafd38e5d0a4894ffec89378b6c6a625ff57e3028921f8ff59318ac"},{file = "MarkupSafe-2.1.3-cp311-cp311-win32.whl", hash = "sha256:dd15ff04ffd7e05ffcb7fe79f1b98041b8ea30ae9234aed2a9168b5797c3effb"},{file = "MarkupSafe-2.1.3-cp311-cp311-win_amd64.whl", hash = "sha256:134da1eca9ec0ae528110ccc9e48041e0828d79f24121a1a146161103c76e686"},- {file = "MarkupSafe-2.1.3-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:f698de3fd0c4e6972b92290a45bd9b1536bffe8c6759c62471efaa8acb4c37bc"},- {file = "MarkupSafe-2.1.3-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:aa57bd9cf8ae831a362185ee444e15a93ecb2e344c8e52e4d721ea3ab6ef1823"},- {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ffcc3f7c66b5f5b7931a5aa68fc9cecc51e685ef90282f4a82f0f5e9b704ad11"},- {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:47d4f1c5f80fc62fdd7777d0d40a2e9dda0a05883ab11374334f6c4de38adffd"},- {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1f67c7038d560d92149c060157d623c542173016c4babc0c1913cca0564b9939"},- {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:9aad3c1755095ce347e26488214ef77e0485a3c34a50c5a5e2471dff60b9dd9c"},- {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:14ff806850827afd6b07a5f32bd917fb7f45b046ba40c57abdb636674a8b559c"},- {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8f9293864fe09b8149f0cc42ce56e3f0e54de883a9de90cd427f191c346eb2e1"},- {file = "MarkupSafe-2.1.3-cp312-cp312-win32.whl", hash = "sha256:715d3562f79d540f251b99ebd6d8baa547118974341db04f5ad06d5ea3eb8007"},- {file = "MarkupSafe-2.1.3-cp312-cp312-win_amd64.whl", hash = "sha256:1b8dd8c3fd14349433c79fa8abeb573a55fc0fdd769133baac1f5e07abf54aeb"},{file = "MarkupSafe-2.1.3-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:8e254ae696c88d98da6555f5ace2279cf7cd5b3f52be2b5cf97feafe883b58d2"},{file = "MarkupSafe-2.1.3-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:cb0932dc158471523c9637e807d9bfb93e06a95cbf010f1a38b98623b929ef2b"},{file = "MarkupSafe-2.1.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9402b03f1a1b4dc4c19845e5c749e3ab82d5078d16a2a4c2cd2df62d57bb0707"},@@ -4040,12 +4030,12 @@ use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"][[package]]name = "requests-hardened"-version = "1.0.0b0"-description = "A library that overrides the default behaviors of the ``requests`` library, and adds new security features."+version = "1.0.0b2"+description = "A library that overrides the default behaviors of the requests library, and adds new security features."optional = falsepython-versions = ">=3.8"files = [- {file = "requests-hardened-1.0.0b0.tar.gz", hash = "sha256:7c8934bb3918235ecaba14f7890d678fe556584c154a1ab511838897649e10c9"},+ {file = "requests-hardened-1.0.0b2.tar.gz", hash = "sha256:28c5591f1f346f4b1a014d97cb0e1addb852bcdcfb5c129b6ca5443587c32c73"},][package.dependencies]@@ -5443,4 +5433,4 @@ test = ["pytest"][metadata]lock-version = "2.0"python-versions = "~3.9"-content-hash = "579d0db66413639fd47a906d2127855db3fd4d8433cc9fc1c280f7db824b5b73"+content-hash = "d6d6d8304e67c4eaaf6d00ea66b8325171317a397915253648995e4dfe4e25ab"diff --git a/pyproject.toml b/pyproject.tomlindex 8539967cd5..fdb6a3ef6b 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -71,7 +71,7 @@ documentation = "https://docs.saleor.io/"Authlib = "^1.0.0"pillow-avif-plugin = "^1.3.1"semantic-version = "^2.10.0"- requests-hardened = "1.0.0b0"+ requests-hardened = "1.0.0b2"[tool.poetry.dependencies.celery]version = ">=4.4.5,<6.0.0"diff --git a/requirements.txt b/requirements.txtindex fb3f0cb425..9d16f668fe 100644--- a/requirements.txt+++ b/requirements.txt@@ -128,7 +128,7 @@ pyxb==1.2.5 ; python_version >= "3.9" and python_version < "3.10"pyyaml==6.0.1 ; python_version >= "3.9" and python_version < "3.10"razorpay==1.4.1 ; python_version >= "3.9" and python_version < "3.10"redis==4.6.0 ; python_version >= "3.9" and python_version < "3.10"-requests-hardened==1.0.0b0 ; python_version >= "3.9" and python_version < "3.10"+requests-hardened==1.0.0b2 ; python_version >= "3.9" and python_version < "3.10"requests==2.31.0 ; python_version >= "3.9" and python_version < "3.10"rsa==4.9 ; python_version >= "3.9" and python_version < "3.10"rx==1.6.3 ; python_version >= "3.9" and python_version < "3.10"diff --git a/requirements_dev.txt b/requirements_dev.txtindex be72bdafb7..234836d068 100644--- a/requirements_dev.txt+++ b/requirements_dev.txt@@ -196,7 +196,7 @@ pyyaml==6.0.1 ; python_version >= "3.9" and python_version < "3.10"razorpay==1.4.1 ; python_version >= "3.9" and python_version < "3.10"redis==4.6.0 ; python_version >= "3.9" and python_version < "3.10"referencing==0.30.2 ; python_version >= "3.9" and python_version < "3.10"-requests-hardened==1.0.0b0 ; python_version >= "3.9" and python_version < "3.10"+requests-hardened==1.0.0b2 ; python_version >= "3.9" and python_version < "3.10"requests==2.31.0 ; python_version >= "3.9" and python_version < "3.10"rich==13.6.0 ; python_version >= "3.9" and python_version < "3.10"rpds-py==0.10.3 ; python_version >= "3.9" and python_version < "3.10"diff --git a/saleor/__init__.py b/saleor/__init__.pyindex 90b70f63a1..dc1f375d64 100644--- a/saleor/__init__.py+++ b/saleor/__init__.py@@ -22,3 +22,4 @@ class PatchedSubscriberExecutionContext(object):_major, _minor, _ = __version__.split(".", 2)schema_version = f"{_major}.{_minor}"+user_agent_version = f"Saleor/{schema_version}"diff --git a/saleor/app/installation_utils.py b/saleor/app/installation_utils.pyindex 3375bc9a5d..2c945c4a9f 100644--- a/saleor/app/installation_utils.py+++ b/saleor/app/installation_utils.py@@ -261,7 +261,9 @@ def install_app(app_installation: AppInstallation, activate: bool = False):)WebhookEvent.objects.bulk_create(webhook_events)- _, token = app.tokens.create(name="Default token") # type: ignore[call-arg] # calling create on a related manager # noqa: E501+ _, token = app.tokens.create(+ name="Default token"+ ) # type: ignore[call-arg] # calling create on a related manager # noqa: E501try:send_app_token(target_url=manifest_data.get("tokenTargetUrl"), token=token)diff --git a/saleor/core/http_client.py b/saleor/core/http_client.pyindex b1c7a3e3cb..a58b8b871c 100644--- a/saleor/core/http_client.py+++ b/saleor/core/http_client.py@@ -1,11 +1,14 @@import requests_hardenedfrom django.conf import settings+from .. import user_agent_version+HTTPConfig = requests_hardened.Config(ip_filter_enable=settings.HTTP_IP_FILTER_ENABLED,- ip_filter_allow_localhost=settings.HTTP_IP_FILTER_ALLOW_LOOPBACK_IPS,- never_allow_redirects=True,+ ip_filter_allow_loopback_ips=settings.HTTP_IP_FILTER_ALLOW_LOOPBACK_IPS,+ never_redirect=True,default_timeout=settings.COMMON_REQUESTS_TIMEOUT,+ user_agent_override=user_agent_version,)HTTPClient = requests_hardened.Manager(HTTPConfig)diff --git a/saleor/core/tests/test_http_client.py b/saleor/core/tests/test_http_client.pynew file mode 100644index 0000000000..a18e830db4--- /dev/null+++ b/saleor/core/tests/test_http_client.py@@ -0,0 +1,27 @@+import requests_hardened+from django.conf import settings+from requests import Request++from ... 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,+)+++def test_user_agent_override():+ # given+ request = Request("GET", "http://www.example.com")+ session = requests_hardened.HTTPSession(HTTPConfig)++ assert request.headers.get("User-Agent") is None++ # when+ session.prepare_request(request)++ # then+ assert request.headers.get("User-Agent") == user_agent_versiondiff --git a/saleor/payment/gateways/adyen/utils/apple_pay.py b/saleor/payment/gateways/adyen/utils/apple_pay.pyindex 66fc666fb6..e7bbed3ed8 100644--- a/saleor/payment/gateways/adyen/utils/apple_pay.py+++ b/saleor/payment/gateways/adyen/utils/apple_pay.py@@ -112,7 +112,7 @@ def make_request_to_initialize_apple_pay(def initialize_apple_pay(payment_data: dict, certificate: str) -> dict:- # The apple pay on the web requires additional step+ # The Apple Pay on the web requires additional stepvalidation_url = payment_data.get("validationUrl", "")merchant_identifier = payment_data.get("merchantIdentifier", "")domain = payment_data.get("domain", "")