Skip to content

Commit

Permalink
fix: return 400 if uri is bad
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Mar 15, 2024
1 parent 134f76f commit f820087
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/rack/canonical_host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def call(env)
else
redirect.response
end
rescue Addressable::URI::InvalidURIError
[400, { Rack::CONTENT_TYPE => "text/plain", Rack::CONTENT_LENGTH => "0" }, []]
end

protected
Expand Down
15 changes: 15 additions & 0 deletions spec/rack/canonical_host_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,21 @@ def call_app

it_behaves_like 'a non-matching request'
end

context 'which is an invalid uri' do
let(:headers) { { 'HTTP_X_FORWARDED_HOST' => '[${jndi:ldap://172.16.26.190:52314/nessus}]/' } }

it { should_not be_redirect }

it { expect(response[0]).to be 400 }

it 'does not call the inner app' do
expect(inner_app).to_not receive(:call)
call_app
end

it { expect(response).to_not have_header('cache-control') }
end
end

context 'without a host' do
Expand Down

0 comments on commit f820087

Please sign in to comment.