-
Notifications
You must be signed in to change notification settings - Fork 18.1k
fix(rls): return a descriptive error for duplicate rule names #42819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
6986be6
0cd4559
57bd8ae
3480d95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,9 +15,27 @@ | |
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| from typing import Optional | ||
|
|
||
| from superset.connectors.sqla.models import RowLevelSecurityFilter | ||
| from superset.daos.base import BaseDAO | ||
| from superset.extensions import db | ||
|
|
||
|
|
||
| class RLSDAO(BaseDAO[RowLevelSecurityFilter]): | ||
| pass | ||
| @classmethod | ||
| def validate_uniqueness(cls, name: str, rule_id: Optional[int] = None) -> bool: | ||
| """ | ||
| Validate that the RLS rule name is unique. | ||
|
|
||
| :param name: RLS rule name | ||
| :param rule_id: id of the rule being updated, excluded from the check so | ||
| that saving a rule without renaming it is not treated as a collision | ||
| :return: True if the name is unique, False otherwise | ||
| """ | ||
| query = db.session.query(RowLevelSecurityFilter).filter( | ||
| RowLevelSecurityFilter.name == name | ||
| ) | ||
| if rule_id is not None: | ||
| query = query.filter(RowLevelSecurityFilter.id != rule_id) | ||
| return not db.session.query(query.exists()).scalar() | ||
|
Comment on lines
+36
to
+41
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: The existence query is only a preflight check and is not atomic with the subsequent insert or update. Two concurrent requests can both observe the name as available, after which one write still raises the database unique-constraint error and the API returns the generic opaque SQLAlchemy message instead of the promised descriptive field error. Catch the unique-constraint violation and translate it to the same validation response, while retaining the database constraint as the authoritative guard. [race condition] Severity Level: Minor 🧹- ⚠️ Concurrent RLS creation can return opaque `422` errors.
- ⚠️ Concurrent renames can lose the descriptive validation message.
- ❌ No duplicate database rows are created due to the constraint.(Use Cmd/Ctrl + Click for best experience) Prompt for AI Agent 🤖This is a comment left during a code review.
**Path:** superset/daos/security.py
**Line:** 36:41
**Comment:**
*Race Condition: The existence query is only a preflight check and is not atomic with the subsequent insert or update. Two concurrent requests can both observe the name as available, after which one write still raises the database unique-constraint error and the API returns the generic opaque SQLAlchemy message instead of the promised descriptive field error. Catch the unique-constraint violation and translate it to the same validation response, while retaining the database constraint as the authoritative guard.
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 |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: The duplicate-name check runs before datasource existence and access validation, so a caller who can invoke RLS creation but lacks access to the submitted datasource receives a duplicate-name response for an existing name and a forbidden response for a nonexistent name. This exposes global rule-name existence and changes the expected authorization response; perform datasource authorization before revealing whether the name is already used. The update command has the same ordering issue. [security]
Severity Level: Minor 🧹
(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