-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
fix(Embedded): Skip CSRF validation for dashboard download endpoints #31798
Changes from all commits
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 |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
from sqlalchemy import and_, distinct, func | ||
from sqlalchemy.orm.query import Query | ||
|
||
from superset import is_feature_enabled | ||
from superset.exceptions import InvalidPayloadFormatError | ||
from superset.extensions import db, event_logger, security_manager, stats_logger_manager | ||
from superset.models.core import FavStar | ||
|
@@ -130,6 +131,29 @@ def wraps(self: BaseSupersetApiMixin, *args: Any, **kwargs: Any) -> Response: | |
return functools.update_wrapper(wraps, f) | ||
|
||
|
||
def validate_feature_flags( | ||
feature_flags: list[str], | ||
) -> Callable[[Callable[..., Response]], Callable[..., Response]]: | ||
""" | ||
A decorator to check if all given feature flags are enabled. | ||
|
||
:param feature_flags: List of feature flag names to be checked. | ||
""" | ||
|
||
def decorate(f: Callable[..., Response]) -> Callable[..., Response]: | ||
@functools.wraps(f) | ||
def wrapper( | ||
self: BaseSupersetModelRestApi, *args: Any, **kwargs: Any | ||
) -> Response: | ||
if not all(is_feature_enabled(flag) for flag in feature_flags): | ||
return self.response_404() | ||
Comment on lines
+148
to
+149
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. Incorrect HTTP Status Code for Disabled FeaturesTell me moreWhat is the issue?The decorator returns a 404 Not Found response when feature flags are disabled, which is semantically incorrect and misleading. Why this mattersA 404 response indicates a resource was not found, but in this case, the resource exists but is intentionally disabled. This could confuse API clients and monitoring systems trying to understand why the endpoint is not accessible. Suggested change ∙ Feature PreviewReturn a 403 Forbidden status code which better represents that the feature exists but access is not permitted: if not all(is_feature_enabled(flag) for flag in feature_flags):
return self.response_403() Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews. |
||
return f(self, *args, **kwargs) | ||
|
||
return wrapper | ||
|
||
return decorate | ||
|
||
|
||
class RelatedFieldFilter: | ||
# data class to specify what filter to use on a /related endpoint | ||
# pylint: disable=too-few-public-methods | ||
|
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.
I am thinking if we really need the couple here at this point or
ENABLE_DASHBOARD_SCREENSHOT_ENDPOINTS
will suffice. What's your thought? I have been meaning to remove this dependency before and this could be a good chance.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.
@geido if we remove the requirement to have
THUMBNAILS
enabled for this endpoint, but then we keep it at thedigest
endpoint, then at the end the process would still not work unless you have both enabled.Also, currently when you trigger a "screenshot generation" it returns the digest link, which returns a
404
status code until it's being processed. IfTHUMBNAILS
is disabled, it would return404
forever and users wouldn't have an easy way to spot the issue.I think we could either:
THUMBNAILS
check for this endpoint, and then update the check on thedigest
endpoint to validate for eitherTHUMBNAILS
ORENABLE_DASHBOARD_SCREENSHOT_ENDPOINTS
. This way you can still download a dashboard screenshot without havingTHUMBNAILS
FF enabled; orTHUMBNAILS
FF is disabled. Also update the frontend (if that's not the case yet) to validate if both FFs are enabled to decide if frontend or backend processing should be used.One potential issue with the first approach is that environments with
ENABLE_DASHBOARD_SCREENSHOT_ENDPOINTS
enabled butTHUMBNAILS
disabled would still expose thedigest
endpoint, so it's possible that disablingTHUMBNAILS
FF would no longer be sufficient to remove thumbnails from displaying in the card views.Let me know your thoughts!
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.
Alright. I think there is a case here to keep both. Maybe @fisjac can consider the above for the work that he is doing around screenshot generation for future improvements. Thanks for this!