codeant-ai-for-open-source[bot] commented on code in PR #40344:
URL: https://github.com/apache/superset/pull/40344#discussion_r3305687874


##########
superset/mcp_service/task/tool/get_task_info.py:
##########
@@ -0,0 +1,108 @@
+# 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.
+
+"""Get task info MCP tool."""
+
+import logging
+from datetime import datetime, timezone
+
+from fastmcp import Context
+from superset_core.mcp.decorators import tool, ToolAnnotations
+
+from superset.extensions import event_logger
+from superset.mcp_service.mcp_core import ModelGetInfoCore
+from superset.mcp_service.task.schemas import (
+    GetTaskInfoRequest,
+    serialize_task_object,
+    TaskError,
+    TaskInfo,
+)
+
+logger = logging.getLogger(__name__)
+
+
+@tool(
+    tags=["discovery"],
+    class_permission_name="Task",
+    annotations=ToolAnnotations(
+        title="Get task info",
+        readOnlyHint=True,
+        destructiveHint=False,
+    ),
+)
+async def get_task_info(
+    request: GetTaskInfoRequest,
+    ctx: Context,
+) -> TaskInfo | TaskError:
+    """Get details for a single async task by ID or UUID.
+
+    Returns task_type, status, scope, and timestamps for the specified task.
+    Non-admin users can only retrieve tasks they are subscribed to.
+
+    Use list_tasks to discover task IDs and UUIDs.
+
+    Example usage:
+    ```json
+    {"identifier": 42}
+    ```
+
+    Or with UUID:
+    ```json
+    {"identifier": "a1b2c3d4-5678-90ab-cdef-1234567890ab"}
+    ```
+    """
+    await ctx.info("Retrieving task: identifier=%s" % (request.identifier,))
+
+    try:
+        from superset.daos.tasks import TaskDAO
+
+        with event_logger.log_context(action="mcp.get_task_info.lookup"):
+            # ModelGetInfoCore handles int ID and UUID string automatically.
+            # TaskDAO.base_filter (TaskFilter) enforces subscription-based 
access.
+            get_tool = ModelGetInfoCore(
+                dao_class=TaskDAO,
+                output_schema=TaskInfo,
+                error_schema=TaskError,
+                serializer=serialize_task_object,
+                supports_slug=False,
+                logger=logger,
+            )
+            result = get_tool.run_tool(request.identifier)
+
+        if isinstance(result, TaskInfo):
+            await ctx.info(
+                "Task retrieved: id=%s, task_type=%s, status=%s"
+                % (result.id, result.task_type, result.status)
+            )
+        else:
+            await ctx.warning(
+                "Task retrieval failed: error_type=%s, error=%s"
+                % (result.error_type, result.error)
+            )
+
+        return result
+
+    except Exception as e:
+        await ctx.error(
+            "Task retrieval failed: identifier=%s, error=%s, error_type=%s"
+            % (request.identifier, str(e), type(e).__name__)
+        )
+        return TaskError(
+            error=f"Failed to get task info: {str(e)}",
+            error_type="InternalError",
+            timestamp=datetime.now(timezone.utc),

Review Comment:
   **Suggestion:** The error response includes the raw exception text in the 
client-facing `error` field, which can leak internal implementation details 
(SQL fragments, stack context, backend identifiers) to untrusted callers. Keep 
detailed exception text only in server logs and return a generic user-safe 
error message in the response. [security]
   
   <details>
   <summary><b>Severity Level:</b> Critical 🚨</summary>
   
   ```mdx
   - ❌ MCP get_task_info tool leaks internal exception messages.
   - ⚠️ Exposed SQL or stack traces aid targeted attacks.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Start the MCP backend, which imports the task tools in
   `superset/mcp_service/app.py:18-21` via `from superset.mcp_service.task.tool 
import
   get_task_info, list_tasks`, registering `get_task_info` as an MCP tool.
   
   2. An MCP client (e.g., an AI agent) invokes the `get_task_info` tool, which 
executes
   `get_task_info()` in `superset/mcp_service/task/tool/get_task_info.py:47-50` 
and enters
   the `try` block at lines 70-99, constructing a `ModelGetInfoCore` with 
`TaskDAO` at lines
   76-83 and calling `get_tool.run_tool(request.identifier)` at line 84.
   
   3. During `get_tool.run_tool()` in 
`superset/mcp_service/mcp_core.py:95-119`, a backend
   failure occurs (for example, a database outage causing SQLAlchemy to raise 
when
   `TaskDAO.find_by_id` is called from `_find_object` at lines 85-93), leading 
to an
   exception being logged via `_log_error` at lines 118-119 and re-raised.
   
   4. The exception propagates back to `get_task_info`, is caught by the 
`except Exception as
   e` block at `superset/mcp_service/task/tool/get_task_info.py:99-104`, and 
the function
   returns `TaskError(error=f"Failed to get task info: {str(e)}", ...)` at 
lines 104-107;
   since `TaskError` is the response schema in 
`superset/mcp_service/task/schemas.py:11-15`,
   the raw `str(e)` (which may include SQL fragments or internal error text) is 
serialized
   into the `error` field and sent back to the MCP client, exposing internal 
implementation
   details.
   ```
   </details>
   
   [Fix in 
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=aab151ce333040559aca797422fd659c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 | [Fix in VSCode 
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=aab151ce333040559aca797422fd659c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/mcp_service/task/tool/get_task_info.py
   **Line:** 104:107
   **Comment:**
        *Security: The error response includes the raw exception text in the 
client-facing `error` field, which can leak internal implementation details 
(SQL fragments, stack context, backend identifiers) to untrusted callers. Keep 
detailed exception text only in server logs and return a generic user-safe 
error message in the response.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40344&comment_hash=1e22d0249f5da8e7db2e7680cd8307b1f5ba929351e895e68e420f8be61e4a4c&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40344&comment_hash=1e22d0249f5da8e7db2e7680cd8307b1f5ba929351e895e68e420f8be61e4a4c&reaction=dislike'>👎</a>



-- 
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