codeant-ai-for-open-source[bot] commented on code in PR #41133:
URL: https://github.com/apache/superset/pull/41133#discussion_r3509714337
##########
superset/dashboards/api.py:
##########
@@ -103,6 +104,8 @@
DashboardColorsConfigUpdateSchema,
DashboardCopySchema,
DashboardDatasetSchema,
+ DashboardExportXlsxPostSchema,
Review Comment:
**Suggestion:** Using `request.get_json(silent=True) or {}` causes malformed
JSON bodies to be silently treated as an empty payload, so invalid client
requests are accepted and exports run with missing filter state instead of
returning a 400. Parse non-empty JSON strictly (or explicitly detect JSON parse
failure) so malformed payloads fail validation. [api mismatch]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
⚠️ Malformed JSON requests accepted as empty filter payload.
⚠️ Excel export ignores intended filters on bad clients.
⚠️ API clients receive 202 instead of validation error.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Call the endpoint `POST /api/v1/dashboard/<pk>/export_xlsx/` implemented
in
`superset/dashboards/api.py:49-138` with header `Content-Type:
application/json` and a
malformed JSON body, for example the string `{"active_data_mask":`
(unterminated object).
2. In `export_xlsx`, the code at lines 105-107 executes
`DashboardExportXlsxPostSchema().load(request.get_json(silent=True) or {})`;
Flask’s
`request.get_json(silent=True)` fails to parse the malformed body and
returns `None`
instead of raising an error.
3. The `or {}` coalesces this `None` into `{}`, so
`DashboardExportXlsxPostSchema().load({})` succeeds, yielding a payload where
`active_data_mask` is the schema’s default empty dict, and no
`ValidationError` is raised
to trigger `response_400`.
4. The handler then enqueues `export_dashboard_excel.apply_async` with
`active_data_mask`
`{}` at `superset/dashboards/api.py:128-137`, returning HTTP 202 and running
the export
without any client-supplied filter state, so a structurally invalid JSON
request is
treated as a successful export with missing filters rather than being
rejected with a 400
error.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=c699ea23a57e474f90bb5edb070d0a49&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=c699ea23a57e474f90bb5edb070d0a49&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/dashboards/api.py
**Line:** 105:107
**Comment:**
*Api Mismatch: Using `request.get_json(silent=True) or {}` causes
malformed JSON bodies to be silently treated as an empty payload, so invalid
client requests are accepted and exports run with missing filter state instead
of returning a 400. Parse non-empty JSON strictly (or explicitly detect JSON
parse failure) so malformed payloads fail validation.
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%2F41133&comment_hash=a0475da6325ac6611d6e3ddfd60138ef02d96445ea9c2ca92e1e86fab0a7ce78&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41133&comment_hash=a0475da6325ac6611d6e3ddfd60138ef02d96445ea9c2ca92e1e86fab0a7ce78&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]