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


##########
superset/views/datasource/views.py:
##########
@@ -83,13 +83,29 @@ def save(self) -> FlaskResponse:
         orm_datasource = DatasourceDAO.get_datasource(
             DatasourceType(datasource_type), datasource_id
         )
-        orm_datasource.database_id = database_id
 
         try:
             security_manager.raise_for_editorship(orm_datasource)
         except SupersetSecurityException as ex:
             raise DatasetForbiddenError() from ex
 
+        if database_id != orm_datasource.database_id:
+            new_database = DatasetDAO.get_database_by_id(database_id)
+            if new_database is None:
+                return json_error_response(_("Database not found."), 
status=422)
+            try:
+                security_manager.raise_for_access(
+                    database=new_database,
+                    table=Table(
+                        orm_datasource.table_name,
+                        orm_datasource.schema,
+                        orm_datasource.catalog,
+                    ),
+                )

Review Comment:
   **Suggestion:** Authorization is evaluated against the existing dataset 
target (`orm_datasource.table_name`, `schema`, and `catalog`), but 
`update_from_object` later applies the request's `table_name`, `schema`, and 
`catalog`. An editor can therefore obtain access to the old table while 
repointing the dataset to an unauthorized table on the new database. Build the 
`Table` from the requested datasource values before calling `raise_for_access`. 
[security]
   
   <details>
   <summary><b>Severity Level:</b> Critical 🚨</summary>
   
   ```mdx
   - ❌ Dataset repointing can bind unauthorized physical tables.
   - ❌ Explore queries may expose data from the unauthorized target.
   - ⚠️ Legacy `/datasource/save/` authorization is incomplete.
   ```
   </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=2d1455d1e32e4baaa4e5537b41ee4fd4&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=2d1455d1e32e4baaa4e5537b41ee4fd4&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/views/datasource/views.py
   **Line:** 97:104
   **Comment:**
        *Security: Authorization is evaluated against the existing dataset 
target (`orm_datasource.table_name`, `schema`, and `catalog`), but 
`update_from_object` later applies the request's `table_name`, `schema`, and 
`catalog`. An editor can therefore obtain access to the old table while 
repointing the dataset to an unauthorized table on the new database. Build the 
`Table` from the requested datasource values before calling `raise_for_access`.
   
   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%2F42936&comment_hash=1f280163fe8918f0aa4e4d8091905902fa307243aec69a11b779670d2b462e06&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42936&comment_hash=1f280163fe8918f0aa4e4d8091905902fa307243aec69a11b779670d2b462e06&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