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

HttpUrl host decode IPv6 address issue #4451

Closed
Yphyllis opened this issue Dec 18, 2018 · 5 comments
Closed

HttpUrl host decode IPv6 address issue #4451

Yphyllis opened this issue Dec 18, 2018 · 5 comments
Labels
bug Bug in existing code
Milestone

Comments

@Yphyllis
Copy link

@test
public void test() {

    String host_ipv4 = "192.168.1.254";
    String host_ipv6 = "::ffff:c0a8:1fe";

    HttpUrl.Builder builder = new HttpUrl.Builder();
    builder.scheme("http");
    builder.host(host_ipv6);

    System.out.println(builder.build().toString());
}

java.lang.AssertionError: Invalid IPv6 address: '::ffff:c0a8:1fe'

at okhttp3.internal.Util.canonicalizeHost(Util.java:408)
at okhttp3.HttpUrl$Builder.canonicalizeHost(HttpUrl.java:1592)
at okhttp3.HttpUrl$Builder.host(HttpUrl.java:1026)
at us.nonda.zus.TimestampTest.test(TimestampTest.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)

The network is right , I can request with IPv4 , but cant with IPv6, please tell me how?

@swankjesse
Copy link
Collaborator

Ugh, OkHttp shouldn't fail like this. It should detect IPv4 mapped addresses and respond accordingly.

https://en.m.wikipedia.org/wiki/IPv6#IPv4-mapped_IPv6_addresses

@Yphyllis
Copy link
Author

yeah, as you say, "::ffff:c0a8:1fe" is a IPv4-mapped IPv6 addresses
but I'm confused, is OkHttp couldn't request with IPv4-mapped IPv6 addresses ?
or I was in a incorrect way?

I also tried "::ffff:192.0.2.128"、"::192.0.2.128"、"0000:0000:0000:0000:0000:FFFF:C0A8:01FE"
they all throwed java.lang.AssertionError: Invalid IPv6 address

very thanks for you replay.

@swankjesse
Copy link
Collaborator

Because it's an IPv4 address OkHttp will only use IPv4 to connect to this host.

@Yphyllis
Copy link
Author

oh, thanks very much

@swankjesse swankjesse added the bug Bug in existing code label Dec 28, 2018
@swankjesse swankjesse added this to the 3.13 milestone Dec 28, 2018
@swankjesse
Copy link
Collaborator

Still worth investigation: do we throw an error we shouldn't when attempting to decode something that looks like an IPv6 address?

swankjesse pushed a commit that referenced this issue Dec 30, 2018
I was worried we weren't handling this case correctly. Fortunately we are.

Closes: #4451
swankjesse pushed a commit that referenced this issue Dec 30, 2018
I was worried we weren't handling this case correctly. Fortunately we are.

Closes: #4451
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug in existing code
Projects
None yet
Development

No branches or pull requests

2 participants