Skip to content

Commit

Permalink
Escape allow list hosts correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed May 4, 2021
1 parent 0303187 commit 1439db5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def sanitize_string(host)
if host.start_with?(".")
/\A(.+\.)?#{Regexp.escape(host[1..-1])}\z/i
else
/\A#{host}\z/i
/\A#{Regexp.escape host}\z/i
end
end
end
Expand Down
11 changes: 11 additions & 0 deletions actionpack/test/dispatch/host_authorization_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,17 @@ class HostAuthorizationTest < ActionDispatch::IntegrationTest
assert_match "Blocked host: example.com#sub.example.com", response.body
end

test "blocks requests to similar host" do
@app = ActionDispatch::HostAuthorization.new(App, "sub.example.com")

get "/", env: {
"HOST" => "sub-example.com",
}

assert_response :forbidden
assert_match "Blocked host: sub-example.com", response.body
end

test "config setting action_dispatch.hosts_response_app is deprecated" do
assert_deprecated do
ActionDispatch::HostAuthorization.new(App, "example.com", ->(env) { true })
Expand Down

0 comments on commit 1439db5

Please sign in to comment.