NIFI-4632: Add the local hostname to the list of validated host headers

This closes #2288.

Signed-off-by: Andy LoPresto <alopresto.apache@gmail.com>
This commit is contained in:
Mark Payne 2017-11-22 09:56:09 -05:00 committed by Andy LoPresto
parent 6169061456
commit cec2764140
No known key found for this signature in database
GPG Key ID: 6EC293152D90B61D
2 changed files with 14 additions and 0 deletions

View File

@ -18,6 +18,7 @@ package org.apache.nifi.web.server;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@ -60,6 +61,12 @@ public class HostHeaderHandler extends ScopedHandler {
validHosts.add("localhost:" + serverPort);
// Different from customizer -- empty is ok here
validHosts.add("");
try {
validHosts.add(InetAddress.getLocalHost().getHostName());
validHosts.add(InetAddress.getLocalHost().getHostName() + ":" + serverPort);
} catch (final Exception e) {
logger.warn("Failed to determine local hostname.", e);
}
logger.info("Created " + this.toString());
}

View File

@ -16,6 +16,7 @@
*/
package org.apache.nifi.web.server;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@ -53,6 +54,12 @@ public class HostHeaderSanitizationCustomizer implements HttpConfiguration.Custo
// Sometimes the hostname is left empty but the port is always populated
validHosts.add("localhost");
validHosts.add("localhost:" + serverPort);
try {
validHosts.add(InetAddress.getLocalHost().getHostName());
validHosts.add(InetAddress.getLocalHost().getHostName() + ":" + serverPort);
} catch (final Exception e) {
logger.warn("Failed to determine local hostname.", e);
}
logger.info("Created " + this.toString());
}