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


##########
superset/mcp_service/chart/schemas.py:
##########
@@ -2725,6 +2725,35 @@ class ChartFiltersInfo(BaseModel):
     )
 
 
+class RestoreChartRequest(BaseModel):
+    """Request schema for restore_chart."""
+
+    identifier: int | str = Field(
+        ...,
+        description=(
+            "Chart identifier - numeric ID or UUID string (charts have no 
slug)."
+        ),
+    )

Review Comment:
   **Suggestion:** `RestoreChartRequest.identifier` accepts `int | str` but 
does not reject booleans. Since `bool` is a subclass of `int`, a request like 
`{"identifier": true}` can be coerced to chart ID `1` and restore the wrong 
chart. Add the same pre-validation used in delete schemas to explicitly reject 
boolean identifiers. [type error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   ⚠️ MCP restore_chart may restore unintended chart ID.
   ⚠️ LLM agents sending booleans risk mis-targeted restores.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. In `superset/mcp_service/chart/schemas.py` lines 49-57 (verified via 
Read),
   `RestoreChartRequest` defines `identifier: int | str = Field(...)` with no
   `field_validator` rejecting boolean values.
   
   2. In the same file, `DeleteChartRequest` at lines 82-99 defines 
`identifier: int | str`
   and adds `reject_bool_identifier` (`@field_validator("identifier", 
mode="before")`) with a
   docstring explaining that `identifier=true` would coerce to chart ID 1 and 
delete the
   wrong object (lines 95-96), confirming Pydantic’s bool→int coercion behavior.
   
   3. The MCP tool `restore_chart` in 
`superset/mcp_service/chart/tool/restore_chart.py`
   lines 85-107 accepts a `RestoreChartRequest` and calls
   `_find_chart_for_restore(request.identifier)`, passing the validated 
`identifier` field
   directly.
   
   4. `_find_chart_for_restore` in the same file at lines 47-64 calls
   `ChartDAO.find_by_id_or_uuid(str(identifier), skip_base_filter=True,
   skip_visibility_filter=True)`. With a request payload `{"identifier": 
true}`, Pydantic
   coerces `identifier` to integer `1`, `str(1)` becomes `"1"`, and
   `BaseDAO.find_by_id_or_uuid` in `superset/daos/base.py` lines 33-35 treats 
`"1"` as a
   digit, converting it to `int("1")` and looking up chart ID 1. If chart ID 1 
is
   soft-deleted and the caller has editorship, the tool restores that chart 
instead of the
   intended target, demonstrating the bug.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=05433a0089674f5986959b0aaa044eaf&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=05433a0089674f5986959b0aaa044eaf&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/chart/schemas.py
   **Line:** 2731:2736
   **Comment:**
        *Type Error: `RestoreChartRequest.identifier` accepts `int | str` but 
does not reject booleans. Since `bool` is a subclass of `int`, a request like 
`{"identifier": true}` can be coerced to chart ID `1` and restore the wrong 
chart. Add the same pre-validation used in delete schemas to explicitly reject 
boolean identifiers.
   
   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%2F41842&comment_hash=d3f5ff63f7300a0eb2fa3236084f18135b2e710c568d639a5bcdac608b28b754&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41842&comment_hash=d3f5ff63f7300a0eb2fa3236084f18135b2e710c568d639a5bcdac608b28b754&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