From d37343bb7dcaa72976ab2d2804ffe8b1c82b906a Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Fri, 25 Mar 2016 19:03:28 -0700 Subject: [PATCH] Fixed: Prevent root folders from being added under the startup folder --- .../RootFolders/RootFolderModule.cs | 4 ++- src/NzbDrone.Core/NzbDrone.Core.csproj | 1 + .../Paths/StartupFolderValidator.cs | 25 +++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/NzbDrone.Core/Validation/Paths/StartupFolderValidator.cs diff --git a/src/NzbDrone.Api/RootFolders/RootFolderModule.cs b/src/NzbDrone.Api/RootFolders/RootFolderModule.cs index 9c9fed0d4..a4c0f892b 100644 --- a/src/NzbDrone.Api/RootFolders/RootFolderModule.cs +++ b/src/NzbDrone.Api/RootFolders/RootFolderModule.cs @@ -16,7 +16,8 @@ public RootFolderModule(IRootFolderService rootFolderService, RootFolderValidator rootFolderValidator, PathExistsValidator pathExistsValidator, DroneFactoryValidator droneFactoryValidator, - MappedNetworkDriveValidator mappedNetworkDriveValidator) + MappedNetworkDriveValidator mappedNetworkDriveValidator, + StartupFolderValidator startupFolderValidator) : base(signalRBroadcaster) { _rootFolderService = rootFolderService; @@ -32,6 +33,7 @@ public RootFolderModule(IRootFolderService rootFolderService, .SetValidator(rootFolderValidator) .SetValidator(droneFactoryValidator) .SetValidator(mappedNetworkDriveValidator) + .SetValidator(startupFolderValidator) .SetValidator(pathExistsValidator); } diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index ae947c2f4..7369f3002 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -1032,6 +1032,7 @@ + diff --git a/src/NzbDrone.Core/Validation/Paths/StartupFolderValidator.cs b/src/NzbDrone.Core/Validation/Paths/StartupFolderValidator.cs new file mode 100644 index 000000000..89fd0893e --- /dev/null +++ b/src/NzbDrone.Core/Validation/Paths/StartupFolderValidator.cs @@ -0,0 +1,25 @@ +using FluentValidation.Validators; +using NzbDrone.Common.EnvironmentInfo; +using NzbDrone.Common.Extensions; + +namespace NzbDrone.Core.Validation.Paths +{ + public class StartupFolderValidator : PropertyValidator + { + private readonly IAppFolderInfo _appFolderInfo; + + + public StartupFolderValidator(IAppFolderInfo appFolderInfo) + : base("Path cannot be an ancestor of the start up folder") + { + _appFolderInfo = appFolderInfo; + } + + protected override bool IsValid(PropertyValidatorContext context) + { + if (context.PropertyValue == null) return true; + + return !_appFolderInfo.StartUpFolder.IsParentPath(context.PropertyValue.ToString()); + } + } +} \ No newline at end of file