File tree 3 files changed +22
-0
lines changed
3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,11 @@ impl FileSystem {
122
122
status: actix_web:: http:: StatusCode :: FORBIDDEN ,
123
123
} ) ;
124
124
}
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
+ }
125
130
} else {
126
131
anyhow:: bail!(
127
132
"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<()> {
880
880
Ok ( ( ) )
881
881
}
882
882
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
+
883
899
async fn get_request_to_with_data (
884
900
path : & str ,
885
901
data : actix_web:: web:: Data < AppState > ,
You can’t perform that action at this time.
0 commit comments