Skip to content

fix(views): emit the normalized target the external-link redirect validated - #46686

Open
sha174n wants to merge 1 commit into
apache:masterfrom
sha174n:chore/redirect-emit-normalized-target
Open

sha174n wants to merge 1 commit into
apache:masterfrom
sha174n:chore/redirect-emit-normalized-target

Conversation

@sha174n

@sha174n sha174n commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

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's url_has_allowed_host_and_scheme does. The endpoint then emitted the original, un-normalized string.

Because urllib (and the browser) read an authority like host\@other differently from the normalized host/@other the 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_url and 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.py
  • pytest tests/integration_tests/views/test_redirect_view.py

ADDITIONAL INFORMATION

  • Has associated issue:
  • 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 changes include necessary synchronization

…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("\\", "/")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Use CodeAnt Skill Fix in Cursor Fix in VSCode Claude

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
👍 | 👎

@codeant-ai-for-open-source

Copy link
Copy Markdown
Contributor

CodeAnt  CodeAnt PR Risk

🟡  Medium Risk

  • The PR needs attention before merging.
  • Normalizing backslashes across the entire URL changes query and fragment values, such as a path parameter containing C:\reports.

Assessed commit: 3580e9f2a400

# stripped control characters otherwise).
if is_safe_redirect_url(target_url):
return redirect(target_url)
return redirect(normalize_redirect_url(target_url))
@codecov

codecov Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.42%. Comparing base (7819e82) to head (3580e9f).

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           
Flag Coverage Δ
hive 33.63% <33.33%> (+<0.01%) ⬆️
mysql 51.83% <100.00%> (-0.01%) ⬇️
postgres 51.85% <100.00%> (+<0.01%) ⬆️
presto 35.32% <33.33%> (+<0.01%) ⬆️
python 88.81% <100.00%> (+<0.01%) ⬆️
sqlite 51.55% <100.00%> (+<0.01%) ⬆️
unit 84.37% <100.00%> (+<0.01%) ⬆️

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

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
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