@@ -776,18 +776,6 @@ pub fn static_asset_handler(req: &mut Request) -> IronResult<Response> {
776776 let filename = req. url . path ( ) [ 2 ..] . join ( "/" ) ;
777777 let storage_path = format ! ( "{}{}" , RUSTDOC_STATIC_STORAGE_PREFIX , filename) ;
778778
779- // Prevent accessing static files outside the root. This could happen if the path
780- // contains `/` or `..`. The check doesn't outright prevent those strings to be present
781- // to allow accessing files in subdirectories.
782- let canonical_path =
783- std:: fs:: canonicalize ( & storage_path) . map_err ( |_| Nope :: ResourceNotFound ) ?;
784- let canonical_root =
785- std:: fs:: canonicalize ( & storage_path) . map_err ( |_| Nope :: ResourceNotFound ) ?;
786-
787- if !canonical_path. starts_with ( canonical_root) {
788- return Err ( Nope :: ResourceNotFound . into ( ) ) ;
789- }
790-
791779 match File :: from_path ( storage, & storage_path, config) {
792780 Ok ( file) => Ok ( file. serve ( ) ) ,
793781 Err ( err) if err. downcast_ref :: < PathNotFoundError > ( ) . is_some ( ) => {
@@ -833,29 +821,6 @@ impl Handler for LegacySharedResourceHandler {
833821 }
834822}
835823
836- /// Serves shared web resources used by rustdoc-generated documentation.
837- ///
838- /// Rustdoc has certain JS, CSS, font and image files that are required for all
839- /// documentation it generates, and these don't change often. We make one copy
840- /// of these per rustdoc release and serve them from a common location.
841- ///
842- /// This handler considers the whole path, and looks for a file at that path in
843- /// the Storage.
844- pub struct SharedResourceHandler ;
845-
846- impl Handler for SharedResourceHandler {
847- fn handle ( & self , req : & mut Request ) -> IronResult < Response > {
848- let storage = extension ! ( req, Storage ) ;
849- let config = extension ! ( req, Config ) ;
850-
851- let storage_path = format ! ( "/{}" , req. url. path( ) . join( "/" ) ) ;
852- match File :: from_path ( storage, & storage_path, config) {
853- Ok ( file) => Ok ( file. serve ( ) ) ,
854- Err ( _) => Err ( Nope :: ResourceNotFound . into ( ) ) ,
855- }
856- }
857- }
858-
859824#[ cfg( test) ]
860825mod test {
861826 use crate :: { test:: * , web:: cache:: CachePolicy , Config } ;
0 commit comments