Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return 400 if uri is bad #69

Merged
merged 2 commits into from
Mar 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: return 400 if uri is bad
G-Rath committed Mar 15, 2024
commit f8200870506b1130860aeee525faba5447628762
2 changes: 2 additions & 0 deletions lib/rack/canonical_host.rb
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions spec/rack/canonical_host_spec.rb
Original file line number Diff line number Diff line change
@@ -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