Copilot commented on code in PR #40587:
URL: https://github.com/apache/superset/pull/40587#discussion_r3679083530


##########
superset/tasks/schemas.py:
##########
@@ -119,14 +119,21 @@ def get_payload_dict(self, obj: object) -> dict[str, 
object] | None:
         return obj.payload_dict  # type: ignore[attr-defined]
 
     def get_properties(self, obj: object) -> dict[str, object]:
-        """Get properties dict, filtering stack_trace if SHOW_STACKTRACE is 
disabled."""
+        """Get properties dict, filtering debugging details when 
SHOW_STACKTRACE
+        is disabled."""

Review Comment:
   The updated docstring is split across lines and its first line is 
incomplete, which is inconsistent with the other one-line method docstrings in 
this schema and makes it harder to read in generated docs/tooltips. Consider 
keeping it as a single concise sentence.



##########
superset/tasks/schemas.py:
##########
@@ -119,14 +119,21 @@ def get_payload_dict(self, obj: object) -> dict[str, 
object] | None:
         return obj.payload_dict  # type: ignore[attr-defined]
 
     def get_properties(self, obj: object) -> dict[str, object]:
-        """Get properties dict, filtering stack_trace if SHOW_STACKTRACE is 
disabled."""
+        """Get properties dict, filtering debugging details when 
SHOW_STACKTRACE
+        is disabled."""
         from flask import current_app
 
         properties = dict(obj.properties_dict)  # type: ignore[attr-defined]
 
-        # Remove stack_trace unless SHOW_STACKTRACE is enabled
+        # Remove internal debugging details unless SHOW_STACKTRACE is enabled.
+        # The full traceback and the raw exception class name disclose internal
+        # file paths, library versions, and architecture details (CWE-209), so
+        # they are gated behind the same flag that controls stack traces
+        # elsewhere in Superset. ``error_message`` is left in place as the
+        # consumer-facing failure reason.

Review Comment:
   With exception_type/stack_trace now conditionally removed when 
SHOW_STACKTRACE is disabled, the OpenAPI field description 
(properties_description) earlier in this file is no longer accurate because it 
lists those keys unconditionally. Updating that description to note the 
conditional/debug-only nature would prevent API-doc confusion for clients.



##########
tests/unit_tests/tasks/test_schemas.py:
##########
@@ -0,0 +1,65 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from types import SimpleNamespace
+
+from flask import current_app
+from pytest_mock import MockerFixture
+
+from superset.tasks.schemas import TaskResponseSchema
+
+
+def _task_with_error_properties() -> SimpleNamespace:
+    return SimpleNamespace(
+        properties_dict={
+            "is_abortable": True,
+            "progress_percent": 1.0,
+            "error_message": "boom",
+            "exception_type": "KeyError",
+            "stack_trace": 'Traceback (most recent call last):\n  File 
"/app/x.py"',
+        }
+    )
+
+
+def test_get_properties_hides_debug_fields_by_default(app_context: None) -> 
None:
+    """
+    By default (SHOW_STACKTRACE disabled) the serialized task properties must
+    not disclose the stack trace or the raw exception class name (CWE-209),
+    while still returning consumer-safe fields like error_message.
+    """
+    properties = 
TaskResponseSchema().get_properties(_task_with_error_properties())

Review Comment:
   This test assumes SHOW_STACKTRACE is disabled by default, but the unit test 
app context is shared and other tests may toggle current_app.config without 
reverting, making this order-dependent/flaky. Explicitly set SHOW_STACKTRACE to 
False inside this test for isolation.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to