@@ -676,6 +676,45 @@ public void testNonEncodedAsciiCharactersExplicitlyAllowed() throws UnsupportedE
676
676
Assert .assertEquals ("/bår" , result .getRequestURI ()); //not decoded
677
677
}
678
678
679
+ @ Test
680
+ public void testDirectoryTraversal () throws Exception {
681
+ byte [] in = "GET /path/..;/ HTTP/1.1\r \n \r \n " .getBytes ();
682
+ ParseState context = new ParseState (10 );
683
+ HttpServerExchange result = new HttpServerExchange (null );
684
+ HttpRequestParser .instance (OptionMap .EMPTY ).handle (ByteBuffer .wrap (in ), context , result );
685
+ Assert .assertEquals ("/path/..;/" , result .getRequestURI ());
686
+ Assert .assertEquals ("/path/..;/" , result .getRequestPath ());
687
+ Assert .assertEquals ("/path/..;/" , result .getRelativePath ());
688
+ Assert .assertEquals ("" , result .getQueryString ());
689
+
690
+ in = "GET /path/../ HTTP/1.1\r \n \r \n " .getBytes ();
691
+ context = new ParseState (10 );
692
+ result = new HttpServerExchange (null );
693
+ HttpRequestParser .instance (OptionMap .EMPTY ).handle (ByteBuffer .wrap (in ), context , result );
694
+ Assert .assertEquals ("/path/../" , result .getRequestURI ());
695
+ Assert .assertEquals ("/path/../" , result .getRequestPath ());
696
+ Assert .assertEquals ("/path/../" , result .getRelativePath ());
697
+ Assert .assertEquals ("" , result .getQueryString ());
698
+
699
+ in = "GET /path/..?/ HTTP/1.1\r \n \r \n " .getBytes ();
700
+ context = new ParseState (10 );
701
+ result = new HttpServerExchange (null );
702
+ HttpRequestParser .instance (OptionMap .EMPTY ).handle (ByteBuffer .wrap (in ), context , result );
703
+ Assert .assertEquals ("/path/.." , result .getRequestURI ());
704
+ Assert .assertEquals ("/path/.." , result .getRequestPath ());
705
+ Assert .assertEquals ("/path/.." , result .getRelativePath ());
706
+ Assert .assertEquals ("/" , result .getQueryString ());
707
+
708
+ in = "GET /path/..~/ HTTP/1.1\r \n \r \n " .getBytes ();
709
+ context = new ParseState (10 );
710
+ result = new HttpServerExchange (null );
711
+ HttpRequestParser .instance (OptionMap .EMPTY ).handle (ByteBuffer .wrap (in ), context , result );
712
+ Assert .assertEquals ("/path/..~/" , result .getRequestURI ());
713
+ Assert .assertEquals ("/path/..~/" , result .getRequestPath ());
714
+ Assert .assertEquals ("/path/..~/" , result .getRelativePath ());
715
+ Assert .assertEquals ("" , result .getQueryString ());
716
+ }
717
+
679
718
680
719
private void runTest (final byte [] in ) throws BadRequestException {
681
720
runTest (in , "some value" );
0 commit comments