Repository navigation
Conversation
…idated The external-link redirect endpoint validates the requested target with is_safe_redirect_url, which normalizes the string before parsing (dropping the control characters a browser strips and rewriting backslashes to forward slashes in special schemes, mirroring Django's url_has_allowed_host_and_scheme). The endpoint then emitted the original, un-normalized string. urllib and the browser read an authority such as host\@other differently from the normalized host/@other the check inspected, so the validated host and the emitted host could diverge. Factor the normalization into normalize_redirect_url and have the view emit that same normalized form once the check passes, so the host the check approves is the host the browser receives. Add unit coverage for the normalization helper and the check/emit agreement, plus a regression test that the endpoint redirects to the configured host for a backslash-authority input. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Comment on lines
+142
to
+143
| stripped = _URL_STRIPPED_CONTROL_CHARS.sub("", url.strip()) | ||
| return stripped.replace("\\", "/") |
Contributor
There was a problem hiding this comment.
Suggestion: normalize_redirect_url rewrites backslashes inside query and fragment values too, so a safe target like ?path=C:\reports redirects with a changed parameter.
Assessment: 🟠 Major · 🔁 Occurrence: Rarely · 🏷️ Logic error
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset/utils/link_redirect.py
**Line:** 142:143
**Comment:**
*Logic Error: `normalize_redirect_url` rewrites backslashes inside query and fragment values too, so a safe target like `?path=C:\reports` redirects with a changed parameter.
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
Contributor
| # stripped control characters otherwise). | ||
| if is_safe_redirect_url(target_url): | ||
| return redirect(target_url) | ||
| return redirect(normalize_redirect_url(target_url)) |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #46686 +/- ##
=======================================
Coverage 86.42% 86.42%
=======================================
Files 3183 3183
Lines 222605 222607 +2
Branches 52996 52996
=======================================
+ Hits 192377 192379 +2
Misses 26758 26758
Partials 3470 3470
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:
|
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
SUMMARY
The alert/report external-link redirect endpoint validates its target with
is_safe_redirect_url, which normalizes the string before parsing it: it drops the control characters a browser removes per the WHATWG URL spec and rewrites backslashes to forward slashes in special schemes, the same way Django'surl_has_allowed_host_and_schemedoes. The endpoint then emitted the original, un-normalized string.Because
urllib(and the browser) read an authority likehost\@otherdifferently from the normalizedhost/@otherthe check inspected, the host that was validated and the host that was emitted could differ for the same input.This change factors that normalization into
normalize_redirect_urland has the view emit that same normalized form once the check passes, so the target the browser receives is exactly the one the check approved. Pure consistency between validation and emission; no behavior change for ordinary internal or relative targets.TESTING INSTRUCTIONS
pytest tests/unit_tests/utils/test_link_redirect.pypytest tests/integration_tests/views/test_redirect_view.pyADDITIONAL INFORMATION