Repository navigation
fix(keys): Unsafe dict access in get_native_filters_params() crashes execution #38272
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
Changes from all commits
06c1f43
69ccc69
27e10a7
7173436
39e1fa2
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 |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| # under the License. | ||
| """A collection of ORM sqlalchemy models for Superset""" | ||
|
|
||
| import logging | ||
| from typing import Any, Optional | ||
|
|
||
| import prison | ||
|
|
@@ -47,6 +48,8 @@ | |
| from superset.utils.backports import StrEnum | ||
| from superset.utils.core import MediumText | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| metadata = Model.metadata # pylint: disable=no-member | ||
|
|
||
|
|
||
|
|
@@ -187,24 +190,46 @@ def __repr__(self) -> str: | |
| def crontab_humanized(self) -> str: | ||
| return get_description(self.crontab) | ||
|
|
||
| def get_native_filters_params(self) -> str: | ||
| def get_native_filters_params(self) -> tuple[str, list[str]]: | ||
| """ | ||
| Generate native filter params for dashboard URL. | ||
|
|
||
| Returns: | ||
| A tuple of (rison_encoded_params, list_of_warning_messages). | ||
| Warnings are returned so they can be surfaced to users in the | ||
| execution log. | ||
| """ | ||
| params: dict[str, Any] = {} | ||
| warnings: list[str] = [] | ||
| dashboard = self.extra.get("dashboard") | ||
| if dashboard and dashboard.get("nativeFilters"): | ||
| for filter in dashboard.get("nativeFilters") or []: # type: ignore | ||
| native_filters = dashboard.get("nativeFilters") or [] | ||
| for native_filter in native_filters: # type: ignore | ||
| native_filter_id = native_filter.get("nativeFilterId") | ||
| filter_type = native_filter.get("filterType") | ||
|
|
||
| if native_filter_id is None or filter_type is None: | ||
| warning_msg = ( | ||
| f"Skipping malformed native filter missing required " | ||
| f"fields: {native_filter}" | ||
| ) | ||
| warnings.append(warning_msg) | ||
| logger.warning(warning_msg) | ||
| continue | ||
|
Comment on lines
+211
to
+218
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. Missing required fields sounds like an error. Are we sure we want to skip these?
Contributor
Author
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. This was the requirement, waiting back on feedback to make sure we are aligned on the scope |
||
|
|
||
| params = { | ||
| **params, | ||
| **self._generate_native_filter( | ||
| filter["nativeFilterId"], | ||
| filter["filterType"], | ||
| filter["columnName"], | ||
| filter["filterValues"], | ||
| native_filter_id, | ||
| filter_type, | ||
| native_filter.get("columnName") or "", | ||
| native_filter.get("filterValues") or [], | ||
| ), | ||
|
alexandrusoare marked this conversation as resolved.
|
||
| } | ||
| # hack(hughhh): workaround for escaping prison not handling quotes right | ||
| rison = prison.dumps(params) | ||
| rison = rison.replace("'", "%27") | ||
| return rison | ||
| return rison, warnings | ||
|
|
||
| def _generate_native_filter( | ||
| self, | ||
|
|
||
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:
nativeFiltersis consumed as a list of dicts, but the code never validates that shape. Ifextra_jsoncontains a non-list value (or list elements that are not dicts), calling.get()onnative_filterwill raiseAttributeErrorand crash report execution. Validate the container and each item before accessing keys, and skip malformed entries with a warning. [type error]Severity Level: Major⚠️
Steps of Reproduction ✅
Prompt for AI Agent 🤖