Skip to content

Commit ca10d3e

Browse files
authored
Patch NiFi to allow disabling the host header check (#694)
* Add patch to bypass NiFi host header check which creates more issues than it solves in a Kubernetes environment. * Change patch to instead of totally disabling the host header check allow disabling it with a config setting. * Renamed patch files. * Remove patchfiles for NiFi 1.21.0 which we do not build from source at the moment. Since 1.21.x will be removed soon, we will probably never build it from source and the presence of patchfiles here would just confuse everybody. Added a README to say why it is not being used but present.
1 parent a79c839 commit ca10d3e

6 files changed

Lines changed: 120 additions & 12 deletions

nifi/stackable/patches/1.21.0/001-NIFI-no-zip-assembly.patch

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This folder is unused, as NiFi version 1.21.0 is not currently being built from source.
2+
3+
We are keeping the folder in place because it would crash the build process if not present
4+
and we ever start looking at building from source.

nifi/stackable/patches/1.23.2/001-NIFI-no-zip-assembly.patch renamed to nifi/stackable/patches/1.23.2/001-NIFI-no-zip-assembly-1.23.2.patch

File renamed without changes.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
Subject: [PATCH] Allow bypassing check for host header.
2+
NiFi has the configuration option 'nifi.web.proxy.host' which controls allowed
3+
values for the host header field in any incoming request for the web ui.
4+
5+
This frequently causes issues when trying to expose the NiFi UI via for example
6+
an ingress, loadbalancer or any similar type of mechanism.
7+
8+
NiFi does not allow to disable this behavior, so at the moment the nifi operator
9+
simply hardcodes all even remotely possible values into this field.
10+
But in order to allow putting for example in ingress in front of NiFi this means
11+
using config overrides to change the value of this option, copy all the values
12+
the operator put in there and add the extra value you need.
13+
14+
This is less than ideal, the proper solution would probably be
15+
https://github.com/stackabletech/nifi-operator/issues/604
16+
17+
But until that is merged this is a simple workaround that allows overriding the list of allowed
18+
hostnames by just setting it to "*" and this will effectively bypass the hostname check entirely if set.
19+
20+
This allows us to keep the default behavior in place for those users where it works and not remove
21+
security features, but also enables users to disable this check if they know what they are doing.
22+
---
23+
Index: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/HostHeaderHandler.java
24+
IDEA additional info:
25+
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
26+
<+>UTF-8
27+
===================================================================
28+
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/HostHeaderHandler.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/HostHeaderHandler.java
29+
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/HostHeaderHandler.java (revision 6ecc398d3f92425447e43242af4992757e25b3c5)
30+
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/HostHeaderHandler.java (date 1716453739677)
31+
@@ -47,6 +47,7 @@
32+
private final String serverName;
33+
private final int serverPort;
34+
private final List<String> validHosts;
35+
+ private boolean allowAllHosts = false;
36+
37+
/**
38+
* Instantiates a handler with a given server name and port 0.
39+
@@ -107,6 +108,10 @@
40+
// The value(s) from nifi.web.proxy.host
41+
hosts.addAll(parseCustomHostnames(niFiProperties));
42+
43+
+ // Check if the setting for allowed hosts has only the wildcard entry and
44+
+ // if so store this in allowAllHost for later use
45+
+ List<String> configuredHostNames = niFiProperties.getAllowedHostsAsList();
46+
+ this.allowAllHosts = configuredHostNames.size() == 1 && configuredHostNames.contains("*");
47+
// empty is ok here
48+
hosts.add("");
49+
50+
@@ -205,7 +210,7 @@
51+
}
52+
53+
boolean hostHeaderIsValid(String hostHeader) {
54+
- return validHosts.contains(hostHeader.toLowerCase().trim());
55+
+ return this.allowAllHosts || validHosts.contains(hostHeader.toLowerCase().trim());
56+
}
57+
58+
@Override

nifi/stackable/patches/1.25.0/001-NIFI-no-zip-assembly.patch renamed to nifi/stackable/patches/1.25.0/001-NIFI-no-zip-assembly-1.25.0.patch

File renamed without changes.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
Subject: [PATCH] Allow bypassing check for host header.
2+
NiFi has the configuration option 'nifi.web.proxy.host' which controls allowed
3+
values for the host header field in any incoming request for the web ui.
4+
5+
This frequently causes issues when trying to expose the NiFi UI via for example
6+
an ingress, loadbalancer or any similar type of mechanism.
7+
8+
NiFi does not allow to disable this behavior, so at the moment the nifi operator
9+
simply hardcodes all even remotely possible values into this field.
10+
But in order to allow putting for example in ingress in front of NiFi this means
11+
using config overrides to change the value of this option, copy all the values
12+
the operator put in there and add the extra value you need.
13+
14+
This is less than ideal, the proper solution would probably be
15+
https://github.com/stackabletech/nifi-operator/issues/604
16+
17+
But until that is merged this is a simple workaround that allows overriding the list of allowed
18+
hostnames by just setting it to "*" and this will effectively bypass the hostname check entirely if set.
19+
20+
This allows us to keep the default behavior in place for those users where it works and not remove
21+
security features, but also enables users to disable this check if they know what they are doing.
22+
---
23+
Index: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/HostHeaderHandler.java
24+
IDEA additional info:
25+
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
26+
<+>UTF-8
27+
===================================================================
28+
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/HostHeaderHandler.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/HostHeaderHandler.java
29+
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/HostHeaderHandler.java (revision 6ecc398d3f92425447e43242af4992757e25b3c5)
30+
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/HostHeaderHandler.java (date 1716453739677)
31+
@@ -47,6 +47,7 @@
32+
private final String serverName;
33+
private final int serverPort;
34+
private final List<String> validHosts;
35+
+ private boolean allowAllHosts = false;
36+
37+
/**
38+
* Instantiates a handler with a given server name and port 0.
39+
@@ -107,6 +108,10 @@
40+
// The value(s) from nifi.web.proxy.host
41+
hosts.addAll(parseCustomHostnames(niFiProperties));
42+
43+
+ // Check if the setting for allowed hosts has only the wildcard entry and
44+
+ // if so store this in allowAllHost for later use
45+
+ List<String> configuredHostNames = niFiProperties.getAllowedHostsAsList();
46+
+ this.allowAllHosts = configuredHostNames.size() == 1 && configuredHostNames.contains("*");
47+
// empty is ok here
48+
hosts.add("");
49+
50+
@@ -205,7 +210,7 @@
51+
}
52+
53+
boolean hostHeaderIsValid(String hostHeader) {
54+
- return validHosts.contains(hostHeader.toLowerCase().trim());
55+
+ return this.allowAllHosts || validHosts.contains(hostHeader.toLowerCase().trim());
56+
}
57+
58+
@Override

0 commit comments

Comments
 (0)