mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 16:11:10 +08:00
SECURITY: Don't allow redirects with periods in case you don't control
other tlds on the same domain.
This commit is contained in:
parent
38e0c6645e
commit
013e3312ad
@ -60,7 +60,9 @@ class StaticController < ApplicationController
|
|||||||
begin
|
begin
|
||||||
forum_uri = URI(Discourse.base_url)
|
forum_uri = URI(Discourse.base_url)
|
||||||
uri = URI(params[:redirect])
|
uri = URI(params[:redirect])
|
||||||
if uri.path.present? && (uri.host.blank? || uri.host == forum_uri.host)
|
if uri.path.present? &&
|
||||||
|
(uri.host.blank? || uri.host == forum_uri.host) &&
|
||||||
|
uri.path !~ /\./
|
||||||
destination = uri.path
|
destination = uri.path
|
||||||
end
|
end
|
||||||
rescue URI::InvalidURIError
|
rescue URI::InvalidURIError
|
||||||
|
@ -89,6 +89,13 @@ describe StaticController do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with a period to force a new host' do
|
||||||
|
it 'redirects to the root path' do
|
||||||
|
xhr :post, :enter, redirect: ".org/foo"
|
||||||
|
expect(response).to redirect_to '/'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'with a full url to someone else' do
|
context 'with a full url to someone else' do
|
||||||
it 'redirects to the root path' do
|
it 'redirects to the root path' do
|
||||||
xhr :post, :enter, redirect: "http://eviltrout.com/foo"
|
xhr :post, :enter, redirect: "http://eviltrout.com/foo"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user