mirror of
https://github.com/discourse/discourse.git
synced 2025-02-20 11:48:26 -06:00
FIX: Unescape URI properly when redirecting to a category
Currently, when a badly named category slug is provided, it can lead to an infinite redirect. This patch addresses the issue by properly unescaping `request.fullpath` so the path is successfully rewritten and the redirect happens as expected.
This commit is contained in:
parent
75d11bfeba
commit
e494bafed3
@ -421,7 +421,7 @@ class ListController < ApplicationController
|
||||
end
|
||||
real_slug = @category.full_slug("/")
|
||||
if CGI.unescape(current_slug) != CGI.unescape(real_slug)
|
||||
url = request.fullpath.gsub(current_slug, real_slug)
|
||||
url = CGI.unescape(request.fullpath).gsub(current_slug, real_slug)
|
||||
if ActionController::Base.config.relative_url_root
|
||||
url = url.sub(ActionController::Base.config.relative_url_root, "")
|
||||
end
|
||||
|
@ -1239,6 +1239,14 @@ RSpec.describe ListController do
|
||||
expect(response).to have_http_status :not_found
|
||||
end
|
||||
end
|
||||
|
||||
context "when provided slug is gibberish" do
|
||||
it "redirects to the proper category" do
|
||||
get "/c/summit'%22()&%25%3Czzz%3E%3CScRiPt%20%3EqlJ2(9585)%3C%2FScRiPt%3E/#{category.id}"
|
||||
expect(response).to have_http_status :moved_permanently
|
||||
expect(response).to redirect_to("/c/#{category.slug}/#{category.id}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "shared drafts" do
|
||||
|
Loading…
Reference in New Issue
Block a user