@@ -92,13 +92,6 @@ void unlock() {
9292
9393 ReconnectMonLock reconnectMonLock = new ReconnectMonLock ();
9494
95- private static final Set <String > ALLOWED_URL_SCHEMES = Collections .unmodifiableSet (
96- new HashSet <>(Arrays .asList ("http" , "https" , "ftp" , "sftp" )));
97-
98- // SSH username: only alphanumeric, dots, hyphens, underscores, optional trailing $
99- private static final java .util .regex .Pattern SSH_USERNAME_PATTERN =
100- java .util .regex .Pattern .compile ("^[a-zA-Z0-9._-]+\\ $?$" );
101-
10295 @ Autowired
10396 protected RESTFacade restf ;
10497 @ Autowired
@@ -753,6 +746,7 @@ public static class SoftwareUpgradePackageCmd extends AgentCommand implements Ha
753746 public String upgradePackagePath ;
754747 public String upgradePackageTargetPath ;
755748 public String upgradeScriptPath ;
749+ public String softwareType ;
756750 public int targetHostSshPort ;
757751 public String targetHostSshUsername ;
758752 @ NoLogging
@@ -2207,27 +2201,13 @@ public void success(UploadFileResponse rsp) {
22072201 cmd .taskUuid = msg .getTaskUuid ();
22082202 cmd .sendCommandUrl = restf .getSendCommandUrl ();
22092203
2210- String scheme ;
2211- try {
2212- URI uri = new URI (msg .getUrl ());
2213- scheme = uri .getScheme ();
2214- } catch (URISyntaxException e ) {
2215- reply .setError (operr ("failed to parse upload URL [%s]: %s" , msg .getUrl (), e .getMessage ()));
2216- bus .reply (msg , reply );
2217- return ;
2218- }
2219- if (scheme == null || scheme .isEmpty ()) {
2220- reply .setError (operr ("upload URL [%s] is missing a protocol prefix" , msg .getUrl ()));
2221- bus .reply (msg , reply );
2222- return ;
2223- }
2224- if (!ALLOWED_URL_SCHEMES .contains (scheme .toLowerCase ())) {
2225- reply .setError (operr ("upload URL [%s] uses unsupported protocol [%s], only %s are allowed" ,
2226- msg .getUrl (), scheme , ALLOWED_URL_SCHEMES ));
2204+ String [] urlResult = RemotePathValidator .validateAndExtractUrlScheme (msg .getUrl ());
2205+ if (urlResult [0 ] != null ) {
2206+ reply .setError (operr (urlResult [0 ]));
22272207 bus .reply (msg , reply );
22282208 return ;
22292209 }
2230- cmd .urlScheme = scheme ;
2210+ cmd .urlScheme = urlResult [ 1 ] ;
22312211
22322212 httpCall (FILE_DOWNLOAD_PATH , cmd , DownloadFileResponse .class , new ReturnValueCompletion <DownloadFileResponse >(msg ) {
22332213 @ Override
@@ -2303,13 +2283,11 @@ protected void handle(final DeleteFilesOnBackupStorageHostMsg msg) {
23032283 }
23042284
23052285 // Validate each file path to prevent path traversal and injection attacks.
2306- for (String filePath : msg .getFilePaths ()) {
2307- String pathErr = RemotePathValidator .validateRemotePath (filePath , "filePath" );
2308- if (pathErr != null ) {
2309- reply .setError (operr (pathErr ));
2310- bus .reply (msg , reply );
2311- return ;
2312- }
2286+ String filePathErr = RemotePathValidator .validateFilePaths (msg .getFilePaths ());
2287+ if (filePathErr != null ) {
2288+ reply .setError (operr (filePathErr ));
2289+ bus .reply (msg , reply );
2290+ return ;
23132291 }
23142292
23152293 CephBackupStorageMonVO mon ;
@@ -2414,9 +2392,9 @@ protected void handle(SoftwareUpgradePackageDeployMsg msg) {
24142392 return ;
24152393 }
24162394
2417- if ( msg . getTargetHostSshUsername () == null || ! SSH_USERNAME_PATTERN . matcher (msg .getTargetHostSshUsername ()). matches ()) {
2418- reply . setError ( operr ( "targetHostSshUsername [%s] is invalid, only alphanumeric characters, dots, hyphens, underscores and trailing dollar sign are allowed" ,
2419- msg . getTargetHostSshUsername () ));
2395+ String usernameErr = RemotePathValidator . validateSshUsername (msg .getTargetHostSshUsername ());
2396+ if ( usernameErr != null ) {
2397+ reply . setError ( operr ( usernameErr ));
24202398 bus .reply (msg , reply );
24212399 return ;
24222400 }
@@ -2457,6 +2435,7 @@ protected void handle(SoftwareUpgradePackageDeployMsg msg) {
24572435 SoftwareUpgradePackageCmd cmd = new SoftwareUpgradePackageCmd ();
24582436 cmd .upgradePackagePath = msg .getUpgradePackagePath ();
24592437 cmd .upgradePackageTargetPath = msg .getUpgradePackageTargetPath ();
2438+ cmd .softwareType = msg .getSoftwareType ();
24602439 cmd .upgradeScriptPath = msg .getUpgradeScriptPath ();
24612440 cmd .targetHostSshPort = msg .getTargetHostSshPort ();
24622441 cmd .targetHostSshUsername = msg .getTargetHostSshUsername ();
0 commit comments