Skip to content

Commit

Permalink
Prevent XSS in the Actionable Exceptions middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Oct 7, 2020
1 parent 91d1e81 commit ddcca86
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "erb"
require "uri"
require "action_dispatch/http/request"
require "active_support/actionable_error"

Expand All @@ -27,7 +28,13 @@ def actionable_request?(request)
end

def redirect_to(location)
body = "<html><body>You are being <a href=\"#{ERB::Util.unwrapped_html_escape(location)}\">redirected</a>.</body></html>"
uri = URI.parse location

if uri.relative? || uri.scheme == "http" || uri.scheme == "https"
body = "<html><body>You are being <a href=\"#{ERB::Util.unwrapped_html_escape(location)}\">redirected</a>.</body></html>"
else
return [400, {"Content-Type" => "text/plain"}, ["Invalid redirection URI"]]
end

[302, {
"Content-Type" => "text/html; charset=#{Response.default_charset}",
Expand Down

0 comments on commit ddcca86

Please sign in to comment.