Subject: | Negotiate proxy authentication doesn't work - wrong host used |
Date: | Tue, 24 May 2011 17:19:33 +0100 |
To: | bug-LWP-Authen-Negotiate [...] rt.cpan.org |
From: | Steven Singer <steven.singer [...] csr.com> |
If you attempt to access a web site and get bounced by your proxy
with error code 407 (proxy authentication required) and if the proxy
says it supports Negotiate authentication then LWP::Authen::Negotiate
doesn't handle it properly.
It's a simple error. The module attempts to look up credentials based on
the host of the URI you're trying to connect to instead of the host of
the URI of the proxy.
That is, suppose you're trying to get to http://www.google.com/ via
the proxy http://myproxy.mysite:8080/ and get a 407 error then the
module looks up credentials for www.google.com instead of
myproxy.mysite. Unsurprisingly, it fails to find any credentials for
www.google.com and so doesn't complete the authentication.
The fix is simple (diff -u output relative to version 0.08):
--- original/LWP/Authen/Negotiate.pm 2009-10-29 20:56:35.000000000 +0000
+++ modified/LWP/Authen/Negotiate.pm 2011-05-24 16:49:29.671089000 +0100
@@ -40,7 +40,7 @@
my ($class,$ua,$proxy,$auth_param,$response,$request,$arg,$size) = @_;
my $uri = URI->new($request->uri);
- my $targethost = $request->uri()->host();
+ my $targethost = $proxy ? $request->{proxy}->host() : $request->uri()->host();
my $otoken;
my $status;
This fix reaches into the HTTP::Request object but then
LWP::Authen::Basic does the same thing. This suggests either that
HTTP::Request should get a documented API to retrieve the proxy and/or
LWP::UserAgent should be doing this manipulation before calling
LWP::Authen::<whatever>.
In any event, with the fix I've given, for 407 errors the module looks
up credentials for myproxy.mysite and everything works. The module
still handles 401 errors correctly.
Version details:
Perl 5.8.8
LWP::Authen::Negotiate 0.08
LWP::UserAgent 6.02
Linux 2.6.18
--
Steven Singer
Software Engineer
Cambridge Silicon Radio Ltd. Tel: +44 (0)1223 692000 Fax: +44 (0)1223 692001
Churchill House, Cambridge Business Park, Cowley Road, Cambridge CB4 0WZ, UK
Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom