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

Empty Host header not supported anymore #4879

Closed
cescoffier opened this issue Oct 2, 2023 · 5 comments
Closed

Empty Host header not supported anymore #4879

cescoffier opened this issue Oct 2, 2023 · 5 comments
Assignees
Labels
Milestone

Comments

@cescoffier
Copy link
Contributor

Describe the bug

Empty host header not supported anymore

curl -iv -H "User-Agent:" -H "Accept:" -H "Host:" http://localhost:8080/foo

Fails with 500 and an NullPointerException in log.

@vietj
Copy link
Member

vietj commented Oct 5, 2023

FTR: correct curl line is curl -iv -H "User-Agent;" -H "Accept;" -H "Host;" http://localhost:8080/foo

@vietj
Copy link
Member

vietj commented Oct 5, 2023

I tried with latest Vert.x 4.4 branch and 4.x branch with an hello-world HTTP server and it does not happen, can you provide more details ? like the exception or maybe I am missing vertx-web handlers that create this NPE (although this is reported on vertx-core)

@cescoffier
Copy link
Contributor Author

So, it seems to be in Vert.x Web.

The NPE is in HostAndPortImpl:

  public HostAndPortImpl(String host, int port) {
    if (host == null) {
      throw new NullPointerException(); // Thrown...
    }
    this.host = host;
    this.port = port;
  }

that line got called from the ForardedPArser of Vert.x Web ( authority = HostAndPort.create(host, port); line 137 )

@cescoffier
Copy link
Contributor Author

cescoffier commented Oct 5, 2023

@vietj

Here is the all in one reproducer:

///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS io.vertx:vertx-web:4.4.5

import io.vertx.core.Vertx;
import io.vertx.ext.web.Router;
import static java.lang.System.*;

public class VertxHostNpe {

    public static void main(String... args) throws Exception {
    
            Vertx vertx = Vertx.vertx();
            Router router = Router.router(vertx);
            router.get("/").handler(ctx -> {
                ctx.response().end("Hello World! " + ctx.request().host());
            });


            vertx.createHttpServer()
                .requestHandler(router)
                .listen(8080);

            Thread.sleep(100000);    

    }
}

Run it with:

jbang "/Users/clement/Downloads/VertxHostNpe.java"

and in another terminal: curl -iv -H "User-Agent:" -H "Accept:" -H "Host;" http://localhost:8080

You will get the NPE I mentioned above:

java.lang.NullPointerException
        at io.vertx.core.net.impl.HostAndPortImpl.<init>(HostAndPortImpl.java:144)
        at io.vertx.core.net.HostAndPort.create(HostAndPort.java:20)
        at io.vertx.ext.web.impl.ForwardedParser.calculate(ForwardedParser.java:137)
        at io.vertx.ext.web.impl.ForwardedParser.host(ForwardedParser.java:76)
        at io.vertx.ext.web.impl.HttpServerRequestWrapper.host(HttpServerRequestWrapper.java:183)
        at VertxHostNpe.lambda$main$0(VertxHostNpe.java:15)

@vietj
Copy link
Member

vietj commented Oct 5, 2023

thanks, was missing that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants