Skip to content

ForwardedParser calculates invalid absolute URI when request target is already absolute #2830

@tmonney

Description

@tmonney

Version

4.5.22, but the code is the same in the main branch

Context

Absolute request URIs are not computed correctly by HttpServerRequestWrapper class when the target is
absolute. For example, with this request:

GET http://localhost:8080/hello HTTP/1.1
Host: some.random.host.com:9876

The io.vertx.ext.web.impl.HttpServerRequestWrapper#absoluteURI() method returns http://some.random.host.com:9876http://localhost:8080/hello, which is obviously wrong.

I would expect the result to be one of

  • http://localhost:8080/hello
  • http://some.random.host.com:9876/hello

The problem seems to be caused by [ForwardedParser#calculate()](https://github.com/vert-x3/vertx-web/blob/master/vertx-web/src/main/java/io/vertx/ext/web/impl/ForwardedParser.java#L136):

if (host != null) {
  this.authority = HostAndPort.create(host, port);
  host = host + (port >= 0 ? ":" + port : "");
  absoluteURI = scheme + "://" + host + delegate.uri();
}

Here delegate.uri() is already absolute, and is just appended as-is.

Steps to reproduce

Clone the reproducer and run mvn:test. The tests should pass, they are actually "verifying" the current faulty behavior.

Do you have a reproducer?

https://github.com/tmonney/vertx-web-absolute-uri

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions