File tree Expand file tree Collapse file tree 3 files changed +22
-0
lines changed
Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,11 @@ impl FileSystem {
122122 status: actix_web:: http:: StatusCode :: FORBIDDEN ,
123123 } ) ;
124124 }
125+ if c. to_str ( ) . map_or ( false , |s| s. starts_with ( '.' ) ) {
126+ anyhow:: bail!( ErrorWithStatus {
127+ status: actix_web:: http:: StatusCode :: FORBIDDEN ,
128+ } ) ;
129+ }
125130 } else {
126131 anyhow:: bail!(
127132 "Unsupported path: {path:?}. Path component '{component:?}' is not allowed."
Original file line number Diff line number Diff line change 1+ select ' text' as component, ' This is a hidden file that should not be accessible' as contents;
Original file line number Diff line number Diff line change @@ -880,6 +880,22 @@ async fn test_request_body_base64() -> actix_web::Result<()> {
880880 Ok ( ( ) )
881881}
882882
883+ #[ actix_web:: test]
884+ async fn test_hidden_files ( ) {
885+ let resp_result = req_path ( "/tests/.hidden.sql" ) . await ;
886+ assert ! (
887+ resp_result. is_err( ) ,
888+ "Accessing a hidden file should be forbidden, but received success: {resp_result:?}"
889+ ) ;
890+ let resp = resp_result. unwrap_err ( ) . error_response ( ) ;
891+ assert_eq ! ( resp. status( ) , http:: StatusCode :: FORBIDDEN ) ;
892+ assert ! (
893+ String :: from_utf8_lossy( & resp. into_body( ) . try_into_bytes( ) . unwrap( ) )
894+ . to_lowercase( )
895+ . contains( "forbidden" ) ,
896+ ) ;
897+ }
898+
883899async fn get_request_to_with_data (
884900 path : & str ,
885901 data : actix_web:: web:: Data < AppState > ,
You can’t perform that action at this time.
0 commit comments