@@ -2916,6 +2916,56 @@ INSTANTIATE_TEST_SUITE_P(SftpServer,
29162916 MessageAndReply{SFTP_EXTENDED, SSH_FX_FAILURE}),
29172917 string_for_param);
29182918
2919+ TEST_F (SftpServer, BlocksSiblingDirectoryBypass)
2920+ {
2921+ mpt::TempDir temp_dir; // e.g., creates /tmp/multipass_test_XYZ
2922+
2923+ std::string sibling_path = temp_dir.path ().toStdString () + " _malicious" ;
2924+ auto file_name = name_as_char_array (sibling_path);
2925+
2926+ auto init_msg = make_msg (SSH_FXP_INIT);
2927+ auto msg = make_msg (SSH_FXP_OPENDIR);
2928+ msg->filename = file_name.data ();
2929+
2930+ auto data = name_as_char_array (" " );
2931+ REPLACE (sftp_client_message_get_data, [&data](auto ...) { return data.data (); });
2932+ REPLACE (sftp_get_client_message, make_msg_handler ());
2933+
2934+ int num_calls{0 };
2935+ auto reply_status = make_reply_status (msg.get (), SSH_FX_PERMISSION_DENIED, num_calls);
2936+ REPLACE (sftp_reply_status, reply_status);
2937+
2938+ auto sftp = make_sftpserver (temp_dir.path ().toStdString ());
2939+ sftp.run ();
2940+
2941+ EXPECT_THAT (num_calls, Eq (1 ));
2942+ }
2943+
2944+ TEST_F (SftpServer, BlocksDirectoryTraversalEscape)
2945+ {
2946+ mpt::TempDir temp_dir;
2947+
2948+ std::string traversal_path = temp_dir.path ().toStdString () + " /../../../../etc/passwd" ;
2949+ auto file_name = name_as_char_array (traversal_path);
2950+
2951+ auto init_msg = make_msg (SSH_FXP_INIT);
2952+ auto msg = make_msg (SSH_FXP_OPENDIR);
2953+ msg->filename = file_name.data ();
2954+
2955+ auto data = name_as_char_array (" " );
2956+ REPLACE (sftp_client_message_get_data, [&data](auto ...) { return data.data (); });
2957+ REPLACE (sftp_get_client_message, make_msg_handler ());
2958+
2959+ int num_calls{0 };
2960+ auto reply_status = make_reply_status (msg.get (), SSH_FX_PERMISSION_DENIED, num_calls);
2961+ REPLACE (sftp_reply_status, reply_status);
2962+
2963+ auto sftp = make_sftpserver (temp_dir.path ().toStdString ());
2964+ sftp.run ();
2965+
2966+ EXPECT_THAT (num_calls, Eq (1 ));
2967+ }
2968+
29192969TEST_F (SftpServer, DISABLE_ON_WINDOWS(mkdirChownHonorsMapsInTheHost))
29202970{
29212971 mpt::TempDir temp_dir;
0 commit comments