New: Prevent Remote Path Mapping local folder being set to System folder or '/'

(cherry picked from commit 0f904e091702a2ac53771ee3aeb5aafe62688035)
This commit is contained in:
Mark McDowall
2025-03-24 20:14:55 -07:00
committed by Bogdan
parent 280cec3d0e
commit 52c5460537

View File

@@ -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<RemotePathMappingResource> CreateMapping(RemotePathMappingResource resource)
[Consumes("application/json")]
public ActionResult<RemotePathMappingResource> CreateMapping([FromBody] RemotePathMappingResource resource)
{
var model = resource.ToModel();
@@ -48,6 +52,7 @@ namespace Readarr.Api.V1.RemotePathMappings
}
[HttpGet]
[Produces("application/json")]
public List<RemotePathMappingResource> GetMappings()
{
return _remotePathMappingService.All().ToResource();
@@ -60,7 +65,7 @@ namespace Readarr.Api.V1.RemotePathMappings
}
[RestPutById]
public ActionResult<RemotePathMappingResource> UpdateMapping(RemotePathMappingResource resource)
public ActionResult<RemotePathMappingResource> UpdateMapping([FromBody] RemotePathMappingResource resource)
{
var mapping = resource.ToModel();