-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Bugfix for redirection handling in Zend\Http\Client #4215
Conversation
Authentication should only be forwarded when inside the same domain (or one of its subdomains); otherwise, you run the risk of exposing your credentials to a third-party if redirected to another domain. Can you implement logic to |
That's quite a good point, however, in ZF1 this is definitely not done, as Zend_Http_Client::request() is more or less the same than Zend\Http\Client::send() and Zend_Http_Client::resetParameters() does not reset the authentication. Just to mention that you might want to fix ZF1 as well. I did not implemented the logic in I added a test with 3 assertions which basically check the following:
I'm still a bit wondering what about the case of a redirection of www.example.org to sub.example.org. Zend\Http\Client would clear the authentication now, even though I think current desktop browsers might handle this case differently. Another thing I feel a little uncomfortable about is that for the following scenario it is completely up to the response of the first server, how the request to the second server looks like: $client->setUri('http://www.example.org/')
->setAuth('myusername', 'mypassword')
->setMethod('GET');
$response = $client->send();
$client->setUri('http://www.google.com/')
->setMethod('GET');
$response = $client->send(); If So maybe it would be good to mention in the docs that you should always reset the client between two requests, unless you know exactly what you're doing. The following would work: $client->setUri('http://www.example.org/')
->setAuth('myusername', 'mypassword')
->setMethod('GET');
$response = $client->send();
$client->resetParameters(true, true)
->setUri('http://www.google.com/')
->setMethod('GET');
$response = $client->send(); As public function reset()
{
$this->resetParameters(true, true);
} |
I would expect peer subdomains to allow redirection without clearing authentication. |
I would expect that if you call |
I agree here. |
@driehle If you address the feedback I've just provided, I'd be happy to include this in 2.2.0. Can you have the changes by the end of the week? |
…lso clear lastRawRequest and lastRawResponse
@weierophinney, I will give it a try ;)
Well, even though this is a good idea, it might be a bit hart to actually detect peer subdomains. That would require a build-in list of TLDs, since there are some TLDs like If such a list of effective TLDs is not shipped with ZF, the actually intented security advancement will not be archived, because e.g. Alternatively, we could keep the current implementation or do some kind of left-trimming the string |
@driehle Oof -- I'd forgotten about the TLD list. Let's instead drop authentication headers on peer domains, and document why and what approaches developers should take. |
@weierophinney Done ;) Maybe we can create a |
Yes, absolutely that's a possibility. While that namespace/classname seems appropriate given the initial use case, I could see an argument for having it as a validator, too, as there may be cases when you want to validate that a given TLD is correct (there could even be integration in the Hostname validator for consuming this). The suffixes can be done as an array -- look at how the hostname validator does this, as well as the new I18n filters and validators that @mwillbanks has been working on (though I think he's now using |
Bugfix for redirection handling in Zend\Http\Client
Merged to develop for release with 2.2.0 -- thanks @driehle -- and looking forward to upcoming contributions. :) |
…-client-bugfix Bugfix for redirection handling in Zend\Http\Client
- per php-cs-fixer
When working with Zend\Http\Client today I discovered two issues:
maxredirects=1
did not follow any redirect,maxredirects=2
followed 1 redirect.The first issue is do to a wrong way of counting the redirects, which I fixed in e196bc3. Basically a compare operator was wrong (
<
instead of<=
). I added a test case for that.The second issue is due to the fact that the
send()
method makes a call toresetParameters()
prior to following the redirect. Unfortunatelly this removes the HTTP authentication as well. I added a new methodclearAuth()
(similar toclearCookies()
) and changedresetParameters()
to only clear the authentication when the newly introduced second parameter istrue
. To not break backward-compatibilty, this parameter is true by default. All this was done in 954a549, a test case is added as well.