Skip to content
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(lang): patch FAB's LocaleView to redirect to previous page #31692

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

pomegranited
Copy link
Contributor

@pomegranited pomegranited commented Jan 3, 2025

SUMMARY

Overrides FAB's LocaleView to redirect to the request's referrer instead of relying on the session page history as suggested here.

This isn't a perfect solution, but it keeps the change very close to the actual issue.

Note that this view is marked out in the tests as an "unsecured" view, because we need to be able to change the current locale even when logged out (so that the login page can be presented in the user's preferred language).

Rejected alternatives

  1. Call update_redirect() whenever a GET view is rendered (like this).
    This is more in line with how Flask AppBuilder works (and was recommended here).
    However, this only works for pages rendered by Superset's backend, and most Superset pages are rendered by the frontend.
  2. Hook into the frontend's action logging to update the page history, e.g when a LOG_ACTIONS_SPA_NAVIGATION event is logged to the backend.
    This approach felt even hackier than the one posted here, and farther from the issue it addresses.
    Also, Flask AppBuilder only provides the update_redirect() method which uses the current request.url, so we'd need to add another method that could use a different url.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before:

Untitled.video.-.Made.with.Clipchamp.12.mp4

After:

Language.redirect.-.Made.with.Clipchamp.mp4

TESTING INSTRUCTIONS

  1. Load Superset with multiple languages enabled.
  2. Visit any page.
  3. Change your current language using the language switcher menu on the top right.
  4. Ensure that your language is changed and you're redirect back to the page in step 2.

ADDITIONAL INFORMATION

  • Fixes Redirect happens whenever user changes language #12768
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

to redirect to the request referrer instead of relying on the session
page_history.

This change is needed because most of Superset's page views are handled
by the frontend, and as such, not stored in the session page_history.
Copy link

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review by Korbit AI

Korbit automatically attempts to detect when you fix issues in new commits.
Category Issue Fix Detected
Error Handling Non-descriptive locale error message ▹ view
Error Handling Unvalidated redirect from Referer header ▹ view
Functionality Insecure Open Redirect ▹ view

Need a new review? Comment /korbit-review on this PR and I'll review your latest changes.

Korbit Guide: Usage and Customization

Interacting with Korbit

  • You can manually ask Korbit to review your PR using the /korbit-review command in a comment at the root of your PR.
  • You can ask Korbit to generate a new PR description using the /korbit-generate-pr-description command in any comment on your PR.
  • Too many Korbit comments? I can resolve all my comment threads if you use the /korbit-resolve command in any comment on your PR.
  • Chat with Korbit on issues we post by tagging @korbit-ai in your reply.
  • Help train Korbit to improve your reviews by giving a 👍 or 👎 on the comments Korbit posts.

Customizing Korbit

  • Check out our docs on how you can make Korbit work best for you and your team.
  • Customize Korbit for your organization through the Korbit Console.

Feedback and Support

superset/initialization/__init__.py Outdated Show resolved Hide resolved
superset/initialization/__init__.py Outdated Show resolved Hide resolved
Comment on lines +715 to +716
if locale not in self.appbuilder.bm.languages:
abort(404, description="Locale not supported.")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-descriptive locale error message category Error Handling

Tell me more
What is the issue?

The error message when aborting with 404 is too generic and doesn't provide context about which locale was attempted.

Why this matters

When debugging issues with locale changes, administrators won't know which specific locale value caused the failure without checking logs or request parameters.

Suggested change

abort(404, description=f"Locale '{locale}' is not supported. Supported locales: {list(self.appbuilder.bm.languages)}")

Chat with Korbit by mentioning @korbit-ai, and give a 👍 or 👎 to help Korbit improve your reviews.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving this one up to the reviewers - see original LocaleView

@pomegranited pomegranited changed the title fix(lang): patch FAB's LocaleView fix(lang): patch FAB's LocaleView to redirect to previous page Jan 3, 2025
@pull-request-size pull-request-size bot added size/M and removed size/S labels Jan 3, 2025
redirect_to = request.headers.get("Referer")
if not redirect_to or not self.is_safe_url(redirect_to):
redirect_to = self.get_redirect()
return redirect(redirect_to)

Check warning

Code scanning / CodeQL

URL redirection from remote source Medium

Untrusted URL redirection depends on a
user-provided value
.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving this one up to the reviewers - see original LocaleView

@rusackas rusackas requested a review from dpgaspar January 3, 2025 21:04
@rusackas
Copy link
Member

rusackas commented Jan 3, 2025

Installing the pre-commit hook should resolve at least some of the CI issues.

/
Superset uses Git pre-commit hooks courtesy of pre-commit. To install run the following:

pip3 install -r requirements/development.txt
pre-commit install
A series of checks will now run when you make a git commit.

Alternatively it is possible to run pre-commit by running pre-commit manually:

pre-commit run --all-files

Copy link

codecov bot commented Jan 7, 2025

Codecov Report

Attention: Patch coverage is 42.85714% with 12 lines in your changes missing coverage. Please review.

Project coverage is 83.74%. Comparing base (76d897e) to head (25814f9).
Report is 1277 commits behind head on master.

Files with missing lines Patch % Lines
superset/initialization/__init__.py 42.85% 12 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #31692       +/-   ##
===========================================
+ Coverage   60.48%   83.74%   +23.26%     
===========================================
  Files        1931      538     -1393     
  Lines       76236    39160    -37076     
  Branches     8568        0     -8568     
===========================================
- Hits        46114    32796    -13318     
+ Misses      28017     6364    -21653     
+ Partials     2105        0     -2105     
Flag Coverage Δ
hive 48.75% <42.85%> (-0.42%) ⬇️
javascript ?
mysql 76.48% <42.85%> (?)
postgres 76.54% <42.85%> (?)
presto 53.26% <42.85%> (-0.55%) ⬇️
python 83.74% <42.85%> (+20.26%) ⬆️
sqlite 76.00% <42.85%> (?)
unit 60.89% <42.85%> (+3.26%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Because we need to be able to change the locale even when logged out,
this view cannot be protected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants