|
| 1 | +From 5eb0363521dbb30e3e47ec8a604f5a5c678bf4fb Mon Sep 17 00:00:00 2001 |
| 2 | +From: Benedikt Labrenz < [email protected]> |
| 3 | +Date: Thu, 22 May 2025 14:47:24 +0200 |
| 4 | +Subject: disable host port validation if list of allowed hosts only contains |
| 5 | + '*' |
| 6 | + |
| 7 | +--- |
| 8 | + .../connector/FrameworkServerConnectorFactory.java | 13 +++++++++++-- |
| 9 | + 1 file changed, 11 insertions(+), 2 deletions(-) |
| 10 | + |
| 11 | +diff --git a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/connector/FrameworkServerConnectorFactory.java b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/connector/FrameworkServerConnectorFactory.java |
| 12 | +index ec1bee66fb..b58c886f4f 100644 |
| 13 | +--- a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/connector/FrameworkServerConnectorFactory.java |
| 14 | ++++ b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/connector/FrameworkServerConnectorFactory.java |
| 15 | +@@ -54,6 +54,8 @@ public class FrameworkServerConnectorFactory extends StandardServerConnectorFact |
| 16 | + |
| 17 | + private final String excludeCipherSuites; |
| 18 | + |
| 19 | ++ private final boolean disableHostPortValidator; |
| 20 | ++ |
| 21 | + private final Set<Integer> validPorts; |
| 22 | + |
| 23 | + private SslContextFactory.Server sslContextFactory; |
| 24 | +@@ -72,6 +74,11 @@ public class FrameworkServerConnectorFactory extends StandardServerConnectorFact |
| 25 | + headerSize = DataUnit.parseDataSize(properties.getWebMaxHeaderSize(), DataUnit.B).intValue(); |
| 26 | + validPorts = getValidPorts(properties); |
| 27 | + |
| 28 | ++ // Check if the property for allowed hosts has only the wildcard entry and |
| 29 | ++ // if so store this in disableHostPortValidator for later use |
| 30 | ++ List<String> configuredHostNames = properties.getAllowedHostsAsList(); |
| 31 | ++ disableHostPortValidator = configuredHostNames.size() == 1 && configuredHostNames.contains("*"); |
| 32 | ++ |
| 33 | + if (properties.isHTTPSConfigured()) { |
| 34 | + if (properties.isClientAuthRequiredForRestApi()) { |
| 35 | + setNeedClientAuth(true); |
| 36 | +@@ -102,8 +109,10 @@ public class FrameworkServerConnectorFactory extends StandardServerConnectorFact |
| 37 | + // Add HostHeaderCustomizer to set Host Header for HTTP/2 and HostHeaderHandler |
| 38 | + httpConfiguration.addCustomizer(new HostHeaderCustomizer()); |
| 39 | + |
| 40 | +- final HostPortValidatorCustomizer hostPortValidatorCustomizer = new HostPortValidatorCustomizer(validPorts); |
| 41 | +- httpConfiguration.addCustomizer(hostPortValidatorCustomizer); |
| 42 | ++ if (!disableHostPortValidator) { |
| 43 | ++ final HostPortValidatorCustomizer hostPortValidatorCustomizer = new HostPortValidatorCustomizer(validPorts); |
| 44 | ++ httpConfiguration.addCustomizer(hostPortValidatorCustomizer); |
| 45 | ++ } |
| 46 | + |
| 47 | + return httpConfiguration; |
| 48 | + } |
0 commit comments