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

Host Parsing of IPv6-URI with port #3

Closed
weierophinney opened this issue Dec 31, 2019 · 2 comments
Closed

Host Parsing of IPv6-URI with port #3

weierophinney opened this issue Dec 31, 2019 · 2 comments

Comments

@weierophinney
Copy link
Member

Hi,

As you probably know IPv6 addresses with ports are wrapped in square brackets (because the colon sign also appears in the IP address itself).

These brackets are not treated (removed) in any way currently, what leads to an behaviour I didn't expect.
I'd expect getHost() to return only the IP address, without brackets, as the port is stored seperately and obtainable via getPort().

Consider this example:

$ipv4Port = new \Zend\Uri\Uri('http://192.168.0.1:8080');
$ipv6Port = new \Zend\Uri\Uri('http://[fe80::240:63ff:fede:3c19]:8080');

echo $ipv4Port->getHost(); // -> 192.168.0.1 - expected
echo $ipv6Port->getHost(); // -> [fe80::240:63ff:fede:3c19] - unexpected

Is this intended behaviour, though, or just not yet adjusted to IPv6?


Originally posted by @kronthto at zendframework/zend-uri#12

@weierophinney
Copy link
Member Author

Even further, if you have an "Non-Domain-Name IPv6 Host URI with Port" thats last segment is fully numeric it gets mistakenly interpreted its last segment as port.
Example:

var_dump(new \Zend\Uri\Uri('http://2001:0db8:0000:85a3:0000:0000:ac1f:8001/foo'));
/*
object(Zend\Uri\Uri)#3 (8) {
  ["scheme":protected]=>
  string(4) "http"
  ["host":protected]=>
  --> string(34) "2001:0db8:0000:85a3:0000:0000:ac1f"// missing :8001
  ["port":protected]=>
  --> int(8001) // no port given
  ["path":protected]=>
  string(4) "/foo"
  ["validHostTypes":protected]=>
  int(31)
  (...)
}
*/

This - I would call it bug - also happens using the stdlib function parse_url though:

var_dump(parse_url('http://2001:0db8:0000:85a3:0000:0000:ac1f:8001/foo'));
/*
array(4) {
  ["scheme"]=>
  string(4) "http"
  ["host"]=>
  --> string(34) "2001:0db8:0000:85a3:0000:0000:ac1f" // missing :8001
  ["port"]=>
  --> int(8001) // no port given
  ["path"]=>
  string(4) "/foo"
}
*/

Originally posted by @kronthto at zendframework/zend-uri#12 (comment)

@weierophinney
Copy link
Member Author

This package is considered feature-complete, and is now in security-only maintenance mode, following a decision by the Technical Steering Committee.
If you have a security issue, please follow our security reporting guidelines.
If you wish to take on the role of maintainer, please nominate yourself

If you are looking for an actively maintained package alternative, we recommend:

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