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

Redirect with authorization credentials to same host for relative paths #700

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion lib/httparty/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def handle_response(body, &block)
def handle_host_redirection
check_duplicate_location_header
redirect_path = options[:uri_adapter].parse(last_response['location']).normalize
return if redirect_path.relative? || path.host == redirect_path.host
return if redirect_path.relative? || path.host == redirect_path.host || uri.host == redirect_path.host
@changed_hosts = true
end

Expand Down
14 changes: 14 additions & 0 deletions spec/httparty/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,20 @@
@request.send(:setup_raw_request)
expect(@request.instance_variable_get(:@raw_request)['authorization']).to eq(@authorization)
end

context 'when uri path is a relative path' do
before do
@request.path = '/v1'
@request.options[:base_uri] = 'http://api.foo.com'
end

it "should send Authorization header when redirecting to the same host" do
@redirect['location'] = 'http://api.foo.com/v2'
@request.perform
@request.send(:setup_raw_request)
expect(@request.instance_variable_get(:@raw_request)['authorization']).to eq(@authorization)
end
end
end
end

Expand Down