Uploaded image for project: 'Apache Knox'
  1. Apache Knox
  2. KNOX-1185

Routes and rewrite rules cannot distinguish resources from directories

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 0.14.0
    • None
    • Server
    • None

    Description

      There is ambiguity for how URL patterns for resources (i.e. no trailing slash) and directories (i.e. trailing slash) are handled.  The first pattern added to a matcher will always take precedence and the second will be ignored.  For example consider the patterns "/oozie" and "/oozie/".  Both of these patterns will match "/oozie" and "/oozie/" making unique processing for each impossible.  

      Fixing this issue may prove disruptive as a large number of service route and rewrite rules may inadvertently be taking advantage of this ambiguity.

      I have created this test below which can be added to org/apache/knox/gateway/util/urltemplate/MatcherTest.java to illustrate the issue.  Note the commented out assertions annotated with the FIX.

      @Test
      public void testTrailingSlashMatching_Knox1185() throws URISyntaxException {
        Matcher<String> matcher;
        Template template;
      
        matcher = new Matcher<String>();
        matcher.add( Parser.parseTemplate( "/oozie" ), "file" );
        assertValidMatch( matcher, "/oozie", "file" );
        assertValidMatch( matcher, "/oozie/", "file" );
      
        matcher = new Matcher<String>();
        matcher.add( Parser.parseTemplate( "/oozie/" ), "dir" );
        assertValidMatch( matcher, "/oozie", "dir" );
        assertValidMatch( matcher, "/oozie/", "dir" );
      
        matcher = new Matcher<String>();
        matcher.add( Parser.parseTemplate( "/oozie" ), "file" );
        matcher.add( Parser.parseTemplate( "/oozie/" ), "dir" );
        matcher.add( Parser.parseTemplate( "/oozie/**" ), "path" );
        assertValidMatch( matcher, "/oozie", "file" );
        //FIX assertValidMatch( matcher, "/oozie/", "dir" ); // Actual=file
        assertValidMatch( matcher, "/oozie/path", "path" );
      
        // Reverse the put order.
        matcher = new Matcher<String>();
        matcher.add( Parser.parseTemplate( "/oozie/**" ), "path" );
        matcher.add( Parser.parseTemplate( "/oozie/" ), "dir" );
        matcher.add( Parser.parseTemplate( "/oozie" ), "file" );
        //FIX assertValidMatch( matcher, "/oozie", "file" ); // Actual=dir
        assertValidMatch( matcher, "/oozie/", "dir" );
        assertValidMatch( matcher, "/oozie/path", "path" );
      
        matcher = new Matcher<String>();
        matcher.add( Parser.parseTemplate( "/oozie/**" ), "path" );
        matcher.add( Parser.parseTemplate( "/oozie/**/" ), "dir" );
        assertValidMatch( matcher, "/oozie/path", "path" );
        //FIX assertValidMatch( matcher, "/oozie/path/", "dir" ); // Actual=path
      
        matcher = new Matcher<String>();
        matcher.add( Parser.parseTemplate( "/oozie/**/" ), "dir" );
        matcher.add( Parser.parseTemplate( "/oozie/**" ), "path" );
        //FIX assertValidMatch( matcher, "/oozie/path", "path" ); // Actual=dir
        assertValidMatch( matcher, "/oozie/path/", "dir" );
      }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            kminder Kevin Minder
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: