@@ -776,18 +776,6 @@ pub fn static_asset_handler(req: &mut Request) -> IronResult<Response> {
776
776
let filename = req. url . path ( ) [ 2 ..] . join ( "/" ) ;
777
777
let storage_path = format ! ( "{}{}" , RUSTDOC_STATIC_STORAGE_PREFIX , filename) ;
778
778
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
-
791
779
match File :: from_path ( storage, & storage_path, config) {
792
780
Ok ( file) => Ok ( file. serve ( ) ) ,
793
781
Err ( err) if err. downcast_ref :: < PathNotFoundError > ( ) . is_some ( ) => {
@@ -833,29 +821,6 @@ impl Handler for LegacySharedResourceHandler {
833
821
}
834
822
}
835
823
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
-
859
824
#[ cfg( test) ]
860
825
mod test {
861
826
use crate :: { test:: * , web:: cache:: CachePolicy , Config } ;
0 commit comments