From ac2d92007e1654d82cd576296406981f331e0066 Mon Sep 17 00:00:00 2001 From: Stevie Robinson Date: Thu, 22 May 2025 02:56:15 +0200 Subject: [PATCH] New: Don't allow remote path to start with space (cherry picked from commit 5ba3ff598770fdf9e5a53d490c8bcbdd6a59c4cc) --- .../RemotePathMappingService.cs | 5 +++++ .../RemotePathMappingController.cs | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/NzbDrone.Core/RemotePathMappings/RemotePathMappingService.cs b/src/NzbDrone.Core/RemotePathMappings/RemotePathMappingService.cs index b706b724a0..188db31903 100644 --- a/src/NzbDrone.Core/RemotePathMappings/RemotePathMappingService.cs +++ b/src/NzbDrone.Core/RemotePathMappings/RemotePathMappingService.cs @@ -96,6 +96,11 @@ private void ValidateMapping(List existing, RemotePathMapping throw new ArgumentException("Invalid Host"); } + if (mapping.RemotePath.StartsWith(" ")) + { + throw new ArgumentException("Remote Path must not start with a space"); + } + var remotePath = new OsPath(mapping.RemotePath); var localPath = new OsPath(mapping.LocalPath); diff --git a/src/Radarr.Api.V3/RemotePathMappings/RemotePathMappingController.cs b/src/Radarr.Api.V3/RemotePathMappings/RemotePathMappingController.cs index b2a159d3e7..2e227fcfe9 100644 --- a/src/Radarr.Api.V3/RemotePathMappings/RemotePathMappingController.cs +++ b/src/Radarr.Api.V3/RemotePathMappings/RemotePathMappingController.cs @@ -1,7 +1,9 @@ using System.Collections.Generic; using FluentValidation; using Microsoft.AspNetCore.Mvc; +using NzbDrone.Common.Extensions; using NzbDrone.Core.RemotePathMappings; +using NzbDrone.Core.Validation; using NzbDrone.Core.Validation.Paths; using Radarr.Http; using Radarr.Http.REST; @@ -21,11 +23,20 @@ public RemotePathMappingController(IRemotePathMappingService remotePathMappingSe _remotePathMappingService = remotePathMappingService; SharedValidator.RuleFor(c => c.Host) - .NotEmpty(); + .NotEmpty(); // We cannot use IsValidPath here, because it's a remote path, possibly other OS. SharedValidator.RuleFor(c => c.RemotePath) - .NotEmpty(); + .NotEmpty(); + + SharedValidator.RuleFor(c => c.RemotePath) + .Must(remotePath => !remotePath.IsNotNullOrWhiteSpace() && !remotePath.StartsWith(" ")) + .WithMessage("Remote Path must not start with a space"); + + SharedValidator.RuleFor(c => c.RemotePath) + .Must(remotePath => !remotePath.IsNotNullOrWhiteSpace() && !remotePath.EndsWith(" ")) + .WithMessage("Remote Path probably should not end with a space") + .AsWarning(); SharedValidator.RuleFor(c => c.LocalPath) .Cascade(CascadeMode.Stop)