diff --git a/src/Tgstation.Server.Host/Controllers/InstanceController.cs b/src/Tgstation.Server.Host/Controllers/InstanceController.cs index 5db9cd5897..e220a74e39 100644 --- a/src/Tgstation.Server.Host/Controllers/InstanceController.cs +++ b/src/Tgstation.Server.Host/Controllers/InstanceController.cs @@ -9,7 +9,6 @@ using System.Linq; using System.Linq.Expressions; using System.Net; using System.Reflection; -using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using Tgstation.Server.Api; @@ -121,6 +120,17 @@ namespace Tgstation.Server.Host.Controllers return BadRequest(new ErrorMessage { Message = "path must not be empty!" }); NormalizeModelPath(model, out var rawPath); + + var localPath = ioManager.ResolvePath("."); + NormalizeModelPath(new Api.Models.Instance + { + Path = localPath + }, out var normalizedLocalPath); + + if (rawPath.StartsWith(normalizedLocalPath, StringComparison.Ordinal)) + return Conflict("Instances cannot be created in the installation directory!"); + + var dirExistsTask = ioManager.DirectoryExists(model.Path, cancellationToken); bool attached = false; if (await ioManager.FileExists(model.Path, cancellationToken).ConfigureAwait(false) || await dirExistsTask.ConfigureAwait(false)) diff --git a/tests/Tgstation.Server.Tests/InstanceManagerTest.cs b/tests/Tgstation.Server.Tests/InstanceManagerTest.cs index 0c9efe68b9..6a09d73d63 100644 --- a/tests/Tgstation.Server.Tests/InstanceManagerTest.cs +++ b/tests/Tgstation.Server.Tests/InstanceManagerTest.cs @@ -51,6 +51,13 @@ namespace Tgstation.Server.Tests }, cancellationToken)).ConfigureAwait(false); await Assert.ThrowsExceptionAsync(() => instanceManagerClient.CreateOrAttach(firstTest, cancellationToken)).ConfigureAwait(false); + //can't create instances in installation directory + await Assert.ThrowsExceptionAsync(() => instanceManagerClient.CreateOrAttach(new Api.Models.Instance + { + Path = "./A/Local/Path", + Name = "NoInstallDirTest" + }, cancellationToken)).ConfigureAwait(false); + //can't move to existent directories await Assert.ThrowsExceptionAsync(() => instanceManagerClient.Update(new Api.Models.Instance {