Skip to content

Commit

Permalink
Redirect with authorization credentials to same host for relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonheecs committed May 6, 2020
1 parent 0986ff3 commit 01534e5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
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

0 comments on commit 01534e5

Please sign in to comment.