Subject: | LWP::Authen::Ntlm does not correctly support HTTP 407 |
Date: | Wed, 3 Feb 2016 00:39:57 +0000 |
To: | "bug-libwww-perl [...] rt.cpan.org" <bug-libwww-perl [...] rt.cpan.org> |
From: | Alec Guertin <A.Guertin [...] F5.com> |
The source code seems to indicate that this library is expected to work for both 401 and 407 since it checks whether it needs to use the “Proxy-Authorization” header or the “Authorization” header in this line:
my $auth_header = $proxy ? "Proxy-Authorization" : "Authorization”;
but does not correctly parse the HTTP response from the server. When scanning the response, the authenticate subroutine only checks for “WWW-Authenticate” headers and not “Proxy-Authenticate” headers. As specified by the HTTP Authentication RFC (RFC 7235), HTTP 407 responses should use the “Proxy-Authenticate” header and not the “WWW-Authenticate” header (see https://tools.ietf.org/html/rfc7235#section-3.2).
I have not tested this, but I also believe that it would be safer for the decision to use the “Proxy-Authorization” header to be based on the HTTP response code (“Authorization” to respond to a HTTP 401, “Proxy-Authorization” to response to a HTTP 407). If a proxy forwards a 401 to the client, this library will incorrectly use the “Proxy-Authorization” header.