Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Fix CVE-2026-48744

Mikail Kocak580b93b6e0fa
diff --git a/saleor/graphql/channel/tests/mutations/test_channel_update.py b/saleor/graphql/channel/tests/mutations/test_channel_update.py
index eebeb231fa..fdcd47fb67 100644
--- a/saleor/graphql/channel/tests/mutations/test_channel_update.py
+++ b/saleor/graphql/channel/tests/mutations/test_channel_update.py
@@ -171,6 +171,9 @@ def test_channel_update_mutation_as_app(
def test_channel_update_mutation_as_customer(user_api_client, channel_USD):
+ old_name = channel_USD.name
+ old_slug = channel_USD.slug
+
# given
channel_id = graphene.Node.to_global_id("Channel", channel_USD.id)
name = "newName"
@@ -187,8 +190,16 @@ def test_channel_update_mutation_as_customer(user_api_client, channel_USD):
# then
assert_no_permission(response)
+ # Shouldn't have updated
+ channel_USD.refresh_from_db(fields=("slug", "name"))
+ assert channel_USD.name == old_name
+ assert channel_USD.slug == old_slug
+
def test_channel_update_mutation_as_anonymous(api_client, channel_USD):
+ old_name = channel_USD.name
+ old_slug = channel_USD.slug
+
# given
channel_id = graphene.Node.to_global_id("Channel", channel_USD.id)
name = "newName"
@@ -205,6 +216,79 @@ def test_channel_update_mutation_as_anonymous(api_client, channel_USD):
# then
assert_no_permission(response)
+ # Shouldn't have updated
+ channel_USD.refresh_from_db(fields=("slug", "name"))
+ assert channel_USD.name == old_name
+ assert channel_USD.slug == old_slug
+
+
+ ("gql_field", "python_field", "new_value"),
+ [
+ (
+ "automaticallyConfirmAllNewOrders",
+ "automatically_confirm_all_new_orders",
+ False,
+ ),
+ (
+ "automaticallyFulfillNonShippableGiftCard",
+ "automatically_fulfill_non_shippable_gift_card",
+ False,
+ ),
+ ("allowUnpaidOrders", "allow_unpaid_orders", True),
+ ("expireOrdersAfter", "expire_orders_after", 1),
+ ("deleteExpiredOrdersAfter", "delete_expired_orders_after", 1),
+ ("markAsPaidStrategy", "order_mark_as_paid_strategy", "TRANSACTION_FLOW"),
+ (
+ "includeDraftOrderInVoucherUsage",
+ "include_draft_order_in_voucher_usage",
+ True,
+ ),
+ ("draftOrderLinePriceFreezePeriod", "draft_order_line_price_freeze_period", 1),
+ (
+ "useLegacyLineDiscountPropagation",
+ "use_legacy_line_discount_propagation_for_order",
+ False,
+ ),
+ ],
+)
+def test_channel_update_order_settings_anonymous_is_denied(
+ api_client,
+ channel_USD,
+ gql_field,
+ python_field,
+ new_value,
+):
+ """Anonymous user shouldn't be able to edit order settings."""
+
+ old_value = getattr(channel_USD, python_field)
+ assert new_value != old_value
+
+ # given
+ channel_id = graphene.Node.to_global_id("Channel", channel_USD.id)
+ variables = {
+ "id": channel_id,
+ "input": {
+ "orderSettings": {
+ gql_field: new_value,
+ },
+ },
+ }
+
+ # when
+ response = api_client.post_graphql(
+ CHANNEL_UPDATE_MUTATION,
+ variables=variables,
+ )
+
+ # then
+ assert_no_permission(response)
+
+ channel_USD.refresh_from_db(fields=(python_field,))
+ assert getattr(channel_USD, python_field) == old_value, (
+ "shouldn't have changed the value"
+ )
+
def test_channel_update_mutation_slugify_slug_field(
permission_manage_channels, staff_api_client, channel_USD
@@ -1023,6 +1107,17 @@ def test_channel_update_order_settings_manage_orders_permission_denied(
staff_api_client,
channel_USD,
):
+ old_name = channel_USD.name
+
+ channel_USD.automatically_confirm_all_new_orders = True
+ channel_USD.automatically_fulfill_non_shippable_gift_card = True
+ channel_USD.save(
+ update_fields=(
+ "automatically_confirm_all_new_orders",
+ "automatically_fulfill_non_shippable_gift_card",
+ )
+ )
+
# given
channel_id = graphene.Node.to_global_id("Channel", channel_USD.id)
variables = {
@@ -1046,12 +1141,35 @@ def test_channel_update_order_settings_manage_orders_permission_denied(
# then
assert_no_permission(response)
+ # Shouldn't have changed the values
+ channel_USD.refresh_from_db(
+ fields=(
+ "name",
+ "automatically_confirm_all_new_orders",
+ "automatically_fulfill_non_shippable_gift_card",
+ )
+ )
+ assert channel_USD.name == old_name
+ assert channel_USD.automatically_confirm_all_new_orders is True
+ assert channel_USD.automatically_fulfill_non_shippable_gift_card is True
+
def test_channel_update_order_settings_manage_orders_as_app_permission_denied(
permission_manage_orders,
app_api_client,
channel_USD,
):
+ old_name = channel_USD.name
+
+ channel_USD.automatically_confirm_all_new_orders = True
+ channel_USD.automatically_fulfill_non_shippable_gift_card = True
+ channel_USD.save(
+ update_fields=(
+ "automatically_confirm_all_new_orders",
+ "automatically_fulfill_non_shippable_gift_card",
+ )
+ )
+
# given
channel_id = graphene.Node.to_global_id("Channel", channel_USD.id)
variables = {
@@ -1075,6 +1193,18 @@ def test_channel_update_order_settings_manage_orders_as_app_permission_denied(
# then
assert_no_permission(response)
+ # Shouldn't have changed the values
+ channel_USD.refresh_from_db(
+ fields=(
+ "name",
+ "automatically_confirm_all_new_orders",
+ "automatically_fulfill_non_shippable_gift_card",
+ )
+ )
+ assert channel_USD.name == old_name
+ assert channel_USD.automatically_confirm_all_new_orders is True
+ assert channel_USD.automatically_fulfill_non_shippable_gift_card is True
+
def test_channel_update_order_mark_as_paid_strategy(
permission_manage_orders,
@@ -2003,6 +2133,15 @@ def test_channel_update_channel_settings_with_checkout_permission(
def test_channel_update_channel_settings_without_permission(
staff_api_client, channel_USD
):
+ channel_USD.use_legacy_error_flow_for_checkout = True
+ channel_USD.automatically_complete_fully_paid_checkouts = False
+ channel_USD.save(
+ update_fields=(
+ "use_legacy_error_flow_for_checkout",
+ "automatically_complete_fully_paid_checkouts",
+ )
+ )
+
# given
channel_id = graphene.Node.to_global_id("Channel", channel_USD.id)
variables = {
@@ -2024,10 +2163,29 @@ def test_channel_update_channel_settings_without_permission(
# then
assert_no_permission(response)
+ # Shouldn't have changed
+ channel_USD.refresh_from_db(
+ fields=(
+ "use_legacy_error_flow_for_checkout",
+ "automatically_complete_fully_paid_checkouts",
+ )
+ )
+ assert channel_USD.use_legacy_error_flow_for_checkout is True
+ assert channel_USD.automatically_complete_fully_paid_checkouts is False
+
def test_channel_update_order_settings_with_manage_orders(
staff_api_client, channel_USD, permission_manage_orders
):
+ channel_USD.use_legacy_error_flow_for_checkout = True
+ channel_USD.automatically_complete_fully_paid_checkouts = False
+ channel_USD.save(
+ update_fields=(
+ "use_legacy_error_flow_for_checkout",
+ "automatically_complete_fully_paid_checkouts",
+ )
+ )
+
# given
channel_id = graphene.Node.to_global_id("Channel", channel_USD.id)
variables = {
@@ -2048,10 +2206,29 @@ def test_channel_update_order_settings_with_manage_orders(
# then
assert_no_permission(response)
+ # Shouldn't have changed
+ channel_USD.refresh_from_db(
+ fields=(
+ "use_legacy_error_flow_for_checkout",
+ "automatically_complete_fully_paid_checkouts",
+ )
+ )
+ assert channel_USD.use_legacy_error_flow_for_checkout is True
+ assert channel_USD.automatically_complete_fully_paid_checkouts is False
+
def test_channel_update_order_and_checkout_settings_with_manage_checkouts(
staff_api_client, channel_USD, permission_manage_checkouts
):
+ channel_USD.use_legacy_error_flow_for_checkout = True
+ channel_USD.automatically_complete_fully_paid_checkouts = False
+ channel_USD.save(
+ update_fields=(
+ "use_legacy_error_flow_for_checkout",
+ "automatically_complete_fully_paid_checkouts",
+ )
+ )
+
# given
channel_id = graphene.Node.to_global_id("Channel", channel_USD.id)
variables = {
@@ -2072,6 +2249,16 @@ def test_channel_update_order_and_checkout_settings_with_manage_checkouts(
# then
assert_no_permission(response)
+ # Shouldn't have changed
+ channel_USD.refresh_from_db(
+ fields=(
+ "use_legacy_error_flow_for_checkout",
+ "automatically_complete_fully_paid_checkouts",
+ )
+ )
+ assert channel_USD.use_legacy_error_flow_for_checkout is True
+ assert channel_USD.automatically_complete_fully_paid_checkouts is False
+
def test_channel_update_with_order_and_checkout_settings(
staff_api_client, channel_USD, permission_manage_checkouts, permission_manage_orders
diff --git a/saleor/permission/tests/test_one_of_permissions_or_auth_filter_required.py b/saleor/permission/tests/test_one_of_permissions_or_auth_filter_required.py
index bb9d9fdb36..a836d86f0c 100644
--- a/saleor/permission/tests/test_one_of_permissions_or_auth_filter_required.py
+++ b/saleor/permission/tests/test_one_of_permissions_or_auth_filter_required.py
@@ -286,3 +286,30 @@ def test_permissions_for_customer(permissions, expected_result, customer_user):
# then
assert result is expected_result
+
+
+ "permissions",
+ [
+ # one permission
+ [CheckoutPermissions.MANAGE_CHECKOUTS],
+ # multiple permissions
+ [
+ CheckoutPermissions.MANAGE_CHECKOUTS,
+ AuthorizationFilters.AUTHENTICATED_USER,
+ ],
+ ],
+)
+def test_permissions_for_anonymous_user(permissions):
+ """An anonymous user shouldn't be flagged as having the permission."""
+
+ # given
+ context = Mock()
+ context.app = None
+ context.user = None
+
+ # when
+ result = all_permissions_required(context, permissions)
+
+ # then
+ assert result is False
diff --git a/saleor/permission/utils.py b/saleor/permission/utils.py
index 776e3cae99..f8b7e89463 100644
--- a/saleor/permission/utils.py
+++ b/saleor/permission/utils.py
@@ -56,10 +56,11 @@ def _get_result_of_permissions_checks(
requestor = get_user_or_app_from_context(context)
- perm_checks_results = []
- if requestor and permissions:
- perm_checks_results = [requestor.has_perm(perm) for perm in permissions]
- return perm_checks_results
+ if not permissions:
+ return []
+ if not requestor:
+ return [False]
+ return [requestor.has_perm(perm) for perm in permissions]
def _get_result_of_authorization_filters_checks(