Skip to content

Fix open redirect vulnerability in URL shortener via backslash bypass#2906

Merged
deniszh merged 2 commits intomasterfrom
copilot/fix-issue-2872-again
Mar 17, 2026
Merged

Fix open redirect vulnerability in URL shortener via backslash bypass#2906
deniszh merged 2 commits intomasterfrom
copilot/fix-issue-2872-again

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 17, 2026

The URL shortener's follow() view was vulnerable to open redirect attacks. While a lstrip('/') guard prevented //evil.com protocol-relative redirects, a backslash bypass remained: storing \evil.com produces a redirect to /\evil.com, which some browsers normalize to //evil.com, redirecting to an external domain.

Changes

  • url_shortener/views.py: Added url_has_allowed_host_and_scheme() validation after URL construction. If the resulting URL fails the safety check, falls back to the browser root.
url = browser_url + link.url.lstrip('/')
if not url_has_allowed_host_and_scheme(url=url, allowed_hosts={request.get_host()}):
    url = browser_url
  • tests/test_url_shortener.py: Added test_follow_open_redirect_backslash_prevention covering the \evil.com bypass case, asserting the redirect passes url_has_allowed_host_and_scheme against testserver.

💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

Co-authored-by: deniszh <1227222+deniszh@users.noreply.github.com>
Copilot AI changed the title [WIP] [2872] Fix issue with Graphite web Fix open redirect vulnerability in URL shortener via backslash bypass Mar 17, 2026
Copilot AI requested a review from deniszh March 17, 2026 21:27
@deniszh deniszh marked this pull request as ready for review March 17, 2026 21:39
@deniszh deniszh merged commit 9c0e365 into master Mar 17, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants