You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by alopresto <gi...@git.apache.org> on 2018/01/19 03:04:25 UTC

[GitHub] nifi pull request #2415: NIFI-4761 Improve host header handling

GitHub user alopresto opened a pull request:

    https://github.com/apache/nifi/pull/2415

    NIFI-4761 Improve host header handling

    Thank you for submitting a contribution to Apache NiFi.
    
    In order to streamline the review of the contribution we ask you
    to ensure the following steps have been taken:
    
    ### For all changes:
    - [x] Is there a JIRA ticket associated with this PR? Is it referenced 
         in the commit message?
    
    - [x] Does your PR title start with NIFI-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
    
    - [x] Has your PR been rebased against the latest commit within the target branch (typically master)?
    
    - [ ] Is your initial contribution a single, squashed commit?
    
    ### For code changes:
    - [x] Have you ensured that the full suite of tests is executed via mvn -Pcontrib-check clean install at the root nifi folder?
    - [x] Have you written or updated unit tests to verify your changes?
    - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)? 
    - [ ] If applicable, have you updated the LICENSE file, including the main LICENSE file under nifi-assembly?
    - [ ] If applicable, have you updated the NOTICE file, including the main NOTICE file found under nifi-assembly?
    - [ ] If adding new Properties, have you added .displayName in addition to .name (programmatic access) for each of the new properties?
    
    ### For documentation related changes:
    - [ ] Have you ensured that format looks appropriate for the output in which it is rendered?
    
    ### Note:
    Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/alopresto/nifi NIFI-4761

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/nifi/pull/2415.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #2415
    
----
commit 1d8728a0c07fbf975ecd8a13e22863e353229302
Author: Andy LoPresto <al...@...>
Date:   2018-01-17T19:36:00Z

    NIFI-4761 Added HostHeaderHandler regression unit tests before adding new functionality.

commit a69de48f0fb996a246607dfa4de393bd75beb890
Author: Andy LoPresto <al...@...>
Date:   2018-01-18T00:46:29Z

    NIFI-4761 Added logic for parsing nifi.web.proxy.host property.
    Added default property in nifi.properties and pom.xml.
    Added logic for IPv6 and custom default hostnames.
    Improved error messaging.
    Added HostHeaderHandler unit tests.

commit 58c180a2c9d37bc28c1b1225a7d8430e4712bc85
Author: Andy LoPresto <al...@...>
Date:   2018-01-18T01:06:50Z

    NIFI-4761 Disabled HostHeaderSanitizationCustomizer in HTTP mode.

commit 219a11bebe10d8b49a9e87a4d37c15bd1d67dd5a
Author: Andy LoPresto <al...@...>
Date:   2018-01-18T01:17:15Z

    NIFI-4761 Fixed HTML escaping in error message.

commit 06bea9af2a9dba618718cd4eb7221873653dbb47
Author: Andy LoPresto <al...@...>
Date:   2018-01-18T01:18:21Z

    NIFI-4761 Improved error message.

commit 2d603554aa4c5bacf5c3658b7fcf8750497f1a6e
Author: Andy LoPresto <al...@...>
Date:   2018-01-18T17:33:49Z

    NIFI-4761 Added failing unit test for parsing custom hostnames.

commit e35b79fac256d1789fc482066b027552dcccd2c7
Author: Andy LoPresto <al...@...>
Date:   2018-01-18T18:11:11Z

    NIFI-4761 Fixed custom hostname parsing.
    Fixed unit tests.

commit d82a3a3fbdbb5392c60a0315ff6c00cfec642d9f
Author: Andy LoPresto <al...@...>
Date:   2018-01-18T18:51:55Z

    NIFI-4761 Added TODO for IPv6 custom hostname parsing and unit test.

commit ccc397a5b70ca61c7371cca12e8f0171d4ef5c10
Author: Andy LoPresto <al...@...>
Date:   2018-01-18T22:38:38Z

    NIFI-4761 Added IPv6 custom hostname parsing and unit tests.

commit 198e3e9025d3501a96099eb64045c97c4a032a37
Author: Andy LoPresto <al...@...>
Date:   2018-01-18T22:43:13Z

    NIFI-4761 Fixed checkstyle issues.

commit 07b848e18ba451e88c21c24ae3164e9f3d31c26b
Author: Andy LoPresto <al...@...>
Date:   2018-01-19T02:08:51Z

    NIFI-4761 Removed empty element in host list when no value defined.
    Improved error message formatting.
    Added unit tests.

commit 0ea380b3a3477d5614f41b3178ed71c5e980d2cf
Author: Andy LoPresto <al...@...>
Date:   2018-01-19T02:14:39Z

    NIFI-4761 Removed HostHeaderSanitizationCustomizer.

commit 92029b341f8ec4a08a3a4f33a4b8ea04637189be
Author: Andy LoPresto <al...@...>
Date:   2018-01-19T02:16:55Z

    NIFI-4761 Removed InvalidPropertiesFormatException from NiFiProperties.

commit d5d5b7b98d5e24b12c225f8b45a36425fc63d113
Author: Andy LoPresto <al...@...>
Date:   2018-01-19T03:01:46Z

    NIFI-4761 Removed InvalidPropertiesFormatException from HostHeaderHandler.

----


---

[GitHub] nifi pull request #2415: NIFI-4761 Improve host header handling

