From c6dbf0ef8e305b9941d109ad80fef421d96b98c7 Mon Sep 17 00:00:00 2001 From: sgibb Date: Tue, 12 Mar 2024 02:21:15 -0400 Subject: [PATCH] Check if scheme is localhost and fail Fixes gh-2919 --- .../org/springframework/cloud/gateway/route/Route.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/route/Route.java b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/route/Route.java index 9193e0e3..7cebb1fc 100644 --- a/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/route/Route.java +++ b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/route/Route.java @@ -187,9 +187,11 @@ public class Route implements Ordered { this.uri = uri; String scheme = this.uri.getScheme(); Assert.hasText(scheme, "The parameter [" + this.uri + "] format is incorrect, scheme can not be empty"); - if (!scheme.equalsIgnoreCase("forward")) { - Assert.hasText(this.uri.getHost(), - "The parameter [" + this.uri + "] format is incorrect, host can not be empty"); + if (scheme.equalsIgnoreCase("localhost")) { + // common error + // TODO: find a general way to detect without breaking existing behavior + throw new IllegalArgumentException( + "The parameter [" + this.uri + "] format is incorrect, scheme can not be localhost"); } if (this.uri.getPort() < 0 && scheme.startsWith("http")) { // default known http ports