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 5, 2021
1 parent 98a0a12 commit ef97441
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 @@ -48,7 +48,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 @@ -213,4 +213,15 @@ class HostAuthorizationTest < ActionDispatch::IntegrationTest
assert_response :forbidden
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
end

0 comments on commit ef97441

Please sign in to comment.