Posted by alopresto <gi...@git.apache.org>.
Github user alopresto commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/2415#discussion_r162529104
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-properties-loader/src/test/groovy/org/apache/nifi/properties/StandardNiFiPropertiesGroovyTest.groovy ---
    @@ -433,4 +433,134 @@ class StandardNiFiPropertiesGroovyTest extends GroovyTestCase {
             // Assert
             assert normalizedContextPath == empty
         }
    +
    +    @Test
    +    void testShouldNormalizeProxyHostProperty() {
    +        // Arrange
    +        String extraSpaceHostname = "somehost.com  "
    +        Properties rawProps = new Properties(["nifi.web.proxy.host": extraSpaceHostname])
    +        NiFiProperties props = new StandardNiFiProperties(rawProps)
    +        logger.info("Created a NiFiProperties instance with raw proxy host property [${extraSpaceHostname}]")
    +
    +        // Act
    +        String normalizedHostname = props.getWhitelistedHosts()
    +        logger.info("Read from NiFiProperties instance: ${normalizedHostname}")
    +
    +        // Assert
    +        assert extraSpaceHostname.startsWith(normalizedHostname)
    +        assert extraSpaceHostname.length() == normalizedHostname.length() + 2
    +    }
    +
    +    @Test
    +    void testShouldHandleNormalizedProxyHostProperty() {
    +        // Arrange
    +        String hostname = "somehost.com"
    +        Properties rawProps = new Properties(["nifi.web.proxy.host": hostname])
    +        NiFiProperties props = new StandardNiFiProperties(rawProps)
    +        logger.info("Created a NiFiProperties instance with raw proxy host property [${hostname}]")
    +
    +        // Act
    +        String normalizedHostname = props.getWhitelistedHosts()
    +        logger.info("Read from NiFiProperties instance: ${normalizedHostname}")
    +
    +        // Assert
    +        assert hostname == normalizedHostname
    +    }
    +
    +    @Test
    +    void testShouldNormalizeMultipleProxyHostsInProperty() {
    +        // Arrange
    +        String extraSpaceHostname = "somehost.com  "
    +        String normalHostname = "someotherhost.com"
    +        String hostnameWithPort = "otherhost.com:1234"
    +        String extraSpaceHostnameWithPort = "  anotherhost.com:9999"
    +        List<String> hosts = [extraSpaceHostname, normalHostname, hostnameWithPort, extraSpaceHostnameWithPort]
    +        String combinedHosts = hosts.join(",")
    +        Properties rawProps = new Properties(["nifi.web.proxy.host": combinedHosts])
    +        NiFiProperties props = new StandardNiFiProperties(rawProps)
    +        logger.info("Created a NiFiProperties instance with raw proxy host property [${combinedHosts}]")
    +
    +        // Act
    +        String normalizedHostname = props.getWhitelistedHosts()
    +        logger.info("Read from NiFiProperties instance: ${normalizedHostname}")
    +
    +        // Assert
    +        def splitHosts = normalizedHostname.split(",")
    +        def expectedValues = hosts*.trim()
    +        splitHosts.every {
    +            assert it.trim() == it
    +            expectedValues.contains(it)
    --- End diff --
    
    Should be `assert expectedValues.contains(it)`. 


---

[GitHub] nifi pull request #2415: NIFI-4761 Improve host header handling

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/nifi/pull/2415


---

[GitHub] nifi issue #2415: NIFI-4761 Improve host header handling

Posted by mcgilman <gi...@git.apache.org>.
Github user mcgilman commented on the issue:

    https://github.com/apache/nifi/pull/2415
  
    Thanks @alopresto! This has been merged to master. I updated the items you pointed out.


---

[GitHub] nifi issue #2415: NIFI-4761 Improve host header handling

Posted by mcgilman <gi...@git.apache.org>.
Github user mcgilman commented on the issue:

    https://github.com/apache/nifi/pull/2415
  
    Will review...


---

[GitHub] nifi pull request #2415: NIFI-4761 Improve host header handling

Posted by alopresto <gi...@git.apache.org>.
Github user alopresto commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/2415#discussion_r162529074
  
    --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/HostHeaderHandler.java ---
    @@ -71,14 +87,124 @@ public HostHeaderHandler(String serverName, int serverPort) {
             logger.info("Created " + this.toString());
         }
     
    +    /**
    +     * Instantiates a handler which accepts incoming requests with a host header that is empty or contains one of the
    +     * valid hosts. See the Apache NiFi Admin Guide for instructions on how to set valid hostnames and IP addresses.
    +     *
    +     * @param niFiProperties the NiFiProperties
    +     */
    +    public HostHeaderHandler(NiFiProperties niFiProperties) {
    +        this.serverName = Objects.requireNonNull(determineServerHostname(niFiProperties));
    +        this.serverPort = determineServerPort(niFiProperties);
    +
    +        // Default values across generic instances
    +        List<String> hosts = generateDefaultHostnames(niFiProperties);
    +
    +        // The value from nifi.web.http|https.host
    +        hosts.add(serverName.toLowerCase());
    +        hosts.add(serverName.toLowerCase() + ":" + serverPort);
    +
    +        // The value(s) from nifi.web.proxy.host
    +        hosts.addAll(parseCustomHostnames(niFiProperties));
    +
    +        // Different from customizer -- empty is ok here
    +        hosts.add("");
    +
    +        this.validHosts = uniqueList(hosts);
    +        logger.info("Determined {} valid hostnames and IP addresses for incoming headers: {}", new Object[]{validHosts.size(), StringUtils.join(validHosts, ", ")});
    +
    +        logger.debug("Created " + this.toString());
    +    }
    +
    +    /**
    +     * Returns the list of parsed custom hostnames from {@code nifi.web.proxy.host} in {@link NiFiProperties}.
    +     * This list is deduplicated (if a host {@code somehost.com:1234} is provided, it will show twice, as the "portless"
    +     * version {@code somehost.com} is also generated). IPv6 addresses are only modified if they adhere to the strict
    +     * formatting using {@code []} around the address as specified in RFC 5952 Section 6 (i.e.
    +     * {@code [1234.5678.90AB.CDEF.1234.5678.90AB.CDEF]:1234} will insert
    +     * {@code [1234.5678.90AB.CDEF.1234.5678.90AB.CDEF]} as well).
    +     *
    +     * @param niFiProperties the properties object
    +     * @returnj the list of parsed custom hostnames
    --- End diff --
    
    Typo in Javadoc. 


---