sha174n commented on code in PR #43998:
URL: https://github.com/apache/superset/pull/43998#discussion_r3960605673


##########
superset/mcp_service/sql_lab/tool/execute_sql.py:
##########
@@ -171,6 +175,29 @@ async def execute_sql(request: ExecuteSqlRequest, ctx: 
Context) -> ExecuteSqlRes
                     
error_type=SupersetErrorType.DATABASE_SECURITY_ACCESS_ERROR.value,
                 )
 
+        # 1b. Enforce dataset/table-level access, matching the SQL Lab
+        # execution path (which calls raise_for_access(..., 
force_dataset_match=
+        # True)). Access to the database connection alone does not authorize
+        # every table on it: the query must resolve to datasets the user is
+        # granted, so the tables it references are validated here before it 
runs.
+        with 
event_logger.log_context(action="mcp.execute_sql.table_access_validation"):
+            try:
+                security_manager.raise_for_access(
+                    database=database,
+                    sql=request.sql,
+                    catalog=request.catalog,
+                    schema=request.schema_name,
+                    template_params=request.template_params,
+                    force_dataset_match=True,
+                )

Review Comment:
   Correct, the call was unreachable behind the preceding `can_access_database` 
gate. Fixed in 23087bcc88: that gate is removed and the whole access decision 
now goes through `raise_for_access(..., force_dataset_match=True)`, matching 
`superset/sqllab/validators.py`.



##########
superset/mcp_service/sql_lab/tool/execute_sql.py:
##########
@@ -171,6 +175,29 @@ async def execute_sql(request: ExecuteSqlRequest, ctx: 
Context) -> ExecuteSqlRes
                     
error_type=SupersetErrorType.DATABASE_SECURITY_ACCESS_ERROR.value,
                 )
 
+        # 1b. Enforce dataset/table-level access, matching the SQL Lab
+        # execution path (which calls raise_for_access(..., 
force_dataset_match=
+        # True)). Access to the database connection alone does not authorize
+        # every table on it: the query must resolve to datasets the user is
+        # granted, so the tables it references are validated here before it 
runs.
+        with 
event_logger.log_context(action="mcp.execute_sql.table_access_validation"):
+            try:
+                security_manager.raise_for_access(
+                    database=database,
+                    sql=request.sql,
+                    catalog=request.catalog,
+                    schema=request.schema_name,
+                    template_params=request.template_params,
+                    force_dataset_match=True,
+                )

Review Comment:
   Correct, the call was unreachable behind the preceding `can_access_database` 
gate. Fixed in 23087bcc88: that gate is removed and the whole access decision 
now goes through `raise_for_access(..., force_dataset_match=True)`, matching 
`superset/sqllab/validators.py`.



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