Skip to content

Commit 1439db5

Browse files
committed
Escape allow list hosts correctly
[CVE-2021-22903]
1 parent 0303187 commit 1439db5

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

actionpack/lib/action_dispatch/middleware/host_authorization.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def sanitize_string(host)
5353
if host.start_with?(".")
5454
/\A(.+\.)?#{Regexp.escape(host[1..-1])}\z/i
5555
else
56-
/\A#{host}\z/i
56+
/\A#{Regexp.escape host}\z/i
5757
end
5858
end
5959
end

actionpack/test/dispatch/host_authorization_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,17 @@ class HostAuthorizationTest < ActionDispatch::IntegrationTest
232232
assert_match "Blocked host: example.com#sub.example.com", response.body
233233
end
234234

235+
test "blocks requests to similar host" do
236+
@app = ActionDispatch::HostAuthorization.new(App, "sub.example.com")
237+
238+
get "/", env: {
239+
"HOST" => "sub-example.com",
240+
}
241+
242+
assert_response :forbidden
243+
assert_match "Blocked host: sub-example.com", response.body
244+
end
245+
235246
test "config setting action_dispatch.hosts_response_app is deprecated" do
236247
assert_deprecated do
237248
ActionDispatch::HostAuthorization.new(App, "example.com", ->(env) { true })

0 commit comments

Comments
 (0)