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


##########
superset/commands/chart/update.py:
##########
@@ -87,14 +87,20 @@ def _validate_new_dashboard_access(
         requested_dashboard_ids = {d.id for d in requested_dashboards}
 
         if new_dashboard_ids := requested_dashboard_ids - 
existing_dashboard_ids:
-            # For NEW dashboard relationships, verify user has ownership
+            # For NEW dashboard relationships, verify user has access first
+            # to avoid leaking information about inaccessible dashboards
             accessible_dashboards = 
DashboardDAO.find_by_ids(list(new_dashboard_ids))
             unauthorized_dashboard_ids = new_dashboard_ids - {
                 d.id for d in accessible_dashboards
             }
 
             if unauthorized_dashboard_ids:
                 exceptions.append(DashboardsNotFoundValidationError())
+                return
+
+            for dash in accessible_dashboards:
+                if dash.is_managed_externally or not 
security_manager.is_owner(dash):
+                    raise DashboardsForbiddenError()

Review Comment:
   **Suggestion:** The new ownership check is duplicated: 
`security_manager.is_owner` is now evaluated in this newly added loop and then 
evaluated again in the existing "Additional ownership check" loop immediately 
below. This adds redundant permission checks on every new dashboard assignment 
and can cause unnecessary extra security/DB work. Keep ownership validation in 
only one place (for example, leave this loop to enforce `is_managed_externally` 
and rely on the existing ownership loop). [performance]
   
   <details>
   <summary><b>Severity Level:</b> Minor ๐Ÿงน</summary>
   
   ```mdx
   - โš ๏ธ Chart update with new dashboards repeats ownership checks.
   - โš ๏ธ Extra security_manager.is_owner calls add unnecessary overhead.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction โœ… </b></summary>
   
   ```mdx
   1. Trigger a chart update via the REST API `PUT /api/v1/chart/<pk>` 
(implemented in
   `superset/charts/api.py:110-144` in `ChartRestApi`, with the PUT handler 
calling
   `UpdateChartCommand(pk, item).run()` at `superset/charts/api.py:438-442`).
   
   2. Include a `dashboards` field in the payload with at least one new 
dashboard ID not
   currently related to the chart so that `dashboard_ids` is non-None and 
contains new IDs
   when `UpdateChartCommand.validate()` runs 
(`superset/commands/chart/update.py:110-183`).
   
   3. Inside `validate()`, the code fetches the dashboards via 
`DashboardDAO.find_by_ids(...,
   skip_base_filter=True)` and then calls 
`_validate_new_dashboard_access(dashboards,
   exceptions)` at `superset/commands/chart/update.py:171-182` whenever there 
are requested
   dashboards.
   
   4. In `_validate_new_dashboard_access()` 
(`superset/commands/chart/update.py:76-108`),
   when `new_dashboard_ids` is non-empty it builds `accessible_dashboards` and 
then executes
   two consecutive loops: first at lines `101-103` checking 
`dash.is_managed_externally or
   not security_manager.is_owner(dash)` and raising `DashboardsForbiddenError`, 
and then at
   lines `105-108` checking `not security_manager.is_owner(dash)` again and 
raising the same
   error, causing `security_manager.is_owner(dash)` to be evaluated twice per 
new accessible
   dashboard without changing behavior, only adding redundant permission work.
   ```
   </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=137bfcec9c3548d8b0ce675a73ed2e95&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=137bfcec9c3548d8b0ce675a73ed2e95&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/commands/chart/update.py
   **Line:** 101:103
   **Comment:**
        *Performance: The new ownership check is duplicated: 
`security_manager.is_owner` is now evaluated in this newly added loop and then 
evaluated again in the existing "Additional ownership check" loop immediately 
below. This adds redundant permission checks on every new dashboard assignment 
and can cause unnecessary extra security/DB work. Keep ownership validation in 
only one place (for example, leave this loop to enforce `is_managed_externally` 
and rely on the existing ownership loop).
   
   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%2F38584&comment_hash=dd3ae423b6d87b16b2eea874242126d9856915459d993f91c3ddcac6c5567260&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38584&comment_hash=dd3ae423b6d87b16b2eea874242126d9856915459d993f91c3ddcac6c5567260&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