-
Notifications
You must be signed in to change notification settings - Fork 18.2k
fix: add missing ownership checks to tag, report-log, and dataset-schema endpoints #43390
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
Open
rusackas
wants to merge
12
commits into
master
Choose a base branch
from
fix/tag-report-log-dataset-schema-checks
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
599697b
fix(tags): check per-object access before deleting tag associations
6ee4820
fix(tags): require ownership before bulk-deleting tags by name
13af5cc
fix(security): make user-registrations API admin-only and read-only
816b98f
fix(reports): scope execution-log API reads to editable schedules
c91505e
fix(datasets): drop email from drill_info's nested user schema
345d7c3
fix(tags): call self.logout() between user switches in delete-tags test
0dbd0df
docs(tags): trim a test docstring
d0861c3
fix(tags): route single-tag DELETE through DeleteTagsCommand
0ceacde
fix(reports): gate execution-log unrestricted read on can_access_all_…
bf4a781
fix(security): restore DELETE on the user-registrations API
b8ffd8d
fix(datasets): drop secondary_label from drill_info's editors field
9da5553
fix(tags): make DeleteTagsCommand's composited exceptions ValidationE…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,19 +18,22 @@ | |
| from functools import partial | ||
| from typing import Any | ||
|
|
||
| from marshmallow import ValidationError | ||
|
|
||
| from superset import security_manager | ||
| from superset.commands.base import BaseCommand | ||
| from superset.commands.exceptions import TagNotFoundValidationError | ||
| from superset.commands.tag.exceptions import ( | ||
| TagDeleteFailedError, | ||
| TagDeleteForbiddenValidationError, | ||
| TaggedObjectDeleteFailedError, | ||
| TaggedObjectNotFoundError, | ||
| TagInvalidError, | ||
| TagNotFoundError, | ||
| ) | ||
| from superset.commands.tag.utils import to_object_model, to_object_type | ||
| from superset.daos.tag import TagDAO | ||
| from superset.exceptions import SupersetSecurityException | ||
| from superset.tags.models import ObjectType | ||
| from superset.tags.models import ObjectType, TagType | ||
| from superset.utils.decorators import on_error, transaction | ||
| from superset.views.base import DeleteMixin | ||
|
|
||
|
|
@@ -134,10 +137,42 @@ def run(self) -> None: | |
| TagDAO.delete_tags(self._tags) | ||
|
|
||
| def validate(self) -> None: | ||
| exceptions = [] | ||
| # Validate tag exists | ||
| for tag in self._tags: | ||
| if not TagDAO.find_by_name(tag): | ||
| exceptions.append(TagNotFoundError(tag)) | ||
| # Every item appended here must be a ValidationError (or subclass), | ||
| # since TagInvalidError.normalized_messages() calls | ||
| # .normalized_messages() on each one to build the aggregated 422 | ||
| # response. | ||
| exceptions: list[ValidationError] = [] | ||
| for tag_name in self._tags: | ||
| tag_name = tag_name.strip() | ||
| tag = TagDAO.find_by_name(tag_name) | ||
| # Validate tag exists | ||
| if not tag: | ||
| exceptions.append( | ||
| TagNotFoundValidationError(f"Tag with name {tag_name} not found.") | ||
| ) | ||
| continue | ||
| # System-generated tags (type:*, editor:*, favorited_by:*) are | ||
| # maintained by Superset itself and must not be deletable through | ||
| # the bulk route. | ||
| if tag.type is not None and tag.type != TagType.custom: | ||
| exceptions.append( | ||
| TagDeleteForbiddenValidationError( | ||
| f"Tag {tag_name} is a system tag and cannot be deleted" | ||
| ) | ||
| ) | ||
| continue | ||
|
Comment on lines
+154
to
+163
Member
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. Btw, while I was working on the Subject feature, I noticed these system generated tags are apparently not used anywhere(!). So while we're at it, I suggest we consider removing them all together if they're not used at all. |
||
| # Deleting a tag cascades removal of all of its associations | ||
| # org-wide, so existence is not enough: require the user to be an | ||
| # admin or the tag's creator (the single-association route | ||
| # enforces per-object access in DeleteTaggedObjectCommand). | ||
| if not ( | ||
|
rusackas marked this conversation as resolved.
|
||
| security_manager.is_admin() | ||
| or (tag.created_by and tag.created_by == security_manager.current_user) | ||
| ): | ||
| exceptions.append( | ||
| TagDeleteForbiddenValidationError( | ||
| f"Access denied to tag {tag_name}" | ||
| ) | ||
| ) | ||
| if exceptions: | ||
| raise TagInvalidError(exceptions=exceptions) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.