File tree Expand file tree Collapse file tree 1 file changed +7
-0
lines changed
crates/bin/docs_rs_web/src/middleware Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,12 @@ pub(crate) async fn security_middleware(
2525 return StatusCode :: NOT_ACCEPTABLE . into_response ( ) ;
2626 }
2727
28+ // `#` is never allowed in any rustdoc URLs, even encoded
29+ if path. contains ( '#' ) {
30+ warn ! ( %uri, "detected `#` in server-side request path" ) ;
31+ return StatusCode :: NOT_ACCEPTABLE . into_response ( ) ;
32+ }
33+
2834 next. run ( req) . await
2935}
3036
@@ -46,6 +52,7 @@ mod tests {
4652 #[ test_case( "/.." ; "relative path" ) ]
4753 #[ test_case( "/asdf/../" ; "relative path 2" ) ]
4854 #[ test_case( "/tiny_http/latest/tiny_http%2f%2e%2e" ; "encoded" ) ]
55+ #[ test_case( "/minidumper/latest/%23%3c%2f%73%63%72%69%70%74%3e%3c%74%65%73%74%65%3e" ; "encoded XSS probe" ) ]
4956 async fn test_invalid_path ( path : & str ) -> Result < ( ) > {
5057 let app = Router :: new ( )
5158 . route ( "/{*inner}" , get ( || async { StatusCode :: OK } ) )
You can’t perform that action at this time.
0 commit comments