From 52c5460537493e67c402689aa3f1f18fc63001c3 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 24 Mar 2025 20:14:55 -0700 Subject: [PATCH] New: Prevent Remote Path Mapping local folder being set to System folder or '/' (cherry picked from commit 0f904e091702a2ac53771ee3aeb5aafe62688035) --- .../RemotePathMappingController.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Readarr.Api.V1/RemotePathMappings/RemotePathMappingController.cs b/src/Readarr.Api.V1/RemotePathMappings/RemotePathMappingController.cs index 20bd2079c..782fee72b 100644 --- a/src/Readarr.Api.V1/RemotePathMappings/RemotePathMappingController.cs +++ b/src/Readarr.Api.V1/RemotePathMappings/RemotePathMappingController.cs @@ -30,8 +30,11 @@ namespace Readarr.Api.V1.RemotePathMappings SharedValidator.RuleFor(c => c.LocalPath) .Cascade(CascadeMode.Stop) .IsValidPath() - .SetValidator(mappedNetworkDriveValidator) - .SetValidator(pathExistsValidator); + .SetValidator(mappedNetworkDriveValidator) + .SetValidator(pathExistsValidator) + .SetValidator(new SystemFolderValidator()) + .NotEqual("/") + .WithMessage("Cannot be set to '/'"); } protected override RemotePathMappingResource GetResourceById(int id) @@ -40,7 +43,8 @@ namespace Readarr.Api.V1.RemotePathMappings } [RestPostById] - public ActionResult CreateMapping(RemotePathMappingResource resource) + [Consumes("application/json")] + public ActionResult CreateMapping([FromBody] RemotePathMappingResource resource) { var model = resource.ToModel(); @@ -48,6 +52,7 @@ namespace Readarr.Api.V1.RemotePathMappings } [HttpGet] + [Produces("application/json")] public List GetMappings() { return _remotePathMappingService.All().ToResource(); @@ -60,7 +65,7 @@ namespace Readarr.Api.V1.RemotePathMappings } [RestPutById] - public ActionResult UpdateMapping(RemotePathMappingResource resource) + public ActionResult UpdateMapping([FromBody] RemotePathMappingResource resource) { var mapping = resource.ToModel();