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


##########
superset/commands/security/update.py:
##########
@@ -50,14 +50,19 @@ def validate(self) -> None:
         self._model = RLSDAO.find_by_id(int(self._model_id))
         if not self._model:
             raise RLSRuleNotFoundError()
-        roles = populate_roles(self._roles)
-        tables = (
-            db.session.query(SqlaTable)
-            .filter(SqlaTable.id.in_(self._tables))  # type: 
ignore[attr-defined]
-            .all()
-        )
-        if len(tables) != len(self._tables):
-            raise DatasourceNotFoundValidationError()
-        raise_for_datasource_access(tables)
-        self._properties["roles"] = roles
-        self._properties["tables"] = tables
+        # Only resolve and overwrite the relationships that are actually 
present
+        # in the request body. A partial update (e.g. changing only the name)
+        # must leave the rule's existing tables/roles bindings untouched rather
+        # than replacing them with empty lists.
+        if "roles" in self._properties:
+            self._properties["roles"] = populate_roles(self._roles)
+        if "tables" in self._properties:
+            tables = (
+                db.session.query(SqlaTable)
+                .filter(SqlaTable.id.in_(self._tables))  # type: 
ignore[attr-defined]
+                .all()
+            )
+            if len(tables) != len(self._tables):
+                raise DatasourceNotFoundValidationError()
+            raise_for_datasource_access(tables)
+            self._properties["tables"] = tables

Review Comment:
   **Suggestion:** The datasource access check is now gated behind `"tables" in 
self._properties`, so a partial update that omits `tables` skips authorization 
against the rule's existing table bindings. This lets a caller update sensitive 
fields (like `clause`/`roles`) on an RLS rule tied to datasources they cannot 
access. Keep partial-update behavior, but enforce access on the effective table 
set: use submitted tables when present, otherwise validate against 
`self._model.tables`. [security]
   
   <details>
   <summary><b>Severity Level:</b> Critical 🚨</summary>
   
   ```mdx
   - ❌ PUT /api/v1/rowlevelsecurity/<pk> skips table access check.
   - ❌ Non-authorized users can modify RLS clause/roles bindings.
   - ⚠️ Weakens dataset isolation enforced via row level security.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. The RLS REST API update endpoint `PUT /api/v1/rowlevelsecurity/<pk>` is 
implemented in
   `superset/row_level_security/api.py:181-241` as `RLSRestApi.put`, which 
loads the request
   body with `RLSPutSchema` (`edit_model_schema.load(request.json)` at line 
235) and then
   calls `UpdateRLSRuleCommand(pk, item).run()` at line 240.
   
   2. `RLSPutSchema` in `superset/row_level_security/schemas.py:147-187` 
defines `tables` as
   an optional field (`required=False` at lines 167-172), so a payload like 
`{"clause":
   "1=1"}` is valid and will be passed to `UpdateRLSRuleCommand` without a 
`"tables"` key.
   
   3. `UpdateRLSRuleCommand.validate` in 
`superset/commands/security/update.py:49-68` loads
   the existing rule via `RLSDAO.find_by_id` (lines 50-52) and then only 
performs the
   datasource lookup and access check when `"tables" in self._properties` (line 
59). If
   `"tables"` is absent from the payload, the block at lines 59-68 (including
   `raise_for_datasource_access(tables)` at line 67) is completely skipped, and
   `self._model.tables` is never checked.
   
   4. `raise_for_datasource_access` in 
`superset/commands/security/utils.py:29-42` enforces
   that `security_manager.can_access_datasource(datasource=table)` is True for 
every
   referenced table, otherwise raising `RLSDatasourceForbiddenError`, which 
`RLSRestApi.put`
   would convert into HTTP 403 (handling at 
`superset/row_level_security/api.py:258-264`).
   Because `UpdateRLSRuleCommand.validate` never calls 
`raise_for_datasource_access` when
   `tables` is omitted, a caller who can hit `PUT 
/api/v1/rowlevelsecurity/<pk>` but for whom
   `can_access_datasource` would return False for one or more of 
`self._model.tables` can
   still successfully send a partial update payload without `"tables"` (e.g. 
`{"clause":
   "new_clause", "roles": [...]}`), and the request will return 200 without any 
datasource
   authorization being enforced against the rule's existing table bindings.
   ```
   </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=2242a7bab5de4e1fa2c7b4dcb3166ab5&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=2242a7bab5de4e1fa2c7b4dcb3166ab5&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/security/update.py
   **Line:** 59:68
   **Comment:**
        *Security: The datasource access check is now gated behind `"tables" in 
self._properties`, so a partial update that omits `tables` skips authorization 
against the rule's existing table bindings. This lets a caller update sensitive 
fields (like `clause`/`roles`) on an RLS rule tied to datasources they cannot 
access. Keep partial-update behavior, but enforce access on the effective table 
set: use submitted tables when present, otherwise validate against 
`self._model.tables`.
   
   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%2F41294&comment_hash=efe106dead8f59e4526090ef4af88516a5c13aa7d989034af1ece8d1c67453de&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41294&comment_hash=efe106dead8f59e4526090ef4af88516a5c13aa7d989034af1ece8d1c67453de&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