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

IPv6 Address URLs Broken [rt.cpan.org #75618] #42

Open
oalders opened this issue Mar 30, 2017 · 0 comments
Open

IPv6 Address URLs Broken [rt.cpan.org #75618] #42

oalders opened this issue Mar 30, 2017 · 0 comments

Comments

@oalders
Copy link
Member

oalders commented Mar 30, 2017

Migrated from rt.cpan.org#75618 (status was 'open')

Requestors:

Attachments:

From nick_lamkins@symantec.com on 2012-03-08 00:37:02:

Net::HTTP doesn't appear to handle ipv6 addresses correctly.

In http_configure of Net/HTTP/Methods.pm, the code will search for something that appears to be a port at the end of PeerAddr (or PeerHost). When using an ipv6 style address, this pattern may incorrectly match the last segment of an ipv6 address.

sub http_configure {
    my($self, $cnf) = @_;

    die "Listen option not allowed" if $cnf->{Listen};
    my $explict_host = (exists $cnf->{Host});
    my $host = delete $cnf->{Host};
    my $peer = $cnf->{PeerAddr} || $cnf->{PeerHost};
    if (!$peer) {
    die "No Host option provided" unless $host;
    $cnf->{PeerAddr} = $peer = $host;
    }

    if ($peer =~ s,:(\d+)$,,) {  # <-- BUG HERE - $peer could be an ipv6 address
    $cnf->{PeerPort} = int($1);  # always override
    }

<snip>

Sample Code using LWP::UserAgent

#!/usr/bin/env perl

use Net::INET6Glue::INET_is_INET6;
use LWP::UserAgent;

my $url = 'http://[1234:1234:1234:5:abc:abcd:abc1:123]:80/foo/bar.pl?param=true';

my $user_agent = LWP::UserAgent->new;
my $request = HTTP::Request->new(GET => $url);
my $response = $user_agent->request($request);

if ($response->is_success) {
    print "OK\n";
} else {
    die($response->status_line);
}

The error is shown as:

500 Can't connect to 1234:1234:1234:5:abc:abcd:abc1:123:80 (Connection refused) at ./bug.pl line 16.

Setting EXTRA_SOCK_OPTS turns out to be an awful workaround.

@LWP::Protocol::http::EXTRA_SOCK_OPTS = (PeerAddr => '1234:1234:1234:5:abc:abcd:abc1:123:80');

Nick Lamkins
Sr. Software Engineer, Symantec Corporation
www.symantec.com<http://www.symantec.com/>
________________________________
Office: (503) 614-5039  Fax: (503) 614-5060
nick_lamkins@symantec.com
________________________________

[cid:9CC5DD25-B7F1-488B-8109-2C9197866A89]

This message (including any attachments) is intended only for the use of the individual or entity to which it is addressed and may contain information that is non-public, proprietary, privileged, confidential, and exempt from disclosure under applicable law or may constitute as attorney work product. If you are not the intended recipient, you are hereby notified that any use, dissemination, distribution, or copying of this communication is strictly prohibited. If you have received this communication in error, notify us immediately by telephone and (i) destroy this message if a facsimile or (ii) delete this message immediately if this is an electronic communication.

From maf@open.ch on 2013-01-24 01:07:46:

I have the same problem. The workaround seems very clumsy. Is there any
intention to fix this?

Could this just be skipped for IPv6 addresses?

From milos.vyletel@sde.cz on 2013-04-10 14:51:35:

I've spent some time over past few days trying to figure out exactly same
issue as is described here. I wish I've had find this bug report sooner.

Anyway, I've reached the same conclusion as Nick. That code should be
skipped for IPv6 or better regexp should be in place to correctly extract
port from all addresses.

What I've found to be easier workaround than setting EXTRA_SOCK_OPTS is to
use double square brackets. I've used same example code above just added some 
debugging output to Net::HTTP::Methods

my $url = 'http://[fc00::3]/';
$VAR1 = {
          'Proto' => 'tcp',
          'PeerAddr' => 'fc00::3',
          'SendTE' => 1,
          'PeerPort' => 3,               # PeerPort incorrectly set to 3
          'KeepAlive' => ''
        };

my $url = 'http://[[fc00::3]]/';
$VAR1 = {
          'Proto' => 'tcp',
          'PeerAddr' => '[fc00::3]',
          'SendTE' => 1,
          'PeerPort' => 80,              # PeerPort is now correctly set to default
          'KeepAlive' => ''
        };

From jfesler@gigo.com on 2014-07-22 21:40:03:

I humbly offer:

https://github.com/libwww-perl/net-http/pull/10
https://github.com/libwww-perl/libwww-perl/pull/58

The combination will use IO::Socket::IP or IO::Socket::INET6 (if found); and uses URI to do host address parsing (in order to correctly parse [2001:db8::1]:80).

From jfesler@gigo.com on 2014-07-25 22:43:24:

My patches appear to be accepted, and a new release produced.

Please consider updating to these packages:

Net::HTTP (6.07)
LWP (6.080
URI (1.64)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant