Repository navigation
fix(i18n): make language pack endpoint public for embedded dashboards - #42438
Conversation
Code Review Agent Run #32e7e7Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #42438 +/- ##
===========================================
+ Coverage 66.18% 79.19% +13.00%
===========================================
Files 2879 2879
Lines 165870 165859 -11
Branches 38352 38348 -4
===========================================
+ Hits 109777 131346 +21569
+ Misses 53863 32034 -21829
- Partials 2230 2479 +249
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Makes the /language_pack/<lang>/ endpoint publicly accessible so embedded dashboards can fetch i18n catalogs without being redirected to /login/.
Changes:
- Removes
@has_accessfrom thelanguage_packview to allow unauthenticated access. - Adds unit tests asserting the endpoint is reachable without auth and that invalid language codes are rejected.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
superset/views/core.py |
Removes access-guard decorator from language pack endpoint so embedded fetches don’t redirect to login. |
tests/unit_tests/views/test_base.py |
Adds tests covering public accessibility and invalid language handling for /language_pack/<lang>/. |
| def test_language_pack_endpoint_rejects_invalid_lang(app: "SupersetApp") -> None: | ||
| """Invalid language codes are rejected with 400.""" | ||
| with app.test_client() as client: | ||
| resp = client.get("/language_pack/../../../etc/passwd/") | ||
| assert resp.status_code in (400, 404) | ||
|
|
||
| resp = client.get("/language_pack/en-US/injection/") | ||
| assert resp.status_code in (400, 404) |
| with app.test_client() as client: | ||
| resp = client.get("/language_pack/en/") | ||
| # The endpoint must be reachable without authentication. | ||
| # In the test environment compiled catalogs may not exist, so | ||
| # a 404 is acceptable; a 302 to /login/ would indicate the old | ||
| # @has_access guard is still in place. | ||
| assert resp.status_code in (200, 404) | ||
| assert resp.status_code != 302 |
| def test_language_pack_endpoint_is_public(app: "SupersetApp") -> None: | ||
| """The language pack endpoint must be accessible without authentication. | ||
|
|
||
| Translation data is non-sensitive and the embedded dashboard SPA needs to | ||
| fetch it with a bare ``fetch()`` (no guest-token header). Previously the | ||
| endpoint was protected by ``@has_access`` which caused a 302 redirect to | ||
| ``/login/`` for unauthenticated requests, silently breaking i18n in | ||
| embedded dashboards (issue #42433). | ||
|
|
||
| When the compiled catalog exists the endpoint returns 200 with JSON. | ||
| When it is missing the endpoint returns 404 (never a 302 to /login/). | ||
| """ | ||
| with app.test_client() as client: | ||
| resp = client.get("/language_pack/en/") |
|
Thanks for digging into this @prathamesh04! The failing CI (mysql/postgres/sqlite) isn't flaky, it's You'll need to add ["Superset", "language_pack"] to the |
|
Thanks @rusackas for the review! Addressed the Copilot suggestions:
CI is now fully green. Ready for re-review. |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
| resp = client.get("/language_pack/en/") | ||
| # The endpoint must be reachable without authentication. | ||
| # In the test environment compiled catalogs may not exist, so | ||
| # a 404 is acceptable; a 302 to /login/ would indicate the old | ||
| # @has_access guard is still in place. | ||
| assert resp.status_code in (200, 404) |
There was a problem hiding this comment.
Suggestion: The successful branch only checks the status code and never verifies that the response is JSON containing a language catalog. An unrelated 200 response, HTML response, or empty payload would satisfy this test while still breaking the frontend's fetch() and translation loading contract. [api mismatch]
Severity Level: Major ⚠️
- ❌ Invalid 200 responses can pass the endpoint test.
- ⚠️ `preamble.ts` translation loading contract remains unverified.
- ⚠️ JSON catalog regressions are detected only by embedded users.Steps of Reproduction ✅
1. Call `/language_pack/en/` through the unauthenticated client at
`tests/unit_tests/views/test_base.py:335-336`.
2. When the catalog exists, `Superset.language_pack()` at `superset/views/core.py:926-930`
returns the file with `mimetype="application/json"`.
3. The test at `tests/unit_tests/views/test_base.py:341` checks only that the status is
not 302; any 200 response, including an unrelated HTML response or an empty body,
satisfies the assertion.
4. Change the handler to return an invalid 200 payload or wrong content type; the test
still passes even though the frontend fetch in `superset-frontend/src/preamble.ts:91-96`
cannot load a usable language catalog. The test should assert the successful branch, JSON
content type, and expected catalog structure, while separately handling environments where
the catalog is mocked or unavailable.(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** tests/unit_tests/views/test_base.py
**Line:** 336:341
**Comment:**
*Api Mismatch: The successful branch only checks the status code and never verifies that the response is JSON containing a language catalog. An unrelated 200 response, HTML response, or empty payload would satisfy this test while still breaking the frontend's `fetch()` and translation loading contract.
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| resp = client.get("/language_pack/../../../etc/passwd/") | ||
| assert resp.status_code in (400, 404) | ||
|
|
||
| resp = client.get("/language_pack/en-US/injection/") | ||
| assert resp.status_code in (400, 404) |
There was a problem hiding this comment.
Suggestion: These URLs contain extra path segments, so Flask can return 404 during routing before language_pack executes; because 404 is accepted, the test does not verify that the handler rejects malformed language codes with 400. Pass malformed values within the single <lang> path segment and assert the handler's intended status. [api mismatch]
Severity Level: Major ⚠️
- ❌ Invalid language-code handling is not actually tested.
- ⚠️ Route-level regressions can be mistaken for validation success.
- ⚠️ Path-validation coverage remains incomplete for the public endpoint.Steps of Reproduction ✅
1. The route is declared as `/language_pack/<lang>/` at `superset/views/core.py:919`, so
`<lang>` accepts one path segment only.
2. Request `/language_pack/../../../etc/passwd/` from
`tests/unit_tests/views/test_base.py:348`; the additional slash-separated segments prevent
Flask routing from invoking `Superset.language_pack()`, so a 404 can occur before the
validation at `superset/views/core.py:921-923`.
3. Request `/language_pack/en-US/injection/` from
`tests/unit_tests/views/test_base.py:351`; the extra `/injection/` segment likewise
exercises routing rather than the handler's regular-expression validation.
4. Replace those requests with single-segment invalid values such as
`/language_pack/en-US/` and `/language_pack/en_US_extra/`; these reach `language_pack()`
and should produce the handler's 400 response at `superset/views/core.py:922-923`, whereas
the current assertions accept 404 and therefore cannot detect a validation regression.(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** tests/unit_tests/views/test_base.py
**Line:** 348:352
**Comment:**
*Api Mismatch: These URLs contain extra path segments, so Flask can return 404 during routing before `language_pack` executes; because 404 is accepted, the test does not verify that the handler rejects malformed language codes with 400. Pass malformed values within the single `<lang>` path segment and assert the handler's intended status.
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
Code Review Agent Run #a303a9Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
f0ff6cb to
8f1d8db
Compare
|
Thanks @rusackas for the review! Addressed the Copilot suggestions:
CI is now fully green. Ready for re-review. |
Code Review Agent Run #4b6c66Actionable Suggestions - 0Additional Suggestions - 1
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
|
I think this just needs a rebase, but otherwise it's looking good! Holler if you want a hand with that. |
|
@prathamesh04 still conflicting with master. Worth knowing master picked up a |
8f1d8db to
0941e75
Compare
Code Review Agent Run #35c163Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Remove @has_access from the /language_pack/<lang>/ endpoint to allow embedded dashboards to fetch translations without authentication. Embedded dashboards use a bare fetch() without the guest-token header, so the endpoint returned a 302 redirect to /login/ instead of the translation catalog. This silently broke i18n for all embedded dashboards using non-English locales. The language pack contains only non-sensitive translation strings and is safe to serve without authentication. Closes apache#42433
0941e75 to
7a04885
Compare
Code Review Agent Run #1df3c7Actionable Suggestions - 0Filtered by Review RulesBito filtered these suggestions based on rules created automatically for your feedback. Manage rules.
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
…#42438) Co-authored-by: Prathamesh Hukkeri <[email protected]>
Summary
Closes #42433
The
/language_pack/<lang>/endpoint was protected by@has_access, which caused a 302 redirect to/login/for unauthenticated requests. This silently broke i18n for all embedded dashboards using non-English locales.Embedded dashboards use a bare
fetch()without the guest-token header, so the async language pack fetch inpreamble.tswas always blocked. The bootstrap-injected pack path (common_bootstrap_payload) also depends on the JSON catalogs existing on disk - the official Docker image ships only.pofiles, so when the pack isNonethe fallback fetch was the only path to load translations, and it was broken.Root Cause
@has_accessblocks embedded guest users: The language pack endpoint requires authenticated access. The embedded SPA barefetch()has no guest-token header so it gets a 302 to/login/messages.jsonfiles are not shipped, soget_language_pack()returnsNone, making the bootstrap-injected pack empty/null@has_accessFix
@has_accessfrom thelanguage_packendpoint (translation data is non-sensitive)Testing Instructions
pytest tests/unit_tests/views/test_base.py::test_language_pack_endpoint_is_public -vpytest tests/unit_tests/views/test_base.py -v