Skip to content

Commit

Permalink
Enabling hostname verification by default
Browse files Browse the repository at this point in the history
Since introduction of the setting 'verifyHost' the hostname
verification was disabled by default for the resteasy-reactive-client,
as the default value for boolean (primitive) is false.

This disabled default makes the reactive client vulnerable to MITM
attacks. In the meantime setting the config explicitly is a workaround
e.g. with 'quarkus.rest-client.verify-host=true'.

This change now adds a proper default both in the configuration and
for the field in the reactive client builder implementation.

Add test case for enabled host verification default

(cherry picked from commit 18f6f4c)
  • Loading branch information
polarctos authored and gsmet committed May 9, 2023
1 parent 0b9437f commit 961f8eb
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ public class RestClientConfig {
public Optional<QueryParamStyle> queryParamStyle;

/**
* Set whether hostname verification is enabled.
* Set whether hostname verification is enabled. Default is enabled.
* This setting should not be disabled in production as it makes the client vulnerable to MITM attacks.
*/
@ConfigItem
public Optional<Boolean> verifyHost;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ public class RestClientsConfig {
public Optional<QueryParamStyle> queryParamStyle;

/**
* Set whether hostname verification is enabled.
* Set whether hostname verification is enabled. Default is enabled.
* This setting should not be disabled in production as it makes the client vulnerable to MITM attacks.
*
* Can be overwritten by client-specific settings.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class ClientBuilderImpl extends ClientBuilder {

private boolean followRedirects;
private boolean trustAll;
private boolean verifyHost;
private boolean verifyHost = true;

private LoggingScope loggingScope;
private Integer loggingBodySize = 100;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.quarkus.it.rest.client.main.MyResponseExceptionMapper.MyException;
import io.quarkus.it.rest.client.main.selfsigned.ExternalSelfSignedClient;
import io.quarkus.it.rest.client.main.wronghost.WrongHostClient;
import io.quarkus.it.rest.client.main.wronghost.WrongHostRejectedClient;
import io.smallrye.mutiny.Uni;
import io.vertx.core.Future;
import io.vertx.core.json.Json;
Expand Down Expand Up @@ -52,6 +53,9 @@ public class ClientCallingResource {
@RestClient
WrongHostClient wrongHostClient;

@RestClient
WrongHostRejectedClient wrongHostRejectedClient;

@Inject
InMemorySpanExporter inMemorySpanExporter;

Expand Down Expand Up @@ -198,6 +202,15 @@ void init(@Observes Router router) {

router.get("/wrong-host").blockingHandler(
rc -> rc.response().setStatusCode(200).end(String.valueOf(wrongHostClient.invoke().getStatus())));

router.get("/wrong-host-rejected").blockingHandler(rc -> {
try {
int result = wrongHostRejectedClient.invoke().getStatus();
rc.response().setStatusCode(200).end(String.valueOf(result));
} catch (Exception e) {
rc.response().setStatusCode(500).end(e.getCause().getClass().getSimpleName());
}
});
}

private Future<Void> success(RoutingContext rc, String body) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.quarkus.it.rest.client.main.wronghost;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;

import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

@RegisterRestClient(baseUri = "https://wrong.host.badssl.com/", configKey = "wrong-host-rejected")
public interface WrongHostRejectedClient {

@GET
@Produces(MediaType.TEXT_PLAIN)
Response invoke();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ io.quarkus.it.rest.client.multipart.MultipartClient/mp-rest/url=${test.url}
# Self-Signed client
quarkus.rest-client.self-signed.trust-store=${self-signed.trust-store}
quarkus.rest-client.self-signed.trust-store-password=${self-signed.trust-store-password}
# Wrong Host client
# Wrong Host client (connection accepted, as host verification is turned off)
quarkus.rest-client.wrong-host.trust-store=${wrong-host.trust-store}
quarkus.rest-client.wrong-host.trust-store-password=${wrong-host.trust-store-password}
quarkus.rest-client.wrong-host.verify-host=false
# Wrong Host client verified (connection rejected, as host verification is turned on by default)
quarkus.rest-client.wrong-host-rejected.trust-store=${wrong-host.trust-store}
quarkus.rest-client.wrong-host-rejected.trust-store-password=${wrong-host.trust-store-password}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.quarkus.it.rest.client.wronghost;

import static io.restassured.RestAssured.when;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;

import org.junit.jupiter.api.Test;
Expand All @@ -17,4 +18,13 @@ public void restClient() {
.statusCode(200)
.body(is("200"));
}

@Test
public void restClientRejected() {
when()
.get("/wrong-host-rejected")
.then()
.statusCode(500)
.body(containsString("SSLHandshakeException"));
}
}

0 comments on commit 961f8eb

Please sign in to comment.